From patchwork Thu Oct 10 09:07:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wiehler X-Patchwork-Id: 13829827 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2082.outbound.protection.outlook.com [40.107.241.82]) (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 7173AB66C; Thu, 10 Oct 2024 09:11:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551485; cv=fail; b=WEeU7TRIlMdEQPSeuDnWcKyxjqng3OWNoJuU/UFewYpLtd4FQvtYLmzvpvtpE5GsGhREiatJKVIVAolDImTpN+fOhXmnA/e0lZzhOEvjJk/d7mi+rYECpmGSDvefAQxzyAS3QrlLP+28sCyNBnPP0HpXlbMEE2eQxA8+/Wq5myk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551485; c=relaxed/simple; bh=nWBwAjmtWrHQjezkX8yKHU4qGSx4T2X1YXeCXeBjqkY=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=ULHPRaEpleQQt+4imbTXDirGicfTCiEzbfpX6q1klerjOBlFZtZjLDAF8W0ndNvbVl7KsMl0ndcYouM/BGCvzsKGMJJLJlnPUCBMylDyUt0qvBxBSAz2hcsZCO/ZRQDxCv9ZCeOuHXJk/VmxezgEsLeBwJEr4YgPkVuPEGQJURw= 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=EexO/Y78; arc=fail smtp.client-ip=40.107.241.82 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="EexO/Y78" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=iIAhLY5J9ylt99H6RrV0esJ7WGQehdyqLlcS+6O2L9I8yZrWJBQWAWQq9ScjhML5ZxmmLt5ycKrrohD1EGbT04sliwnzWx7F5fyTya0ryfuJILMi23WnfCCuOVW2UJRBHWDrknRZzkQY10NE02l7qYcGmxwtf0OQo1/Er5Y/PCwchK121YnOEkiP7K77HyxJ4Tu5t9V62cdi/nCHxGRx0Td8VaND718+YBwkoN3x0g6m8208QsIojpn3nIo/F6xggzVKkUJVugu4apCik1FlWS913rXVqWPu19TFbLy1zz7JCCy6F7rCsaPEvQjilqe9CP/x23x6EavtUAHWNaH5ag== 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=mL5Ywg/26+01JEogw3M4dGMw5q8T9FaP1kRzVv0U74U=; b=KonCt8ZNyWXs8phyVgb61Yjns95B62HHfUnQTO1RBsUK02dMWLYtubtOWjqmAO8/G/u3jA3h/gKg2kIxfEUu2WVvymwK//S80LbT8yeQopWwqYc5uYF6Rjbnrvbs4/jH+hQ+xzs+Efead9Q80TVwm+HI/9IRUhUAnSEkBB4t3/ba8+KBIjTnQUXytFRpcNqjzNcFRxboJx6tTn0OmoCPxwuduKRi/J5y4OmgwnMIACaBMPGJILkHl2baVW26fcFbQODYGdrvuHE5t7HXahUNQ7jX0PBJPQqbF6TqyVgxoPBHnCKClSjOGAw2XI10x87YuDtoJ2D/xWQqOC6b4tPwqQ== 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=mL5Ywg/26+01JEogw3M4dGMw5q8T9FaP1kRzVv0U74U=; b=EexO/Y784lkjYDQuYHiATi6FHJUBJ7yP5WjaxgqXKhF0xSdvF+iHc8sc0OouqLEc+Kaa4cJtb+bsLRmRH9mU4FZHdvmbyFlRoctSn7319mRvkYserSF72pw2JDTUc7CETkuTvrp5K+0zvalXv7pkMi/4M6E6dDzd570NN53aiB6NwVwwVozzj+s4U1adSNiRx4jqT6lWySueqEH11hC93lN4aAMi5mfACLIV42zU34W2rkNJA/jjjSDPzxToj/yxKmUkVB3IU5p8e6Dc0WhjtkB3CQittTwmKdGXw03odGkI4N2pcmtANNjYV8NfinFRQq89IcaB3aPlEPkYh0mx7A== 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 DB9PR07MB9768.eurprd07.prod.outlook.com (2603:10a6:10:4c2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Thu, 10 Oct 2024 09:11:18 +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.8048.013; Thu, 10 Oct 2024 09:11:18 +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 v3 1/4] ip6mr: Lock RCU before ip6mr_get_table() call in ip6mr_vif_seq_start() Date: Thu, 10 Oct 2024 11:07:39 +0200 Message-ID: <20241010090741.1980100-2-stefan.wiehler@nokia.com> X-Mailer: git-send-email 2.42.0 X-ClientProxiedBy: FR4P281CA0242.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f5::20) To PAWPR07MB9688.eurprd07.prod.outlook.com (2603:10a6:102:383::17) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAWPR07MB9688:EE_|DB9PR07MB9768:EE_ X-MS-Office365-Filtering-Correlation-Id: cc464372-9855-49a2-8449-08dce90b8038 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: QQG99HxiMSCTT0JKuM9R6ghW8crUTWL57ug9x3oM3j4jhFJNde1AWZ9w6WTNytY8fxZpDPPyXeNzuTaP3UWLfjos+6UDOw/aLH7yF+py4OKRelNUvcr7XRDxvOGxPtZFll+UyQdsALVXub3kbqHFqPLCLRgGIOm+Vkfanyji/wd8Kifrub707Ep5VP9aaIZUmc8vWrCairkLoHVAJzLM2Op8RO00hiBkxpec+r61Ez1ZBuKTvIuNHxNn5nZsmj6svm3ii+JIKE6sixLCt+LDofBMt3hH+bBhFIq4YZKJokt1+6vaUhP/ii1GD0bhMAu1pQkNbB9qExI8yoRbRfXrfUsMhe8wwTytzS9wOpWYNTom+s8wNM4Kl4r1syNoWaJKbMUx5s+Nj6kd8WJmXXOUzqwpx+NSRnTXV20uBwy7DxCdF2CwE808pMYcRtzk2GY0FSHSpv7anzwEnR7A2QfYdZx3yf1/Bv0KFKZ5GOUCC4jsKKSVtsp7CADMsuyjkOKDaJrC5so9vaPAIBa8Jh9qGExk4LT2R1rpMBMLZRax+yfly46M2kN8uCas6xY0nQb9C1hFENxCX+44hI5jhxoJZYaZuH8MCqFIT625EsSwQaukqjNR3qKXg5Cso2x32q7ivNI1KfaCBGMkJt5CASyL+QJ7Ro3w2xWTUR25uykeXyHV1aRuMgkNpn4MP5eC8DVSlpOSgv+Z6d4OzCEH5dIYqt0Ex4xonQV6tqnklycLs3kg1ehMSfrQCnWAlMb/oPN1Nex3mMmR7r1hR1XezgXpz/kDTcFArzljrVo3kbjb9XUzHCJReym6lDBVElxfjXXTXu9GFPvVWxOvJzkta/KBmpRRImHDTMhhu/er8Uz4Jz4wykI8c9Sa53vwBicljvYVqq9U5di/pPplgKk4gXDR07EPCQ6vdepSAvzKFrIZWLJn1Kk1hi+xD+sMX8qmul9z7uLz3q6FF29njcemMi9urq+B1BZ+xxej48BQLL2wvYvz9AnsRErIXLBBT3LH23evYFIIpXwCD5dmBm4I6NCLh72uNZzgEB4BLRddJ92pK9wGMoAfXubmgmmnL1UFE4iIfwqRM6dk2Y8k+fbweax1Dtl1BJr2mYYnwWTxbXvpqmk4yRjOmU6jjoEA59czKnV4ezcvfs89cC+Jhz5HOxsrh3JD2BcG/akF5fPPdi7JAZtPWd9uL2q7supoQLsIfIiCos3hjVV933kOD0TcvjCvouEUFWQMufUrr8//njf4Ti05nArQMjEH3NtkU3yAvBhB6deehyRkENhc375299xuzmrNkSCVMBGuvhCa7dyLm55EPFhc8PXKKi4WuBtfLifEUSSZgbQKdjbb+kO0ooSp5w== 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)(376014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cKc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zxV7owRJsqD8/lKNqbqtCKAGnfGKmmE+fibt8pVsUG+N79IqPU9Fh3lhATdR/Eqg9Soe6SYnBQ9rxidc7Gv5olunWmWENNohnGvygEVcJsBmd/LtyFDt0WQRO+1VnXFEQQtSqiHUFWiyBKRT+uHv619b5X6Nu4D7XWxMO9GsX9/HYtt2OrHT0yzsFI+ZvuMA9SCkLMJZMQOcG9RDNiuGMhLw0dYjPCQZJx3f37n1yIHZj1udAGUMtGeJaF+vstG/gfAM17iySBPeUxsqKFxmr1e2ryHA2xe/7igtRYOoX6oO2UNbEqTDV/LsvCSJjsCQlETL7p1q0ZhPw8gsJBc5OPVAwuzkgbYXbsHhdA5JJFRPTWZev3OP6hq/QL48trw/mgypUYJeDj5olgqNKbwVvsnn4xV9CsF8sMkI+3gsT1sYw89jTF6r9e9g6ezIMesMdEsGfth3Z7PRQvSW1NMzpq2eXZUiRak5CDLC08jpnpku0nyAz7dyubsAEp2xztdvlj8GACySvI9E52ZpqoAQ== X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc464372-9855-49a2-8449-08dce90b8038 X-MS-Exchange-CrossTenant-AuthSource: PAWPR07MB9688.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 09:11:18.5935 (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: 6ljRDu+njxpH4Acl5TQiJgZCEUVemP4bfc0syGDqn9ObNsaYyZw8vh7ebe0beRW96wxjTHVS1+yyfBuvlnqC9fiuaLJ4VQfzgWbE44wYg5c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB9768 X-Patchwork-Delegate: kuba@kernel.org When IPV6_MROUTE_MULTIPLE_TABLES is enabled, calls to ip6mr_get_table() must be done under RCU or RTNL lock. Signed-off-by: Stefan Wiehler Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables") Reviewed-by: Eric Dumazet --- v3: - split into separate patches v2: https://patchwork.kernel.org/project/netdevbpf/patch/20241001100119.230711-2-stefan.wiehler@nokia.com/ - rebase on top of net tree - add Fixes tag - refactor out paths v1: https://patchwork.kernel.org/project/netdevbpf/patch/20240605195355.363936-1-oss@malat.biz/ --- net/ipv6/ip6mr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 2ce4ae0d8dc3..268e77196753 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -411,13 +411,13 @@ static void *ip6mr_vif_seq_start(struct seq_file *seq, loff_t *pos) struct net *net = seq_file_net(seq); struct mr_table *mrt; + rcu_read_lock(); mrt = ip6mr_get_table(net, RT6_TABLE_DFLT); if (!mrt) return ERR_PTR(-ENOENT); iter->mrt = mrt; - rcu_read_lock(); return mr_vif_seq_start(seq, pos); } From patchwork Thu Oct 10 09:07:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wiehler X-Patchwork-Id: 13829828 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2055.outbound.protection.outlook.com [40.107.249.55]) (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 9E9FE1BD4FD; Thu, 10 Oct 2024 09:11:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551512; cv=fail; b=orCmSd1+Nyc1f/DJM/ZhbM0x06eEHTpSLY+I6Vapa7hOuAdgHU+tmTLslnwvxcvb2Pe4i0pAINgmsncbB4f3xGFlUjbT35ceGM9e0MJJYArS32NxXqrFAhk8mJ3EgWuLwI1S0Yy8DRL25ZZQou0++8nAdBX/oPaRuv/drzlhBBM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551512; c=relaxed/simple; bh=eQHygMMgvNeZSm6NrFOVvJy8TU/mGOXUnY+Pc8gr37I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Jb+OWfe9Gl9gyX1LCxFi0XeQoT9VmC14/Hm6R74YyKQ2rEhqEeuSfhPwENWRzKMdGdzqX1BmSuvtxr+kxaZqPTVoE3AXqCu/MbpSbrPtugC20WeCgZ/BbIzwKOlHkhZvg02f31dd8tEqG0ZjjKZj9NfCAF9Xtv70cMN/e7slXwo= 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=OVzJilm0; arc=fail smtp.client-ip=40.107.249.55 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="OVzJilm0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jqJx6lE+8+YnUZb8nah06pGvoUBNrUbF6MMEl6OC5M6c7UpWHHctyEyJZBqkq1OmezcDCtG4PRTFIZexi7j8c4UgoI0Bwy6jeK8PMAmcm8zRbB5CyFUepbCljHIW9JduKrKyoE9FSyVdqigStRtt6ogTBpUC2EauqP45p/RmBCF/YmbFW0O6YU9BbWJTN598os4wfe0+5mWPPORu82NGLzwuSALfnsX9Mq+G9dk6UjUMbFybyyp7qXgP6wWaeNDdZfeLvxi2uHO7KRp30GyUSMkCnpMZYUx3+g1k1HLzzkc66QRFY2PSOfVfd+AYfgL2/NVwVd9qUNfaMB4otMUoNQ== 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=0SKoqhpEI4x2dzpIhplvexTJZkBWoERG2IYvfdmjl+U=; b=jLiR8Q1czBuNbRjNngLNvGa9yz3nZxBmT7mx6YDBsY9S5CX8GbEPsDumIOe1W4aew7WFdvYlbSx2p1b+57MUuM0WReV1oNNsI7IoLRU3Hccq7zNL3EqcQXQpyfYQuHIxknoMbeL13tKqOJEex+1E6dcUTc5ZizK1cSKxnlGkOiXr/u3GZaKq9Z/WsM+CyblkskUOK6L8k4I4onXh2P9p1LquZ2ju0VW8hYu4JKxK7lAEh0A2A/pfGK53MXT9AHyKTE89hyOf2r6kMjUJDbPoEGv9+/IlT7DQHSKCY1ZXtuwSseYDR2pVjKvWo2D+x6ozTv1ZS9B3d9Lm7XtAZOJwQg== 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=0SKoqhpEI4x2dzpIhplvexTJZkBWoERG2IYvfdmjl+U=; b=OVzJilm0WeefKGqQn50W1phikXSXhW/7LAbnlsz7mh0HsJdpSUa+MpgUiZ1X+VkEMSda3j+EnQSTLi2a1AIIH+O7YjERkhUyiRubX0Ed7t1pLUEyuYOHDO6E9BmrDHKcEqT5Gcfz4k1lNYSLSzQ1Tv00HLZiR5HalofTaKycPBVOY9g82zxBvRWQcZblEJXT1afcbQKK2eTuN8l5gWNBIbyOwR4t0YV1BwaKhLnhF1qiAt4izCwh/LI/7V1DVWHVanSod6JnYXIoXaoqMjy0JYkuF9uj+eunSVXGXinc+ubIpm6/iPT9U5w3EkEmWFcb44K8MZ39erSfRCOBnlP6UQ== 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 AS4PR07MB9630.eurprd07.prod.outlook.com (2603:10a6:20b:4fb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Thu, 10 Oct 2024 09:11:47 +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.8048.013; Thu, 10 Oct 2024 09:11:47 +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 v3 2/4] ip6mr: Lock RCU before ip6mr_get_table() call in ip6mr_ioctl() Date: Thu, 10 Oct 2024 11:07:41 +0200 Message-ID: <20241010090741.1980100-4-stefan.wiehler@nokia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241010090741.1980100-2-stefan.wiehler@nokia.com> References: <20241010090741.1980100-2-stefan.wiehler@nokia.com> X-ClientProxiedBy: FR4P281CA0242.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f5::20) To PAWPR07MB9688.eurprd07.prod.outlook.com (2603:10a6:102:383::17) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAWPR07MB9688:EE_|AS4PR07MB9630:EE_ X-MS-Office365-Filtering-Correlation-Id: 14db0767-6243-4c2a-8bda-08dce90b9143 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: n2cKb7cGIv/jjVJ7eYZXfivo1RoLTeJBVzLqkJQtkV10it7gsJUKVmKokz0zl5UgPvqq6vZHMimc0MyHDJLuPelURSY9XlOF06CUKHitI8FrDpWYW9zq9S8P8IpPNHEg64gBV5fQeCeSKms5uO7G2zzHdIoNumVL8+eI6CmzXV9gS6xaSkk6gP9z0kAu6WiG+BiQ+aRKg+zlAJEki9GniOFJx0B1vCh2gYdjreI6st8Z4flbWAKuRQYomzAJfm5ALSz2fhPLyHlCsjsUIM+le4t3Swj+OiKsIv6JfzM6AAB5VihnVy5Lk9DpyRqz/yTkqvdkk8ps//7Tz6RF8/B5HJg4ae2Q9JaYBJJ36ESf3KFR1FKdb/87aS/ayhlufuAxNtp7ukj9kxX9i/aVGB0KYGomzT5Aqmt/nh+zS56tyb0Jx4PHu5lI+/tdPVwhMyNb0z8Q+JEPW1KYWkIZZfmQQmvuaNTDLWFd7jgdnJTRDUcD3oCVtsi6jcjH+KtxaatxJu1skw19s9GvlNvoo339RQLA0JIQyXeD2pC/DhN+M7UnqLfhUEqDXfwF8jdaEU/5F64hyyErditq6lFD7BU9mHocpB4ecHsrxnDj8krL+D7HHfbVSIdpL16nOQRBlF31MmIxfioRezdoo1JSbi/1589uCCP1eO27om7sK96Oi4Jwyhr4vF4xmHwNoIQRiWAtpoq2dyQCadfIeIVrZ9Rpf7RarANM3B77cAj2ZmS/ojAKuWNl97gQUBeSplaHftwDpCR0erv088uzW2FAd1bE0WvRZ912i5i4YudoZhzVCDf0ypp/YFWCgDRWZ4Z/ktj4Kq2xwKwEHxnFxe/98CfSnc4oejOu10g+gSwC40b25MWOpYfRoNiSFsm1zitXW51h0VoApiZtuZiTngttH0CNE7mlYZ7fd04Rlzh5WpNA25axLdUYkBVEYhIAfMAOHS0IiFlDeh5Kkkdbnec4IDaOvilRP9VSXXspRD9M3DV/iZoULqBmvrq9g0O7bY6gFPKjRfZewE7IsUQQ5fqdBk+wmb3lPMOsGCR1bp6Ke8N93+t4OcwIOjt0o4fxQEaAGVX+yYruVprgyVSvKiAO8jhUG63ABf9lmwmwMgA+8RYk5Q11xD3uGZ/6JpG/w0s06IEZUWfoEUbt+A0ZlpXLU1aJ+TzS7SrVkycii0Ce5wiXk1kXBVZ6j0L/4eIuJslggxVcivgoqAcPvjNpRrTgLrQ/ZT3mXimEMGA6+v4n9Cv71sx/GcV5c24G0ZAW8aYbi0Y0yUvjyttw1Bsa7Y6uL9UeaSUS5JeMjN/uFWzYhIoFu889coDTsCzF98lhGmqNE7nPvmmvSVHIISL1Nda6RVCeOQ== 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)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I+PzBmuDEmhgOqbIIOvdje5QGMcFEB+Pn7khKRe93EdZc9R9SS+myL2ecK3SU60oqQIos2OZZT82ejgYQDVAhi2DrGt9wv/6EvjDHcjPI5irMZa3ghBphXNM4GmAFOwCDbWt4SZHPnLKRxavKN9qlBPBQJG5gVC5QaFNru4astSm4HgsVOVaXl1m4lb4UEQuOGXGL5iyyV6WCIK1FWT8f9SSjH5d6NXohSdOH6IZb7sUSMwWsdc2YuvO5MWQeFjeJGvzu0BZ3DbKg2hVnqxMd4wVf/T9JXgZcBeB4UvcUqO7HpwViy5Zw0CqUIN/ZB/MaI8xB7ttABy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WJocL64kXSpwZGLiFjUjWhTCRPh02RGhvwIp+HhGiWwsmTmsKTmVWZ6rYOOwuI3fmgzn1Jce5ZaVT8qGw7Ydl9C2z9Z407eGW9c7RbCmq0FqdFj9ootT7r2301FTqKsHFEoD5nYGEUS7bIiVa2sYjxnI2yRJUrKgKzlyjV9Pyhx8B04z1ovwieejok47m8cWHL0i1If1qNb+qKQ2TtpSJUV4M4PTez/UvA== X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 14db0767-6243-4c2a-8bda-08dce90b9143 X-MS-Exchange-CrossTenant-AuthSource: PAWPR07MB9688.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 09:11:47.1573 (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: Lp9OvwEjp0Dfz25FFOQeRqyrQwsLcQji9iNqNKz1cqYwr+4FGjlYxGameNKRXE+chzHLod12sSQ0U7QcMQlvCdfcu0msYv+mzjTH6JGqNSc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR07MB9630 X-Patchwork-Delegate: kuba@kernel.org When IPV6_MROUTE_MULTIPLE_TABLES is enabled, calls to ip6mr_get_table() must be done under RCU or RTNL lock. Detected by Lockdep-RCU: [ 48.834645] WARNING: suspicious RCU usage [ 48.834647] 6.1.103-584209f6d5-nokia_sm_x86 #1 Tainted: G S O [ 48.834649] ----------------------------- [ 48.834651] /net/ipv6/ip6mr.c:132 RCU-list traversed in non-reader section!! [ 48.834654] other info that might help us debug this: [ 48.834656] rcu_scheduler_active = 2, debug_locks = 1 [ 48.834658] no locks held by radvd/5777. [ 48.834660] stack backtrace: [ 48.834663] CPU: 0 PID: 5777 Comm: radvd Tainted: G S O 6.1.103-584209f6d5-nokia_sm_x86 #1 [ 48.834666] Hardware name: Nokia Asil/Default string, BIOS 0ACNA113 06/07/2024 [ 48.834673] Call Trace: [ 48.834674] [ 48.834677] dump_stack_lvl+0xb7/0xe9 [ 48.834687] lockdep_rcu_suspicious.cold+0x2d/0x64 [ 48.834697] ip6mr_get_table+0x9f/0xb0 [ 48.834704] ip6mr_ioctl+0x50/0x360 [ 48.834713] ? sk_ioctl+0x5f/0x1c0 [ 48.834719] sk_ioctl+0x5f/0x1c0 [ 48.834723] ? find_held_lock+0x2b/0x80 [ 48.834731] sock_do_ioctl+0x7b/0x140 [ 48.834737] ? proc_nr_files+0x30/0x30 [ 48.834744] sock_ioctl+0x1f5/0x360 [ 48.834754] __x64_sys_ioctl+0x8d/0xd0 [ 48.834760] do_syscall_64+0x3c/0x90 [ 48.834765] entry_SYSCALL_64_after_hwframe+0x6e/0xd8 [ 48.834769] RIP: 0033:0x7fda5f56e2ac [ 48.834773] Code: 1e fa 48 8d 44 24 08 48 89 54 24 e0 48 89 44 24 c0 48 8d 44 24 d0 48 89 44 24 c8 b8 1 0 00 00 00 c7 44 24 b8 10 00 00 00 0f 05 <3d> 00 f0 ff ff 89 c2 77 0b 89 d0 c3 0f 1f 84 00 00 00 00 00 48 8b [ 48.834776] RSP: 002b:00007fff52d4bda8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [ 48.834782] RAX: ffffffffffffffda RBX: 000000000171cd80 RCX: 00007fda5f56e2ac [ 48.834784] RDX: 00007fff52d4bdb0 RSI: 0000000000008913 RDI: 0000000000000003 [ 48.834787] RBP: 000000000171cd30 R08: 0000000000000007 R09: 000000000000003c [ 48.834789] R10: 0000000000000004 R11: 0000000000000246 R12: 0000000000000003 [ 48.834791] R13: 0000000000000000 R14: 0000000000000004 R15: 000000000040d43c [ 48.834802] Signed-off-by: Stefan Wiehler Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables") --- v3: - split into separate patches v2: https://patchwork.kernel.org/project/netdevbpf/patch/20241001100119.230711-2-stefan.wiehler@nokia.com/ - rebase on top of net tree - add Fixes tag - refactor out paths v1: https://patchwork.kernel.org/project/netdevbpf/patch/20240605195355.363936-1-oss@malat.biz/ --- net/ipv6/ip6mr.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 268e77196753..b18eb4ad21e4 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1884,18 +1884,23 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void *arg) struct mfc6_cache *c; struct net *net = sock_net(sk); struct mr_table *mrt; + int err; + rcu_read_lock(); mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); - if (!mrt) - return -ENOENT; + if (!mrt) { + err = -ENOENT; + goto out; + } switch (cmd) { case SIOCGETMIFCNT_IN6: vr = (struct sioc_mif_req6 *)arg; - if (vr->mifi >= mrt->maxvif) - return -EINVAL; + if (vr->mifi >= mrt->maxvif) { + err = -EINVAL; + goto out; + } vr->mifi = array_index_nospec(vr->mifi, mrt->maxvif); - rcu_read_lock(); vif = &mrt->vif_table[vr->mifi]; if (VIF_EXISTS(mrt, vr->mifi)) { vr->icount = READ_ONCE(vif->pkt_in); @@ -1905,12 +1910,11 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void *arg) rcu_read_unlock(); return 0; } - rcu_read_unlock(); - return -EADDRNOTAVAIL; + err = -EADDRNOTAVAIL; + goto out; case SIOCGETSGCNT_IN6: sr = (struct sioc_sg_req6 *)arg; - rcu_read_lock(); c = ip6mr_cache_find(mrt, &sr->src.sin6_addr, &sr->grp.sin6_addr); if (c) { @@ -1920,11 +1924,16 @@ int ip6mr_ioctl(struct sock *sk, int cmd, void *arg) rcu_read_unlock(); return 0; } - rcu_read_unlock(); - return -EADDRNOTAVAIL; + err = -EADDRNOTAVAIL; + goto out; default: - return -ENOIOCTLCMD; + err = -ENOIOCTLCMD; + goto out; } + +out: + rcu_read_unlock(); + return err; } #ifdef CONFIG_COMPAT From patchwork Thu Oct 10 09:07:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wiehler X-Patchwork-Id: 13829829 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2086.outbound.protection.outlook.com [40.107.241.86]) (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 34FAA1B5337; Thu, 10 Oct 2024 09:12:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.241.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551535; cv=fail; b=oKMGMFYN7Dxe5lRSsILOcN94/1dn0QM0ZJCgx0tPRPSOMHPfP/QH3Ya9NCI88QgR3YSCDjmf/hvDLWfaARvjDMNp2lwqxjG97kkVHHBmodp+PZv3VTlf4pXyNoI7lKIEaVI/u4pMfNSN/J8Gr/A24+2ucToPuadCtacom+3th6Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551535; c=relaxed/simple; bh=HGtka4HLM6n8ER8CwfiJfSkKXmuw1ZiOGTCJnElYHxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ayMdF6EMV2QbWa6MrxhaSQIfeWRBy9m4B/56BXD2YVOTd5bG3nTKqz11M8WJDh+xp+lubqOvC54xby9kLQVNqiPQn6OooL146HB+doeZxf9CzNZtoSw8BeZ6wFYKhaZGgtDDUSRnLkaJ061jDNt6MTU3NFJBDt2kb2xZW1dvfh8= 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=onWY8W0J; arc=fail smtp.client-ip=40.107.241.86 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="onWY8W0J" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e0/LQ+IuV1uZMdnsRQKS1T+LV4kR2tcS9mwK99fQj8m6QmknGt/lq4WdxFWk4EaJP896OCAawWGQlXKQ9IDLlYertsWLkDs/P0UuPSHn6b8G6Jkyxp5+V77SXEn7T9gW6f29yvf/srjNA/7eOjLPwxoILHF0eW3z/KP+ygw3YWvkzCKjwM8PezBLPtfLK97sLxqx9VjjLoDH2SxycXesw9emX83IBWh6uM0TQvV9quB6EQPu/GQ4zWuL08BK1Em79IQGtHNeh1nhDbO2z31KMl2NbLKviyBHgo+XLIKBavTxhXZoKKbXAJEr4u1vxNUIN69Ne0HZEFqbBUPq6vrt1w== 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=0EE9j6S/0qGV93YmOkgse62HQd3fdQyz/hUR6ip68DM=; b=qRKx9Jqe0UMSRImfi4oJ+bsdOKWqAIZM38vof6//+p+XXsvgeVPK5T2IO5UwmdwUGnt3Bxh8jXABR5rIm5tJYsKDaOoI9e9GxybSfWVQlNa/aV2Jp1tNiw9dFWKZAUZjDGAL1g0xVqZ1ektVwWFl8F4wj4MLX2tp+8xPkc1evggSmwStTZL/+07K51tD7RbRn5JWNpXHw+gJW86YeEsyBcsTsMEQJWp6TViMxyAZKDdvkO7MtJrNcSQj5K+xYemQTUCeWaokqdDSp1HkdmlYLMv2mW66TS6ZWAWJuiLnxO69J9SZqFfKSGqXfk8zPaSIZ7T1PLE524L1fCK4OfY9+Q== 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=0EE9j6S/0qGV93YmOkgse62HQd3fdQyz/hUR6ip68DM=; b=onWY8W0JWp/vHFVwopWgpg4aDPC9Yskw/TrOKvVgip8fQOd7/iV+pWH5NOW4W3Pcq9OkCcFGZuCtCWJMIHVA9jK92zB6+zaZxA9wZJTNrK5BvzEpjv41llAVOkPBi0262APCV9CeMSx/6SErguLQ19kY6WPThiYi6jWsaawDY+UsWGuFAhQ0Bun715xiJgOxGZspqm53vIHcRUoaoWvmgzf1W56zuiZC1y2DHrmTEWl/2RK244WXVKbUY84bgcZ640pE7x7K/6AlB34eUstF9kfnHyoLjUNE7wXFqWZL1XNIo7AOCkwKcesuzbEcbooZZSAIV/oTKBv0eU4jz2eO8w== 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 AS4PR07MB9630.eurprd07.prod.outlook.com (2603:10a6:20b:4fb::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.18; Thu, 10 Oct 2024 09:12:09 +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.8048.013; Thu, 10 Oct 2024 09:12:09 +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 v3 3/4] ip6mr: Lock RCU before ip6mr_get_table() call in ip6mr_compat_ioctl() Date: Thu, 10 Oct 2024 11:07:44 +0200 Message-ID: <20241010090741.1980100-7-stefan.wiehler@nokia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241010090741.1980100-2-stefan.wiehler@nokia.com> References: <20241010090741.1980100-2-stefan.wiehler@nokia.com> X-ClientProxiedBy: FR4P281CA0242.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f5::20) To PAWPR07MB9688.eurprd07.prod.outlook.com (2603:10a6:102:383::17) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAWPR07MB9688:EE_|AS4PR07MB9630:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a522fa2-29cd-438c-108c-08dce90b9e97 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|52116014|376014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: yrtgoShKAsdjX8i07MGKfREKCzI+Rms31yBtlMkDh7PtAyoaMCkf96VlygX+5WB5ntyChzUfYqZsHJhHOFBNILJe5qsMxcdPw0E3GAkEokxXy504Gi7VNYhywSPMVscJuIOv05wZijX7acBkHa+FfEpvlpDIuz4o2iQvjG5GXlkE1PpWfYRoY/zsHNbub2apnasR9aR3TecDuMRuTtBjVC/5vtaM+ZBgQ48Bd3OyN7q5GgwG6Vy0V0w87YNmaTFtvkf36CZLzXMG4Cuk4dZIQOrOeMaDlfSjIJPMN107qWP9haExEShIbyjG4wkfhTReL90e9EQrZSauMgZ4xf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1;SRV:;IPV:NLI;SFV:NSPM;H:PAWPR07MB9688.eurprd07.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(52116014)(376014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: msykVHLB/M0fW5FOt9iE82wYzjtmuLGyXOvU6JC6YwaA0dsAnh6g2ak1GwMI7GzkboDoA0b6+htlIX0c+IE3LUgLVGqme5UzdlBQX+5JUfmj/hoVFxvS8YoYOwVREve4H6rpEu019Nr5xsYDWn//w7cs1AG955Fybcwn5fnoR+c0JhFwrD4t4T9txMg2FJx0g9EKHU3c/faCeD+x/jlEi1/Vc5pnXtCE+ChrUTR0oBXhH4MXx1CcNQrasNOvtjUu/uc2sV0mbWmWTZ45n4FIdF8MatIc5nPLZxkbzESsJVuKN8HddsTA0wyrXArdyULMSM0EwHvT2VbDyR/lW29htNakXlsnYoKuCydqtjF2HW5nG3I0pG+CJS6810HpWw5OJAKlwSp0JhJJmK2b9JyTO3YhPR/zr8s5rLrjLuAauxrwh6rhXmwsysXYSqVGfiyAMWChOlsi5ehAlY3m20tpYUF0woImPAnfhUECBvAmRFFXQs1NAR4Yoim593ZY/hfvVDaVWUSngOmlespSCEf5Vghe0NAR1ONe8Sy5lKQmq+3Q7Sv4xjmGXRtQ0qf9phaglA1feZPxgpHkYjMzBmW64IZpehNsO4oOgc0oHRoZ1Oq3p6Osr0MvDZ1p7+y35hQaGlH/D18bHXtR0s5ecVHBd/Vf4x+hoITuBXRirqNMVrzVHPSxEiBP5Y2Vnwuj9sJ5SSXCfFdAT94as9pYPxrJK6nlr4HJZwl9QNOmwNnoZpyRvFVXO1vq4K8hXBKHRV7kiljlzMvPT/tefKxs0iER8rSrWq3pAtbHk3jefGIjyt58zeEIRdfRu0fQHVfSoGFfFu+Yc2qP4WeGQs36MxMoMW/qOz8HXS87avaV75VnKJdssGbWMaWN1sjY8gY/387NJCZbifKq4sKSPYrLcuMQuhw1tnPzYchaCSqrfc646Q4T1wcB5AzPXiNQBx1BOd+NIf72wH0vSUVTZZjFmyjNWYK24Zp//Qq4CQ3X2IbFGGTrjSmwTFJgxLOyf3zgM6ai2CZVQThxsOhGRQ+Np1siNdduD9PGFYDgMFs/5LEvJlySpSduKiXOaNfxG6s7Ea18DyBtLOCgQBaPLn1IbfpB+ic/VfPGt37rCCqRdHxv3pDvyvUWLpxbKk5WQXCJXkvKDMMIv8MXQCivFgtU4+I67JApQN6BHHpp4zti+QmLK+aNizZ5I0reI5fAe3FbIkBPxZLn3BEqUGK65GNlFP1PZD1nk7onZlPQU0cbHhw8ns/oGbYdNEJLZGxnYssj8PSw96JYn+bmSE2N+/Y4X4JRDZNk5KUh4F7y28ViNQhny/GL1Ne00DSlHaBSoYbLhBpOwiNdG+NGIrA0dnw9tKCoXa81lqVQhaE6az7EZbnf8k0giTY0Ft5P1XsvMigNgVsl0CP43VgZSit9YcrqVW484MHrdepUE7sa/ofVSedkJMw8KJsV9G9kFwpdXUYdBpO0huidWDTMXutxaqI1nouoM5oEJtv0jWH6bQmc+yj5jYYH0IVT1qmqNKhvtN9TNDnHpmaCJl9/2KMoMo232ldaZ+r4h8qjhQUzYvCPiSKEDiusMIuhP/685gs7bWXay0ttLMDCeV5MQTqIxaW0mJFjaA== X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a522fa2-29cd-438c-108c-08dce90b9e97 X-MS-Exchange-CrossTenant-AuthSource: PAWPR07MB9688.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 09:12:09.5376 (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: n2483V1JeKd65J4cb9q1wlhXsLAhl5D7dnoeO48cwp18uJZbeQCGc9/xyS0l/owqqpCQa+6MiQ9GwRK6HFlpwzh5SjcxZHxU5RVu2RDS34Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR07MB9630 X-Patchwork-Delegate: kuba@kernel.org When IPV6_MROUTE_MULTIPLE_TABLES is enabled, calls to ip6mr_get_table() must be done under RCU or RTNL lock. Copy from user space must be performed beforehand as we are not allowed to sleep under RCU lock. Signed-off-by: Stefan Wiehler Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables") --- v3: - split into separate patches v2: https://patchwork.kernel.org/project/netdevbpf/patch/20241001100119.230711-2-stefan.wiehler@nokia.com/ - rebase on top of net tree - add Fixes tag - refactor out paths v1: https://patchwork.kernel.org/project/netdevbpf/patch/20240605195355.363936-1-oss@malat.biz/ --- net/ipv6/ip6mr.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index b18eb4ad21e4..415ba6f55a44 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -1961,10 +1961,7 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) struct mfc6_cache *c; struct net *net = sock_net(sk); struct mr_table *mrt; - - mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); - if (!mrt) - return -ENOENT; + int err; switch (cmd) { case SIOCGETMIFCNT_IN6: @@ -1972,8 +1969,30 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) return -EFAULT; if (vr.mifi >= mrt->maxvif) return -EINVAL; + break; + case SIOCGETSGCNT_IN6: + if (copy_from_user(&sr, arg, sizeof(sr))) + return -EFAULT; + break; + default: + return -ENOIOCTLCMD; + } + + + rcu_read_lock(); + mrt = ip6mr_get_table(net, raw6_sk(sk)->ip6mr_table ? : RT6_TABLE_DFLT); + if (!mrt) { + err = -ENOENT; + goto out; + } + + switch (cmd) { + case SIOCGETMIFCNT_IN6: + if (vr.mifi >= mrt->maxvif) { + err = -EINVAL; + goto out; + } vr.mifi = array_index_nospec(vr.mifi, mrt->maxvif); - rcu_read_lock(); vif = &mrt->vif_table[vr.mifi]; if (VIF_EXISTS(mrt, vr.mifi)) { vr.icount = READ_ONCE(vif->pkt_in); @@ -1987,12 +2006,9 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) return 0; } rcu_read_unlock(); - return -EADDRNOTAVAIL; + err = -EADDRNOTAVAIL; + goto out; case SIOCGETSGCNT_IN6: - if (copy_from_user(&sr, arg, sizeof(sr))) - return -EFAULT; - - rcu_read_lock(); c = ip6mr_cache_find(mrt, &sr.src.sin6_addr, &sr.grp.sin6_addr); if (c) { sr.pktcnt = c->_c.mfc_un.res.pkt; @@ -2004,11 +2020,13 @@ int ip6mr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg) return -EFAULT; return 0; } - rcu_read_unlock(); - return -EADDRNOTAVAIL; - default: - return -ENOIOCTLCMD; + err = -EADDRNOTAVAIL; + goto out; } + +out: + rcu_read_unlock(); + return err; } #endif From patchwork Thu Oct 10 09:07:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Wiehler X-Patchwork-Id: 13829830 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2085.outbound.protection.outlook.com [40.107.249.85]) (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 8BC9B1B5ED6; Thu, 10 Oct 2024 09:12:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551551; cv=fail; b=AeTM+c+Vsi0HB5fSXWiuqt+XikxoJ+TBP3WrdDQVFxPO6e9OfbM94iJQ9aMfuf0rna7yXc2LEb6Fyr5Kx5ZKovEPnEEGwgd6E9Fpy1waYbZAl0IcZAZuLBuIW8qIOa4tvlBSABbLr2V83Re5730/FUlblvdo2p9TDAjpMxP0PK4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728551551; c=relaxed/simple; bh=oWJfv7n0moS66M5NUU6/0w6G92QQlvIRNK6fSLlXeBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ph0a2yQyqb67rgfBqQU4zbz5Rvb+ZgcRNAVGb1o7Gy3X0NMVPwGBHNYJSayuUt93bEpKeYyG/ADMcf/Hx0s9qcVbqzk276tNN78ecKeb1F+zXZRHiRBhgTWSYr7OAPV+By5V/ODfHkYrDDN0fhV7wZ2qfPEbOFNZu9nNMppGPug= 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=mgf30k59; arc=fail smtp.client-ip=40.107.249.85 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="mgf30k59" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g0tCDoLCCxj1dNdyxXpfmcduMWTIZjm8GyOiV0HNQemZvj6WI4h6EAkx4AyZh/bZxlX9FS2bvkYd5Zom5eeDFTWFiN1QCoRbj1hHfuqftgesaL9D15ETskArbDdqQRShGZDodi4MfzfZDwv+JXjz5wdrQMNTdIXgnP6F3wKJtqZt5HxMHf1MccuC4FQgH/iwguv0SIHXKmcKkzpEpXy1wxZ7F+3EUw2sUR63LKjWATrJ9rhPlu8ubpforrBk4lK5Y2pQ4uG2cLpRh3KXN+FnqNx4ChNzsKlYyouPmrlaNmS29748sGu6YpcargF0tryIYIHUtsUXkHTyyC7RAfqHNw== 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=GQaOgy/+o9lLTYAKrT+lbChtHdwIEenLzXIFZDT1pnA=; b=x4g8UriJ9rIoa4vYRsbf42trhY7nCdF0ume4LEKoXgOjAUwBsscrFOnetYuUlGQznHvvm+rLmXSQ389+yOcNwIHiW/+6s/zKKRf7yYPdf6eiuuTLkv/0VS3rqT7zYscn+NHupagmF1RqZ8qHrqbtL53E68XSEzbAaAwnB6a2xu9ZE5fTSMO1nf+K4jc3yKvI3gAMCuJsqEcYdz7YFhteQqFeBUxzXLvsjYnkBcz2iEra0Il0soPR60c/UsaWkljrT/jEu91wAMfJ5Lln72u0heMJ+AIXNGIdMTYQoo5BeyQGLKF7ltnmTLlp6yV/HMIoo169VaJtdTU0DR1A7UsN/Q== 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=GQaOgy/+o9lLTYAKrT+lbChtHdwIEenLzXIFZDT1pnA=; b=mgf30k592FFsZ6yCT+Kiygck1QuNTwSf8gpEYA6Mwle335DVuPgMFIx/Hc06e/zjA+6O+qxtWwTT6IoZ4UBUFclDeRb5i21usgW+EroPYioOYYsiWrZB4tuk4OEYS9rL2OVERkulKqPyEqwwVcdhkIHSvWWwBmefcZlq4M+oCWWTutqyx3fgIxkhhiytCw86UC4t67jkwFtqmGdNUlgaAt5Xjo4aOJ/csX4yzHei7mOnFJclHFdrDFmDhoLbaAPZZNguVJcSlvwO0Se+WKAGqJK2zdNYcDroZ0KOqBDNqu4bZA0YZOZGF6C/qQUVm/dnewpdjm4IzVxWuquIYvBHcw== 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 DB9PR07MB9768.eurprd07.prod.outlook.com (2603:10a6:10:4c2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.16; Thu, 10 Oct 2024 09:12:25 +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.8048.013; Thu, 10 Oct 2024 09:12:25 +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 v3 4/4] ip6mr: Lock RCU before ip6mr_get_table() call in ip6mr_get_route() Date: Thu, 10 Oct 2024 11:07:46 +0200 Message-ID: <20241010090741.1980100-9-stefan.wiehler@nokia.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20241010090741.1980100-2-stefan.wiehler@nokia.com> References: <20241010090741.1980100-2-stefan.wiehler@nokia.com> X-ClientProxiedBy: FR4P281CA0242.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f5::20) To PAWPR07MB9688.eurprd07.prod.outlook.com (2603:10a6:102:383::17) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAWPR07MB9688:EE_|DB9PR07MB9768:EE_ X-MS-Office365-Filtering-Correlation-Id: e89bdbe4-93d5-422e-8532-08dce90ba7d7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|1800799024|366016|38350700014; X-Microsoft-Antispam-Message-Info: +hPWKmyeNOVlsRfih2lUWqLu8EGQb0DvxnaD86ETOEcO2yHY7xJMFWpkbLNWrvt+Q2VDCU865UX+bHRBf6Cvv4RzB6ohAx74UBd3kBSH1s1ohiQz07daWj7QBQCdk1zkCrVBh39NqIUpbCyU8Dp7rCZnD6P5mA9JMMCblEtCgUR8spN3mCoY6euDLnqokqlTJh6/+4O8uAwn5MKADkw0J9DqvLy9mzzS+C+Fni8Ej0EGf2Pc+ln32QBwDNelm8pGgUh0bCQqxzaaijR+A9ehFZFjCPGF4rlv2Bu0fHx8UY/xaejeR8R1pChZoEHrLeq9rWSHmzXXO9M2rbtAcFvbAauWFR/u5IybowKfgclY2xMMTHO5grlHneDJ++6i3DH4FnuQaKwPJPzMtyh6viy0aNU5KvZ1xh3rRYrh1RAe/rnOTr6v3UnXw1ApRXHeItPCJvolU0vSMwWmnVlB4BmFmveWHyzJoRVv46w+9LCozCA+VK77SehUvFAHnAqyWE2AndOoglqxENg+VnSDRDEQKVQltKZpdRdhUzabEpDLK2FaJzu5s5nyCYP2U1avPWgSW1b80bvdO5CmXXxCGMXeK1qXL5IkTpsSCmq2M0DGnp8ax9casCPXmZlSp8To/51VTQqlT1YYYAs94wrLaueBdRsQEETl2KFCpQrA2SxHFlm2AEpuphGZVMZlAwCBwhbEnXoris0X1NMyoL9PNMZzcwA+iYI8b8gpPEk/PbpNKUzEQUVek4/1xG29POjMp7NvKQJbE3UQlCbHkeZ37S8RMuHwBl1lv7jzwhuvG2pRzk36fthfmxRlM43ZH6t4FaLG7LLSaPcKVHvDNbEtSErbjyZ0e14J/QJfkuwK0iTvWBq2Si1pOKJfi3TNV6EvJlpYpr9yNV6OIKCYEEnTaA1J/nuvbIGS9WN6fgQmTCNWqq40+pXLSijFSZKhupyMLRTX/yoSCTAjipFsh+L4AP0UR7JNxh3YBnk6Icy+K7tgNAALqOC/kKWAIzDU7YH3KAdpKhSfW++qqH+E493/DWIEObaD3lVp3ihT3/Gwkf7VhqwMGpn5bBCN8DjRi/9h90mM0SxcV41ldnwk69HAclNGkS9TPMAkjg/jalYnaIBT/A8/5Be6n/9bmGHc2tcTh1s8PA/3L6UfNC0gPJgqqGUvBRZ+riPZCFxr15rAV4KnHj/IQgLZ+BTBbHCMD2yTx8FOIUpridZsrQ9iIa5jm6Jl48CS+iaZuylKmR8UiSu6oQyzw0zAdj+UvmnVOYUGhuVNXqj+fL9KOFXiljMxp7kbSGOJ/CMQT0LLK9zoLjoDDsxxjcGolRWmQMXrXY5J4anEyiA1Q1GmeRV6Y9q985Ebcg== 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)(376014)(52116014)(1800799024)(366016)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NOlYx7qzWvG59+Rs/6ulSFQt21SQ4fq5oix0GhptiCrY+umKAvFxqeO/HMeBEFBUn61ozq+ssd/X2x7lE1zmrSptMonU7PKjcV6ZzEhdsw/EIlo4hwgi9IZWEQjHkKfaWK07ohNXR3ywxq77nFe4k/dESwyRh/PV3dplMTRkY2Q9e5SwubW53Zy+kixDZZFJG+SLqNzWo5EyYfpp4QPB2Q9oKtr3zDNWq17IVhBmq1IhNfBi8ZB0LXQysK5PGygoyPUTAZdONoZNryHX6i2bgmhULgzCtLCTPtxzC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Am0T86AIpln2QLWH2WBzFwL0KV90ai1UUJbp2AO3yK8I9IrgKJVJY6wzsn9RzkU8D/nSVmq4KO4U5/AGWeM4l7oHz1gUx+jOgxKLoVVEd+f0S1CDE4xUlKUkRhVwoRmZKj5itAvYWy8YW1B9Gc8+G60l9JolapXOLQOrGfnXqx9b4TuZesuF4AVK5oOv7YnjzI9NfGs6gA8aV+0GQ7K5IaQH2IfQisy6rXPorW7avTaZzG+OF7sKH13c7bBLOE9jdKw== X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e89bdbe4-93d5-422e-8532-08dce90ba7d7 X-MS-Exchange-CrossTenant-AuthSource: PAWPR07MB9688.eurprd07.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2024 09:12:25.0284 (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: EiL7tyGd35PQcFhTFv6NTAqyyPzu3RyoTK+2igAQQBvLgmvbHpC8nadyTQ2CxhM81BXuFhpcDpIsP9hg8G/fWb7Lf9NbNegobECU6qb5yU4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR07MB9768 X-Patchwork-Delegate: kuba@kernel.org When IPV6_MROUTE_MULTIPLE_TABLES is enabled, calls to ip6mr_get_table() must be done under RCU or RTNL lock. Signed-off-by: Stefan Wiehler Fixes: d1db275dd3f6 ("ipv6: ip6mr: support multiple tables") --- v3: - split into separate patches v2: https://patchwork.kernel.org/project/netdevbpf/patch/20241001100119.230711-2-stefan.wiehler@nokia.com/ - rebase on top of net tree - add Fixes tag - refactor out paths v1: https://patchwork.kernel.org/project/netdevbpf/patch/20240605195355.363936-1-oss@malat.biz/ --- net/ipv6/ip6mr.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c index 415ba6f55a44..0bc8d6b0569f 100644 --- a/net/ipv6/ip6mr.c +++ b/net/ipv6/ip6mr.c @@ -2302,11 +2302,13 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, struct mfc6_cache *cache; struct rt6_info *rt = dst_rt6_info(skb_dst(skb)); + rcu_read_lock(); mrt = ip6mr_get_table(net, RT6_TABLE_DFLT); - if (!mrt) - return -ENOENT; + if (!mrt) { + err = -ENOENT; + goto out; + } - rcu_read_lock(); cache = ip6mr_cache_find(mrt, &rt->rt6i_src.addr, &rt->rt6i_dst.addr); if (!cache && skb->dev) { int vif = ip6mr_find_vif(mrt, skb->dev); @@ -2324,15 +2326,15 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, dev = skb->dev; if (!dev || (vif = ip6mr_find_vif(mrt, dev)) < 0) { - rcu_read_unlock(); - return -ENODEV; + err = -ENODEV; + goto out; } /* really correct? */ skb2 = alloc_skb(sizeof(struct ipv6hdr), GFP_ATOMIC); if (!skb2) { - rcu_read_unlock(); - return -ENOMEM; + err = -ENOMEM; + goto out; } NETLINK_CB(skb2).portid = portid; @@ -2354,12 +2356,13 @@ int ip6mr_get_route(struct net *net, struct sk_buff *skb, struct rtmsg *rtm, iph->daddr = rt->rt6i_dst.addr; err = ip6mr_cache_unresolved(mrt, vif, skb2, dev); - rcu_read_unlock(); - return err; + goto out; } err = mr_fill_mroute(mrt, skb, &cache->_c, rtm); + +out: rcu_read_unlock(); return err; }