From patchwork Tue Mar 21 15:07:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Child X-Patchwork-Id: 13182868 X-Patchwork-Delegate: kuba@kernel.org 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 5365DC7619A for ; Tue, 21 Mar 2023 15:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231443AbjCUPH7 (ORCPT ); Tue, 21 Mar 2023 11:07:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbjCUPH6 (ORCPT ); Tue, 21 Mar 2023 11:07:58 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBF26509BD for ; Tue, 21 Mar 2023 08:07:41 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32LEfKpa003883; Tue, 21 Mar 2023 15:07:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : mime-version; s=pp1; bh=ffF23+WiHLiUqptO9gsH1+0QQJSdSLaPNPLpini8e6M=; b=nPBi2DTUsMDHgE8ME1jEYLsRKVYmoO2ZtSVKxwMtObyuwkbzH8tqVt69IE/LNRCoBrwH tl/F9pr7Y9/UzLhxFNIs56AgoY7SOwKcHfq01kNa8VLIbAI4/wbi7Yv0JsgC8/YwxAnZ 7WzIIiSPzoHRWVTjK4fPAD32K4is/swBKGfIrAQLXFUnTHX699PYcLp5JgphnUmyHE1B PiBbNN+4ypdTVt6DKFQNPjO7PQL4UNuJGhKTiui6VmUdMK/prz93rAuX0xkssIFPIFjM lWVKVOI9yj5H2z+S/Vsm1z6Jb6nqg3wgMk7M2N3R3vOYGG/YDnjVzfyMXOEAT+txxzA+ xQ== Received: from ppma01dal.us.ibm.com (83.d6.3fa9.ip4.static.sl-reverse.com [169.63.214.131]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3pfbpmdtsm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Mar 2023 15:07:32 +0000 Received: from pps.filterd (ppma01dal.us.ibm.com [127.0.0.1]) by ppma01dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32LEZrVN020656; Tue, 21 Mar 2023 15:07:31 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma01dal.us.ibm.com (PPS) with ESMTPS id 3pd4x7fwh7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Mar 2023 15:07:31 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32LF7Tx829033050 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Mar 2023 15:07:29 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7FF535805B; Tue, 21 Mar 2023 15:07:29 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9342058055; Tue, 21 Mar 2023 15:07:28 +0000 (GMT) Received: from li-8d37cfcc-31b9-11b2-a85c-83226d7135c9.ibm.com.com (unknown [9.77.147.181]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Mar 2023 15:07:28 +0000 (GMT) From: Nick Child To: netdev@vger.kernel.org Cc: Nick Child , Piotr Raczynski Subject: [PATCH net-next v2 1/2] net: Catch invalid index in XPS mapping Date: Tue, 21 Mar 2023 10:07:24 -0500 Message-Id: <20230321150725.127229-1-nnac123@linux.ibm.com> X-Mailer: git-send-email 2.31.1 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 7k9PJvKSEJFfkGLgauQvsGGjonLmdkkM X-Proofpoint-GUID: 7k9PJvKSEJFfkGLgauQvsGGjonLmdkkM X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-21_11,2023-03-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303210118 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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 --- Changes since v1 (respond to Jakubs review): - send to net-next instead of net - use WARN_ON_ONCE instead of a conditonal returning error v1 - https://lore.kernel.org/netdev/20230320215229.53b7dfa7@kernel.org/ net/core/dev.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/dev.c b/net/core/dev.c index c7853192563d..c278beee6792 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2535,6 +2535,8 @@ int __netif_set_xps_queue(struct net_device *dev, const unsigned long *mask, struct xps_map *map, *new_map; unsigned int nr_ids; + WARN_ON_ONCE(index >= dev->num_tx_queues); + if (dev->num_tc) { /* Do not allow XPS on subordinate device directly */ num_tc = dev->num_tc; From patchwork Tue Mar 21 15:07:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Child X-Patchwork-Id: 13182867 X-Patchwork-Delegate: kuba@kernel.org 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 D9306C6FD1D for ; Tue, 21 Mar 2023 15:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230344AbjCUPH6 (ORCPT ); Tue, 21 Mar 2023 11:07:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231305AbjCUPH4 (ORCPT ); Tue, 21 Mar 2023 11:07:56 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC136509AE for ; Tue, 21 Mar 2023 08:07:33 -0700 (PDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 32LEhJoK030431 for ; Tue, 21 Mar 2023 15:07:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : mime-version; s=pp1; bh=qkKNDP+Er/pK+Hl/KcmMIAOm35Mulo/z+wug/iPcEm4=; b=qx7ttqMTBGtG6l4sRO3+zzY8V2Wc2CuFle1OWjBRK/x6/Hss6Y4bZYdOnqWulL38nLHS OYC3/FLIQvmphAjL61l9KNWyj43SiqyMuChZL4I1Uk+WfUV9JONgwxFZbypHis3jzoV7 ZCiRf47+v05UdfaVYK5T4/aqw1s4ee+4ixOJ79IPtC/QqDyqTvcGsKHa37bGdMNovMV5 kOR2YFDl8C/IX0Ukg1CQlE4qe/klG6kILRP4PJWa2jdS0NAiARiU7/U+mMoApIVMff7x ZLxY2LtG4oZPqiT8T7HdfgpSbd43Tdqi002sgG2ykMlohVILDrkVo/cA2HFCfoZLYsIK dA== Received: from ppma01wdc.us.ibm.com (fd.55.37a9.ip4.static.sl-reverse.com [169.55.85.253]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3pfc52n9p5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 21 Mar 2023 15:07:32 +0000 Received: from pps.filterd (ppma01wdc.us.ibm.com [127.0.0.1]) by ppma01wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 32LCSYMm031919 for ; Tue, 21 Mar 2023 15:07:32 GMT Received: from smtprelay05.wdc07v.mail.ibm.com ([9.208.129.117]) by ppma01wdc.us.ibm.com (PPS) with ESMTPS id 3pd4x6u6e3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 21 Mar 2023 15:07:32 +0000 Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay05.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 32LF7UdS42140052 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 21 Mar 2023 15:07:30 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8549F5805B; Tue, 21 Mar 2023 15:07:30 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB6D35804B; Tue, 21 Mar 2023 15:07:29 +0000 (GMT) Received: from li-8d37cfcc-31b9-11b2-a85c-83226d7135c9.ibm.com.com (unknown [9.77.147.181]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 21 Mar 2023 15:07:29 +0000 (GMT) From: Nick Child To: netdev@vger.kernel.org Cc: Nick Child Subject: [PATCH net-next v2 2/2] netdev: Enforce index cap in netdev_get_tx_queue Date: Tue, 21 Mar 2023 10:07:25 -0500 Message-Id: <20230321150725.127229-2-nnac123@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230321150725.127229-1-nnac123@linux.ibm.com> References: <20230321150725.127229-1-nnac123@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: a6eFMBTaou-J-9CTfENp54fGbwqtkgSM X-Proofpoint-ORIG-GUID: a6eFMBTaou-J-9CTfENp54fGbwqtkgSM X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-21_11,2023-03-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 malwarescore=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 spamscore=0 bulkscore=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303150002 definitions=main-2303210118 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org When requesting a TX queue at a given index, warn on out-of-bounds referencing if the index is greater than the allocated number of queues. Specifically, since this function is used heavily in the networking stack use DEBUG_NET_WARN_ON_ONCE to avoid executing a new branch on every packet. Signed-off-by: Nick Child --- Changes since v1 (respond to Jakubs review): - send to net-next instead of net - use DEBUG_NET_WARN_ON_ONCE instead of a conditonal returning 1st queue v1 - https://lore.kernel.org/netdev/20230320214942.38395e6e@kicinski-fedora-PC1C0HJN/ include/linux/netdevice.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 23b0d7eaaadd..838b7310a80b 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2482,6 +2482,7 @@ static inline struct netdev_queue *netdev_get_tx_queue(const struct net_device *dev, unsigned int index) { + DEBUG_NET_WARN_ON_ONCE(index >= dev->num_tx_queues); return &dev->_tx[index]; }