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: <CAJ+HfNj0i_bPXz+3_aHgTu6O-bDD9auMFGxSn6A9g=X_+e0=4Q@mail.gmail.com>
Date:   Mon, 30 Jul 2018 14:00:44 +0200
From:   Björn Töpel <bjorn.topel@...il.com>
To:     Jakub Kicinski <jakub.kicinski@...ronome.com>
Cc:     Alexei Starovoitov <alexei.starovoitov@...il.com>,
        Daniel Borkmann <daniel@...earbox.net>,
        Jesper Dangaard Brouer <brouer@...hat.com>,
        Björn Töpel <bjorn.topel@...el.com>,
        "Karlsson, Magnus" <magnus.karlsson@...el.com>,
        oss-drivers@...ronome.com, Netdev <netdev@...r.kernel.org>
Subject: Re: [RFC bpf-next 3/6] xsk: don't allow umem replace at stack level

Den tors 26 juli 2018 kl 23:44 skrev Jakub Kicinski
<jakub.kicinski@...ronome.com>:
>
> Currently drivers have to check if they already have a umem
> installed for a given queue and return an error if so.  Make
> better use of XDP_QUERY_XSK_UMEM and move this functionality
> to the core.
>
> We need to keep rtnl across the calls now.
>
> Signed-off-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
> Reviewed-by: Quentin Monnet <quentin.monnet@...ronome.com>
> ---
>  include/linux/netdevice.h |  7 ++++---
>  net/xdp/xdp_umem.c        | 37 ++++++++++++++++++++++++++++---------
>  2 files changed, 32 insertions(+), 12 deletions(-)
>
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index 6717dc7e8fbf..a5a34f0fb485 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -872,10 +872,10 @@ struct netdev_bpf {
>                 struct {
>                         struct bpf_offloaded_map *offmap;
>                 };
> -               /* XDP_SETUP_XSK_UMEM */
> +               /* XDP_QUERY_XSK_UMEM, XDP_SETUP_XSK_UMEM */
>                 struct {
> -                       struct xdp_umem *umem;
> -                       u16 queue_id;
> +                       struct xdp_umem *umem; /* out for query*/
> +                       u16 queue_id; /* in for query */
>                 } xsk;
>         };
>  };
> @@ -3566,6 +3566,7 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
>                       int fd, u32 flags);
>  u32 __dev_xdp_query(struct net_device *dev, bpf_op_t xdp_op,
>                     enum bpf_netdev_command cmd);
> +int xdp_umem_query(struct net_device *dev, u16 queue_id);
>
>  int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
>  int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
> diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
> index c199d66b5f3f..911ca6d3cb5a 100644
> --- a/net/xdp/xdp_umem.c
> +++ b/net/xdp/xdp_umem.c
> @@ -11,6 +11,8 @@
>  #include <linux/slab.h>
>  #include <linux/bpf.h>
>  #include <linux/mm.h>
> +#include <linux/netdevice.h>
> +#include <linux/rtnetlink.h>
>
>  #include "xdp_umem.h"
>  #include "xsk_queue.h"
> @@ -40,6 +42,21 @@ void xdp_del_sk_umem(struct xdp_umem *umem, struct xdp_sock *xs)
>         }
>  }
>
> +int xdp_umem_query(struct net_device *dev, u16 queue_id)
> +{
> +       struct netdev_bpf bpf;
> +
> +       ASSERT_RTNL();
> +
> +       memset(&bpf, 0, sizeof(bpf));
> +       bpf.command = XDP_QUERY_XSK_UMEM;
> +       bpf.xsk.queue_id = queue_id;
> +
> +       if (!dev->netdev_ops->ndo_bpf)
> +               return 0;
> +       return dev->netdev_ops->ndo_bpf(dev, &bpf) ?: !!bpf.xsk.umem;
> +}
> +
>  int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
>                         u32 queue_id, u16 flags)
>  {
> @@ -62,28 +79,30 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
>         bpf.command = XDP_QUERY_XSK_UMEM;
>
>         rtnl_lock();
> -       err = dev->netdev_ops->ndo_bpf(dev, &bpf);
> -       rtnl_unlock();
> -
> -       if (err)
> -               return force_zc ? -ENOTSUPP : 0;
> +       err = xdp_umem_query(dev, queue_id);
> +       if (err) {
> +               err = err < 0 ? -ENOTSUPP : -EBUSY;
> +               goto err_rtnl_unlock;
> +       }
>
>         bpf.command = XDP_SETUP_XSK_UMEM;
>         bpf.xsk.umem = umem;
>         bpf.xsk.queue_id = queue_id;
>
> -       rtnl_lock();
>         err = dev->netdev_ops->ndo_bpf(dev, &bpf);
> -       rtnl_unlock();
> -
>         if (err)
> -               return force_zc ? err : 0; /* fail or fallback */
> +               goto err_rtnl_unlock;
> +       rtnl_unlock();
>
>         dev_hold(dev);
>         umem->dev = dev;
>         umem->queue_id = queue_id;
>         umem->zc = true;
>         return 0;
> +
> +err_rtnl_unlock:
> +       rtnl_unlock();
> +       return force_zc ? err : 0; /* fail or fallback */
>  }
>
>  static void xdp_umem_clear_dev(struct xdp_umem *umem)
> --
> 2.17.1
>

Nice!

For a non-RFC version,

Acked-by: Björn Töpel <bjorn.topel@...el.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ