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=1796385190; b=H7N9t35laCxCO1GsGITOXh4uILU6OxCr3BHdSkGy8ivqOu5EQsqIRFFHfHQVi2zkZeOW MPvLPmLQTj0r4i/gysj3TZZqlADZA6flCffYTqJyjQztLL9jMejU6zBKRv02VoWnh13mZ ZqpGP6foNtGkhKnQO9D/KGb3/yCwmo9RK38WkSEM5tMVQdHsQLY2kgUCkbLi3KecutM6L tFIsqiYfTboLTIAlJi3CPZLmCm1GQHBSvft0R3vOTFs7EaCQceiZcmzssxztG1pPU2bJN /ltyS6y7+KBLtJ92C+juxD6M7c9oopsIGxYXcLPiy2JHCJgtDnm9da1bJRCpxoiI0Sg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385190; 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=yhwBFfCdv5CTFLgqlwka25oECqdQr2sTwvQmp4q4s9g=; b=Gic2ov+D3b/65fatq75HgMN/AhimLtyiPFYBeA7qLe2I47rj6mshFcFSkjBDu2J3RMNH BcFRILLoE0O5dahP7qpAt9TE5fCDg6iuG4tTr5lI3kq3WJByKH5VXh62HJxirIx0G820A qjqkIaPqRNPgs7gqdMq+qjjsHeAEfJnAuPsHI+kzZiOYUVRcYYL6pAmgR2Ck3CGltChS2 u6qRjJXJFMXrvz5ggb46frCnTgu8EN/1SaTSCGbvC6Ey3U7HFGoDSFKqhN+8sZlM6LmQD l9P0c7y+6sEDjWbNh/7/77JL4jj753H7kvCvFcTXEicbf17BoWE//6tF0DpiQkCmg+Q== 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=Py3pYHcd; 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 40119606A32C; Fri, 4 Dec 2026 11:53:10 +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=Py3pYHcd Received: by smtp.kernel.org (Postfix) with ESMTPSA id B109D1F000C2; Fri, 4 Dec 2026 11:53:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385190; bh=yhwBFfCdv5CTFLgqlwka25oECqdQr2sTwvQmp4q4s9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Py3pYHcdBOgeZeDQA8G/jxTjl6h3d8awhJW7sfk5SKT9PAa6/hIIhVjOC/k7gh9Iw w990w4TeJwkHoPmaXV3BNMigaPiuO42JUTNT8ddfKvcyqBRmKc/J/xflST/C9YIg0k 8O6aFWH7vkpW8nQX3UZo+ABtQnZp16zorUjHsrD0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mohammed , Namjae Jeon , Sasha Levin Subject: [PATCH 6.6 0454/1167] ksmbd: fix fd_limit accounting across durable reconnects Date: Fri, 4 Dec 2026 18:58:01 +0900 Message-ID: <20261204100713.838199342@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Namjae Jeon [ Upstream commit df5c868f6b80ca16c171cfac5e4e6c9be83ba4c2 ] A disconnected durable handle keeps its ksmbd_file and the fd_limit reservation taken at its initial open. Reconnecting allocates another volatile ID and takes another reservation for the same file. Final close returns only one reservation, so repeated reconnects permanently reduce the server-wide open-file budget. Move reservation into ksmbd_open_fd() and release it on every creation failure. Keep the reservation until final close, including while a durable handle is disconnected. Make ID allocation independent of fd_limit so reconnects neither consume nor return slots. This also avoids returning an unreserved slot when persistent ID allocation fails. New opens continue to return -EMFILE when the budget is exhausted, keeping the existing STATUS_INSUFFICIENT_RESOURCES mapping. Fixes: c8efcc786146 ("ksmbd: add support for durable handles v1/v2") Reported-by: Mohammed Signed-off-by: Namjae Jeon [ sashal: Context lines used the literal GFP_KERNEL instead of the KSMBD_DEFAULT_GFP macro, which this tree lacks, so both conflicting hunks were resolved with GFP_KERNEL. ] Signed-off-by: Sasha Levin --- fs/smb/server/vfs_cache.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index 142aa00499805..ab47cee8a89ad 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -721,11 +721,6 @@ static int __open_id(struct ksmbd_file_table *ft, struct ksmbd_file *fp, u64 id = 0; int ret; - if (type == OPEN_ID_TYPE_VOLATILE_ID && fd_limit_depleted()) { - __open_id_set(fp, KSMBD_NO_FID, type); - return -EMFILE; - } - idr_preload(GFP_KERNEL); write_lock(&ft->lock); ret = idr_alloc_cyclic(ft->idr, fp, KSMBD_START_FID, INT_MAX - 1, @@ -735,7 +730,6 @@ static int __open_id(struct ksmbd_file_table *ft, struct ksmbd_file *fp, ret = 0; } else { id = KSMBD_NO_FID; - fd_limit_close(); } __open_id_set(fp, id, type); @@ -755,10 +749,15 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp) struct ksmbd_file *fp; int ret; + /* Durable reconnects reuse the slot held for the lifetime of fp. */ + if (fd_limit_depleted()) + return ERR_PTR(-EMFILE); + fp = kmem_cache_zalloc(filp_cache, GFP_KERNEL); if (!fp) { pr_err("Failed to allocate memory\n"); - return ERR_PTR(-ENOMEM); + ret = -ENOMEM; + goto err_fd_limit; } INIT_LIST_HEAD(&fp->blocked_works); @@ -801,6 +800,8 @@ struct ksmbd_file *ksmbd_open_fd(struct ksmbd_work *work, struct file *filp) /* fp->conn was set and refcounted before every branch here. */ ksmbd_conn_put(fp->conn); kmem_cache_free(filp_cache, fp); +err_fd_limit: + fd_limit_close(); return ERR_PTR(ret); } -- 2.53.0