forked from mirrors/linux
		
	riscv: bpf: Avoid breaking W^X
We allocate Non-executable pages, then call bpf_jit_binary_lock_ro() to enable executable permission after mapping them read-only. This is to prepare for STRICT_MODULE_RWX in following patch. Signed-off-by: Jisheng Zhang <jszhang@kernel.org> Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
This commit is contained in:
		
							parent
							
								
									1d27d85442
								
							
						
					
					
						commit
						fc8504765e
					
				
					 1 changed files with 2 additions and 1 deletions
				
			
		| 
						 | 
					@ -152,6 +152,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
 | 
				
			||||||
	bpf_flush_icache(jit_data->header, ctx->insns + ctx->ninsns);
 | 
						bpf_flush_icache(jit_data->header, ctx->insns + ctx->ninsns);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!prog->is_func || extra_pass) {
 | 
						if (!prog->is_func || extra_pass) {
 | 
				
			||||||
 | 
							bpf_jit_binary_lock_ro(jit_data->header);
 | 
				
			||||||
out_offset:
 | 
					out_offset:
 | 
				
			||||||
		kfree(ctx->offset);
 | 
							kfree(ctx->offset);
 | 
				
			||||||
		kfree(jit_data);
 | 
							kfree(jit_data);
 | 
				
			||||||
| 
						 | 
					@ -169,7 +170,7 @@ void *bpf_jit_alloc_exec(unsigned long size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
 | 
						return __vmalloc_node_range(size, PAGE_SIZE, BPF_JIT_REGION_START,
 | 
				
			||||||
				    BPF_JIT_REGION_END, GFP_KERNEL,
 | 
									    BPF_JIT_REGION_END, GFP_KERNEL,
 | 
				
			||||||
				    PAGE_KERNEL_EXEC, 0, NUMA_NO_NODE,
 | 
									    PAGE_KERNEL, 0, NUMA_NO_NODE,
 | 
				
			||||||
				    __builtin_return_address(0));
 | 
									    __builtin_return_address(0));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue