{"id":2229662,"url":"http://patchwork.ozlabs.org/api/1.1/covers/2229662/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/cover/20260428140856.941847-1-charsyam@gmail.com/","project":{"id":12,"url":"http://patchwork.ozlabs.org/api/1.1/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":""},"msgid":"<20260428140856.941847-1-charsyam@gmail.com>","date":"2026-04-28T14:08:53","name":"[v2,0/3] ksmbd: fix connection and durable handle teardown races","submitter":{"id":93166,"url":"http://patchwork.ozlabs.org/api/1.1/people/93166/?format=json","name":"DaeMyung Kang","email":"charsyam@gmail.com"},"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/cover/20260428140856.941847-1-charsyam@gmail.com/mbox/","series":[{"id":501865,"url":"http://patchwork.ozlabs.org/api/1.1/series/501865/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=501865","date":"2026-04-28T14:08:55","name":"ksmbd: fix connection and durable handle teardown races","version":2,"mbox":"http://patchwork.ozlabs.org/series/501865/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/covers/2229662/comments/","headers":{"Return-Path":"\n <linux-cifs+bounces-11216-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=jbn354As;\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-11216-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=\"jbn354As\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=209.85.216.46","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 4g4kyX14nrz1xvV\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 01:35:00 +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 A5D943483ACC\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 14:09:14 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 21AC843E4B4;\n\tTue, 28 Apr 2026 14:09:03 +0000 (UTC)","from mail-pj1-f46.google.com (mail-pj1-f46.google.com\n [209.85.216.46])\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 AE5ED43E9FF\n\tfor <linux-cifs@vger.kernel.org>; Tue, 28 Apr 2026 14:09:01 +0000 (UTC)","by mail-pj1-f46.google.com with SMTP id\n 98e67ed59e1d1-35d9b4f93f0so1965581a91.3\n        for <linux-cifs@vger.kernel.org>;\n Tue, 28 Apr 2026 07:09:01 -0700 (PDT)","from ser8.. ([221.156.231.192])\n        by smtp.gmail.com with ESMTPSA id\n 41be03b00d2f7-c7fcade0f56sm2190526a12.21.2026.04.28.07.08.59\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Tue, 28 Apr 2026 07:09:00 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777385343; cv=none;\n b=ofeZ66z4VeAYWV9JxeYzpLutDE+aRCM9YV7/hH63ldte9buhdFoRAUarvPGGBKLro32Dzq0sIC90rXnw2l9d8pPK8M0qkHZzFXrXPtKRDsu70sg8wb9jClCgW9b8NhOlLFtAGUo2aSQnRyt9DGRcLnTBAqWAL0mbf9ouJteagX4=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777385343; c=relaxed/simple;\n\tbh=8hOzvSWdN2Ya+Uwd1l9pCURqaATyLwXy+tZggJd6cOU=;\n\th=From:To:Cc:Subject:Date:Message-ID:MIME-Version;\n b=BeMf+LQ9LO7TnE4aOXJCRrY3SWmfG20tuX76HCafAiPY1kOaKqKib9GEHG6qOYcXJ0WYaWTSDSJdvCiaiZBVryx6f7llwMagh0aEwyBytjvj37YFUWed/pWwKLKVItUI8uUADKrwbQ5VXOKFIoNvlqxgxju+7xV4ClXX5giW22Q=","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=jbn354As; arc=none smtp.client-ip=209.85.216.46","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1777385341; x=1777990141;\n darn=vger.kernel.org;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:from:to:cc:subject:date:message-id:reply-to;\n        bh=Gmp90OIC+H2EFfcAVybHPwuARwmtO3NkTHTeqIIClX4=;\n        b=jbn354AsjCmt+LLCK7kKjJozDCvCzZCeqsH3y3Y+pPSTZ3J0DrCCX9jGS3TH8dq3Zv\n         mY5exrBywKKckMqbtb3aP334UZNRuOeqQkuG6ShnPpX3IF/TPlrZZDa22fBA64/c3lsM\n         s8hmL9Z7sGX4m7jbO8Xg2yAXM8fGon+lX6gswT3mhQ4u9WMzY7nyJLqAt9XR/kxgGD2K\n         JECCYAhPHg8w559ZDKA0RV7Pvb1YXnkU0G1TLR9XHgp2qkhH1E0xIWGYvBO2dsPSdx3R\n         3I6yvtFFvnwhsW6gluvN8kfhXTEfDv6PintR7hNAIq8GfWgVK6DWxX2e/pCPog8ok4HQ\n         9jFQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1777385341; x=1777990141;\n        h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n         :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n         :message-id:reply-to;\n        bh=Gmp90OIC+H2EFfcAVybHPwuARwmtO3NkTHTeqIIClX4=;\n        b=r0phYbQEt9N0tDr09WCiH8VOZTvvmoqBF8uWFQ9dvcJs3eKWtsOdPyD/5PM87qXuvB\n         NYistSHc9HBsMA5DmVcDsh+RE2opmxzaWF3XOFWHAw3r+t6T+MugvLcTzu21ZstgUJSu\n         3AdneRbG/fPd6un38xLS5zM9tWn543mZvagW43RSnhE8Z8FfA4oWbf9BISt2XCoP9kzM\n         D5PoITolnKIRHrC9MF0znfEu05+oJKOj/351biqhwhi49uDAHWfmChgEgv11LnIQjWMJ\n         psqpOH0seSaUxqmSbxLV5ogVOUi42znVjiumRLp+vBg6X0xHvQX863gSlLTkQyzjHJbU\n         8c4Q==","X-Forwarded-Encrypted":"i=1;\n AFNElJ+q5aAt9uF5VD3aKbJXTjhf1lZJIknwHecbJAp8IKKZXS3vUS3WhxDx1Cw5jxESpHT1eMXbQ43Sn/DY@vger.kernel.org","X-Gm-Message-State":"AOJu0Yz+VHO+mncI+ChcCh+KoxHpLoI7BLsjcAlCuea/MguBgLH6HsQ6\n\t1EgJMd5yTxPGsq2ABbBYETLuYPGd5LPRl1u3nmmyrN3Qpcdhttmc0+sx","X-Gm-Gg":"AeBDieuXqBq/kJaS4iuXBTm677NBuplj7O+BUvlGcBaK8ssI3XdwN+wxonhgHJzY3Qc\n\twq4HNb7o1pPIo3sLAYydbfCUyd/UoPs0t2NICDafIZ7hHlO49rUbbGKqlBRAI4zSuwLOPXZmz90\n\tuU3Uvrh7IKUKEK2Lfje4v4xKndccRZ5EaxUsGAaeGKZxD14anVi94uY3kta8bVzGLiQegPvsZqP\n\tJ/mMIoSZTMOyC8SFu4uYeKFAFN7XT205dnZHLzk5uMxfzHcUocAMKHB9Gpsza04o7hhlebkE9yt\n\t10LdGO3NIZvfMTk8J1QpX3w1WcF6UApgbaxpyf0MpsVyAd+w9RR4mpcY+SPJhAYnGMrCR8IP3eJ\n\t6/L9IxU8GJ+RYnjmL2gBq7nPAr91b8jokrflRTNptVnoNW35cG3v2LdZ2i46lC2bypODWyGhdRu\n\tvCyoUUeqUANZYW6v8gvBxfoLm97tc=","X-Received":"by 2002:a17:90b:58cb:b0:362:bac0:1f54 with SMTP id\n 98e67ed59e1d1-36490cdb873mr2536931a91.6.1777385341011;\n        Tue, 28 Apr 2026 07:09:01 -0700 (PDT)","From":"DaeMyung Kang <charsyam@gmail.com>","To":"Namjae Jeon <linkinjeon@kernel.org>,\n\tSteve French <smfrench@gmail.com>","Cc":"Sergey Senozhatsky <senozhatsky@chromium.org>,\n\tTom Talpey <tom@talpey.com>,\n\tHyunchul Lee <hyc.lee@gmail.com>,\n\tRonnie Sahlberg <lsahlber@redhat.com>,\n\tlinux-cifs@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tDaeMyung Kang <charsyam@gmail.com>","Subject":"[PATCH v2 0/3] ksmbd: fix connection and durable handle teardown\n races","Date":"Tue, 28 Apr 2026 23:08:53 +0900","Message-ID":"<20260428140856.941847-1-charsyam@gmail.com>","X-Mailer":"git-send-email 2.43.0","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":"This series fixes lifetime bugs around ksmbd connection shutdown,\nsession file-table teardown, and durable handle scavenging.\n\nPatch 1 centralizes the final struct ksmbd_conn release so every last\nputter runs ida_destroy() and transport cleanup.  The release is queued\nto a dedicated workqueue because transport teardown can sleep, while\none known last-putter is an RCU callback.\n\nPatch 2 hardens __close_file_table_ids() by taking a transient\nksmbd_file reference, unpublishing from the session idr under ft->lock,\nand doing sleepable preserve/close work outside ft->lock.  It also\nmakes the FP_NEW window visible to the opener through\nksmbd_update_fstate().\n\nPatch 2 is scoped to file-table teardown and the FP_NEW publication\nwindow.  It does not try to fix durable reconnect rollback on later\nsmb2_open() error paths (and the related post-FP_INITED reference\nwindow in fresh smb2_open).  Both already exist before this series\nand need either an explicit unpublish-on-error step or an extra\nsession-owned reference.  That is left as follow-up work.  The\nFP_NEW -> FP_INITED failure reuses smb2_open()'s existing -ENOENT to\nSTATUS_OBJECT_NAME_INVALID mapping to avoid changing wire behavior in\nthis lifetime fix.\n\nPatch 3 closes two related races in the durable scavenger against any\nwalker that iterates f_ci->m_fp_list (ksmbd_lookup_fd_inode() and the\nshare-mode checks).  The scavenger no longer reuses fp->node as a\nscavenger-private collect-list node, takes an explicit transient\nreference under global_ft.lock, and drops both the durable lifetime\nand transient refs with atomic_sub_and_test(2, ...) after the\nm_fp_list unlink so an in-flight m_fp_list walker that snatched fp\nowns the final close cleanly.  fp->persistent_id is cleared inside\n__ksmbd_remove_durable_fd() so a delayed final close cannot re-issue\nidr_remove() on a slot that idr_alloc_cyclic() may have already\nre-handed to a new durable handle.  __put_fd_final() bypasses the\nper-conn open_files_count decrement when fp is detached from any\nsession table (fp->conn cleared by session_fd_check() at durable\npreserve, paired with the volatile_id clear at unpublish), since the\nwalker that owns the final close in that case runs from an unrelated\nwork->conn whose counter never tracked this durable fp.\n\nThe series is intentionally scoped to lifetime/race fixes and the\nwalker-final-putter regression that the durable scavenger handoff in\npatch 3 newly exposes.  Pre-existing reconnect rollback and per-conn\nopen_files_count accounting gaps are left as follow-up work so this\nseries does not have to claim a full durable-reconnect or accounting\ncleanup.\n\nValidation:\n  * abrupt-disconnect kmemleak/kprobe A/B for connection release\n  * same-session two-tcon DEBUG_LIST/DEBUG_OBJECTS_WORK stress\n  * forced durable-preserve sleep-path harness for session teardown\n  * KASAN-enabled direct SMB2 coverage for session/tree teardown and\n    durable-preserve paths\n  * KASAN-enabled direct SMB2 coverage for durable scavenger expiry\n    racing with m_fp_list lookups\n  * checkpatch --strict for all patches\n  * make -j$(nproc) M=fs/smb/server\n\nv1 -> v2:\n  * Split the original change into bisectable patches: connection final\n    release, session file-table teardown, and durable scavenger races.\n  * Keep sleepable session preserve/close work out of ft->lock and make\n    the FP_NEW publication race visible through a cleared volatile id.\n  * Document that durable reconnect rollback on later smb2_open()\n    error paths is a pre-existing follow-up item, and keep the\n    existing -ENOENT to STATUS_OBJECT_NAME_INVALID wire mapping for\n    this lifetime fix.\n  * Avoid reusing fp->node as a temporary durable scavenger list node\n    and take a transient reference in the durable scavenger so\n    concurrent ksmbd_lookup_fd_inode() walkers cannot UAF on freed fp.\n    These two fixes are folded into a single patch because the\n    list-head-reuse fix alone leaves a deterministic UAF window for\n    m_fp_list walkers; bisecting onto an intermediate state would land\n    on a use-after-free that pre-patch chaos merely made less\n    reproducible.\n  * Clear fp->persistent_id in __ksmbd_remove_durable_fd() so a holder\n    that owns the final close after a scavenger removal does not\n    re-issue idr_remove() on a persistent id that may have already been\n    handed out to a new durable handle.\n  * Bypass the per-conn open_files_count decrement in __put_fd_final()\n    when fp is detached from any session table, so an m_fp_list walker\n    that owns the final close of a scavenged durable fp does not\n    underflow an unrelated conn's stats counter.\n  * Document the ksmbd_conn_wq lifetime invariant in ksmbd_conn_put()\n    instead of guarding with WARN_ON_ONCE, so a violation surfaces as\n    a NULL deref rather than a silent leak of the final release.\n\nDaeMyung Kang (3):\n  ksmbd: centralize ksmbd_conn final release to plug transport leak\n  ksmbd: harden file lifetime during session teardown\n  ksmbd: close durable scavenger races against m_fp_list lookups\n\n fs/smb/server/connection.c | 101 +++++++++--\n fs/smb/server/connection.h |   6 +\n fs/smb/server/oplock.c     |   7 +-\n fs/smb/server/server.c     |  12 ++\n fs/smb/server/smb2pdu.c    |   6 +-\n fs/smb/server/vfs_cache.c  | 341 ++++++++++++++++++++++++++++++-------\n fs/smb/server/vfs_cache.h  |   4 +-\n 7 files changed, 396 insertions(+), 81 deletions(-)"}