bpf: Remove bpf_probe_write_user() warning message
Subsystems (4)
PATCH v2 1/2 bpf: Remove bpf_probe_write_user() warning message
The warning message for bpf_probe_write_user() was introduced in 96ae52279594 ("bpf: Add bpf_probe_write_user BPF helper to be called in tracers"), with the following in the commit message:
Given this feature is meant for experiments, and it has a risk of crashing the system, and running programs, we print a warning on when a proglet that attempts to use this helper is installed, along with the pid and process name.
After 8 years since 96ae52279594, bpf_probe_write_user() has found successful applications beyond experiments [1, 2], with no other good alternatives. Despite its intended purpose for "experiments", that doesn't stop Hyrum's law, and there are likely many more users depending on this helper: "[..] it does not matter what you promise [..] all observable behaviors of your system will be depended on by somebody."
The ominous "helper that may corrupt user memory!" has offered no real benefit, and has been found to lead to confusion where the system administrator is loading programs with valid use cases.
As such, remove the warning message.
---
v2:
* Just delete the message entirely (suggested by Andrii Nakryiko)
--- kernel/trace/bpf_trace.c | 3 --- 1 file changed, 3 deletions(-)
kernel/trace/bpf_trace.c +0 -3
@@ -362,9 +362,6 @@ static const struct bpf_func_proto *bpf_get_probe_write_proto(void)if (!capable (CAP_SYS_ADMIN ))return NULL ; -pr_warn_ratelimited ("%s[%d] is installing a program with bpf_probe_write_user helper that may corrupt user memory!" , - current->comm,task_pid_nr (current)); -return &bpf_probe_write_user_proto; }
Signature · 1 line
2.47.0.338.g60cca15819-goog
PATCH v2 2/2 bpf: Refactor bpf_tracing_func_proto() and remove bpf_get_probe_write_proto()
With bpf_get_probe_write_proto() no longer printing a message, we can avoid it being a special case with its own permission check.
Refactor bpf_tracing_func_proto() similar to bpf_base_func_proto() to have a section conditional on bpf_token_capable(CAP_SYS_ADMIN), where the proto for bpf_probe_write_user() is returned. Finally, remove the unnecessary bpf_get_probe_write_proto().
This simplifies the code, and adding additional CAP_SYS_ADMIN-only helpers in future avoids duplicating the same CAP_SYS_ADMIN check.
---
v2:
* New patch.
--- kernel/trace/bpf_trace.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)
kernel/trace/bpf_trace.c +18 -12
@@ -357,14 +357,6 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = { .arg3_type = ARG_CONST_SIZE, }; -static const struct bpf_func_proto *bpf_get_probe_write_proto (void ) -{ -if (!capable (CAP_SYS_ADMIN )) -return NULL ; - -return &bpf_probe_write_user_proto; -} -#define MAX_TRACE_PRINTK_VARARGS 3#define BPF_TRACE_PRINTK_SIZE 1024
@@ -1417,6 +1409,12 @@ late_initcall(bpf_key_sig_kfuncs_init);static const struct bpf_func_proto *bpf_tracing_func_proto (enum bpf_func_id func_id,const struct bpf_prog *prog) { +const struct bpf_func_proto *func_proto; + + func_proto =bpf_base_func_proto (func_id, prog); +if (func_proto) +return func_proto; +switch (func_id) {case BPF_FUNC_map_lookup_elem:return &bpf_map_lookup_elem_proto;
@@ -1458,9 +1456,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_perf_event_read_proto;case BPF_FUNC_get_prandom_u32:return &bpf_get_prandom_u32_proto; -case BPF_FUNC_probe_write_user: -return security_locked_down (LOCKDOWN_BPF_WRITE_USER ) <0 ? -NULL :bpf_get_probe_write_proto ();case BPF_FUNC_probe_read_user:return &bpf_probe_read_user_proto;case BPF_FUNC_probe_read_kernel:
@@ -1539,7 +1534,18 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)case BPF_FUNC_trace_vprintk:return bpf_get_trace_vprintk_proto ();default : -return bpf_base_func_proto (func_id, prog); +break ; + } + +if (!bpf_token_capable (prog->aux->token,CAP_SYS_ADMIN )) +return NULL ; + +switch (func_id) { +case BPF_FUNC_probe_write_user: +return security_locked_down (LOCKDOWN_BPF_WRITE_USER ) <0 ? +NULL : &bpf_probe_write_user_proto; +default : +return NULL ; } }
Signature · 1 line
2.47.0.338.g60cca15819-goog
Re: [PATCH bpf-next v2 2/2] bpf: Refactor bpf_tracing_func_proto() and remove bpf_get_probe_write_proto()
Quoted 8 lines · Marco Elver
With
bpf_get_probe_write_proto()no longer printing a message, we can avoid it being a special case with its own permission check.Refactor
bpf_tracing_func_proto()similar tobpf_base_func_proto()to have a section conditional onbpf_token_capable(CAP_SYS_ADMIN), where the proto forbpf_probe_write_user()is returned. Finally, remove the unnecessarybpf_get_probe_write_proto().
Quoted 8 lines
This simplifies the code, and adding additional CAP_SYS_ADMIN-only helpers in future avoids duplicating the same
CAP_SYS_ADMINcheck.Suggested-by Andrii Nakryiko <[email protected]>Signed-off-by Marco Elver <[email protected]>---
v2:
* New patch.
jirka
Quoted 69 lines
--- kernel/trace/bpf_trace.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)kernel/trace/bpf_trace.c +18
-12@@ -357,14 +357,6 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = { .arg3_type = ARG_CONST_SIZE, }; -static const struct bpf_func_proto *bpf_get_probe_write_proto (void ) -{ -if (!capable (CAP_SYS_ADMIN )) -return NULL ; - -return &bpf_probe_write_user_proto; -} -#define MAX_TRACE_PRINTK_VARARGS 3#define BPF_TRACE_PRINTK_SIZE 1024@@ -1417,6 +1409,12 @@ late_initcall(bpf_key_sig_kfuncs_init);static const struct bpf_func_proto *bpf_tracing_func_proto (enum bpf_func_id func_id,const struct bpf_prog *prog) { +const struct bpf_func_proto *func_proto; + + func_proto =bpf_base_func_proto (func_id, prog); +if (func_proto) +return func_proto; +switch (func_id) {case BPF_FUNC_map_lookup_elem:return &bpf_map_lookup_elem_proto;@@ -1458,9 +1456,6 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_perf_event_read_proto;case BPF_FUNC_get_prandom_u32:return &bpf_get_prandom_u32_proto; -case BPF_FUNC_probe_write_user: -return security_locked_down (LOCKDOWN_BPF_WRITE_USER ) <0 ? -NULL :bpf_get_probe_write_proto ();case BPF_FUNC_probe_read_user:return &bpf_probe_read_user_proto;case BPF_FUNC_probe_read_kernel:@@ -1539,7 +1534,18 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)case BPF_FUNC_trace_vprintk:return bpf_get_trace_vprintk_proto ();default : -return bpf_base_func_proto (func_id, prog); +break ; + } + +if (!bpf_token_capable (prog->aux->token,CAP_SYS_ADMIN )) +return NULL ; + +switch (func_id) { +case BPF_FUNC_probe_write_user: +return security_locked_down (LOCKDOWN_BPF_WRITE_USER ) <0 ? +NULL : &bpf_probe_write_user_proto; +default : +return NULL ; } }Signature · 1 line
2.47.0.338.g60cca15819-goog
Re: [PATCH bpf-next v2 2/2] bpf: Refactor bpf_tracing_func_proto() and remove bpf_get_probe_write_proto()
In reply to Marco ElverQuoted 41 lines · Marco Elver
With
bpf_get_probe_write_proto()no longer printing a message, we can avoid it being a special case with its own permission check.Refactor
bpf_tracing_func_proto()similar tobpf_base_func_proto()to have a section conditional onbpf_token_capable(CAP_SYS_ADMIN), where the proto forbpf_probe_write_user()is returned. Finally, remove the unnecessarybpf_get_probe_write_proto().This simplifies the code, and adding additional CAP_SYS_ADMIN-only helpers in future avoids duplicating the same
CAP_SYS_ADMINcheck.Suggested-by Andrii Nakryiko <[email protected]>Signed-off-by Marco Elver <[email protected]>---
v2:
* New patch.--- kernel/trace/bpf_trace.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)kernel/trace/bpf_trace.c +0
-8@@ -357,14 +357,6 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = { .arg3_type = ARG_CONST_SIZE, }; -static const struct bpf_func_proto *bpf_get_probe_write_proto (void ) -{ -if (!capable (CAP_SYS_ADMIN )) -return NULL ; - -return &bpf_probe_write_user_proto; -} -#define MAX_TRACE_PRINTK_VARARGS 3#define BPF_TRACE_PRINTK_SIZE 1024
kernel/trace/bpf_trace.c late_initcall(bpf_key_sig_kfuncs_init); · line 1416
Quoted 8 lines
kernel/trace/bpf_trace.c +5
-0@@ -1417,6 +1409,12 @@ late_initcall(bpf_key_sig_kfuncs_init);static const struct bpf_func_proto *bpf_tracing_func_proto (enum bpf_func_id func_id,const struct bpf_prog *prog) { +const struct bpf_func_proto *func_proto; + + func_proto =bpf_base_func_proto (func_id, prog); +if (func_proto) +return func_proto;
As indicated by the patch robot failure, we can't move this call up and needs to remain the last call after all others because we may override a function proto in bpf_base_func_proto here (like done for BPF_FUNC_get_smp_processor_id).
Let me fix that.
Daniel Borkmann
maintainerRe: [PATCH bpf-next v2 2/2] bpf: Refactor bpf_tracing_func_proto() and remove bpf_get_probe_write_proto()
Quoted 56 lines · Marco Elver
Quoted 41 lines · Marco Elver
With
bpf_get_probe_write_proto()no longer printing a message, we can avoid it being a special case with its own permission check.Refactor
bpf_tracing_func_proto()similar tobpf_base_func_proto()to have a section conditional onbpf_token_capable(CAP_SYS_ADMIN), where the proto forbpf_probe_write_user()is returned. Finally, remove the unnecessarybpf_get_probe_write_proto().This simplifies the code, and adding additional CAP_SYS_ADMIN-only helpers in future avoids duplicating the same
CAP_SYS_ADMINcheck.Suggested-by Andrii Nakryiko <[email protected]>Signed-off-by Marco Elver <[email protected]>---
v2:
* New patch.--- kernel/trace/bpf_trace.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-)kernel/trace/bpf_trace.c +0
-8@@ -357,14 +357,6 @@ static const struct bpf_func_proto bpf_probe_write_user_proto = { .arg3_type = ARG_CONST_SIZE, }; -static const struct bpf_func_proto *bpf_get_probe_write_proto (void ) -{ -if (!capable (CAP_SYS_ADMIN )) -return NULL ; - -return &bpf_probe_write_user_proto; -} -#define MAX_TRACE_PRINTK_VARARGS 3#define BPF_TRACE_PRINTK_SIZE 1024kernel/trace/bpf_trace.c late_initcall(bpf_key_sig_kfuncs_init); · line 1416
Quoted 8 lines
kernel/trace/bpf_trace.c +5
-0@@ -1417,6 +1409,12 @@ late_initcall(bpf_key_sig_kfuncs_init);static const struct bpf_func_proto *bpf_tracing_func_proto (enum bpf_func_id func_id,const struct bpf_prog *prog) { +const struct bpf_func_proto *func_proto; + + func_proto =bpf_base_func_proto (func_id, prog); +if (func_proto) +return func_proto;As indicated by the patch robot failure, we can't move this call up and needs to remain the last call after all others because we may override a function proto in
bpf_base_func_protohere (like done forBPF_FUNC_get_smp_processor_id).
Quoted 1 line
Let me fix that.
I was about to comment on that, I would leave this as it was before, otherwise rest lgtm.
Quoted 20 lines · Marco Elver
The warning message for
bpf_probe_write_user()was introduced in96ae52279594("bpf: Addbpf_probe_write_userBPF helper to be called in tracers"), with the following in the commit message:Given this feature is meant for experiments, and it has a risk of crashing the system, and running programs, we print a warning on when a proglet that attempts to use this helper is installed, along with the pid and process name.
After 8 years since
96ae52279594,bpf_probe_write_user()has found successful applications beyond experiments [1, 2], with no other good alternatives. Despite its intended purpose for "experiments", that doesn't stop Hyrum's law, and there are likely many more users depending on this helper: "[..] it does not matter what you promise [..] all observable behaviors of your system will be depended on by somebody."The ominous "helper that may corrupt user memory!" has offered no real benefit, and has been found to lead to confusion where the system administrator is loading programs with valid use cases.
Quoted 6 lines
As such, remove the warning message.
jirka
Quoted 24 lines
---
v2:
* Just delete the message entirely (suggested by Andrii Nakryiko)--- kernel/trace/bpf_trace.c | 3 --- 1 file changed, 3 deletions(-)kernel/trace/bpf_trace.c +0
-3@@ -362,9 +362,6 @@ static const struct bpf_func_proto *bpf_get_probe_write_proto(void)if (!capable (CAP_SYS_ADMIN ))return NULL ; -pr_warn_ratelimited ("%s[%d] is installing a program with bpf_probe_write_user helper that may corrupt user memory!" , - current->comm,task_pid_nr (current)); -return &bpf_probe_write_user_proto; }Signature · 1 line
2.47.0.338.g60cca15819-goog