From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.61.66 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796002508; b=a8ScPsJk6EXBgJ/bvDiam4vYiZNFdRxvNrrvlbefk5+0DvZDEYgxN6ij1xuGcxC0nosV kqOAwfN519wqM4K4qJOrx5jMXwupjFZMqUY+XiIM2rJfSCmVqaeTQFYPQUgfAqRw2gd31 pdUb3nI2KguH90pkMzz4zbWLUft99+hx4/tH8Apf09eqrL+xHGu3EX67GhITbkAc9/k2n WENaOjDDypDaylvdZnvafk5wPMtxw8sNr86OilPm9fplEGkF12Oh76Ya9MbMAYJgiV1Ca HFahrg+WFZZkVRZjjOcr8SpnQ9TA2qFuBGqX4XmZ3wVQW/2Qm9qvvoZbXbSN+XT+YUQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796002508; h=DMARC-Filter:DKIM-Signature:Received:Received:Message-ID:Date: User-Agent:Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-ClientProxiedBy:MIME-Version: X-MS-PublicTrafficType:X-MS-TrafficTypeDiagnostic: X-MS-Office365-Filtering-Correlation-Id:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=1xbb63pjP486G37hsF9plgXLvfChku4VLfPQesBMcs4=; b=g3RdRI0i5B51fWV733l6KjlcJbAn23oJ8wyJV1GgG5AWmosZBRESPC+xmm3NUXeGSzLF S7dgzxMqk84Ejjkdf2bWH2LFlM8aVNNFFkZfi9ZE0yvLZvj6fHQfAYfykn9X9VU8rBfsf T/P6aLc5GOqkcenBa1ip9470kDsQkRPpufawSnVU74rviJgMlsbwMYNkEe4rTyUCWOqjR Lh2l5Tm7HIslCzgbFQzyYQgstkpq5JMLRRqqlq2VEvrK6wEynCA2Kanhz+J2iEXu04wYd daF6fa/zE8wzFcpZGRUbniA7JD/pxAG5dBCkYBTu2OLXrAqj/YiYch74vIkbIDp0YXw== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=EmWPl5TU; arc=pass header.oldest-pass=0 smtp.remote-ip=52.101.61.66 Received: from DM1PR04CU001.outbound.protection.outlook.com (mail-centralusazon11010066.outbound.protection.outlook.com [52.101.61.66]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57118606A330; Mon, 30 Nov 2026 01:35:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 57118606A330 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, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=EmWPl5TU ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eFHEafXExoL4F1WuXxAVvMSoPPLWq3xZC0ME/5vWPxBveYhqxSvtXUpmXermnD4Bk2zFZLV3DOnUr6UfLAfQ8rR8/gDxOrLl8TALXJzIkYIrJnIm1ZKMZSM1arAm/+DaTlVqRxIOa6yp458wdBhMCJK3wqWP474EaGGFYN17QahTkEtIzMpyFWzV9n6xA8gsEuqLyVIF4axbBgS2FiACRqgNGjlLtUb40p822V5hFm2zlIXZRS2vlr68JPcWL464rayyvt8ESpOoWHS6Maxgc8DvXOMPbPc3Shh2DXR/14DExmVAuyc9j3HG5qgVuWUVb33DwmHgI95SIKIURcrOJg== 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=1xbb63pjP486G37hsF9plgXLvfChku4VLfPQesBMcs4=; b=VDE76iyUnjIkpGsK61t000aLqNge3jNhYoHGP4OwmLhrYcwK+ByRIGXukoPEbuDUVKU/VSu2IOS1D+TOC9cpns/tSY2KveQA+Rnj67ZRVG/I8rRZawGYMnOXAuVxyozGWpFRsNUhQo/Tjq77oblB35o54eF/WyMc/+9QYIhPRg26s4H6OIsY96HM471h+0G5btNzfO+6x1nlU0BiI/LXgzuyl7iHH8PN+SZHtHn8CDAe0VXGNT7O+vmh4+VK+0vQrDTXNPzKQ8gHVkHQdYWgF3DcluGKQNg5KzxJDznN7SthuneVfSs+Elr206abShBKdyy+F2H6wmFIERMUiVKp1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none 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=1xbb63pjP486G37hsF9plgXLvfChku4VLfPQesBMcs4=; b=EmWPl5TUDEjlOQBjylwO/ma+zJLFecfd0cZa+1JOAzksNMvBnIHxkgQeLYm6/BTe+HAZHHWHntyTLM8uYmUPVnsaGY3i+cPkDwK54SjqcBSQvbhy28N9I/yNdp/Sd4ZHpysbp4hfqp9qyUvITnvlpy0uxRf80I4bHlSbJwpmXcZwNmypGED0BFP3GI4lpVZY9KU9ASrfd6LDhZb4Lv9kv6OzAzbWkiBtp0Filc/CGDDtYTW42p2efIV4GGXJdteSHvuW4VfVT9BYcpmoiZEX8BcrdQ0qcBAFLmAeA5gq2HUnpUMdco8R9kynxz0RjH3SMFeVeDUT9tZd3FlWc4U0eg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SAVPR12MB999143.namprd12.prod.outlook.com (2603:10b6:806:4e5::21) by MN0PR12MB5953.namprd12.prod.outlook.com (2603:10b6:208:37c::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.7; Mon, 30 Nov 2026 01:35:02 +0000 Received: from SAVPR12MB999143.namprd12.prod.outlook.com ([fe80::219e:6553:2ec0:3761]) by SAVPR12MB999143.namprd12.prod.outlook.com ([fe80::219e:6553:2ec0:3761%4]) with mapi id 15.21.0662.007; Mon, 30 Nov 2026 01:35:02 +0000 Message-ID: Date: Mon, 30 Nov 2026 09:34:52 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH ipsec 2/4] xfrm: Serialize device state teardown To: netdev-bot+sashiko@kernel.org Cc: netdev@vger.kernel.org, ipsec@lists.linux.dev, steffen.klassert@secunet.com, herbert@gondor.apana.org.au, davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, fw@strlen.de, linux-kernel@vger.kernel.org, cjubran@nvidia.com References: <20261125013412.1123866-3-jianbol@nvidia.com> <179591848106.3135.4138564500710245659@kernel.org> Content-Language: en-US From: Jianbo Liu In-Reply-To: <179591848106.3135.4138564500710245659@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: JH0PR01CA0178.apcprd01.prod.exchangelabs.com (2603:1096:990:75::7) To SAVPR12MB999143.namprd12.prod.outlook.com (2603:10b6:806:4e5::21) X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SAVPR12MB999143:EE_|MN0PR12MB5953:EE_ X-MS-Office365-Filtering-Correlation-Id: b7ed79a5-651f-419b-e8dc-08df4e822755 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|23010399003|1800799024|4143699003|6133799003|261009223027099003|18002099003|22082099003|3023799007|10067099003|261102130727099003|11063799006|56012099006|261102123227099003|261028144727099003|261022075727099003|261022105027099003|261026140227099003|261021121427099003|261021123027099003|261026121527099003; X-Microsoft-Antispam-Message-Info: 27vKSfbhB9wTJy+yrhAgt8ssrASa8zjegAGMXMGoILWhQ7cp4inWLSHgsOBy8/mKvIfLWCGTEhDRYClI73A5Vhr1MXJ9/RvlJfdvZi1zafJwCKZaVUygLFrNmsoef3gt84ps2A+r6XUAMTsnrZS22Rose697ya143GvX111I+McJNksGyWprKs4JwrN+SENOtJeYShUQKc3s9zDAe+q/pf2QgPrTFRbgTl4mxtKFJpkVwa0cPUjqIXZMT6nc9BsGVKSoFr9TIK4Y1O8Z0Z8vCnvsUuzi2QQQY2oEB8GWpZqVQL74GSSbZN8V7iUXMr+QJm76rmuSKZZ7K5HkF8w7R5j+VInmY67VmtP62Uyvdczmw9FJOkYWUbBtUNMKZeqgKrp2bcMVDGoBl7ovUS5v3UYMrBzFfIipyMNvue/GYKyeNLc/bExJx8rEgGt4ZYc7NfMgQHAnf5EEuvDB648RLNeJRqu40rrxYhgdQ6/O4we7KF3jdwGg9Zt38wtlA8kOx75FiIUH2kt7uSYy2lq4ihSTbtP+YuI3gUO8iBtQ0CPGzqrjPkI2mjLbNftd6D7qeKMftgF1BxHsPWf7PObtphD/AtYI9RA4RAbipHgx1izGTQMWUfJZgS8m4BGIAHz/07gWAwHIsUdrKfzn4VT3mOoRu3JU92/l6uSnULayTm8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SAVPR12MB999143.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(23010399003)(1800799024)(4143699003)(6133799003)(261009223027099003)(18002099003)(22082099003)(3023799007)(10067099003)(261102130727099003)(11063799006)(56012099006)(261102123227099003)(261028144727099003)(261022075727099003)(261022105027099003)(261026140227099003)(261021121427099003)(261021123027099003)(261026121527099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?MUpwWTN1QWtUejhUMDJ4RzhPZHJQK085dTNBei94MVR5ckpzejRqNElqdHZQ?= =?utf-8?B?WDBkTDdUMWFlS1k0UXdobWoxYm1vb3NSdmFtS2cwZ2UxVHdadmVLT0pLdnp1?= =?utf-8?B?eXQ3L2xZMjlxMXM5MmhNVkhYWTlXQjNPblQ5YnlmNzB0YjdqTHdnRnlFeHpo?= =?utf-8?B?ZzhQNmR5TDZvY3gvQ0M5SGNRWnBkUXNLc09MUXlndFYyM3hmakZHWi9ud0d6?= =?utf-8?B?NEI4VFpuZlZZWmxjekFQSjI4WEdsaVBFRjl3djcwN1JYcE5oTkk5Yi9HSHlD?= =?utf-8?B?UHhMUWhVR1dDM0FyZUpLdXFadzNmSnIv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NjNK?= =?utf-8?B?UHBUSElZU1J2SEsrT1hjR2ZSWGpJQ1FxVGphSVBwa3IwcnVKZGQ0ZzI1bFFT?= =?utf-8?B?UTVacVRQMDZnUkVyUGtsV3U0Z1JZa2Y0Y0ZGUFdTaW1Xb3JtaW9iTU1PckNT?= =?utf-8?B?UHVIdTliYkpzcmFRZWwvRUpPMnRlS2l1VUpkMzQyeS9vT3VpRVlReDA4czBi?= =?utf-8?B?S3h5YTdDdWVjeHNqT3dWNGJlZ2YvSUswOUg2d1BjQmVkazlGbFpmUT09?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7ed79a5-651f-419b-e8dc-08df4e822755 X-MS-Exchange-CrossTenant-AuthSource: SAVPR12MB999143.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 01:35:02.3914 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6CRSwa5Mfb+KwkXdXA5Uj/jwC7K/aciQdT/8gSRbXLTacdBcbrTKsRs4hNnMJuP0EOybSdcWApTsUj2qL7zY/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5953 On 11/29/2026 10:14 AM, netdev-bot+sashiko@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 2 potential > issue(s) to consider. > > Critical: 0 · High: 1 (1) · Medium: 1 · Low: 0 > > If you believe none of the issues are legitimate, please reply to each > issue of Medium severity or higher and explain why the AI is wrong. > If any of them are legitimate and you plan to respin, please let patchwork > know by including "pw-bot: cr" as a separate line at the end of your reply > (one such reply per series is enough). > > - [High] The new `!dev` rejection in xfrm_dev_offload_ok() does not stop > xfrm_dev_direct_output() from using a NULL device, although the commit… > - [Medium] xfrm_dev_state_flush() now skips states on > xfrm_state_dev_gc_list whose refcount is already zero (`if… > > Pre-existing issues: > - [High] This problem wasn't introduced by this patch, but the patch's > design depends on it. > > -- > > xfrm: Serialize device state teardown > > This commit makes xfrm_dev_state_free() claim the device by clearing > xso->dev under x->lock and xfrm_state_dev_gc_lock. Only one caller then > unlinks the state and calls xdo_dev_state_free(). xfrm_dev_state_flush() > now takes a state reference before moving entries off the device GC list, > and xfrm_dev_offload_ok() rejects offloaded states with no device. > > Link: https://lore.kernel.org/netdev/20260908224854.1591115-1-kuba@kernel.org/ > >> diff --git a/net/xfrm/xfrm_device.c b/net/xfrm/xfrm_device.c >> index f153bf695b9dd..3bbb970cd337f 100644 >> --- a/net/xfrm/xfrm_device.c >> +++ b/net/xfrm/xfrm_device.c >> @@ -422,11 +422,11 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x) >> int mtu; >> struct dst_entry *dst = skb_dst(skb); >> struct xfrm_dst *xdst = (struct xfrm_dst *)dst; >> - struct net_device *dev = x->xso.dev; >> + struct net_device *dev = READ_ONCE(x->xso.dev); >> bool check_tunnel_size; >> >> if (!x->type_offload || >> - (x->xso.type == XFRM_DEV_OFFLOAD_UNSPECIFIED && x->encap)) >> + (x->xso.type == XFRM_DEV_OFFLOAD_UNSPECIFIED ? !!x->encap : !dev)) >> return false; > > [Severity: High] > > The commit message says this check stops xfrm_output() from using "the > NULL device in xfrm_dev_direct_output()". Does it cover that case? > > The !dev test only looks at the local READ_ONCE() copy, and that copy is > never passed back to the caller. For a tunnel mode packet offload state > with !skb->sk, xfrm_output() does: > > net/xfrm/xfrm_output.c:xfrm_output() { > ... > if (x->xso.type == XFRM_DEV_OFFLOAD_PACKET) { > if (!xfrm_dev_offload_ok(skb, x)) { > ... > if (x->props.mode == XFRM_MODE_TUNNEL && !skb->sk) > return xfrm_dev_direct_output(sk, x, skb); > ... > } > > xfrm_dev_direct_output() then runs the LOCAL_OUT netfilter hooks. After > that it reads x->xso.dev again with a plain load and no NULL check: > > net/xfrm/xfrm_output.c:xfrm_dev_direct_output() { > ... > err = skb_dst(skb)->ops->local_out(net, sk, skb); > if (unlikely(err != 1)) > return err; > ... > skb->dev = x->xso.dev; > __skb_push(skb, skb->dev->hard_header_len); > return dev_queue_xmit(skb); > } > > Suppose xfrm_dev_state_free() runs WRITE_ONCE(xso->dev, NULL) on another > CPU between the check and that read. Can skb->dev->hard_header_len then > dereference NULL? > > In this commit the window looks wide. The first loop of > xfrm_dev_state_flush() calls xfrm_dev_state_free() right after > xfrm_state_delete(), while forwarded packets on other CPUs can still be > sending on the bundle: > > err = xfrm_state_delete(x); > xfrm_dev_state_free(x); > > The later commit in the series, "xfrm: Wait for an RCU grace period > before freeing device state", narrows the window but does not seem to > close it. synchronize_rcu() only waits for readers that were already > running when the grace period started. > > For example, take a forwarded skb held by NFQUEUE in FORWARD or > POST_ROUTING. It still has a refcounted bundle dst that pins x. It can be > reinjected through nf_reinject() in a new RCU section after x has been > deleted. xfrm_output() does not check km.state on the packet offload path. > > Would it be more robust to pass the checked dev into > xfrm_dev_direct_output()? Another option is to READ_ONCE() it there, > check for NULL and drop the packet. The window is pre-existing. To close it, I think xfrm_output() has to read the device once and pass it down. That is a change of its own, and I'd rather leave it out of this fix. > >> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c >> index 3eb012ed86576..8465ae0647427 100644 >> --- a/net/xfrm/xfrm_state.c >> +++ b/net/xfrm/xfrm_state.c >> @@ -790,20 +790,28 @@ EXPORT_SYMBOL_GPL(xfrm_dev_state_delete); >> void xfrm_dev_state_free(struct xfrm_state *x) >> { > > [ ... ] > >> + spin_lock_bh(&x->lock); >> + spin_lock(&xfrm_state_dev_gc_lock); >> + dev = xso->dev; >> + if (!dev || !dev->xfrmdev_ops) { >> + spin_unlock(&xfrm_state_dev_gc_lock); >> + spin_unlock_bh(&x->lock); >> + return; >> } >> + if (!hlist_unhashed(&x->dev_gclist)) >> + hlist_del(&x->dev_gclist); >> + WRITE_ONCE(xso->dev, NULL); >> + spin_unlock(&xfrm_state_dev_gc_lock); >> + spin_unlock_bh(&x->lock); >> + >> + if (dev->xfrmdev_ops->xdo_dev_state_free) >> + dev->xfrmdev_ops->xdo_dev_state_free(dev, x); >> + netdev_put(dev, &xso->dev_tracker); >> } > > [Severity: High] > > This isn't a bug introduced by this patch, but the new locking scheme > depends on it. The commit message says "x->lock also keeps xso->dev > stable for the stats updates that hold it". However, not every stats > caller holds x->lock. > Already posted a seperate fix: https://lore.kernel.org/all/20261125020835.1132797-1-jianbol@nvidia.com/ With it every stats refresh holds x->lock. > copy_to_user_state() in net/xfrm/xfrm_user.c does this with only > xfrm_cfg_mutex held: > > if (x->xso.dev) > xfrm_dev_state_update_stats(x); > > There are two ways to reach it. One is xfrm_get_sa() -> > xfrm_state_netlink() -> dump_one_state(), with just a state reference. > The other is xfrm_notify_sa(), after xfrm_del_sa() has already put the > state on xfrm_state_dev_gc_list. > > The mlx5 callback accepts xfrm_cfg_mutex as enough protection and reads > x->xso.dev again: > > drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c:mlx5e_xfrm_update_stats() { > struct mlx5e_ipsec_sa_entry *sa_entry = to_ipsec_sa_entry(x); > ... > struct net *net = dev_net(x->xso.dev); > ... > lockdep_assert(lockdep_is_held(&x->lock) || > lockdep_is_held(&net->xfrm.xfrm_cfg_mutex) || > lockdep_is_held(&net->xfrm.xfrm_state_lock)); > ... > } > > xfrm_dev_state_flush() runs from the netdev notifier and takes neither > xfrm_cfg_mutex nor xfrm_state_lock around xfrm_dev_state_free(). That > function clears xso->dev and then calls mlx5e_xfrm_free_state(), which > does kfree(sa_entry). > > Could an XFRM_MSG_GETSA, or the notification sent for XFRM_MSG_DELSA, > race with NETDEV_DOWN and hit dev_net(NULL)? Could it use sa_entry after > it has been freed? > > With this patch the NULL write now happens before the driver free, which > seems to make the dev_net(NULL) case more likely. The synchronize_rcu() > added later in the series won't help here, because this reader is not in > an RCU read-side section. > >> @@ -974,6 +982,7 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali > > [ ... ] > >> @@ -1012,21 +1021,29 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali >> >> mutex_lock(&xfrm_state_gc_mutex); >> spin_lock_bh(&xfrm_state_dev_gc_lock); >> -restart_gc: >> hlist_for_each_entry_safe(x, tmp, &xfrm_state_dev_gc_list, dev_gclist) { >> xso = &x->xso; >> >> if (xso->dev == dev) { >> - spin_unlock_bh(&xfrm_state_dev_gc_lock); >> - xfrm_dev_state_free(x); >> - spin_lock_bh(&xfrm_state_dev_gc_lock); >> - goto restart_gc; >> + if (!refcount_inc_not_zero(&x->refcnt)) >> + continue; > > [Severity: Medium] > > What happens to a state whose last reference is dropped at the same time > as this flush? > > xfrm_state_put() does refcount_dec_and_test() first. Only after that does > __xfrm_state_destroy() queue the GC work: > > net/xfrm/xfrm_state.c:__xfrm_state_destroy() { > ... > spin_lock_bh(&xfrm_state_gc_lock); > hlist_add_head(&x->gclist, &xfrm_state_gc_list); > spin_unlock_bh(&xfrm_state_gc_lock); > schedule_work(&xfrm_state_gc_work); > } > > The putter could be preempted or interrupted after the refcount reaches > zero but before schedule_work(). One example is a preemptible netlink > handler dropping its xfrm_state_lookup() reference. The flush would then > see refcount 0 here and skip the state. > > The xfrm_flush_gc() at the end is only flush_work(&xfrm_state_gc_work), > so it does not wait for work that has not been queued yet. > > In that case xfrm_dev_down() or xfrm_dev_unregister() could return while: > > - xso->dev still points at the device > - the netdev_hold() reference is still held > - xdo_dev_state_free() has not run yet > > The driver callback would run later from the GC worker, after the flush > has already returned. > > Before this patch the flush called xfrm_dev_state_free() on every matching > dev_gc_list entry regardless of refcount, serialized with GC by > xfrm_state_gc_mutex. Is this gap intended? It also appears to remain at > the end of the series. The flush does not free every state of the device before this patch either. __xfrm_state_delete() takes a state out of the bydst hash before xfrm_dev_state_delete() puts it on xfrm_state_dev_gc_list. A state that another task is deleting at that point is on neither list. Both loops of the flush miss it, and the GC frees its device state when the last reference is dropped, which can be much later. So no caller can rely on all device states being freed when the flush returns. > >> + hlist_del_init(&x->dev_gclist); >> + /* xfrm_dev_state_free() may consume dev_gclist. The >> + * reference prevents state GC from using gclist until >> + * this flush removes it and drops the reference. >> + */ >> + hlist_add_head(&x->gclist, &flush_list); >> } > > [ ... ] > >> + hlist_for_each_entry_safe(x, tmp, &flush_list, gclist) { >> + hlist_del_init(&x->gclist); >> + xfrm_dev_state_free(x); >> + xfrm_state_put(x); >> + } >> + >> xfrm_flush_gc(); >> >> return err; >