bpf: Add missing access_ok call to copy_user_syms
Subsystems (5)
Jiri Olsa
reviewerPATCH 1/1 bpf: Add missing access_ok call to copy_user_syms
As reported by sashiko we use __get_user without prior access_ok call on the user space pointer. Adding the missing call for the whole pointer array.
Plus removing the err check in the error path, because it's not needed and also we can return -ENOMEM directly from the first kvmalloc_array fail path.
Cc: [email protected]
[1] https://lore.kernel.org/bpf/[email protected]/
--- kernel/trace/bpf_trace.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
kernel/trace/bpf_trace.c +6 -5
@@ -2376,9 +2376,12 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32int err = -ENOMEM ;unsigned int i; +if (!access_ok (usyms, cnt *sizeof (*usyms))) +return -EFAULT ; + syms =kvmalloc_array (cnt,sizeof (*syms),GFP_KERNEL );if (!syms) - goto error; +return -ENOMEM ; buf =kvmalloc_array (cnt,KSYM_NAME_LEN ,GFP_KERNEL );if (!buf)
@@ -2403,10 +2406,8 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32return 0 ; error: -if (err) { -kvfree (syms); -kvfree (buf); - } +kvfree (syms); +kvfree (buf);return err; }
Signature · 1 line
2.54.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing access_ok() checks for user pointers uoffsets, uref_ctr_offsets, and ucookies before using __get_user() in bpf_uprobe_multi_link_attach. --
commit cd20e04dceb618df71198c96a9e801e033dcb0a0
Author: Jiri Olsa <[email protected]>
bpf: Add missing access_ok call to copy_user_syms
The patch adds a missing access_ok() check for the user pointer array usyms in copy_user_syms() before accessing it via __get_user(). It also cleans up the error path by returning -ENOMEM directly upon memory allocation failure instead of using a goto.
Quoted 20 lines
kernel/trace/bpf_trace.c +4
-1@@ -2331,9 +2331,12 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32int err = -ENOMEM ;unsigned int i; +if (!access_ok (usyms, cnt *sizeof (*usyms))) +return -EFAULT ; + syms =kvmalloc_array (cnt,sizeof (*syms),GFP_KERNEL );if (!syms) - goto error; +return -ENOMEM ; buf =kvmalloc_array (cnt,KSYM_NAME_LEN ,GFP_KERNEL );if (!buf)@@ -2358,10 +2361,8 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32return 0 ;
kernel/trace/bpf_trace.c static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 · line 2367
Quoted 10 lines
kernel/trace/bpf_trace.c +2
-4error: -if (err) { -kvfree (syms); -kvfree (buf); - } +kvfree (syms); +kvfree (buf);return err; }
[Severity: High]
This is a pre-existing issue, but while reviewing this patch I noticed a similar pattern in bpf_uprobe_multi_link_attach() within the same file.
kernel/trace/bpf_trace.c:bpf_uprobe_multi_link_attach() {
...
for (i = 0; i < cnt; i++) {
if (__get_user(uprobes[i].offset, uoffsets + i)) {
err = -EFAULT;
goto error_free;
}
if (uprobes[i].offset < 0) {
err = -EINVAL;
goto error_free;
}
if (uref_ctr_offsets && __get_user(uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) {
err = -EFAULT;
goto error_free;
}
if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) {
err = -EFAULT;
goto error_free;
}
...
}Are the user-provided array pointers uoffsets, uref_ctr_offsets, and ucookies missing overarching access_ok() validations before being accessed in this loop?
Since __get_user() explicitly bypasses the access_ok() validation performed by get_user(), reading these pointers without a prior check could potentially allow an attacker to pass arbitrary kernel memory addresses and trigger unauthorized reads or crashes.
Does this function need the same fix as copy_user_syms()?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 5 lines · On Tue, Jun 16, 2026 at 08:42:03AM +0000, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Missingaccess_ok()checks for user pointersuoffsets,uref_ctr_offsets, anducookiesbefore using__get_user()inbpf_uprobe_multi_link_attach. --
it's fixed in separate post in here:
https://lore.kernel.org/bpf/[email protected]/
jirka
Quoted 81 lines
commit
cd20e04dceb618df71198c96a9e801e033dcb0a0
Author: Jiri Olsa <[email protected]>
bpf: Add missingaccess_okcall tocopy_user_symsThe patch adds a missing
access_ok()check for the user pointer array usyms incopy_user_syms()before accessing it via__get_user(). It also cleans up the error path by returning-ENOMEMdirectly upon memory allocation failure instead of using a goto.Quoted 20 lines
kernel/trace/bpf_trace.c +4
-1@@ -2331,9 +2331,12 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32int err = -ENOMEM ;unsigned int i; +if (!access_ok (usyms, cnt *sizeof (*usyms))) +return -EFAULT ; + syms =kvmalloc_array (cnt,sizeof (*syms),GFP_KERNEL );if (!syms) - goto error; +return -ENOMEM ; buf =kvmalloc_array (cnt,KSYM_NAME_LEN ,GFP_KERNEL );if (!buf)@@ -2358,10 +2361,8 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32return 0 ;kernel/trace/bpf_trace.c static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 · line 2367
Quoted 10 lines
kernel/trace/bpf_trace.c +2
-4error: -if (err) { -kvfree (syms); -kvfree (buf); - } +kvfree (syms); +kvfree (buf);return err; }[Severity: High]
This is a pre-existing issue, but while reviewing this patch I noticed a similar pattern inbpf_uprobe_multi_link_attach()within the same file.kernel/trace/bpf_trace.c:bpf_uprobe_multi_link_attach() { ... for (i = 0; i < cnt; i++) { if (__get_user(uprobes[i].offset, uoffsets + i)) { err = -EFAULT; goto error_free; } if (uprobes[i].offset < 0) { err = -EINVAL; goto error_free; } if (uref_ctr_offsets && __get_user(uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) { err = -EFAULT; goto error_free; } if (ucookies && __get_user(uprobes[i].cookie, ucookies + i)) { err = -EFAULT; goto error_free; } ... }Are the user-provided array pointers uoffsets,
uref_ctr_offsets, and ucookies missing overarchingaccess_ok()validations before being accessed in this loop?Since
__get_user()explicitly bypasses theaccess_ok()validation performed byget_user(), reading these pointers without a prior check could potentially allow an attacker to pass arbitrary kernel memory addresses and trigger unauthorized reads or crashes.Does this function need the same fix as
copy_user_syms()?Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 6 lines · Jiri Olsa
As reported by sashiko we use
__get_userwithout prioraccess_okcall on the user space pointer. Adding the missing call for the whole pointer array.Plus removing the err check in the error path, because it's not needed and also we can return
-ENOMEMdirectly from the firstkvmalloc_arrayfail path.
Quoted 6 lines
Cc: [email protected]
[1] https://lore.kernel.org/bpf/[email protected]/Fixes 0236fec57a15 ("bpf: Resolve symbols with ftrace_lookup_symbols for kprobe multi link")Reported-by Sashiko <[email protected]>Signed-off-by Jiri Olsa <[email protected]>
Quoted 35 lines
--- kernel/trace/bpf_trace.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)kernel/trace/bpf_trace.c +6
-5@@ -2376,9 +2376,12 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32int err = -ENOMEM ;unsigned int i; +if (!access_ok (usyms, cnt *sizeof (*usyms))) +return -EFAULT ; + syms =kvmalloc_array (cnt,sizeof (*syms),GFP_KERNEL );if (!syms) - goto error; +return -ENOMEM ; buf =kvmalloc_array (cnt,KSYM_NAME_LEN ,GFP_KERNEL );if (!buf)@@ -2403,10 +2406,8 @@ static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32return 0 ; error: -if (err) { -kvfree (syms); -kvfree (buf); - } +kvfree (syms); +kvfree (buf);return err; }
This patch was applied to bpf/bpf.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf.git (master)
by Alexei Starovoitov <[email protected]>:
Quoted 6 lines · On Tue, 16 Jun 2026 10:30:56 +0200 you wrote:
As reported by sashiko we use
__get_userwithout prioraccess_okcall on the user space pointer. Adding the missing call for the whole pointer array.Plus removing the err check in the error path, because it's not needed and also we can return
-ENOMEMdirectly from the firstkvmalloc_arrayfail path.
Quoted 8 lines
Cc: [email protected]
[1] https://lore.kernel.org/bpf/[email protected]/Fixes 0236fec57a15 ("bpf: Resolve symbols with ftrace_lookup_symbols for kprobe multi link")Reported-by Sashiko <[email protected]>Signed-off-by Jiri Olsa <[email protected]>[...]
Here is the summary with links:
- [bpf] bpf: Add missing access_ok call to copy_user_syms
https://git.kernel.org/bpf/bpf/c/d5dc200c3a3f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html