diff mbox series

[bpf-next,2/3] net: sysctl: No need to check CAP_SYS_ADMIN for bpf_jit_*

Message ID 1652079475-16684-3-git-send-email-yangtiezhu@loongson.cn (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series Modify some code in sysctl_net_core.c | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on z15 + selftests
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest + selftests
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers warning 7 maintainers not CCed: hmukos@yandex-team.ru edumazet@google.com kafai@fb.com john.fastabend@gmail.com yhs@fb.com kpsingh@kernel.org songliubraving@fb.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 2 this patch: 2
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tiezhu Yang May 9, 2022, 6:57 a.m. UTC
The mode of the following procnames are defined as 0644, 0600, 0600
and 0600 respectively in net_core_table[], normal user can not write
them, so no need to check CAP_SYS_ADMIN in the related proc_handler
function, just remove the checks.

/proc/sys/net/core/bpf_jit_enable
/proc/sys/net/core/bpf_jit_harden
/proc/sys/net/core/bpf_jit_kallsyms
/proc/sys/net/core/bpf_jit_limit

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
 net/core/sysctl_net_core.c | 9 ---------
 1 file changed, 9 deletions(-)

Comments

Daniel Borkmann May 9, 2022, 3:02 p.m. UTC | #1
On 5/9/22 8:57 AM, Tiezhu Yang wrote:
> The mode of the following procnames are defined as 0644, 0600, 0600
> and 0600 respectively in net_core_table[], normal user can not write
> them, so no need to check CAP_SYS_ADMIN in the related proc_handler
> function, just remove the checks.
> 
> /proc/sys/net/core/bpf_jit_enable
> /proc/sys/net/core/bpf_jit_harden
> /proc/sys/net/core/bpf_jit_kallsyms
> /proc/sys/net/core/bpf_jit_limit
> 
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>

I don't think we can make this assumption - there are various other (non-BPF)
sysctl handlers in the tree doing similar check to prevent from userns' based
CAP_SYS_ADMIN.

> ---
>   net/core/sysctl_net_core.c | 9 ---------
>   1 file changed, 9 deletions(-)
> 
> diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
> index cf00dd7..059352b 100644
> --- a/net/core/sysctl_net_core.c
> +++ b/net/core/sysctl_net_core.c
> @@ -268,9 +268,6 @@ static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write,
>   	int ret, jit_enable = *(int *)table->data;
>   	struct ctl_table tmp = *table;
>   
> -	if (write && !capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	tmp.data = &jit_enable;
>   	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
>   	if (write && !ret) {
> @@ -291,9 +288,6 @@ static int
>   proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write,
>   				    void *buffer, size_t *lenp, loff_t *ppos)
>   {
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
>   }
>   # endif /* CONFIG_HAVE_EBPF_JIT */
> @@ -302,9 +296,6 @@ static int
>   proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write,
>   				     void *buffer, size_t *lenp, loff_t *ppos)
>   {
> -	if (!capable(CAP_SYS_ADMIN))
> -		return -EPERM;
> -
>   	return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
>   }
>   #endif
>
Tiezhu Yang May 10, 2022, 2:42 a.m. UTC | #2
On 05/09/2022 11:02 PM, Daniel Borkmann wrote:
> On 5/9/22 8:57 AM, Tiezhu Yang wrote:
>> The mode of the following procnames are defined as 0644, 0600, 0600
>> and 0600 respectively in net_core_table[], normal user can not write
>> them, so no need to check CAP_SYS_ADMIN in the related proc_handler
>> function, just remove the checks.
>>
>> /proc/sys/net/core/bpf_jit_enable
>> /proc/sys/net/core/bpf_jit_harden
>> /proc/sys/net/core/bpf_jit_kallsyms
>> /proc/sys/net/core/bpf_jit_limit
>>
>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>
> I don't think we can make this assumption - there are various other
> (non-BPF)
> sysctl handlers in the tree doing similar check to prevent from userns'
> based
> CAP_SYS_ADMIN.
>

OK, thank you for your reply, let me drop this patch now,
I will send v2 (patch #1 and #3) later.

Thanks,
Tiezhu
diff mbox series

Patch

diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
index cf00dd7..059352b 100644
--- a/net/core/sysctl_net_core.c
+++ b/net/core/sysctl_net_core.c
@@ -268,9 +268,6 @@  static int proc_dointvec_minmax_bpf_enable(struct ctl_table *table, int write,
 	int ret, jit_enable = *(int *)table->data;
 	struct ctl_table tmp = *table;
 
-	if (write && !capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	tmp.data = &jit_enable;
 	ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 	if (write && !ret) {
@@ -291,9 +288,6 @@  static int
 proc_dointvec_minmax_bpf_restricted(struct ctl_table *table, int write,
 				    void *buffer, size_t *lenp, loff_t *ppos)
 {
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
 }
 # endif /* CONFIG_HAVE_EBPF_JIT */
@@ -302,9 +296,6 @@  static int
 proc_dolongvec_minmax_bpf_restricted(struct ctl_table *table, int write,
 				     void *buffer, size_t *lenp, loff_t *ppos)
 {
-	if (!capable(CAP_SYS_ADMIN))
-		return -EPERM;
-
 	return proc_doulongvec_minmax(table, write, buffer, lenp, ppos);
 }
 #endif