From nobody Tue Nov 26 14:30:20 2024 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2077.outbound.protection.outlook.com [40.107.241.77]) (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 551761E0DE5; Thu, 17 Oct 2024 17:42:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729186943; cv=fail; b=T5GWVdVx8qH4DNUVZipAmQPJadZh4hGeg8mUq4Kr6wfPR/bYwzYi01/FLKtuAhw/H97ZAo/MwjbTqjEch/dvKOCFrBUVHJre+LOYXMzQhJrfpzr8Mrea/7UksEzzV5wH6aH+PXYp8J1Gfed+wUHx7dPo2/hJiLQSLi5RflvJ3Ss= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729186943; c=relaxed/simple; bh=oagg/QKxHvgPVqHwmV1uYjqfAE2MWo1gIE8DBlOU7aE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=gMZe3g9ObdGeTl9vN7l+HMdnkRDN/4XtDbcJROy1+Zk3iYScVCFuvXdPk6JYh5lVCOM9wFgHEk1NxxAf2EAfkHHuV8ojHu97n9BAGGNRLjmJKk19flgbyH24opBNokK79uDGWkQviQNO9kERJqlzKJY15kO7Z387ckQwa6oDwyU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia.com; spf=fail smtp.mailfrom=nokia.com; dkim=pass (2048-bit key) header.d=nokia.com header.i=@nokia.com header.b=fOlz/VKw; arc=fail smtp.client-ip=40.107.241.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nokia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nokia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nokia.com header.i=@nokia.com header.b="fOlz/VKw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XrwjqQjS1HiwcnH5QV+quMK1N+YgvpcsLsUAMxKLisgqwJFedmQQA2L1CNdRFJSAD/YJtjpoblqbHTBs54EpWblCXPubrJJ/GEmHDyy+79gexBbXcpsWCXLjGkjBbZ/k8s+DVG/0Vf9nms/bxrX/YfEfrTpfQPykt3DYYeD7FkKksPXg4mtkFCfE3V1LK0h7vFURs8aqZEsYTby3CePmfhDGnlTkvCdUWYROFlyHXGEV218O4VjcC4CMNZQMC3sgP+2fuPL+yASeH4PDhxi9XdcnHd1+uPhTS61VirBVGMGIf3KObaXKFobkKDix/apsa2ZANOTO+1GtA7833AnD+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=+2XYd+ef4QXPkhNAZAaNzaPV6vCmrjU3M3yiht1TQP4=; b=pQyMHn2X+cVH83v+clfwac7tzLX83Kf2kCUSGLbxmWtAEjkto3n/TMITiIb/+ofu9A4m1VJ8JVgkOswlM9/BsUUCq9vkyohwqYr+CulV636hZuTFw8KG3dPceHsyzUde6+brV0qr0D9f6ZHd8oX/TRDM14h+V8jbjQotujwOO9OP7dRRAT2iQoHfrAqpA5sxD4W5Mh7nVAVPewiZb3ZDSb8DfLRNdYaML6YHPZhvkpVcR36kSjpjiizDi/xzjzbuTZEygWhWt5Y6vF89aQhBCSeLxnDBdFrqTLGxdvtmI+08yvx6FzPe/izNvRh6R6GDRfgzmawLFczv07VX5RK6bA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nokia.com; dmarc=pass action=none header.from=nokia.com; dkim=pass header.d=nokia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nokia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+2XYd+ef4QXPkhNAZAaNzaPV6vCmrjU3M3yiht1TQP4=; b=fOlz/VKwe11/FbbL6iSn2P21kSHI7LdgI3Di1ybufPxa7Rps1ff3L3X9VT8Ev7MCKuq4tE1ouWwgH2m1CZy5w3FYAN9pidiS3Xyqut8bO3oDqXAXj+DOUSJE3TwlqJ81nM8gKpw9CbwBGYYb6WxG+dY1ebCg8eCvrNTPzlSOl+SX2QwW9Nqe63GNleKxVcdSZruWjFosHrFanbbgq//Nlxt4Vg7S0xp3dULw53Y/w+Ip6/0wQM2UbXs6AeEvFQiaxkPBfVxG7s+9jW08wtQ7GtFC0fIGIZJsCfxztagnRHR4Q02mJuW0/N2xSz26MxygBm97XShxQ0PMpoHqJQwBUw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nokia.com; Received: from PAWPR07MB9688.eurprd07.prod.outlook.com (2603:10a6:102:383::17) by GV2PR07MB9009.eurprd07.prod.outlook.com (2603:10a6:150:b1::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.19; Thu, 17 Oct 2024 17:42:01 +0000 Received: from PAWPR07MB9688.eurprd07.prod.outlook.com ([fe80::6b9d:9c50:8fe6:b8c5]) by PAWPR07MB9688.eurprd07.prod.outlook.com ([fe80::6b9d:9c50:8fe6:b8c5%4]) with mapi id 15.20.8069.018; Thu, 17 Oct 2024 17:42:01 +0000 From: Stefan Wiehler To: "David S . Miller" , David Ahern , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Stefan Wiehler Subject: [PATCH net v6 07/10] ip6mr: Lock RCU before ip6mr_get_table() call in ip6_mroute_setsockopt() Date: Thu, 17 Oct 2024 19:37:49 +0200 Message-ID: <20241017174109.85717-8-stefan.wiehler@nokia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241017174109.85717-1-stefan.wiehler@nokia.com> References: <20241017174109.85717-1-stefan.wiehler@nokia.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FR0P281CA0197.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ad::20) To PAWPR07MB9688.eurprd07.prod.outlook.com (2603:10a6:102:383::17) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAWPR07MB9688:EE_|GV2PR07MB9009:EE_ X-MS-Office365-Filtering-Correlation-Id: 8b78e508-c36c-4788-42d7-08dceed2f735 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?N1+lTCVvyHZK0ugfchn6UWlWllz0cDTK74Rr7Gsjv0PkdXyccUR0z9snmwtA?= =?us-ascii?Q?xM+WARMColTa4Ot/ktG3G8p/WCGop9YAl6haqce29aBnbETJIn3c5AMzBvyn?= =?us-ascii?Q?2CDITNWXPi5gmfGJte/1iIob1PIoid+bHCGUrnGKBp+9OBDq2CY7804zjGW4?= =?us-ascii?Q?fYoe0QUi+UAq8tjurkosMoabmxEfK/ZZPJWFxjRwdV0GcszGbK7Eo5eGS4HD?= =?us-ascii?Q?4lIFRdINsUmNKF6c4tpnB/5doO0KQ7mRf6OJsl/iVBGxnZ1IMS4nqFlHrHDo?= =?us-ascii?Q?PZfTvgSdO4A4HrN2cNQ6f/c/fPv2gqpvyFgnMiUv53fKctC8Zs0flkVJt+bb?= =?us-ascii?Q?g/QV/otjEhbIj0JWe5urqubO19wZfeOclO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B7+f1JlXVxwSmDWhF+ZU2gUFCWKaWArzEH8arnhn8ppS+Z2yIONeP//l+?= =?us-ascii?Q?ZkiprwMSfB5lEDakz4eKtrnDAIRCq85FoEzGZRwX0utk2685R2jdiXLecc+3?= =?us-ascii?Q?U1tJIWA=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAWPR07MB9688.eurprd07.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?tS/ZARH1LtQ8WwVnnuy9yJfEUtfrxaFKy5KJxhcN2tRhGv+bCBvYqanoT4ju?= =?us-ascii?Q?3Y7rt7vtb2QW5mIY2aJ9L0iPj3nTsQ6St3K0NxmpkSjs2m3tHlGHf4aPEF28?= =?us-ascii?Q?hmZbo4PqVpz+U3i/y3bScrZ65JZOYMbH4u8q/niXLqpjtTEyF4N30mgxHhl9?= =?us-ascii?Q?1yO7sAMWWM3nRmiTg4sLpY1fwM271EGLYGXcmzwixIrqiaAEar7MrV06LUOy?= =?us-ascii?Q?YhstMpUkb1vW8b5Wz58G9b/LH8pR42wawXzl2bGJindjVU6j2jvNEfY2mYkb?= =?us-ascii?Q?igK43Pc4Jd9/Mup1Fi+nXnjnaekiGizZakrNYp6IqEg1faOvQE3sZvkZ7g0j?= =?us-ascii?Q?C9Zzpf4fJLtoRZRgvR/CgNEVgXQmfzYugOALqI4YyexdAuDdziy6Nfa0vKnu?= =?us-ascii?Q?eG9Vz82hP4gEwhbBukVP12eL439oNRwsOMThUN+Rme+aQek2evk32HRLlLsJ?= =?us-ascii?Q?hzGLHMCQRGJ+jUNRASl+Kdun5YsQsARgx/0GYyLPggwCq15aVlpWEXuP3mPq?= =?us-ascii?Q?bmL+ptb322/QMfZVTJhZpTPg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52E5p?= =?us-ascii?Q?+bK3P5HzoJhGdK5P/VfS441V7JMBjLj60ha6yKapPMloFRgF4h/dLcBQ43Da?= =?us-ascii?Q?VIC0Y0qELbtltSkXXmQbgPohAvrhzZwtwBMPmtuLOfW75gVzyYq8BS3FsKTD?= =?us-ascii?Q?nE2Mqa1LRi9mNcP46zMs+pPHdqZbU0jAJM/0seLQtKbjaeOtzwC5FrVXsjO9?= =?us-ascii?Q?Xw=3D=3D?= X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8b78e508-c36c-4788-42d7-08dceed2f735 X-MS-Exchange-CrossTenant-AuthSource: PAWPR07MB9688.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2024 17:41:43.8603 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 5d471751-9675-428d-917b-70f44f9630b0 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y73rTUYzb7mln5O4ZfC54Xkt6PZ+vfUfXlyAtNlqa3/tyuS5pzNJA/21y9cuZJ/qI4+MeAyFwwbb7LapRSVl1W/JWbDgrTp2xor9xYOzfzc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR07MB9009 Content-Type: text/plain; charset="utf-8" When IPV6_MROUTE_MULTIPLE_TABLES is enabled, multicast routing tables must be read under RCU or RTNL lock. Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables") Signed-off-by: Stefan Wiehler --- net/ipv6/ip6mr.c | 165 +++++++++++++++++++++++++++-------------------- 1 file changed, 95 insertions(+), 70 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 90d0f09cdd4e..4726b9e156c7 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1667,7 +1667,7 @@ EXPORT_SYMBOL(mroute6_is_socket); int ip6_mroute_setsockopt(struct sock *sk, int optname, sockptr_t optval, unsigned int optlen) { - int ret, parent =3D 0; + int ret, flags, v, parent =3D 0; struct mif6ctl vif; struct mf6cctl mfc; mifi_t mifi; @@ -1678,48 +1678,103 @@ int ip6_mroute_setsockopt(struct sock *sk, int opt= name, sockptr_t optval, inet_sk(sk)->inet_num !=3D IPPROTO_ICMPV6) return -EOPNOTSUPP; =20 + switch (optname) { + case MRT6_ADD_MIF: + if (optlen < sizeof(vif)) + return -EINVAL; + if (copy_from_sockptr(&vif, optval, sizeof(vif))) + return -EFAULT; + break; + + case MRT6_DEL_MIF: + if (optlen < sizeof(mifi_t)) + return -EINVAL; + if (copy_from_sockptr(&mifi, optval, sizeof(mifi_t))) + return -EFAULT; + break; + + case MRT6_ADD_MFC: + case MRT6_DEL_MFC: + case MRT6_ADD_MFC_PROXY: + case MRT6_DEL_MFC_PROXY: + if (optlen < sizeof(mfc)) + return -EINVAL; + if (copy_from_sockptr(&mfc, optval, sizeof(mfc))) + return -EFAULT; + break; + + case MRT6_FLUSH: + if (optlen !=3D sizeof(flags)) + return -EINVAL; + if (copy_from_sockptr(&flags, optval, sizeof(flags))) + return -EFAULT; + break; + + case MRT6_ASSERT: +#ifdef CONFIG_IPV6_PIMSM_V2 + case MRT6_PIM: +#endif +#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES + case MRT6_TABLE: +#endif + if (optlen !=3D sizeof(v)) + return -EINVAL; + if (copy_from_sockptr(&v, optval, sizeof(v))) + return -EFAULT; + break; + /* + * Spurious command, or MRT6_VERSION which you cannot + * set. + */ + default: + return -ENOPROTOOPT; + } + + rcu_read_lock(); mrt =3D ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); - if (!mrt) - return -ENOENT; + if (!mrt) { + ret =3D -ENOENT; + goto out; + } =20 if (optname !=3D MRT6_INIT) { if (sk !=3D rcu_access_pointer(mrt->mroute_sk) && - !ns_capable(net->user_ns, CAP_NET_ADMIN)) - return -EACCES; + !ns_capable(net->user_ns, CAP_NET_ADMIN)) { + ret =3D -EACCES; + goto out; + } } =20 switch (optname) { case MRT6_INIT: - if (optlen < sizeof(int)) - return -EINVAL; + if (optlen < sizeof(int)) { + ret =3D -EINVAL; + goto out; + } =20 - return ip6mr_sk_init(mrt, sk); + ret =3D ip6mr_sk_init(mrt, sk); + goto out; =20 case MRT6_DONE: - return ip6mr_sk_done(sk); + ret =3D ip6mr_sk_done(sk); + goto out; =20 case MRT6_ADD_MIF: - if (optlen < sizeof(vif)) - return -EINVAL; - if (copy_from_sockptr(&vif, optval, sizeof(vif))) - return -EFAULT; - if (vif.mif6c_mifi >=3D MAXMIFS) - return -ENFILE; + if (vif.mif6c_mifi >=3D MAXMIFS) { + ret =3D -ENFILE; + goto out; + } rtnl_lock(); ret =3D mif6_add(net, mrt, &vif, sk =3D=3D rtnl_dereference(mrt->mroute_sk)); rtnl_unlock(); - return ret; + goto out; =20 case MRT6_DEL_MIF: - if (optlen < sizeof(mifi_t)) - return -EINVAL; - if (copy_from_sockptr(&mifi, optval, sizeof(mifi_t))) - return -EFAULT; rtnl_lock(); ret =3D mif6_delete(mrt, mifi, 0, NULL); rtnl_unlock(); - return ret; + goto out; =20 /* * Manipulate the forwarding caches. These live @@ -1731,10 +1786,6 @@ int ip6_mroute_setsockopt(struct sock *sk, int optna= me, sockptr_t optval, fallthrough; case MRT6_ADD_MFC_PROXY: case MRT6_DEL_MFC_PROXY: - if (optlen < sizeof(mfc)) - return -EINVAL; - if (copy_from_sockptr(&mfc, optval, sizeof(mfc))) - return -EFAULT; if (parent =3D=3D 0) parent =3D mfc.mf6cc_parent; rtnl_lock(); @@ -1746,47 +1797,27 @@ int ip6_mroute_setsockopt(struct sock *sk, int optn= ame, sockptr_t optval, rtnl_dereference(mrt->mroute_sk), parent); rtnl_unlock(); - return ret; + goto out; =20 case MRT6_FLUSH: - { - int flags; - - if (optlen !=3D sizeof(flags)) - return -EINVAL; - if (copy_from_sockptr(&flags, optval, sizeof(flags))) - return -EFAULT; rtnl_lock(); mroute_clean_tables(mrt, flags); rtnl_unlock(); - return 0; - } + ret =3D 0; + goto out; =20 /* * Control PIM assert (to activate pim will activate assert) */ case MRT6_ASSERT: - { - int v; - - if (optlen !=3D sizeof(v)) - return -EINVAL; - if (copy_from_sockptr(&v, optval, sizeof(v))) - return -EFAULT; mrt->mroute_do_assert =3D v; - return 0; - } + ret =3D 0; + goto out; =20 #ifdef CONFIG_IPV6_PIMSM_V2 case MRT6_PIM: { bool do_wrmifwhole; - int v; - - if (optlen !=3D sizeof(v)) - return -EINVAL; - if (copy_from_sockptr(&v, optval, sizeof(v))) - return -EFAULT; =20 do_wrmifwhole =3D (v =3D=3D MRT6MSG_WRMIFWHOLE); v =3D !!v; @@ -1798,24 +1829,21 @@ int ip6_mroute_setsockopt(struct sock *sk, int optn= ame, sockptr_t optval, mrt->mroute_do_wrvifwhole =3D do_wrmifwhole; } rtnl_unlock(); - return ret; + goto out; } =20 #endif #ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES case MRT6_TABLE: - { - u32 v; - - if (optlen !=3D sizeof(u32)) - return -EINVAL; - if (copy_from_sockptr(&v, optval, sizeof(v))) - return -EFAULT; /* "pim6reg%u" should not exceed 16 bytes (IFNAMSIZ) */ - if (v !=3D RT_TABLE_DEFAULT && v >=3D 100000000) - return -EINVAL; - if (sk =3D=3D rcu_access_pointer(mrt->mroute_sk)) - return -EBUSY; + if (v !=3D RT_TABLE_DEFAULT && v >=3D 100000000) { + ret =3D -EINVAL; + goto out; + } + if (sk =3D=3D rcu_access_pointer(mrt->mroute_sk)) { + ret =3D -EBUSY; + goto out; + } =20 rtnl_lock(); ret =3D 0; @@ -1825,16 +1853,13 @@ int ip6_mroute_setsockopt(struct sock *sk, int optn= ame, sockptr_t optval, else raw6_sk(sk)->ip6mr_table =3D v; rtnl_unlock(); - return ret; - } + goto out; #endif - /* - * Spurious command, or MRT6_VERSION which you cannot - * set. - */ - default: - return -ENOPROTOOPT; } + +out: + rcu_read_unlock(); + return ret; } =20 /* --=20 2.42.0