From patchwork Mon Mar 11 16:23:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13589062 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2079.outbound.protection.outlook.com [40.107.237.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0FD4F4AEEF for ; Mon, 11 Mar 2024 16:24:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.79 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174250; cv=fail; b=giAVSVGG0kEXLjsMtoFwAIx1sZi4Fudc28UquFujPvgwwkzbTCTFaG0O8Cx8sWIsrzmIa2h+gQrEHXIYqBlBQGtLeRw9KNEjuwTQYG3gvuyxAAxE/KPtewyF4IX+6h+uu47dqGgc90C0UKWpXcZbiBdUl127Evds7hnDZzUrWoA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174250; c=relaxed/simple; bh=E5cexZB0C+YzeTco2vJBtv9SJP1ya/Frzy7g5Nj5v0c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=seGQdIE/OlwADQPZRtpV952ZQXQZXS7zA7CByddnL1i8W2ncZqHf4wpOlqWic+XVP9HS6pMih4nipONu7uoUgjbxFB+veo66C+elR7MChrgNZLOU4sv/+OQPIxhgHZZcHcUti0DRA9b+cnAkQZLOQ4m877PJWNrdlFzCAIG09Kk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=e9PoV60/; arc=fail smtp.client-ip=40.107.237.79 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="e9PoV60/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IzSt2rFkeFpjsKaXmZ8m6OaC57Pqw5XzuFFBHtjVvxhdNdaP1QmCxcAYm9MTlpM4DTwJttu8wy34nD2XO7iSf0CGr32adKGc+xJwTbWFjH1OMx/3b/Q9jAmZQiWAal2j8n2LNf3ExXKhsobg5jnIpsX/I2HXBVg/bfuLiQLcy1nbvtJjZVOuVT+9iOqMtn77SAzdkUDwW7xtOi98LXziLhKyI3KQ2uBPVbYOU5tvLeCoK4Q7ssnwKbrqY5q71in9Z2pG9PgMOC08lHDhiqk0ZQYx4uPd3P1mfJp83KTONQ7ZQRn35f4camUS8PCuQFMAGs7Ub/U1CrPMA1Vyhme9Bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HV/4rUU4D/DQ5aoxESjWrg4Zzb0FcJaxidPPhg1kF1c=; b=K9Gry+6n1HE0oBF93RinSQPcOnMSzCSTsT30z7PM/XSETnGVrWoUB6e0DMXmG7j20SHjnyYb25mD0HF+balzrrBgmxzPRPNX86WJKFrZrQMJFEGVppzWry2/Y03djGKwYNikXiO22l4VWko2l60EeGk3bbm6h+lv7/QGS2BiDEj5P/py4NrLFeXncCPnX1HQAXCynNS+UGaLdCO6sznxLV6mVm+mioac284fMI5JW9nT3wxSpHNLlTUvw++TFNtKJu6kHptLqr97Woeh9qwW4e2p0csUCYpDzO4nPcN18IAmk8lvDU6tNdWtj/COZzA8tSzg32qnrLQGI65fe7cgbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HV/4rUU4D/DQ5aoxESjWrg4Zzb0FcJaxidPPhg1kF1c=; b=e9PoV60/THl8heXmEopokizcohA9Ck2v2fLvsJORoMN0wupUt2X2jmqdUPMSFaY+TfPJQEz6Qj5Jdx/ON4ldh3g/hEFNQsvO3+G8+hvLgukBTlePbvUWikuHkdnsDJfBiwzqr7po8sWIzv18D8StwvEJzDXhXMqQf5V6uS7RCsiTOsfvSmsnSZhc95UxSMy1xmsO+7PHD6jV7bzUut9hodFnAIRGy/jpKqsdj1sUaVkPdio63bpezL1UZmc46z23MMiDyYYTjF0Cnp2YNpvyFiI1F0UwtAWP82P5IQOLddyiNUrMk53eGsstXGNPZD7FEQrH+MzFmcfLq6GnAJdPhA== Received: from SJ2PR07CA0001.namprd07.prod.outlook.com (2603:10b6:a03:505::11) by LV3PR12MB9214.namprd12.prod.outlook.com (2603:10b6:408:1a4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.35; Mon, 11 Mar 2024 16:24:05 +0000 Received: from SJ1PEPF00001CE8.namprd03.prod.outlook.com (2603:10b6:a03:505:cafe::64) by SJ2PR07CA0001.outlook.office365.com (2603:10b6:a03:505::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36 via Frontend Transport; Mon, 11 Mar 2024 16:24:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ1PEPF00001CE8.mail.protection.outlook.com (10.167.242.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Mon, 11 Mar 2024 16:24:04 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 11 Mar 2024 09:23:48 -0700 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 11 Mar 2024 09:23:45 -0700 From: Ido Schimmel To: CC: , , , , , , Ido Schimmel Subject: [PATCH net-next v2 1/4] nexthop: Only parse NHA_OP_FLAGS for get messages that require it Date: Mon, 11 Mar 2024 18:23:04 +0200 Message-ID: <20240311162307.545385-2-idosch@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162307.545385-1-idosch@nvidia.com> References: <20240311162307.545385-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE8:EE_|LV3PR12MB9214:EE_ X-MS-Office365-Filtering-Correlation-Id: aa6c072e-4f48-41cb-7962-08dc41e7ab88 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V0VR/c6gjS4/MraursVVsqg49NL5UEtgktet/MgMkYr4I7yAI2PlrlBkzgXpuIqEFobV6vYF6WRkjgdKcrZEo+my02HuDLANv3nWEvTqILLYYaMEMBBw1q+vir/7Vzeaxaff6n+PXXVi+WoOaSLoeZw2qbf0q3OY1g7NhOHMHi6wTZU8xe8Zyo0UxVAeb2fsM79/n78Zwlk4xf9alftRyFbfGfjG9V3HYImg0MBpBnLCikAKqudDVXzha2B5FOHkaS8FgUhk7uLiWiM5ZRLcV9kCyQP0Smx04La6toX5Vdb/NoV4rIZq97723garPn4mYYS7lAcO3yyTSUaXI6LsL/BOJZ+fo/ECRJEw9JqW9Yy6m050TnP84FpMz/nMB+V8Q5TSmmLe6DqqAwzimHcI4etQlPLG8srRTGt2KYq8Rp3HCp+wOdM0BEZ2zfuWxwt5OhPu622gkmNGIq81zEPPHVNYH9aGTb7XkGA2DIlGzU97NBYzNLKKPayrKJoMjiJgVbCSAVMRVx+MduanwXkhATsdDvemPtB3S+CIHGvnAUDUD0x6/WvBaQ5Qe1rDnisnHZ5I9tLWIk6vC/JwjJGKRSBVqU63HRMF/PVGDxE+iWkMCMYvK7T7R4oDKVqU69PfQxVqdexKypoxB6zDwf0Ymwlgmjw0k4CKDk+9XY6HxczLEq6XcC1mz3CVWs8DaSTy9uEbP7MkFkGLcrsfCaRFBrLrjw6J8oIgKC4sXcymr1WdWuEdHYX7XgTGBIUkE75v X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(1800799015)(82310400014)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:24:04.9616 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aa6c072e-4f48-41cb-7962-08dc41e7ab88 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9214 X-Patchwork-Delegate: kuba@kernel.org The attribute is parsed into 'op_flags' in nh_valid_get_del_req() which is called from the handlers of three message types: RTM_DELNEXTHOP, RTM_GETNEXTHOPBUCKET and RTM_GETNEXTHOP. The attribute is only used by the latter and rejected by the policies of the other two. Pass 'op_flags' as NULL from the handlers of the other two and only parse the attribute when the argument is not NULL. This is a preparation for a subsequent patch. Signed-off-by: Ido Schimmel Reviewed-by: David Ahern --- Notes: v2: * New patch net/ipv4/nexthop.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 5eb3ba568f4e..03bacf9c0502 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3229,10 +3229,12 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh, return -EINVAL; } - if (tb[NHA_OP_FLAGS]) - *op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); - else - *op_flags = 0; + if (op_flags) { + if (tb[NHA_OP_FLAGS]) + *op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); + else + *op_flags = 0; + } return 0; } @@ -3249,7 +3251,6 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, .portid = NETLINK_CB(skb).portid, }; struct nexthop *nh; - u32 op_flags; int err; u32 id; @@ -3258,7 +3259,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack); + err = nh_valid_get_del_req(nlh, tb, &id, NULL, extack); if (err) return err; @@ -3715,7 +3716,6 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { struct nlattr *tb[NHA_MAX + 1]; - u32 op_flags; int err; err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, @@ -3723,7 +3723,7 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh, if (err < 0) return err; - err = nh_valid_get_del_req(nlh, tb, id, &op_flags, extack); + err = nh_valid_get_del_req(nlh, tb, id, NULL, extack); if (err) return err; From patchwork Mon Mar 11 16:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13589063 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2073.outbound.protection.outlook.com [40.107.95.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC467495CB for ; Mon, 11 Mar 2024 16:24:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174251; cv=fail; b=PmjfFf8UJbOm6XVWoMd++BaU3r3szww0Q8EITheyeNP/YJpRK6dsX9Ly82AS1U3p9QQkXTC506Q2HccKfYNisOIqcB4lkGKBMnUWehNVkR/TfQaYoHv2CVxrfoL2mnYwlhhjs0oddXQ/kIJ1khN+fPgO0cfzudJMu0/g6jFRxS8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174251; c=relaxed/simple; bh=Bt54MjHmwV4FjMTBgq+KezsLmF1a8FhC0ex7gTL9RQ8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lp5w6GE+2v7zl6O25zIB+f6E50BGv79ulAMenTHckTn8NPg+8uhNm5BmN098tmgISn64fwiw9qRpxtHym8cYm2vghg+8ZhdZaxVwrmoHWJ6LCI9Cf0uwn815ymp9TziXwTw5A34nvo/sBOwJ2nHbI85MvfZjtf036MttSDMHbww= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=S3DGDYkP; arc=fail smtp.client-ip=40.107.95.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="S3DGDYkP" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AHi9zlQj/tZjk8nuxrX0P+yAYqOlJadmwMGTDfGSBnWP4A/MYbd4QgEzlCok3SN+u+SIRssWI9WCvXTa1KbTcwR7C7nrb8Gg0qS69Ld8jzNmAphV+JBfvJVBTuYVM39Tv4NeTGo0fM77FZRZ+ZaxWFEszX9I7WzmWpMLdhTBaQ4RJfK14pE2ncmz6nEtyPEO1lw//wlt8ea76zFxTqMurue5ezD6q4LlEZ9t9fDYON28EQ25AdR2OBkZkZE7RGIMLNudsYh8cPznUZ/xz52x3I2DH14rlq4P0z2ApqP0zB3bPNkr/kHASDvD9FAlGLkcK959yMx34eT9unFvgpHQpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=h5jWqU+UjeQKRm9GKPwgtxwGec2O14vQ2HSizMTRnJU=; b=TojG9ndqdK31foKyCh1/r/bJREyH8Gg9CPNj1XsL/GTbpLnqm/P9NyjR8XKZutYK65wZLirzw3Wgrv5gJLNB9pDxsa/kkUcURdBFl67OsdIBI615S/ucHt7Bra0jOJQqzjazaV1k7EsfLM4RmXvvNnAFW+jUSTVsWC3fCOPSmtMyXFSzMUDwBZQiHHG/Vs1a04rIwKZzrtwq6uKgseka8JGctLHR1RQjRBMATTmFL830SL6hiMCB2M4m5vQi5uHV8txM1hFmg1XK+4geFO/cq47pZrMyQIUJAThmJa8X7HveeZ2YjfOg3H4UXxdQZkoZPuCUNBfAOpLePAHH47NxZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=h5jWqU+UjeQKRm9GKPwgtxwGec2O14vQ2HSizMTRnJU=; b=S3DGDYkPNlrAjRoGpVlCMLCxV/5FAW3ZSQAz8jFRqhIvcY0PFVb99UZNCgxXFqFf3pYhXhoqVRyfHNW9S0gs0kDvgF/O1hA/XjzYuw67wyvDCyamkcv1Q+Zy1ST/ACwQ15FBsRBaHCz96dC9SNluSL/hZVuv+Xq8E2NWRAybKPZIhIc8iqJwPVUJ6JJjF8X2OzdVCV3O3mUJFDIc5MFKRP71TKRO8qdMk6gUwGW/QHQMcyHy7Rg80FQ5rDo5KGJ4A9P6+HTwW6REue2cY279w+Jj2a8J2YyNdFyRQWjthE0GKkYj2oXIoWnHPg5IFSxt5x0hSVG0PgV1rO4gX/qEmA== Received: from SJ2PR07CA0018.namprd07.prod.outlook.com (2603:10b6:a03:505::22) by MW5PR12MB5681.namprd12.prod.outlook.com (2603:10b6:303:19e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.35; Mon, 11 Mar 2024 16:24:06 +0000 Received: from SJ1PEPF00001CE8.namprd03.prod.outlook.com (2603:10b6:a03:505:cafe::9b) by SJ2PR07CA0018.outlook.office365.com (2603:10b6:a03:505::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.35 via Frontend Transport; Mon, 11 Mar 2024 16:24:06 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ1PEPF00001CE8.mail.protection.outlook.com (10.167.242.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Mon, 11 Mar 2024 16:24:06 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 11 Mar 2024 09:23:50 -0700 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 11 Mar 2024 09:23:48 -0700 From: Ido Schimmel To: CC: , , , , , , Ido Schimmel Subject: [PATCH net-next v2 2/4] nexthop: Only parse NHA_OP_FLAGS for dump messages that require it Date: Mon, 11 Mar 2024 18:23:05 +0200 Message-ID: <20240311162307.545385-3-idosch@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162307.545385-1-idosch@nvidia.com> References: <20240311162307.545385-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE8:EE_|MW5PR12MB5681:EE_ X-MS-Office365-Filtering-Correlation-Id: 95631b53-bfa9-47cd-e64f-08dc41e7ac57 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DQVcc5TxSMp8UOd6L3EbnnoBFLsZ2DUW7e1KzUy4sMq1K+8nxbv6ZvQAR9xIuezgicAUEnTf9jDdVGormTRGSuW8Gkv7UWJCy3XFCktfWn98lTorq2ATmbqcLWhc7ONHmXBK0JtU5mR3IjeU0s/wi/NOTfdXR6nbV3W6bzw/ED67wm8inay0kXxQj96r72UVphwvWw8q6D41Oy7nAv8XvlhKSd07mx/QhYZqWRhg8hShL8jJBk/SrcbRKnovtjFNDWAbKqKAmsWyk27DXXzvk9kTVufCg7pO+DslySuuWDy2UMvoAJtmYGdNhtAJlGhlZ5IZBgJzSssbkxkR6sG+LjzFjpIG35YVtF52OUQRoIF6REweu3EG9kZfpZH4x2Ffy9oUtPN/yc4e2FKa1gtvlY8gW2ID4Ae3hNSYWOsXODvTROQLKFYBS0WaQKLPI2EBmtP3OHNeHuk1kitvnC5r0BDsjsFjmObGhDIFtKpQwElNqn3SlEMeZpPAiJ64a2c1JDpHMmRv09ipvDdgx953d2c6ZMRFffm2+wg6Csq8OTFVM/doG/KbKf7/zPToY1/xFNTw7/3s1DmgILta8koN1uIRVl7nl6+M6gYTBwR80zgh7w1IoiybXG76gwHbsoCA0KX7H9LfCaaGbP0TleXp2lK5ny8xdTasAGVpFpTXYN77URGY0mo8hTHRRIfOBWjLYeIXp0kT880eTN/WE0x+BwXVjBT6S7tSoU0FfIgfb42KXkxKYnhvshBlF1RNQqz4 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(1800799015)(82310400014)(376005)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:24:06.3054 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 95631b53-bfa9-47cd-e64f-08dc41e7ac57 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR12MB5681 X-Patchwork-Delegate: kuba@kernel.org The attribute is parsed in __nh_valid_dump_req() which is called by the dump handlers of RTM_GETNEXTHOP and RTM_GETNEXTHOPBUCKET although it is only used by the former and rejected by the policy of the latter. Move the parsing to nh_valid_dump_req() which is only called by the dump handler of RTM_GETNEXTHOP. This is a preparation for a subsequent patch. Signed-off-by: Ido Schimmel Reviewed-by: David Ahern --- Notes: v2: * New patch net/ipv4/nexthop.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 03bacf9c0502..573da3660cb3 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3397,11 +3397,6 @@ static int __nh_valid_dump_req(const struct nlmsghdr *nlh, struct nlattr **tb, return -EINVAL; } - if (tb[NHA_OP_FLAGS]) - filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); - else - filter->op_flags = 0; - return 0; } @@ -3417,6 +3412,11 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh, if (err < 0) return err; + if (tb[NHA_OP_FLAGS]) + filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]); + else + filter->op_flags = 0; + return __nh_valid_dump_req(nlh, tb, filter, cb->extack); } From patchwork Mon Mar 11 16:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13589064 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57A374F1E5 for ; Mon, 11 Mar 2024 16:24:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174256; cv=fail; b=FJ8h6NEB3Ef3nqlPUhygn89EGbhYISB6D3YSBwUCmdBA/8uSFcTa/W3AT+WR8sSK7jusd07CBkrOpADUXlXqvTPdtHz+pFntfOaEBRX0rhYVN29B9wDt0WaftSd5JBlZzJJZ6ERFDJ49I7+jUZRJtTRBVmYusVmZqG4T4Oh73Ac= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174256; c=relaxed/simple; bh=bR5REPjw1FjZrdC2h/AfjWvhvyVpjvknj5OV+Jh5w5U=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SW3q7DSQi6zLl1d+41dz3uqmK7QA8FriKDLlyIniMsuTu/oidxCcdvAXNHZVRkxLDSuw6MW+Lfv+FS2YwDiPARNmUyU5+KHa2nQcqYZA2gwIlatQBYBCHNPbaNK6aE6WVXL9R7TmZ+pJRrpcnL60YK0Gr23bsBtCt5oiga5lg9U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=nTlfH6mR; arc=fail smtp.client-ip=40.107.236.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="nTlfH6mR" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a7AF8MPXxRXBEUXb9fdMwadquZhoik/kySe6qXH1deDTQv0qbRnzfNf5Lhtw7ZBtj/rLeFBWBiN9w4Db/3WfMF55URu8YqHXvw7upz45JQplLrhyrUcYglYXPEoXVhlwuqVI8g/Fc4l2CQErfMuSGuyw4vjs1kQ+xGCqI4isodcQxU8f+kMKya/ZNmYjoO7JlKyPaTyIKU/oZbEqUSEz86JrRTZ7Y7u4GvQCZ6It2kcWfTUjiQuHoarw9ipr+jNueUZy/Pwp6UOt9Vde6T4GFmLfqz6874eyb+A0VSyqXS5rcjIj82ZdIPDfca+xek/5vdyThnvzZZWT/lFZCW6eFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xXWSRFjXEDssIRmhqC/MZXA+fWmhyOO66AJI6QyO8i4=; b=WuqY4bEwA77NwCzBwjyGsGF5DXSRHK/z4GUozmOaIRWCMPFoc2hX9wJEfzFOzcQpbsgCoHm7dQMJOHb/jwJGTTz0DoKdMZfW034q8MZ5kUKr6dnwsQpfIDhV+VumRhCjbLfo/oabqPi+aLJPJt0TrrSxPm/tMboYU93wU5OTVDOfWM5Wil0zPg90/fBSvH70+OqSx2Qzm0DP7OOWm8DglXaCs3/lU98kkiciY2agoqkTEmiJWfk7WyqBEX6QuppCMPDBmcXpDvyYnrbKbC7GQJ+QyxYB4IRtyA4nh/Jdl7sA5WoPBkYmAMU2HZKX0ylGZTm026fMrTKYezZ87qbMeg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xXWSRFjXEDssIRmhqC/MZXA+fWmhyOO66AJI6QyO8i4=; b=nTlfH6mReefH4tCksGWun3/LFKGT0jwBqgoAdGVbJPPIvTfrNteD6d7eY4xkKE5B7/NBqSR7f9MiHoo39WcL4hV0jMPyg2C+6CbEMU0zAhLDmgq6UVaX7NhtllEKE7XdhQW1wFTyeV1xPnUO18DklAVAXGGtuMfyKuKenAwCwaKMkM7/W8dQ2KKRU0Ofcgf33orAxx0p5Rjbr3v0fusiWmLhF44SfLFxLqXDa507qRvnlzFHN+HyzJMA1Z2BpcATi4ABOhrTQ2gTMw7Kb0BnWqqDTlctrmMlnM9RTM7z58CrPB7K6MsLBlnvjaYz+fhGrSMiywLqdlX6xbqlX23z1Q== Received: from SJ2PR07CA0021.namprd07.prod.outlook.com (2603:10b6:a03:505::23) by SA1PR12MB7221.namprd12.prod.outlook.com (2603:10b6:806:2bd::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.35; Mon, 11 Mar 2024 16:24:09 +0000 Received: from SJ1PEPF00001CE8.namprd03.prod.outlook.com (2603:10b6:a03:505:cafe::cf) by SJ2PR07CA0021.outlook.office365.com (2603:10b6:a03:505::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.35 via Frontend Transport; Mon, 11 Mar 2024 16:24:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SJ1PEPF00001CE8.mail.protection.outlook.com (10.167.242.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Mon, 11 Mar 2024 16:24:08 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 11 Mar 2024 09:23:53 -0700 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 11 Mar 2024 09:23:50 -0700 From: Ido Schimmel To: CC: , , , , , , Ido Schimmel Subject: [PATCH net-next v2 3/4] nexthop: Fix out-of-bounds access during attribute validation Date: Mon, 11 Mar 2024 18:23:06 +0200 Message-ID: <20240311162307.545385-4-idosch@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162307.545385-1-idosch@nvidia.com> References: <20240311162307.545385-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF00001CE8:EE_|SA1PR12MB7221:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c5fe2f3-d1ed-4ba5-9c61-08dc41e7adb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qWViTuaf0giqRzk8soV0tNKY+kr385525nFz7NzS1uGu92xA1QNojWR29dvYRNKgCs8d77Hv7Gs9rvY3R23SDQCzdsKTi3FcQfp+j2U6HoS3bHUmX29kI+s1bL9gzMfCCAI0+G866Y1jH4GHYjgIbRb2Zmz/K2FnhIxW5JyrzA2MEYlr8bgLimj2XudH752wtBHsl00DMY3v7hbQMWw2K6u4iEE8tiWt8ORCgUFSgUl6PSCwy7iyuX5+XnbvfyZvPxKpXloybvIvlAEQkMr/Z87GTZBdcwHgrDO86eOIA6x9IzTOIaLuV2G3+lGacbCanl5t/wTTs6sMEebTwU/hxsI8sDJLmRZ5LadLV+stfmfwKk0vFaDu/0aKwq0D53zYy3n/53U4Ti8JNiTbbEtNe7b9wKBblbx5eEZ12SazDQRBlvSC9b2IEO40KhWIdKAMOkWno9wkwUs55o6edpqrmemCwjSywVnJvZC3H7EvK8xdojMHqdFR9ruflQ7GBSJYoduiXGiZb43KUB5l9/aBQLSI2d33S06uw4Mzkp5kAe6TTBWArvGXY5StnOOJ5ZlFy3myk/ZkfNB5318S+NRPw7T2NxnBfjxv28moXa4qf9RktzIMPXZtct0XHpYcVRMVeLDBuxlPTqTZLa+LGEExx67dUbbN93zSyQsHTvLof+GKCWGUGeJOBuzhJsNJSZHmcCjjE6BUlrm5tnM0zIw/+vl5e8A44tlmtkuXrwbRcw7qSvDHHX+1ojeiW6lh+KfbyF46xomV5BgP3Ug29tmYWQ== X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(82310400014)(376005)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:24:08.5866 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c5fe2f3-d1ed-4ba5-9c61-08dc41e7adb1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ1PEPF00001CE8.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7221 X-Patchwork-Delegate: kuba@kernel.org Passing a maximum attribute type to nlmsg_parse() that is larger than the size of the passed policy will result in an out-of-bounds access [1] when the attribute type is used as an index into the policy array. Fix by setting the maximum attribute type according to the policy size, as is already done for RTM_NEWNEXTHOP messages. Add a test case that triggers the bug. No regressions in fib nexthops tests: # ./fib_nexthops.sh [...] Tests passed: 236 Tests failed: 0 [1] BUG: KASAN: global-out-of-bounds in __nla_validate_parse+0x1e53/0x2940 Read of size 1 at addr ffffffff99ab4d20 by task ip/610 CPU: 3 PID: 610 Comm: ip Not tainted 6.8.0-rc7-custom-gd435d6e3e161 #9 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014 Call Trace: dump_stack_lvl+0x8f/0xe0 print_report+0xcf/0x670 kasan_report+0xd8/0x110 __nla_validate_parse+0x1e53/0x2940 __nla_parse+0x40/0x50 rtm_del_nexthop+0x1bd/0x400 rtnetlink_rcv_msg+0x3cc/0xf20 netlink_rcv_skb+0x170/0x440 netlink_unicast+0x540/0x820 netlink_sendmsg+0x8d3/0xdb0 ____sys_sendmsg+0x31f/0xa60 ___sys_sendmsg+0x13a/0x1e0 __sys_sendmsg+0x11c/0x1f0 do_syscall_64+0xc5/0x1d0 entry_SYSCALL_64_after_hwframe+0x63/0x6b [...] The buggy address belongs to the variable: rtm_nh_policy_del+0x20/0x40 Fixes: 2118f9390d83 ("net: nexthop: Adjust netlink policy parsing for a new attribute") Reported-by: Eric Dumazet Closes: https://lore.kernel.org/netdev/CANn89i+UNcG0PJMW5X7gOMunF38ryMh=L1aeZUKH3kL4UdUqag@mail.gmail.com/ Reported-by: syzbot+65bb09a7208ce3d4a633@syzkaller.appspotmail.com Closes: https://lore.kernel.org/netdev/00000000000088981b06133bc07b@google.com/ Signed-off-by: Ido Schimmel Reviewed-by: David Ahern --- Notes: v2: * Resize 'tb' using ARRAY_SIZE net/ipv4/nexthop.c | 29 ++++++++++++--------- tools/testing/selftests/net/fib_nexthops.sh | 6 +++++ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 573da3660cb3..0011b0076c5b 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -3243,8 +3243,8 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh, static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_del)]; struct net *net = sock_net(skb->sk); - struct nlattr *tb[NHA_MAX + 1]; struct nl_info nlinfo = { .nlh = nlh, .nl_net = net, @@ -3254,8 +3254,9 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, int err; u32 id; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, - rtm_nh_policy_del, extack); + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_del) - 1, rtm_nh_policy_del, + extack); if (err < 0) return err; @@ -3276,16 +3277,17 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh, struct netlink_ext_ack *extack) { + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)]; struct net *net = sock_net(in_skb->sk); - struct nlattr *tb[NHA_MAX + 1]; struct sk_buff *skb = NULL; struct nexthop *nh; u32 op_flags; int err; u32 id; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, - rtm_nh_policy_get, extack); + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_get) - 1, rtm_nh_policy_get, + extack); if (err < 0) return err; @@ -3404,10 +3406,11 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh, struct nh_dump_filter *filter, struct netlink_callback *cb) { - struct nlattr *tb[NHA_MAX + 1]; + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump)]; int err; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_dump) - 1, rtm_nh_policy_dump, cb->extack); if (err < 0) return err; @@ -3547,10 +3550,11 @@ static int nh_valid_dump_bucket_req(const struct nlmsghdr *nlh, struct netlink_callback *cb) { struct nlattr *res_tb[ARRAY_SIZE(rtm_nh_res_bucket_policy_dump)]; - struct nlattr *tb[NHA_MAX + 1]; + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump_bucket)]; int err; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_dump_bucket) - 1, rtm_nh_policy_dump_bucket, NULL); if (err < 0) return err; @@ -3715,10 +3719,11 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh, u32 *id, u16 *bucket_index, struct netlink_ext_ack *extack) { - struct nlattr *tb[NHA_MAX + 1]; + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get_bucket)]; int err; - err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX, + err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, + ARRAY_SIZE(rtm_nh_policy_get_bucket) - 1, rtm_nh_policy_get_bucket, extack); if (err < 0) return err; diff --git a/tools/testing/selftests/net/fib_nexthops.sh b/tools/testing/selftests/net/fib_nexthops.sh index d5a281aadbac..ac0b2c6a5761 100755 --- a/tools/testing/selftests/net/fib_nexthops.sh +++ b/tools/testing/selftests/net/fib_nexthops.sh @@ -2066,6 +2066,12 @@ basic() run_cmd "$IP nexthop get id 1" log_test $? 2 "Nexthop get on non-existent id" + run_cmd "$IP nexthop del id 1" + log_test $? 2 "Nexthop del with non-existent id" + + run_cmd "$IP nexthop del id 1 group 1/2/3/4/5/6/7/8" + log_test $? 2 "Nexthop del with non-existent id and extra attributes" + # attempt to create nh without a device or gw - fails run_cmd "$IP nexthop add id 1" log_test $? 2 "Nexthop with no device or gateway" From patchwork Mon Mar 11 16:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ido Schimmel X-Patchwork-Id: 13589066 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2073.outbound.protection.outlook.com [40.107.100.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B1054F5EA for ; Mon, 11 Mar 2024 16:24:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.100.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174263; cv=fail; b=BoKtBu3KvjjT6FdbHR77f3AaBaF4E492ld32e25npt3aCHFZzRj5s4gHnvhYvd+P/ando77U2KmgW2tRAG4x3vLmP3pOybsD2ENhdQY/ExFznScH2ly5OBytJoypQXNYhOwHN7anSd4nlpAcFOZoGBwyZYSaOHTXFAppQjC6ncc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710174263; c=relaxed/simple; bh=rHX6p7x4H6ncYycHugaRpeQgR7zEvCiR8xK3LhjQnMg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=m+kJNhYU2altXxx9FGTc3RF02nZ5Bt9eJitrsh5UinHd44V3uHAxNyayvzyONRg2vD8ECbs8h8/BcCP1m348+oiyTgXhBtI5NcNnhaNVvrDQXFr3NIlWgjFy1Cl5X/PDH3g8LuYvnZZ7cPU1MdvdCZzlsTCoHDj7u/u8zuJnhTY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=NswXS5Al; arc=fail smtp.client-ip=40.107.100.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="NswXS5Al" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hbqoURfVhMgzHLQgiSjaBYifrk+INeNe5H6WNex4Xp5QM7HK1ScwzDReZ3i553lr+UhQJbWqiexLN9iarDTm6e8bhnNhpayj8tqNG0cgedvZk5J92X76P6HTJXQEpN74OFxAxb6zF1gql0DWsC1VDT2+XcLhe4Q27Zku0cDMVEqhDp7m+pOIUpBDII8uGRH5Stif3zWN1YSXscVCLPXOe30H2Y9txU6lGJ1KEhM0aut4mo3yuFVAd+EE/Gv91b0Hvu8gWWWSLHroZI5Ah8JTGT3iV/TCiEIyTgm60mQ6Dc9Pv+q+kQSdCrTTzTMWLP3X2qSAQyh4JZvkpLpLQUwzXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=SA69OsRiu9eT95+NDY4+UQ1Rej6hmrl731IUoyUcXB8=; b=IaIbWm/yDUnCxAr6bceGS8UNJ7Q0UkRCc8rCn/j06y4OnMo52wC1kSVE1mkmj5paZkERyatElpZNkyXBd2M61lz6u8Y4FQlVFaL390HdHvR3aNph/5MZNCr+QEkbs4Db1v8eLm2O1Yudo11B39+iCPxz0q/iQw1o67JKR11L23lCIEWyGEc22Yl3m8hhbj/CGOqv2rcrgSArCtPiESQUZZN88kdo8D2I0jUS2pLfpcwJFKX3W9oaYsiLewhlxCHqVj3T4M2dHzgcDQv0tBajPJnNdFshxsezCqP6t+BwwJWIXeRwujAA6Y2bFkbKJ65f8yOoqlA5ZfmqHmXCLwm2HA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SA69OsRiu9eT95+NDY4+UQ1Rej6hmrl731IUoyUcXB8=; b=NswXS5Al7V6VCLn+vNBvZ15wCg7/F7/ENLlMGMhGeDrUeQ2gjihdZbQRkKXSrLgytc+Z/8satEBv1LlKvObpBo4tKGYrWdsCaHRXtLioMBVyzV/sTakIB7boMKy+XRcfYypit/Kur7Q6O8PNM6NlofWXPjTJR8M7r4KGN0Q1F8xP+qXBHAceJsA3R6zlZzvpaDFE9IyQbLiboxhz1ecFPOnpiLzC31KIfkzkP1tmecgerQmHPtjmENK8xda6LkWV7sL7zoPDpSJSDS5yzft+AigO6FsH/eizHl1kJxny2acyT/0WXmBwPVQUCmNOItUsxt9OtweLluDYRAb1iveMfA== Received: from BL1P223CA0023.NAMP223.PROD.OUTLOOK.COM (2603:10b6:208:2c4::28) by CY8PR12MB7100.namprd12.prod.outlook.com (2603:10b6:930:60::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.33; Mon, 11 Mar 2024 16:24:17 +0000 Received: from MN1PEPF0000ECDA.namprd02.prod.outlook.com (2603:10b6:208:2c4:cafe::b1) by BL1P223CA0023.outlook.office365.com (2603:10b6:208:2c4::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.36 via Frontend Transport; Mon, 11 Mar 2024 16:24:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by MN1PEPF0000ECDA.mail.protection.outlook.com (10.167.242.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.12 via Frontend Transport; Mon, 11 Mar 2024 16:24:17 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Mon, 11 Mar 2024 09:23:56 -0700 Received: from dev-r-vrt-155.mtr.labs.mlnx (10.126.230.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.12; Mon, 11 Mar 2024 09:23:53 -0700 From: Ido Schimmel To: CC: , , , , , , Ido Schimmel Subject: [PATCH net-next v2 4/4] nexthop: Fix splat with CONFIG_DEBUG_PREEMPT=y Date: Mon, 11 Mar 2024 18:23:07 +0200 Message-ID: <20240311162307.545385-5-idosch@nvidia.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240311162307.545385-1-idosch@nvidia.com> References: <20240311162307.545385-1-idosch@nvidia.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN1PEPF0000ECDA:EE_|CY8PR12MB7100:EE_ X-MS-Office365-Filtering-Correlation-Id: 69e7b6ba-de1e-447a-796a-08dc41e7b2c1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o+ubLeRlLFx/fwrNCP8JCU+HiOkhfrdcp+HK7YWOMHGPqMqSafxZMq72kiv/v5SlNY6LYCHAzBw9RARosYsHlf5+smRctuZq44Pgi7nhzvw+shVUNBZFxcCiZAPMVxBe+MZO74iYpGELs2YgMdKPtEevghzctt23rUm2i3hCfD+fLUAEf6wWJb66CUU76yxn5MHp3sPfC/NuCvV617SkvB1KKC6jX+GI0MwBlPU1ndukQ/bVTGbGaqyLUvqzs5rxNtCmeKwMpQR9DVIDct/QZk2QgiiEPWj7zHfdo/+carDpfSjGf+0X9V7jMEtGF8q1isNz5W0CTPUTbflUR+N/zZczx4Di7R7Nr0lvvxBk8o4WhNbvH2zNjOT4GfXfJlpewW+UDJz7bA8cYOCMH/dNloSpaOuh/jd8keeUK9GDf3mnhwbzybOmcg2jEIlrCvt7ADpJCxCf5gTqPaFTYDkQ5zyhYEjAKcw0oibScZQekzhDIO0beWvfMr/qiLWfJtYiGq5T0q2121IXDLvDy8Q78FpWc/uHGtH5SBk4QzNSdDeBHdISu+OL9Wdid0e/J3rl7AmTj6jecg38l+Yx8KAOmg4mYPh/Okk7+AbOVtKVtQRdzzbxBp1tnRFmfZ03yYVGghOZcToFHPyFrLQDr/GFqWxf0+buAasP3i6JE7nGgi1JTFAH3ETivMmI48LBNYi04tij2qVWVP5G7T70aldN4J6iFko0FgeoPYRKoK7lrEG9RZp6E0OREUy/W6kpN91X X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(376005)(82310400014)(1800799015)(36860700004);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2024 16:24:17.0011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 69e7b6ba-de1e-447a-796a-08dc41e7b2c1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: MN1PEPF0000ECDA.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7100 X-Patchwork-Delegate: kuba@kernel.org Locally generated packets can increment the new nexthop statistics from process context, resulting in the following splat [1] due to preemption being enabled. Fix by using get_cpu_ptr() / put_cpu_ptr() which will which take care of disabling / enabling preemption. BUG: using smp_processor_id() in preemptible [00000000] code: ping/949 caller is nexthop_select_path+0xcf8/0x1e30 CPU: 12 PID: 949 Comm: ping Not tainted 6.8.0-rc7-custom-gcb450f605fae #11 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014 Call Trace: dump_stack_lvl+0xbd/0xe0 check_preemption_disabled+0xce/0xe0 nexthop_select_path+0xcf8/0x1e30 fib_select_multipath+0x865/0x18b0 fib_select_path+0x311/0x1160 ip_route_output_key_hash_rcu+0xe54/0x2720 ip_route_output_key_hash+0x193/0x380 ip_route_output_flow+0x25/0x130 raw_sendmsg+0xbab/0x34a0 inet_sendmsg+0xa2/0xe0 __sys_sendto+0x2ad/0x430 __x64_sys_sendto+0xe5/0x1c0 do_syscall_64+0xc5/0x1d0 entry_SYSCALL_64_after_hwframe+0x63/0x6b [...] Fixes: f4676ea74b85 ("net: nexthop: Add nexthop group entry stats") Signed-off-by: Ido Schimmel Reviewed-by: David Ahern --- net/ipv4/nexthop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index 0011b0076c5b..aaf940d15afe 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -673,10 +673,11 @@ static void nh_grp_entry_stats_inc(struct nh_grp_entry *nhge) { struct nh_grp_entry_stats *cpu_stats; - cpu_stats = this_cpu_ptr(nhge->stats); + cpu_stats = get_cpu_ptr(nhge->stats); u64_stats_update_begin(&cpu_stats->syncp); u64_stats_inc(&cpu_stats->packets); u64_stats_update_end(&cpu_stats->syncp); + put_cpu_ptr(cpu_stats); } static void nh_grp_entry_stats_read(struct nh_grp_entry *nhge,