From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50CD9C77B73 for ; Thu, 4 May 2023 21:18:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229870AbjEDVSD (ORCPT ); Thu, 4 May 2023 17:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbjEDVSA (ORCPT ); Thu, 4 May 2023 17:18:00 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 507CA1386B; Thu, 4 May 2023 14:17:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2D4CE63850; Thu, 4 May 2023 19:52:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C731C4339C; Thu, 4 May 2023 19:52:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683229944; bh=EDJ8xgwfZmJvZP/oI0VldhPcP6EQrhu6jfQi+R/yZhU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W8AARW1ycx1Gg/7v949706hN4B4J9LusE1nUtPP/txW/NjOIl50H8ztC8r+zFMNoa CBpHL8Ox4Ws+IkgvtXD1hWKijzZl3E7sljMbF9QmnJDjZ+PIprrtQqMBNfdD5bshPL VbIE1DDiXDmvGp/vXf0Xd8u5mdTtxrTopgMSpv1uVA9znOcjLAUrMX2U+FbiWgEtQK 79r3apbSq4xBgEAcSNXhgvoIvwk3dPCMj6Ue6a7mDb0OnMOawhKsssINTcjdz0aOV4 05Rl5tiHUFiJJQgi1yiQ9H0vADZ25QoH4oYC8E+1nMqVht87zeS0Bf4UvqyR48vEwT m+dTefCzQuYmA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Nick Child , Piotr Raczynski , Jakub Kicinski , Sasha Levin , davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, kuniyu@amazon.com, liuhangbin@gmail.com, jiri@resnulli.us, andy.ren@getcruise.com, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 05/13] net: Catch invalid index in XPS mapping Date: Thu, 4 May 2023 15:51:57 -0400 Message-Id: <20230504195207.3809116-5-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230504195207.3809116-1-sashal@kernel.org> References: <20230504195207.3809116-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nick Child [ Upstream commit 5dd0dfd55baec0742ba8f5625a0dd064aca7db16 ] When setting the XPS value of a TX queue, warn the user once if the index of the queue is greater than the number of allocated TX queues. Previously, this scenario went uncaught. In the best case, it resulted in unnecessary allocations. In the worst case, it resulted in out-of-bounds memory references through calls to `netdev_get_tx_queue( dev, index)`. Therefore, it is important to inform the user but not worth returning an error and risk downing the netdevice. Signed-off-by: Nick Child Reviewed-by: Piotr Raczynski Link: https://lore.kernel.org/r/20230321150725.127229-1-nnac123@linux.ibm.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/core/dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index 86f762a1cf7ac..a4d68da682322 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2165,6 +2165,8 @@ int netif_set_xps_queue(struct net_device *dev, const struct cpumask *mask, struct xps_map *map, *new_map; bool active = false; + WARN_ON_ONCE(index >= dev->num_tx_queues); + if (dev->num_tc) { num_tc = dev->num_tc; tc = netdev_txq_to_tc(dev, index); -- 2.39.2