bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <daniel@iogearbox.net>
To: Magnus Karlsson <magnus.karlsson@intel.com>
Cc: bjorn.topel@intel.com, ast@kernel.org, netdev@vger.kernel.org,
	jonathan.lemon@gmail.com, bpf@vger.kernel.org
Subject: Re: [PATCH bpf v2] xsk: fix crash in poll when device does not support ndo_xsk_wakeup
Date: Thu, 3 Oct 2019 17:00:54 +0200	[thread overview]
Message-ID: <20191003150054.GD9196@pc-66.home> (raw)
In-Reply-To: <1569997919-11541-1-git-send-email-magnus.karlsson@intel.com>

On Wed, Oct 02, 2019 at 08:31:59AM +0200, Magnus Karlsson wrote:
> Fixes a crash in poll() when an AF_XDP socket is opened in copy mode
> and the bound device does not have ndo_xsk_wakeup defined. Avoid
> trying to call the non-existing ndo and instead call the internal xsk
> sendmsg function to send packets in the same way (from the
> application's point of view) as calling sendmsg() in any mode or
> poll() in zero-copy mode would have done. The application should
> behave in the same way independent on if zero-copy mode or copy mode
> is used.
> 
> Fixes: 77cd0d7b3f25 ("xsk: add support for need_wakeup flag in AF_XDP rings")
> Reported-by: syzbot+a5765ed8cdb1cca4d249@syzkaller.appspotmail.com
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>

Applied, thanks!

[...]
> +static int xsk_generic_xmit(struct sock *sk)
>  {
> -	u32 max_batch = TX_BATCH_SIZE;
>  	struct xdp_sock *xs = xdp_sk(sk);
> +	u32 max_batch = TX_BATCH_SIZE;
>  	bool sent_frame = false;
>  	struct xdp_desc desc;
>  	struct sk_buff *skb;
> @@ -394,6 +392,18 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m,
>  	return err;
>  }
>  
> +static int __xsk_sendmsg(struct sock *sk)

Bit unclear why you don't just pass xs directly in here from both call
sites ...

> +{
> +	struct xdp_sock *xs = xdp_sk(sk);
> +
> +	if (unlikely(!(xs->dev->flags & IFF_UP)))
> +		return -ENETDOWN;
> +	if (unlikely(!xs->tx))
> +		return -ENOBUFS;
> +
> +	return xs->zc ? xsk_zc_xmit(xs) : xsk_generic_xmit(sk);

... and for the xsk_generic_xmit() pass in &xs->sk. Presumably generated
code should be the same, but maybe small cleanup for next batch of AF_XDP
patches.

> +}
> +
>  static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
>  {
>  	bool need_wait = !(m->msg_flags & MSG_DONTWAIT);
> @@ -402,21 +412,18 @@ static int xsk_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)
>  
>  	if (unlikely(!xsk_is_bound(xs)))
>  		return -ENXIO;
> -	if (unlikely(!(xs->dev->flags & IFF_UP)))
> -		return -ENETDOWN;
> -	if (unlikely(!xs->tx))
> -		return -ENOBUFS;
> -	if (need_wait)
> +	if (unlikely(need_wait))
>  		return -EOPNOTSUPP;
>  
> -	return (xs->zc) ? xsk_zc_xmit(sk) : xsk_generic_xmit(sk, m, total_len);
> +	return __xsk_sendmsg(sk);
>  }

Thanks,
Daniel

      reply	other threads:[~2019-10-03 15:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-02  6:31 [PATCH bpf v2] xsk: fix crash in poll when device does not support ndo_xsk_wakeup Magnus Karlsson
2019-10-03 15:00 ` Daniel Borkmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191003150054.GD9196@pc-66.home \
    --to=daniel@iogearbox.net \
    --cc=ast@kernel.org \
    --cc=bjorn.topel@intel.com \
    --cc=bpf@vger.kernel.org \
    --cc=jonathan.lemon@gmail.com \
    --cc=magnus.karlsson@intel.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).