diff mbox series

[bpf] bpf_trace: bail out from bpf_kprobe_multi_link_attach when in compat

Message ID 20220506142148.GA24802@asgard.redhat.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf] bpf_trace: bail out from bpf_kprobe_multi_link_attach when in compat | expand

Checks

Context Check Description
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf-VM_Test-1 fail Logs for Kernel LATEST on ubuntu-latest + selftests
bpf/vmtest-bpf-VM_Test-2 fail Logs for Kernel LATEST on z15 + selftests
netdev/tree_selection success Clearly marked for bpf
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
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: 9 this patch: 9
netdev/cc_maintainers success CCed 14 of 14 maintainers
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 Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 9 this patch: 9
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Eugene Syromiatnikov May 6, 2022, 2:21 p.m. UTC
Since bpf_kprobe_multi_link_attach doesn't support 32-bit kernels
for whatever reason, having it enabled for compat processes on 64-bit
kernels makes even less sense due to discrepances in the type sizes
that it does not handle.

Fixes: 0dcac272540613d4 ("bpf: Add multi kprobe link")
Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
---
 kernel/trace/bpf_trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Alexei Starovoitov May 10, 2022, 6:10 p.m. UTC | #1
On Fri, May 6, 2022 at 7:22 AM Eugene Syromiatnikov <esyr@redhat.com> wrote:
>
> Since bpf_kprobe_multi_link_attach doesn't support 32-bit kernels
> for whatever reason,

Jiri,
why did you add this restriction?

> having it enabled for compat processes on 64-bit
> kernels makes even less sense due to discrepances in the type sizes
> that it does not handle.

I don't follow this logic.
bpf progs are always 64-bit. Even when user space is 32-bit.
Jiri's check is for the kernel.

> Fixes: 0dcac272540613d4 ("bpf: Add multi kprobe link")
> Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
> ---
>  kernel/trace/bpf_trace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> index d8553f4..9560af6 100644
> --- a/kernel/trace/bpf_trace.c
> +++ b/kernel/trace/bpf_trace.c
> @@ -2410,7 +2410,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
>         int err;
>
>         /* no support for 32bit archs yet */
> -       if (sizeof(u64) != sizeof(void *))
> +       if (sizeof(u64) != sizeof(void *) || in_compat_syscall())
>                 return -EOPNOTSUPP;
>
>         if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI)
> --
> 2.1.4
>
Eugene Syromiatnikov May 10, 2022, 6:41 p.m. UTC | #2
On Tue, May 10, 2022 at 11:10:35AM -0700, Alexei Starovoitov wrote:
> On Fri, May 6, 2022 at 7:22 AM Eugene Syromiatnikov <esyr@redhat.com> wrote:
> >
> > Since bpf_kprobe_multi_link_attach doesn't support 32-bit kernels
> > for whatever reason,
> 
> Jiri,
> why did you add this restriction?
> 
> > having it enabled for compat processes on 64-bit
> > kernels makes even less sense due to discrepances in the type sizes
> > that it does not handle.
> 
> I don't follow this logic.
> bpf progs are always 64-bit. Even when user space is 32-bit.
> Jiri's check is for the kernel.

The interface as defined (and implemented in libbpf) expects arrays of userspace
pointers to be passed (for example, syms points to an array of userspace
pointers—character strings; same goes for addrs, but with generic userspace
pointers) without regard to possible difference in the pointer size in case
of compat userspace.

> > Fixes: 0dcac272540613d4 ("bpf: Add multi kprobe link")
> > Signed-off-by: Eugene Syromiatnikov <esyr@redhat.com>
> > ---
> >  kernel/trace/bpf_trace.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
> > index d8553f4..9560af6 100644
> > --- a/kernel/trace/bpf_trace.c
> > +++ b/kernel/trace/bpf_trace.c
> > @@ -2410,7 +2410,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
> >         int err;
> >
> >         /* no support for 32bit archs yet */
> > -       if (sizeof(u64) != sizeof(void *))
> > +       if (sizeof(u64) != sizeof(void *) || in_compat_syscall())
> >                 return -EOPNOTSUPP;
> >
> >         if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI)
> > --
> > 2.1.4
> >
>
Alexei Starovoitov May 10, 2022, 10:30 p.m. UTC | #3
On Tue, May 10, 2022 at 11:42 AM Eugene Syromiatnikov <esyr@redhat.com> wrote:
>
> On Tue, May 10, 2022 at 11:10:35AM -0700, Alexei Starovoitov wrote:
> > On Fri, May 6, 2022 at 7:22 AM Eugene Syromiatnikov <esyr@redhat.com> wrote:
> > >
> > > Since bpf_kprobe_multi_link_attach doesn't support 32-bit kernels
> > > for whatever reason,
> >
> > Jiri,
> > why did you add this restriction?
> >
> > > having it enabled for compat processes on 64-bit
> > > kernels makes even less sense due to discrepances in the type sizes
> > > that it does not handle.
> >
> > I don't follow this logic.
> > bpf progs are always 64-bit. Even when user space is 32-bit.
> > Jiri's check is for the kernel.
>
> The interface as defined (and implemented in libbpf) expects arrays of userspace
> pointers to be passed (for example, syms points to an array of userspace
> pointers—character strings; same goes for addrs, but with generic userspace
> pointers) without regard to possible difference in the pointer size in case
> of compat userspace.

I see. So kprobe_multi.syms and kprobe_multi.addrs will be 'long'
and 32-bit user space will have an issue with the 64-bit kernel.
Let's fix it properly.
We can remove sizeof(u64) != sizeof(void *) and keep libbpf as-is
by keeping syms and addrs 'long' in uapi.
As far as I can see 32-bit user space on a 32-bit kernel
should work with existing code.
in_compat_syscall() can be used to extend addrs/syms.
Jiri Olsa May 16, 2022, 8:38 p.m. UTC | #4
On Tue, May 10, 2022 at 03:30:10PM -0700, Alexei Starovoitov wrote:
> On Tue, May 10, 2022 at 11:42 AM Eugene Syromiatnikov <esyr@redhat.com> wrote:
> >
> > On Tue, May 10, 2022 at 11:10:35AM -0700, Alexei Starovoitov wrote:
> > > On Fri, May 6, 2022 at 7:22 AM Eugene Syromiatnikov <esyr@redhat.com> wrote:
> > > >
> > > > Since bpf_kprobe_multi_link_attach doesn't support 32-bit kernels
> > > > for whatever reason,
> > >
> > > Jiri,
> > > why did you add this restriction?

sorry, I overlooked this email

the reason for that check is that we link addrs array with cookies
which are u64 and we need to swap cookies together with addrs when
we sort them

but now when I look at that, that could perhaps work event if
unsigned long is 32 bits, will check

> > >
> > > > having it enabled for compat processes on 64-bit
> > > > kernels makes even less sense due to discrepances in the type sizes
> > > > that it does not handle.
> > >
> > > I don't follow this logic.
> > > bpf progs are always 64-bit. Even when user space is 32-bit.
> > > Jiri's check is for the kernel.
> >
> > The interface as defined (and implemented in libbpf) expects arrays of userspace
> > pointers to be passed (for example, syms points to an array of userspace
> > pointers—character strings; same goes for addrs, but with generic userspace
> > pointers) without regard to possible difference in the pointer size in case
> > of compat userspace.
> 
> I see. So kprobe_multi.syms and kprobe_multi.addrs will be 'long'
> and 32-bit user space will have an issue with the 64-bit kernel.
> Let's fix it properly.
> We can remove sizeof(u64) != sizeof(void *) and keep libbpf as-is
> by keeping syms and addrs 'long' in uapi.
> As far as I can see 32-bit user space on a 32-bit kernel
> should work with existing code.
> in_compat_syscall() can be used to extend addrs/syms.

I'll check Eugene's new patchset

jirka
diff mbox series

Patch

diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index d8553f4..9560af6 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -2410,7 +2410,7 @@  int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
 	int err;
 
 	/* no support for 32bit archs yet */
-	if (sizeof(u64) != sizeof(void *))
+	if (sizeof(u64) != sizeof(void *) || in_compat_syscall())
 		return -EOPNOTSUPP;
 
 	if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI)