lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEivzxd5a8qykjbi03dyPD4hfBMsbKNTr=b0MEd2gamjC-stZA@mail.gmail.com>
Date:   Wed, 10 May 2023 16:47:21 +0200
From:   Aleksandr Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
To:     Stanislav Fomichev <sdf@...gle.com>
Cc:     nhorman@...driver.com, davem@...emloft.net,
        Daniel Borkmann <daniel@...earbox.net>,
        Christian Brauner <brauner@...nel.org>,
        Marcelo Ricardo Leitner <marcelo.leitner@...il.com>,
        Xin Long <lucien.xin@...il.com>, linux-sctp@...r.kernel.org,
        linux-kernel@...r.kernel.org, netdev@...r.kernel.org
Subject: Re: [PATCH net-next] sctp: add bpf_bypass_getsockopt proto callback

On Wed, May 10, 2023 at 4:32 PM Stanislav Fomichev <sdf@...gle.com> wrote:
>
> On Wed, May 10, 2023 at 6:15 AM Alexander Mikhalitsyn
> <aleksandr.mikhalitsyn@...onical.com> wrote:
> >
> > Add bpf_bypass_getsockopt proto callback and filter out
> > SCTP_SOCKOPT_PEELOFF and SCTP_SOCKOPT_PEELOFF_FLAGS socket options
> > from running eBPF hook on them.
> >
> > These options do fd_install(), and if BPF_CGROUP_RUN_PROG_GETSOCKOPT
> > hook returns an error after success of the original handler
> > sctp_getsockopt(...), userspace will receive an error from getsockopt
> > syscall and will be not aware that fd was successfully installed into fdtable.
> >
> > This patch was born as a result of discussion around a new SCM_PIDFD interface:
> > https://lore.kernel.org/all/20230413133355.350571-3-aleksandr.mikhalitsyn@canonical.com/
> >
> > Fixes: 0d01da6afc54 ("bpf: implement getsockopt and setsockopt hooks")
> > Cc: Daniel Borkmann <daniel@...earbox.net>
> > Cc: Christian Brauner <brauner@...nel.org>
> > Cc: Stanislav Fomichev <sdf@...gle.com>
> > Cc: Neil Horman <nhorman@...driver.com>
> > Cc: Marcelo Ricardo Leitner <marcelo.leitner@...il.com>
> > Cc: Xin Long <lucien.xin@...il.com>
> > Cc: linux-sctp@...r.kernel.org
> > Cc: linux-kernel@...r.kernel.org
> > Cc: netdev@...r.kernel.org
> > Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
>
> Acked-by: Stanislav Fomichev <sdf@...gle.com>
>
> with a small nit below

Hi Stanislav!

Thanks for your review.

I've also added a Suggested-by tag with your name in -v2, because
you've given me this idea to use bpf_bypass_getsockopt.
Hope that you are comfortable with it.

>
> > ---
> >  net/sctp/socket.c | 25 +++++++++++++++++++++++++
> >  1 file changed, 25 insertions(+)
> >
> > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > index cda8c2874691..a9a0ababea90 100644
> > --- a/net/sctp/socket.c
> > +++ b/net/sctp/socket.c
> > @@ -8281,6 +8281,29 @@ static int sctp_getsockopt(struct sock *sk, int level, int optname,
> >         return retval;
> >  }
> >
>
> [...]
>
> > +bool sctp_bpf_bypass_getsockopt(int level, int optname)
>
> static bool ... ? You're not making it indirect-callable, so seems
> fine to keep private to this compilation unit?

Sure, my bad. Fixed in v2.

Kind regards,
Alex

>
> > +{
> > +       /*
> > +        * These options do fd_install(), and if BPF_CGROUP_RUN_PROG_GETSOCKOPT
> > +        * hook returns an error after success of the original handler
> > +        * sctp_getsockopt(...), userspace will receive an error from getsockopt
> > +        * syscall and will be not aware that fd was successfully installed into fdtable.
> > +        *
> > +        * Let's prevent bpf cgroup hook from running on them.
> > +        */
> > +       if (level == SOL_SCTP) {
> > +               switch (optname) {
> > +               case SCTP_SOCKOPT_PEELOFF:
> > +               case SCTP_SOCKOPT_PEELOFF_FLAGS:
> > +                       return true;
> > +               default:
> > +                       return false;
> > +               }
> > +       }
> > +
> > +       return false;
> > +}
> > +
> >  static int sctp_hash(struct sock *sk)
> >  {
> >         /* STUB */
> > @@ -9650,6 +9673,7 @@ struct proto sctp_prot = {
> >         .shutdown    =  sctp_shutdown,
> >         .setsockopt  =  sctp_setsockopt,
> >         .getsockopt  =  sctp_getsockopt,
> > +       .bpf_bypass_getsockopt  = sctp_bpf_bypass_getsockopt,
> >         .sendmsg     =  sctp_sendmsg,
> >         .recvmsg     =  sctp_recvmsg,
> >         .bind        =  sctp_bind,
> > @@ -9705,6 +9729,7 @@ struct proto sctpv6_prot = {
> >         .shutdown       = sctp_shutdown,
> >         .setsockopt     = sctp_setsockopt,
> >         .getsockopt     = sctp_getsockopt,
> > +       .bpf_bypass_getsockopt  = sctp_bpf_bypass_getsockopt,
> >         .sendmsg        = sctp_sendmsg,
> >         .recvmsg        = sctp_recvmsg,
> >         .bind           = sctp_bind,
> > --
> > 2.34.1
> >

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ