Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp4915313imc; Mon, 25 Feb 2019 13:32:58 -0800 (PST) X-Google-Smtp-Source: AHgI3IbD7PEc06Xnl14ZdgZY1KhEW77FIyJMegbDVtvmwXIaha2NMFhUQcUubhxo2kiqy3dzGh/h X-Received: by 2002:a17:902:82cc:: with SMTP id u12mr22699225plz.189.1551130377894; Mon, 25 Feb 2019 13:32:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551130377; cv=none; d=google.com; s=arc-20160816; b=d7znJmbe9Z77y4ZbzFePWPPzsWf9gvWul6Rr9wS+p0aOKq3VWQpjlgL2n42iH7Aqgg TZqMxO2tETCL7WRO39Nh95vsev/5I3KEi+6JMoORRECqqc4N0PMB29mCj+puRoSjhPLW KNqFBczJLdCerD3lzeJM6uV+4PtPK5WDrDafvIdotsFH5qy/iW5bYGtV8LA3Irk5RNw7 rHhsAQEgJgO/+x2FEuC7AuBgf7titPNzVTHwX3RPhNf35QmdlWDYj7ROz1ocKho32voc JdhziaxTBm13RIoQW8SqOwGb8xyxJSmWWy7coQmyYcW4W1M8PhTJE4EiYPMt0pZOoB65 aNtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5NvvSlTotXmpRxAZ00u/vdb9KxrvUwiPfRo2VXJZuik=; b=dhE8xzDxs1KGoJCDY/PYrU8Cp8MUDiBwS8O3UDq0JYfonS8jVZgMZDsDD0bT38IsDY rt9gdTc6k1d7EJsCeNO1vvb4NUNixNpsyPoYsR9m2KsTgFHtfq++F17UcA+cQpfm4c8z 8EIPk1cgTYU08Y9ccscVhYi7TX4w8fG+SOCCqsA6sDhAKGkEWOVljHZaiavrZUT6cI3Q bkeyy/N2FJ+wWCmhlpwyVfnJD1Gi1CwVG76+3xWyOU5Th+Vk6oUJy8SGgolU/IYG+ecZ +vEicNjB/+QdDWje4z720REfBHZKNYMhYpr3xRhbG8GcUe/aRZ5jep0QmrkU4U2fRR5C pNuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z22pjbLC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b8si10045313plr.54.2019.02.25.13.32.42; Mon, 25 Feb 2019 13:32:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=z22pjbLC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732486AbfBYVc0 (ORCPT + 99 others); Mon, 25 Feb 2019 16:32:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:37918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731459AbfBYVcZ (ORCPT ); Mon, 25 Feb 2019 16:32:25 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DABE021841; Mon, 25 Feb 2019 21:32:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1551130344; bh=pwTJi5CspWCLqkxb9AsFpR0MRxiF9on9h1nvBZDnZYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=z22pjbLCVUlnOLrPV7IUaDVyD5xaDuCtTr7Ifil6/3SolMoi1Z0aHrQ+2WNg1y3i0 t7G1P8D6MkV51qOTlbOopxZzNxKz6f3OohzOZe1c5rhGsrQk0S8ianCoxP0F8Bcyo5 fGiDJpFJemrqawZZZj8B1POP9FmvXnzxHJ633oXI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jakub Spizewski , Krzysztof Kazimierczak , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Daniel Borkmann , Sasha Levin Subject: [PATCH 4.20 090/183] xsk: Check if a queue exists during umem setup Date: Mon, 25 Feb 2019 22:11:03 +0100 Message-Id: <20190225195109.786461366@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225195054.748060397@linuxfoundation.org> References: <20190225195054.748060397@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit cc5b5d3565048ae57d14e5674a5fb085b2ab0193 ] In the xdp_umem_assign_dev() path, the xsk code does not check if a queue for which umem is to be created exists. It leads to a situation where umem is not assigned to any Tx/Rx queue of a netdevice, without notifying the stack about an error. This affects both XDP_SKB and XDP_DRV modes - in case of XDP_DRV_ZC, queue index is checked by the driver. This patch fixes xsk code, so that in both XDP_SKB and XDP_DRV mode of AF_XDP, an error is returned when requested queue index exceedes an existing maximum. Fixes: c9b47cc1fabca ("xsk: fix bug when trying to use both copy and zero-copy on one queue id") Reported-by: Jakub Spizewski Signed-off-by: Krzysztof Kazimierczak Acked-by: Björn Töpel Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- net/xdp/xdp_umem.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index a264cf2accd0f..d4de871e7d4d7 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -41,13 +41,20 @@ void xdp_del_sk_umem(struct xdp_umem *umem, struct xdp_sock *xs) * not know if the device has more tx queues than rx, or the opposite. * This might also change during run time. */ -static void xdp_reg_umem_at_qid(struct net_device *dev, struct xdp_umem *umem, - u16 queue_id) +static int xdp_reg_umem_at_qid(struct net_device *dev, struct xdp_umem *umem, + u16 queue_id) { + if (queue_id >= max_t(unsigned int, + dev->real_num_rx_queues, + dev->real_num_tx_queues)) + return -EINVAL; + if (queue_id < dev->real_num_rx_queues) dev->_rx[queue_id].umem = umem; if (queue_id < dev->real_num_tx_queues) dev->_tx[queue_id].umem = umem; + + return 0; } struct xdp_umem *xdp_get_umem_from_qid(struct net_device *dev, @@ -88,7 +95,10 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev, goto out_rtnl_unlock; } - xdp_reg_umem_at_qid(dev, umem, queue_id); + err = xdp_reg_umem_at_qid(dev, umem, queue_id); + if (err) + goto out_rtnl_unlock; + umem->dev = dev; umem->queue_id = queue_id; if (force_copy) -- 2.19.1