Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F196E37999A; Wed, 7 Jan 2026 15:53:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767801229; cv=none; b=aPuM0ZZrksvjuBJbJk6TvY/M5COZqMcRYjqI0426ENkGyY1DmeYdpTSzRLwcec8mByjN2v8kFzKiAq1tTW1m5GK4Vlx/3GU1xlZHKqXcxezCNYLAtcSUMS4In47VIKSIhDAoSBmGyPRMVz1NZQ/4iMfIjohMxuV1O4zexLlNxTg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767801229; c=relaxed/simple; bh=wP0SRYC/Uxw5ny2yW3zdrW+ttw0FFwCtSvbWxScNDCI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dZTV3W1MIlVBZr10jua+tf7l9R4T26RzTBYnmT52DkscT8V3qmwPpSgD3zNWFLDBoIxrzEWa9Q11C8XLKUE4DGAEVPVbnMAkfx+iwE0jYTGW1ekeomvEFfahqabNwdTap6M8CFbc7MUOKGL8lMltRpJJ2t7yctZ4YdU7CjpIzMk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H55d2JFh; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H55d2JFh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FA64C19422; Wed, 7 Jan 2026 15:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767801227; bh=wP0SRYC/Uxw5ny2yW3zdrW+ttw0FFwCtSvbWxScNDCI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H55d2JFh40C+r1p8kV4nxrqGW8kBYOZK52kE9lTL5e1vz+63kHZIcGR7Dlr37DE+L BTgRmZwVkcNvJLBoP7BXIaY2cAVG9tlAu2/f4229Aa8Lt0RsCUlMmvwqLo3bbv28zP juTIMHMWpetvItuM0DPtvadcBXtVgOwdWgzceyciO+zdZ87t0wHfw7P6DVcqlU1SM5 +V7Z1M5scgjCzzimdBdCYkugLFFA7aMydC3pfzNsLL4DvKa/vEdTr/HiQ7ZUKCmbhF xXkISt/l3Qt6at6lRMZuwlqzGoqebUXGl+WS/gi6FmQexM+8qDkjMskWIvcegGIYJK pCG/fBZiE6+NQ== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: ZhangGuoDong , ChenXiaoSong , Namjae Jeon , Steve French , Sasha Levin , smfrench@gmail.com, linux-cifs@vger.kernel.org Subject: [PATCH AUTOSEL 6.18-6.6] smb/server: fix refcount leak in parse_durable_handle_context() Date: Wed, 7 Jan 2026 10:53:12 -0500 Message-ID: <20260107155329.4063936-10-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260107155329.4063936-1-sashal@kernel.org> References: <20260107155329.4063936-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.18.3 Content-Transfer-Encoding: 8bit From: ZhangGuoDong [ Upstream commit 3296c3012a9d9a27e81e34910384e55a6ff3cff0 ] When the command is a replay operation and -ENOEXEC is returned, the refcount of ksmbd_file must be released. Signed-off-by: ZhangGuoDong Signed-off-by: ChenXiaoSong Acked-by: Namjae Jeon Signed-off-by: Steve French Signed-off-by: Sasha Levin --- LLM Generated explanations, may be completely bogus: ### 3. CLASSIFICATION - **Type**: Bug fix (refcount/memory leak) - **Pattern**: Classic missed put() in error path - **Severity**: Medium - causes memory leak affecting long-running servers - **Not applicable**: No new features, no device IDs, no API changes ### 4. SCOPE AND RISK ASSESSMENT | Aspect | Assessment | |--------|------------| | Lines changed | 1 (single line addition) | | Files touched | 1 (fs/smb/server/smb2pdu.c) | | Complexity | Very low - standard refcount balance fix | | Risk of regression | Very low - only affects specific error path | | Subsystem maturity | ksmbd is relatively mature with active maintenance | ### 5. USER IMPACT - **Affected users**: Users of ksmbd (in-kernel SMB server) - **Bug trigger**: When a SMB durable v2 open request is NOT a replay operation - **Consequence**: Memory leak - `ksmbd_file` structures are not freed - **Long-term impact**: Memory exhaustion on busy SMB servers over time ### 6. STABILITY INDICATORS - **Acked-by**: Namjae Jeon (ksmbd maintainer) - authoritative - **Fix pattern**: Textbook refcount leak fix - very well understood - **Code path**: Clear and deterministic - when -ENOEXEC is returned, reference must be released ### 7. DEPENDENCY CHECK - **Self-contained**: Yes - no dependencies on other commits - **Affected versions**: Introduced in v6.9-rc1 via commit c8efcc786146a - **Applies to stable trees**: 6.9.y, 6.10.y, 6.11.y, 6.12.y, etc. - **Clean backport**: Should apply cleanly to any tree containing c8efcc786146a ### Technical Analysis The bug mechanism is straightforward: 1. `ksmbd_lookup_fd_cguid()` looks up a file by GUID and returns it with an incremented refcount via `ksmbd_fp_get()` 2. The caller at line 2816 stores this in `dh_info->fp` 3. In the error path (line 2820-2822), when NOT a replay operation, the code returns -ENOEXEC 4. **The bug**: The `goto out` statement jumps to a label that simply returns, without releasing the reference 5. **The fix**: Add `ksmbd_put_durable_fd(dh_info->fp)` before `goto out` to properly decrement the refcount This is a standard kernel refcount bug pattern: lookup functions return referenced objects, and callers must ensure all exit paths release the reference. ### Conclusion This commit is an excellent candidate for stable backporting: - **Obviously correct**: Standard refcount leak fix pattern used throughout the kernel - **Fixes a real bug**: Memory leak that can affect production servers - **Small and surgical**: Single line addition with zero risk of breaking unrelated code - **No new features**: Pure bug fix - **Well-tested**: Acked by the subsystem maintainer - **Clear scope**: Only affects the specific -ENOEXEC error path in durable handle parsing The fix is minimal, addresses a genuine resource leak, and follows established kernel patterns. The risk of regression is essentially zero since the fix only adds a missing cleanup call in a specific error path. **YES** fs/smb/server/smb2pdu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 3795fb90e161..e4ac9d72faa0 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -2822,6 +2822,7 @@ static int parse_durable_handle_context(struct ksmbd_work *work, SMB2_CLIENT_GUID_SIZE)) { if (!(req->hdr.Flags & SMB2_FLAGS_REPLAY_OPERATION)) { err = -ENOEXEC; + ksmbd_put_durable_fd(dh_info->fp); goto out; } -- 2.51.0