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=40.93.196.12 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796003756; b=E/RhvMW40P/fLnxHsHTrtiR/yxtXmCebKjEiPfSRLaJRA6dfcIXjvpdUX+Q4Qcs5hI9e Lodfpk0SunDI6SxgL6zNc8DfnjqEvCUNFnycwn7lQOD6bHXqdsYiIKKWs7X8Q3vRVLY2a 1FWZlvql/0cy/yo35R0eeqKxzfEoYXaz6whAOC4bnQANKFO6BgzVDWXBl2RwwA/7BmKxX Mmi1HyM97vNDLQ8d48OxBxPaGFoRY/A1JmKq2UxWxzGNWSAJ4rwsdfZBlfYvPMvUHelen EfrS/CIkNgWTOmaI6UPZfHGIhHJbxL+RlyMtVUopp3Wwsf6nvcw61vJLek9xgemnLcw== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796003756; 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=1K6KHKSEWIrSjQfKEWWwLoAgSBppd0PhasGS+Ku7ejY=; b=ixEs3gw3uYe2HnGF6Sl11mJYyFAliwnDzAQ2JN4Y1C8AMBECv+hO2IghJKy3XNUL29C8 LB7Q7qWGCRNkLmojE+lZmhFjN5emYyrIanUdoEWs5ssNWYeZYvQlbjgp7JAblbbjNmGmP hiDIpDbcMCLM0kimGqhucXG/Ll6x+NTr8J5nJRikCm7hBPj6kuzCXrg+kGPR/tDsZba9C cXTiHnaZfhl2QpEYBKLefdNxTLP8kVS6wYWfy3W7AFbAIytFVS5WbNw8oH4uewbY6peuM t0w3tcfbs8AWfDe5J9SXw1kpNquNblLFxgmVNe/jpBLjJXq5565UjF1TMxM8SXts8cw== 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=t38fzisz; arc=pass header.oldest-pass=0 smtp.remote-ip=40.93.196.12 Received: from SA9PR02CU001.outbound.protection.outlook.com (mail-southcentralusazon11013012.outbound.protection.outlook.com [40.93.196.12]) (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 51A27606A68A; Mon, 30 Nov 2026 01:55:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51A27606A68A 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=t38fzisz ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=peQyRFQ91ojwlTfVgwMvhwoIKvmbG5CTrl03/nTnZp/YrK69A69jQOqoWV520BdbT58tlasscP0tVvcqzTY8jehWrufxpQTanGdcYZzfDMhdN9Zgu3zBesMVewGsrMGCSE5Ka2PdwKJYO4LY6c0OHu8OmkY4TeN8WHuBrcYVWrKNpYZh4gBRqiqiu8pkprRp4afjUEBU8TjlwzneRred4uEt1SjP9XQ82BeZMFVGi7ZD4Ar3G/ldJ5zmHIQHuLnMbvOauyr5vblt/gv3GIapzNt6hma/YLRlJg1lcyTqchCOIGF6+LpwWbZ7aMm1urQc3k0FAl6WTcAAPyRQr88vdA== 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=1K6KHKSEWIrSjQfKEWWwLoAgSBppd0PhasGS+Ku7ejY=; b=JuDpB1kSGImSAo42MKgBfVBUTkS43hWmZJcnOqxkrXDQK0tcDCcD2Lt2+QY8pSco96uXYcMkoMWBa+5FVwuQdT5pnpWlEL0eI6QNEhWD20275xpiBv1ZYPcSx3aRxEI1FszL7dA0alfWrGu8yf3cLWdK3KLc+zzacw9vLFEbTCOvSj3QswfoWMuq/dgy36IIbTGyozJlDyWqAnoyWUysOXXy6q89LraQY8hwrdlDAP1Kr8vZVkT1D/BVzJdIQ+Efnl947fOGQPLgixs3DIkTvK9S/0OegozoksTZMnPbAKICMYx7MtNXDFAlL8Jvi2KKxEhDGnhBKr2CMO1oxDFEGg== 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=1K6KHKSEWIrSjQfKEWWwLoAgSBppd0PhasGS+Ku7ejY=; b=t38fziszrsPrifnmJGfDB3Ph71IlmG9Xk+N+vz6VIP/eR3JWJOcCFpxqHCvXOiY49zdRIUo9sIdrCUa2jvGUGbalknzPQeOMxcbKABdp/Pe3Qe1je4/pNL/+Xfty79aQ9634zZPby208v1QAS3/hijBCHuAuhTC/3XMKxSY1Ze/s9pyjuRnpGWXoFuz+TLLXTHiZCkQcfHdDVZXh+xcG6xzizdnxUD4azDeUIxMGTWpotzR5kZ0wB5Vss39J2q+Z9IxXHWQf8ADrfsi1EMu9vd0Dbpqnux3iGTy1RRU7G5kTPUBwGkscn0AXGXmsyTJqQ1lEyIKjlwipmV5qxDMXsQ== 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 DS6PR12MB626099.namprd12.prod.outlook.com (2603:10b6:8:4c8::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 01:55:52 +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:55:52 +0000 Message-ID: <4181b9e2-29d6-4bf1-8665-f96d243bd2ec@nvidia.com> Date: Mon, 30 Nov 2026 09:55:43 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH ipsec 3/4] xfrm: Wait for an RCU grace period before freeing device state 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-4-jianbol@nvidia.com> <179591848241.3135.5652486461526198891@kernel.org> Content-Language: en-US From: Jianbo Liu In-Reply-To: <179591848241.3135.5652486461526198891@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SGAP274CA0023.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::35) To SAVPR12MB999143.namprd12.prod.outlook.com (2603:10b6:806:4e5::21) X-Mailing-List: linux-kernel@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_|DS6PR12MB626099:EE_ X-MS-Office365-Filtering-Correlation-Id: 9330849b-0748-4d5e-58f9-08df4e85105a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|1800799024|7416014|376014|10067099003|56012099006|261028144727099003|261026140227099003|261026121527099003|261021123027099003|261021121427099003|261022105027099003|261022075727099003|261102123227099003|261009223027099003|18002099003|22082099003|11063799006|4143699003; X-Microsoft-Antispam-Message-Info: btc8dWbCFji1Zt5YDgWg5NoEqhJTW/390lWCDT41QR6Uj8FzFUkpmERQfKdocLF6LMXzZMgZEiFDxvK2SaThx9QW2vBoMreYycJj0pP8kEsFAYs5z7TFaH83H9gYNMWmGaiv5o6oQn2IBgkxQo+k0lXY75wTbQbPXyBdyMemkd5t81dNV4/P1dqUr6c/B77afiAQjh4hoYqsNZZ5vT/iFjsYMZuPHxNzCjycGcxWvYljDCegxQp55UveqIHzOXfTsxa6zInhVET04wFMPKVk98crqsGvW5eHWCzQIxGCOTpKmWMe82jTse+VrzHlGO8qWkFO8f4bZhE3IYeaizLtGtR0GFNO5IF4Rw0xlT3uK+mADsihMnzBhWclVxiPaxLQj8FP1tw3d3jWrbf0zhPlWDiW7TYpYpSeT1XmoSN12ry2FMeaVdUzyra09zRyT0tLRi3ZkaJeJ3Ks6M8m+nzmLU8Y4XD7dLFbMA8y6lNPxCcramdeJbOgBtJGmMNWhQAOO8AhYWJpyCZbhMUEgt5X07Y1HDKrh/1uUhfywinByM5uBd+DuJoHXq0ugJ3vCZGfx62ayFgKo70VVzJ5/XrHuS4AXhGVlEDDwjQnOoRTyZwrUEFkILOjAwyNFbuREv+5N/KReuZx+5GsEHFOv6s39V5mxHnBt+ijE+xS9H8LeDA= 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)(366016)(23010399003)(1800799024)(7416014)(376014)(10067099003)(56012099006)(261028144727099003)(261026140227099003)(261026121527099003)(261021123027099003)(261021121427099003)(261022105027099003)(261022075727099003)(261102123227099003)(261009223027099003)(18002099003)(22082099003)(11063799006)(4143699003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SElKQkN2OGNQc3QrZDFEeFlJeGhiUDBiVXp6ckx2M0xIaDY0bSs3YVFBVTl0?= =?utf-8?B?QzZkTHJpVVExTlRDZXltZDRid1Rha1ZJNWluNkJKeU0rNDRhUHRtMjZtV1Fu?= =?utf-8?B?UCs4NXQ4R1ZKNVpITnR4cUZxU0tCamt3dXZVYWRPVFUrZ2FlMnA3ZkR4d2lD?= =?utf-8?B?MWV2aFdQL1ZaZmlYcm5wY1daTzRlZmxEVHd3Y2wxdkpBa29XV09NZXJYcTA0?= =?utf-8?B?TkZldXJyajBTRFpmS3QveUJ4b1pmL1FxOU5UTnIvM1F5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bXlVelNlOEpBZlJZVmRaVGhadE9PSEJ4K2t1?= =?utf-8?B?djljdzJvWFhDbVZ6TU8rQ1dDeG81RGpKZjdTakdVOFFBcE9kZ1E3S1A5Q2JN?= =?utf-8?B?cllPVENGNDNtUzRUUkNqSGxZZCs1N1ZqelA4Y3o2SEU4UGVzcGxZZ2xxVzhO?= =?utf-8?B?UG80NG9wQlg3elRPNnlkUTk5NlFKVDJ0RlhVUVNLVWcwd0swb3dMTDJyS04v?= =?utf-8?Q?ronpfP3K1kd5LDR9SJ?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9330849b-0748-4d5e-58f9-08df4e85105a 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:55:52.4925 (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: qsEqb/vNwRIoHaCCrc7sEyR6CgWHdVU5rA4TvTLqclTknqKmTewAmTCFdCi3EPw1xcbbKQcuRZhltv4wp69q7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS6PR12MB626099 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: 0 (1) · Medium: 1 · Low: 1 > > 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). > > - [Medium] The patch removes the synchronous xfrm_dev_state_free() after > xfrm_state_delete() in xfrm_dev_state_flush() (net/xfrm/xfrm_state.c,… > - [Low] The new synchronize_rcu() in xfrm_dev_state_flush() > (net/xfrm/xfrm_state.c:1041) runs with RTNL held. > > Pre-existing issues: > - [High] This problem wasn't introduced by this patch, but the patch > leaves a second caller of the same use-after-free. > > -- > > xfrm: Wait for an RCU grace period before freeing device state > > This patch removes the xfrm_dev_state_free() call that ran right after > xfrm_state_delete() in xfrm_dev_state_flush(). Device state freeing now > depends on the dev GC list collection pass or on the state GC. It also > adds a synchronize_rcu() between collecting the states and calling > xfrm_dev_state_free(), so that a grace period separates > xdo_dev_state_delete() and xdo_dev_state_free(). > >> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c >> index 8465ae0647427..9883fb3545f8f 100644 >> --- a/net/xfrm/xfrm_state.c >> +++ b/net/xfrm/xfrm_state.c >> @@ -1000,7 +1000,6 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali >> spin_unlock_bh(&net->xfrm.xfrm_state_lock); >> >> err = xfrm_state_delete(x); >> - xfrm_dev_state_free(x); >> >> xfrm_audit_state_delete(x, err ? 0 : 1, >> task_valid); > > [Severity: Medium] > With the synchronous free gone, can a state deleted by the flush end up > neither on flush_list nor visible to xfrm_flush_gc()? > > The commit message covers two cases. Either the collection pass finds the > state with a reference left, or the flush dropped the last reference. > What happens when some other holder (an skb secpath, a dst bundle, a > netlink handler) drops the last reference after the flush loop's > xfrm_state_put() but before the collection pass? > > xfrm_state_put()->__xfrm_state_destroy() does: > > 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); > > spin_unlock_bh() can run pending softirqs or act as a preemption point > before schedule_work() is reached. If the collection pass in > xfrm_dev_state_flush() runs during that gap, it sees a zero refcount and > skips the state: > > if (!refcount_inc_not_zero(&x->refcnt)) > continue; > > flush_list may then be empty, so synchronize_rcu() is skipped. > xfrm_flush_gc()->flush_work() also returns at once, because the work is > not queued yet. > > Would xfrm_dev_state_flush() then return for NETDEV_DOWN or > NETDEV_UNREGISTER with xso->dev still set, the netdev reference still > held and xdo_dev_state_free() not yet called? It is the same window discussed in previous patch. But the state GC frees the device state right after, following its own grace period, and unregister waits for the netdevice reference. > > The state GC would free it later, but only after the device is down. On > unregister, netdev_wait_allref would wait for it. On mlx5, operations > such as mlx5_eswitch_block_ipsec could fail for a while because the SA > is still there. > > Before this patch, the flush loop freed the states it deleted while it > still held a reference. The earlier "xfrm: Serialize device state > teardown" patch in this series added the zero-refcount skip, and this > patch now applies it to the states the flush deletes. > > [ ... ] > >> @@ -1038,6 +1037,9 @@ int xfrm_dev_state_flush(struct net *net, struct net_device *dev, bool task_vali >> spin_unlock_bh(&xfrm_state_dev_gc_lock); >> mutex_unlock(&xfrm_state_gc_mutex); >> >> + if (!hlist_empty(&flush_list)) >> + synchronize_rcu(); >> + > > [Severity: High] > This is a pre-existing issue, not one introduced by this patch. The > commit message says the required ordering is > xdo_dev_state_delete() -> synchronize_rcu() -> xdo_dev_state_free(), but > the grace period is only added here. > > Does bond_ipsec_del_sa_all() in drivers/net/bonding/bond_main.c have the > same use-after-free? Yes, it calls xdo_dev_state_delete() and xdo_dev_state_free() of the old slave back to back. But the issues related to bonding (here and next patch) need the fixes of its own. This series does not touch it. > > It runs when the active slave changes, via bond_change_active_slave(). > For each offloaded SA it calls delete and then free back to back on the > old slave: > > drivers/net/bonding/bond_main.c:bond_ipsec_del_sa_all() { > ... > if (ipsec->xs->km.state != XFRM_STATE_DEAD) > real_dev->xfrmdev_ops->xdo_dev_state_delete(real_dev, > ipsec->xs); > spin_unlock_bh(&ipsec->xs->lock); > > if (real_dev->xfrmdev_ops->xdo_dev_state_free) > real_dev->xfrmdev_ops->xdo_dev_state_free(real_dev, > ipsec->xs); > ... > } > > With an mlx5 slave, mlx5e_xfrm_del_state() removes sa_entry with > xa_erase_bh(&ipsec->sadb, ...). mlx5e_xfrm_free_state() then calls > kfree(sa_entry). At the same time, the RX path on the old slave can be > in: > > mlx5e_ipsec_offload_handle_rx_skb() > rcu_read_lock(); > sa_entry = xa_load(&ipsec->sadb, sa_handle); > ... > xfrm_state_hold(sa_entry->x); > rcu_read_unlock(); > > If xa_load() ran before the erase, can xfrm_state_hold(sa_entry->x) read > freed memory after the kfree()? > > The hardware RX rule is only removed later, inside free_state, by > mlx5e_accel_ipsec_fs_del_rule(). Tagged packets can keep arriving during > this window. The commit message doesn't mention this path. Should it > also get a grace period between delete and free? > > [Severity: Low] > xfrm_dev_state_flush() is only called from xfrm_dev_down() and > xfrm_dev_unregister() in net/xfrm/xfrm_device.c. Both are netdev > notifier handlers that run under RTNL. Would synchronize_net() be a > better fit here? > > synchronize_net() switches to synchronize_rcu_expedited() when > rtnl_is_locked(). With synchronize_rcu(), each device with offloaded SAs > adds a full normal grace period to RTNL hold time. During batched > unregister or netns dismantle, these grace periods run back to back. > > In the same call, xfrm_flush_gc() may also wait for > xfrm_state_gc_task(), which runs its own synchronize_rcu(). > > [ ... ] >