{"id":2224793,"url":"http://patchwork.ozlabs.org/api/patches/2224793/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260418172844.1333378-2-charsyam@gmail.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/projects/12/?format=json","name":"Linux CIFS Client","link_name":"linux-cifs-client","list_id":"linux-cifs.vger.kernel.org","list_email":"linux-cifs@vger.kernel.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260418172844.1333378-2-charsyam@gmail.com>","list_archive_url":null,"date":"2026-04-18T17:28:43","name":"[1/2] ksmbd: fix active_num_conn leak when alloc_transport() fails","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"d65d0c56d3e0cfd2a4daf4f8ee18f47615108b35","submitter":{"id":93166,"url":"http://patchwork.ozlabs.org/api/people/93166/?format=json","name":"DaeMyung Kang","email":"charsyam@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260418172844.1333378-2-charsyam@gmail.com/mbox/","series":[{"id":500457,"url":"http://patchwork.ozlabs.org/api/series/500457/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=500457","date":"2026-04-18T17:28:42","name":"ksmbd: connection accounting and session teardown fixes","version":1,"mbox":"http://patchwork.ozlabs.org/series/500457/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224793/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224793/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-cifs+bounces-10900-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-cifs@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=S4a7aoy3;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c15:e001:75::12fc:5321; helo=sin.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10900-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=\"S4a7aoy3\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.214.176","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=gmail.com"],"Received":["from sin.lore.kernel.org (sin.lore.kernel.org\n [IPv6:2600:3c15:e001:75::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fyf0g3tWlz1yGt\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 19 Apr 2026 03:30:43 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sin.lore.kernel.org (Postfix) with ESMTP id 5223B300515F\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 17:30:40 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 0B06932C8B;\n\tSat, 18 Apr 2026 17:30:38 +0000 (UTC)","from mail-pl1-f176.google.com (mail-pl1-f176.google.com\n [209.85.214.176])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id CC66A18C2C\n\tfor <linux-cifs@vger.kernel.org>; Sat, 18 Apr 2026 17:30:36 +0000 (UTC)","by mail-pl1-f176.google.com with SMTP id\n d9443c01a7336-2ab08e6c553so2429575ad.3\n        for <linux-cifs@vger.kernel.org>;\n Sat, 18 Apr 2026 10:30:36 -0700 (PDT)","from ser8.. ([221.156.231.192])\n        by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2b5fa9ff3bfsm69694965ad.7.2026.04.18.10.30.33\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Sat, 18 Apr 2026 10:30:35 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1776533437; cv=none;\n b=egH43Og8EJ+GCkftw1qS9xKvNNyVr9Cd7TUABFvBiMFITPmNhO/syQ8VfxynWWXREneCSi1oKnwd5OCE65zkKBKfaKpjXfamINJoIUYl0FZYzy91UyZnGZMTpF5iz//fzPwv0031gRrtG9hYxkHPPE6YP3oxmAK5vle1NwVia3A=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1776533437; c=relaxed/simple;\n\tbh=vv+uXWXTBOrZTKIXNUPiy6z/3X6izwegkuK8RtLwUfA=;\n\th=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:\n\t MIME-Version;\n b=sxwaqCM2m9Zn9fyZaXJgks0hQtCiTYp2HoG4BgaLSNEreoTpbnDB+WVfDRKM8WlOobjoaV9lDb9VLfGPuZFhUFN3LuktOn/vBnKqtq+zFtQdCO5KB+jNUQW/i4Irtx8u0Pv0RLdYlTY1Vb9OsZHO3BzoGWJG2pvIPN7vNKj2Y8s=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=gmail.com;\n spf=pass smtp.mailfrom=gmail.com;\n dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com\n header.b=S4a7aoy3; arc=none smtp.client-ip=209.85.214.176","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1776533436; x=1777138236;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=3lo0L+uxbWuB7MGwK8DGzVQOOZjXqL0ZQUgEg2W2lmI=;\n        b=S4a7aoy3tUvTUTXw+BOjDg7X0HRrz6kWXCg9C2Yv65Nm5h5NuBjeZTpQDaly1AHg5K\n         Qoiv1j2J1X6LgZs09hW/VRPoyqTM3mQFxAG5f03Au6iBd/LXz7jXsuujJYpc21DWUjKP\n         j+eJ7imew6hzPXzC9jHoBfXL1GE4tHznPb+TTM/A5TiQW64X1qmu9oWsuOCabYOjKtrU\n         04ijDFJpdOeOY0sFhxLG7es7YDROQGMMlUgR8Qw6MUsCTKcsJ8RxDV3hgxUBesppvVI/\n         yCXYeySgBFHVmqHFeUbO/7+yFr8JU7ktyVwUTcJwb+roC7SEHPJ4bNWm1rWa3SHcjbqL\n         TVRA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1776533436; x=1777138236;\n        h=content-transfer-encoding:mime-version:references:in-reply-to\n         :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n         :to:cc:subject:date:message-id:reply-to;\n        bh=3lo0L+uxbWuB7MGwK8DGzVQOOZjXqL0ZQUgEg2W2lmI=;\n        b=RNAzMetUKxZ/Qo/rA+MlYEP1XZQNQdakM4yg8cUFHCDV/i93cOKbTS/AO+eEqmUop6\n         uW2sxVhyvSCAgzpp+zbonOO/jLlEsJCQ5ofyal2ajaYNclecUXiBLxwjv1ymcwm/ibIU\n         /mqu49yEvhGaI+flQcqflHxOsCgd+fRr9WcjzKHp5O845KQ6mlsduzFpzKLt8jGONF9+\n         R6BJ9twCNk1y4uKZNQ665CICp+bBDTaVWmPa7k9DuHHK1r70JTYjFFanQZKogZwLxxLS\n         CxyLBokuLhSc4Fy2h72RJZdhGc1TzU5aKU7ZK4VYyYfZ0YT8V98TNtNTIbE6zQULm+Gf\n         wH5Q==","X-Forwarded-Encrypted":"i=1;\n AFNElJ8NnzLFr5Rrq8fIjjdfTQypG+itRuTUzmoDTOw/A1p1q0gYA+x0T3/G+uPo23mjbsJtN3M0+NSvSw+s@vger.kernel.org","X-Gm-Message-State":"AOJu0YzG7N84jiO6SFEGSZBw8bVgfjWXiCrJkmSOLSyZpJ5y4UkwuzGb\n\t1PzIA4JeU554epNCLJTCIRNxksc4Vn2ObwHCD1uB9dSWlx+7rapZS9iC","X-Gm-Gg":"AeBDies05QdzXC5v8RbMJobaYJYZ7bBp/D539iI3Uw2qSbkTaCylFqSLFiTVAy6/V1H\n\t9p2Sg0gX46s4SqKJbYfEl7v8PNDjiJ7dciJdOkSQ+qASgu9TRFnPHKQx05Kg69lFvfZF8UoPlG8\n\tDzl1wTPM7X/z7IKC4M3pvQpS7vFSOw/iDsnHhUcBpXRGqzMga1e8ed9g+v7xfgyyhu7kog7Dl8V\n\t6lOklXqjvQDiGMSJwEy7NTsNznib1dofDHGj9hicQqs6ssZdJG/poHvjiz2wCfvz4KT0CsYkQWG\n\tcamxV0jRdXCX5f9bJbEcHKNWrsjcQgRB5uBftQmzSGSZdXs7bC+mpUt8QgFMu+opASgf+FESgFE\n\toSGk71V7+FVwxnZp5xZh3YSUqB5+Gt7GMPrQzwgMr+2mD+el7NPUKfvBwVZ6bUpMMuv/+NGOGbe\n\tWGgWusfn2pPW0WPBPwZ5bQw8uNXnU=","X-Received":"by 2002:a17:902:d505:b0:2ae:3f3f:67c4 with SMTP id\n d9443c01a7336-2b5f9d67131mr40408135ad.0.1776533436099;\n        Sat, 18 Apr 2026 10:30:36 -0700 (PDT)","From":"DaeMyung Kang <charsyam@gmail.com>","To":"linkinjeon@kernel.org,\n\tsmfrench@gmail.com","Cc":"senozhatsky@chromium.org,\n\ttom@talpey.com,\n\tlinux-cifs@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tstable@vger.kernel.org,\n\tHenrique Carvalho <henrique.carvalho@suse.com>,\n\tDaeMyung Kang <charsyam@gmail.com>","Subject":"[PATCH 1/2] ksmbd: fix active_num_conn leak when alloc_transport()\n fails","Date":"Sun, 19 Apr 2026 02:28:43 +0900","Message-ID":"<20260418172844.1333378-2-charsyam@gmail.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260418172844.1333378-1-charsyam@gmail.com>","References":"<20260418172844.1333378-1-charsyam@gmail.com>","Precedence":"bulk","X-Mailing-List":"linux-cifs@vger.kernel.org","List-Id":"<linux-cifs.vger.kernel.org>","List-Subscribe":"<mailto:linux-cifs+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-cifs+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit"},"content":"ksmbd_kthread_fn() increments active_num_conn right after accept(),\nbefore calling ksmbd_tcp_new_connection().  The decrement normally\nhappens in ksmbd_tcp_disconnect() at the end of the connection's\nlifetime.\n\nIf alloc_transport() fails in ksmbd_tcp_new_connection(), the function\nreleases the socket and returns -ENOMEM without going through\nksmbd_tcp_disconnect(), so active_num_conn never gets decremented.\nUnder memory pressure, repeated failures monotonically inflate the\ncounter until max_connections is reached and new clients are refused\nindefinitely.\n\nDecrement active_num_conn on this error path, matching the accounting\nrule used by ksmbd_kthread_fn() and ksmbd_tcp_disconnect().\n\nCommit 77ffbcac4e56 (\"smb: server: fix leak of active_num_conn in\nksmbd_tcp_new_connection()\") fixed the sibling leak on the kthread_run()\nfailure path; this patch closes the remaining one.\n\nReproduced with a debug build that adds a temporary module parameter\nguarding an early return at the top of alloc_transport(), forcing\nthe first N accept-time transport allocations to fail:\n\n  * Configure ksmbd with \"max connections = 3\".\n  * Force 5 successive alloc_transport() failures at the accept path.\n  * Without the fix: active_num_conn drifts up to max_connections and\n    subsequent legitimate mount.cifs attempts are refused with\n    \"ksmbd: Limit the maximum number of connections(3)\" in dmesg.\n  * With the fix: the counter is correctly decremented on each\n    failure and legitimate mounts continue to succeed.\n\nTested by injecting 5 alloc_transport() failures with\nmax_connections=3 and verifying that subsequent mount.cifs attempts\nstill succeed on the patched kernel while the unpatched kernel\nrefuses them.\n\nFixes: 0d0d4680db22 (\"ksmbd: add max connections parameter\")\nCc: stable@vger.kernel.org\nSigned-off-by: DaeMyung Kang <charsyam@gmail.com>\n---\n fs/smb/server/transport_tcp.c | 2 ++\n 1 file changed, 2 insertions(+)","diff":"diff --git a/fs/smb/server/transport_tcp.c b/fs/smb/server/transport_tcp.c\nindex 7e29b06820e2..400412444838 100644\n--- a/fs/smb/server/transport_tcp.c\n+++ b/fs/smb/server/transport_tcp.c\n@@ -182,6 +182,8 @@ static int ksmbd_tcp_new_connection(struct socket *client_sk)\n \n \tt = alloc_transport(client_sk);\n \tif (!t) {\n+\t\tif (server_conf.max_connections)\n+\t\t\tatomic_dec(&active_num_conn);\n \t\tsock_release(client_sk);\n \t\treturn -ENOMEM;\n \t}\n","prefixes":["1/2"]}