From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= Subject: [PATCH bpf-next 3/8] xsk: proper queue id check at bind Date: Tue, 22 May 2018 09:34:58 +0200 Message-ID: <20180522073503.2199-4-bjorn.topel@gmail.com> References: <20180522073503.2199-1-bjorn.topel@gmail.com> To: magnus.karlsson@intel.com, magnus.karlsson@gmail.com, ast@fb.com, daniel@iogearbox.net, netdev@vger.kernel.org Return-path: Received: from mga05.intel.com ([192.55.52.43]:21728 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751455AbeEVHfN (ORCPT ); Tue, 22 May 2018 03:35:13 -0400 In-Reply-To: <20180522073503.2199-1-bjorn.topel@gmail.com> Sender: netdev-owner@vger.kernel.org List-ID: From: Magnus Karlsson Validate the queue id against both Rx and Tx on the netdev. Also, make sure that the queue exists at xmit time. Reported-by: Jesper Dangaard Brouer Tested-by: Jesper Dangaard Brouer Signed-off-by: Magnus Karlsson --- net/xdp/xsk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index cb1acd7009f4..29707354cf78 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -142,6 +142,11 @@ static int xsk_generic_xmit(struct sock *sk, struct msghdr *m, goto out; } + if (xs->queue_id >= xs->dev->real_num_tx_queues) { + err = -ENXIO; + goto out; + } + skb = sock_alloc_send_skb(sk, len, !need_wait, &err); if (unlikely(!skb)) { err = -EAGAIN; @@ -305,7 +310,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) goto out_unlock; } - if (sxdp->sxdp_queue_id >= dev->num_rx_queues) { + if ((xs->rx && sxdp->sxdp_queue_id >= dev->real_num_rx_queues) || + (xs->tx && sxdp->sxdp_queue_id >= dev->real_num_tx_queues)) { err = -EINVAL; goto out_unlock; } -- 2.14.1