From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387994; b=siqidOawul5PB0RELTmav6D1XxlnQVFMupamVBcZ9Wr17mUqee8+el139EVL0soXqwUZ 2UWJAuFCs4t6T8Z3c39HILvkT4hFPX5cY/ZpZ5cl4Q6BDIiVSF+5rJgQWxlU9bZiQPYag FQYDY6au91aXfw+bbMvQDHptE5lqq2UWFUnPePvasw3L4cRBHPe2/071TCRrLrFKjB2+3 tVh1CaVsn7v8vdzxwQ5CObfUNBMfspnRLHLeSYX7zojyg5880ZaoLMH8GnNzLB8vOfV4h r9eqdoVZBn9GVrX1we3iSx3GmIdF3FBRWW8MQxDHuOFrnKBpuvyYof8T4hJgjp8jy1Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387994; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=0va7AQsljvfv0AJJ/zoTgbnyvcqBIqPueMR5Pway0T0=; b=HV8EeqQYRp444sNb/gGDSZmIdkwGyHMz+IMFbbLLSvqcjfa8vsIWzdclfz4jrHQC2Zrl Waom0/MPBoscci248D9h9ekpc+W7E4t6BmyVs0rYkUI9lgL3r0FBx9hEnMVw0RNpN1clU 1ly/0/MVaf9AXCVu5VOom3q+gK+0RW6ybeU2YKZLUzXZmd6tJRsqiRsGynFNF0vGAUDZK 9ewRY3a/uJUsasoH0+XANnNnz2Vp4m98ATNzQJcJS/TLl2z4Upmmy7kvgSNiKsOMJ09Ub RthGBRMzs8dZ6lLLyWlpEp4tovYboXuqNjYqgQyL2bu3jlLj78IECXoeiyoO/oU99DQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ib3hK4h4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BC7F606A33B; Fri, 4 Dec 2026 12:39:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ib3hK4h4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B2D51F000CE; Fri, 4 Dec 2026 12:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387994; bh=0va7AQsljvfv0AJJ/zoTgbnyvcqBIqPueMR5Pway0T0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ib3hK4h40KFswS3C+Seha2Geje9xXREWL+EYYfVwZ6nqvScvujHOW6L1su2Vb/x3u nBMMMnTRkuqTMcKMMrOjZGeqzxCrqPXxh1GXtPCq5XdPnYqbK6BjFRSI06MMKZ/E5o K4f+Jgrz25rw+dFH0OpN1lA25fJ+nNWZBPxe+PSM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Guikun Yang , Fernando Fernandez Mancera , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.1 0442/1059] devlink: region: fix snapshot id leak on kernel-allocated ids Date: Fri, 4 Dec 2026 18:59:33 +0900 Message-ID: <20261204100655.757976527@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Fernando Fernandez Mancera [ Upstream commit ef8f0a1d888e0280452792f6d4edad237c934a51 ] When DEVLINK_CMD_REGION_NEW is issued without a snapshot id, the kernel allocates one with __devlink_region_snapshot_id_get(). That helper counts the caller as a user of the id, and the caller must release this hold once it is done. devlink_nl_region_new_doit() never drops it. The refcount of the id goes 1 (allocation) -> 2 (snapshot created) and stays at 2. When the snapshot is deleted the count only drops to 1, so the id is never erased from the snapshot_ids xarray. The id then stays in use for the lifetime of the devlink instance: requesting a snapshot with that explicit id fails with -EEXIST, and there is no snapshot left to delete to clean it up. Reproducer steps: # devlink region new pci/0000:13:00.0/device-caps pci/0000:13:00.0/device-caps: snapshot 0 # devlink region del pci/0000:13:00.0/device-caps snapshot 0 # devlink region new pci/0000:13:00.0/device-caps snapshot 0 kernel answers: File exists Drop the caller's reference right after the snapshot has been created, as the snapshot then holds its own. Fixes: 043b3e22768d ("devlink: let kernel allocate region snapshot id") Reported-by: Guikun Yang Closes: https://lore.kernel.org/netdev/tencent_BE912BA710539F285F9FCF28E854ABEFCD07@qq.com/ Signed-off-by: Fernando Fernandez Mancera Link: https://patch.msgid.link/20261026174403.512-1-fmancera@suse.de Signed-off-by: Jakub Kicinski [ sashal: Applied the hunk to devlink_nl_cmd_region_new() in leftover.c, since this tree has no region.c and devlink_nl_region_new_doit() under its newer name. ] Signed-off-by: Sasha Levin --- net/devlink/leftover.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 568e4efd8868a..7f526cbe0d33d 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -6310,6 +6310,11 @@ devlink_nl_cmd_region_new(struct sk_buff *skb, struct genl_info *info) if (!snapshot_id_attr) { struct sk_buff *msg; + /* Drop the allocation reference, the snapshot + * now holds its own. + */ + __devlink_snapshot_id_decrement(devlink, snapshot_id); + snapshot = devlink_region_snapshot_get_by_id(region, snapshot_id); if (WARN_ON(!snapshot)) { -- 2.53.0