From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3229441033 for ; Tue, 28 Apr 2026 14:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777385343; cv=none; b=BkgBLOl9a1ejiX5TSO6wBHK5FpVV6Vl8j2hlcN+wltFzryibq6KALL2kCx90lLMa6lmbksSpi30CkxsTvhC6alp9uceyCERPK/dz7cXqrsLVcYq0yMNKkALhyork6ydDqk6sMPgCPbO/uL/cBy0Vi/el8XN/rTlAiLwbqfEnDaA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777385343; c=relaxed/simple; bh=8hOzvSWdN2Ya+Uwd1l9pCURqaATyLwXy+tZggJd6cOU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=BeMf+LQ9LO7TnE4aOXJCRrY3SWmfG20tuX76HCafAiPY1kOaKqKib9GEHG6qOYcXJ0WYaWTSDSJdvCiaiZBVryx6f7llwMagh0aEwyBytjvj37YFUWed/pWwKLKVItUI8uUADKrwbQ5VXOKFIoNvlqxgxju+7xV4ClXX5giW22Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jbn354As; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jbn354As" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-35e4617924eso1780639a91.1 for ; Tue, 28 Apr 2026 07:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777385341; x=1777990141; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Gmp90OIC+H2EFfcAVybHPwuARwmtO3NkTHTeqIIClX4=; b=jbn354AsjCmt+LLCK7kKjJozDCvCzZCeqsH3y3Y+pPSTZ3J0DrCCX9jGS3TH8dq3Zv mY5exrBywKKckMqbtb3aP334UZNRuOeqQkuG6ShnPpX3IF/TPlrZZDa22fBA64/c3lsM s8hmL9Z7sGX4m7jbO8Xg2yAXM8fGon+lX6gswT3mhQ4u9WMzY7nyJLqAt9XR/kxgGD2K JECCYAhPHg8w559ZDKA0RV7Pvb1YXnkU0G1TLR9XHgp2qkhH1E0xIWGYvBO2dsPSdx3R 3I6yvtFFvnwhsW6gluvN8kfhXTEfDv6PintR7hNAIq8GfWgVK6DWxX2e/pCPog8ok4HQ 9jFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777385341; x=1777990141; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Gmp90OIC+H2EFfcAVybHPwuARwmtO3NkTHTeqIIClX4=; b=S+JLaA9rMg+vf6x97YfI7fAGn5TADdI5GtsAY2An8agsIhNmrWdOh3AppY+hfT5eGL qIBvYiy1yJ+9vmwV7QTHfDEaX/6EyqGHjLl0n0mjYzLcx/KSu8zI/87k6rANNXwIAt18 63gzeggYhLStj0oApCSuiO7qSUSvYr14mUN74Jy2Xv50BvwKP9amq+cQsOivNUnkcZY7 RhEbV7J44yjyUGv8zMm9ha9gtpZa8gDspLJZ8xpUl92GywQ+sqcX5F9asTqKgdztiV5B rqPrbzqhp04Kok9FEOb1150cZ0/9K2MlqAgcjynISBwN5xoKpBXcxon4QLodXFpPwGmM jEbA== X-Forwarded-Encrypted: i=1; AFNElJ+LU4IXkpyjRumvTMXRXUk0lUD8lX3HKB2qEhjYPRLmExxjPQPWMYxQYLu5kEL2hOdCjeGNK/Ked8kCjqM=@vger.kernel.org X-Gm-Message-State: AOJu0YxfYSDkIVDfv1HcC5jLcQ6I76gyoQjBe88nW9x+dj6006x26h4L GXltxNZBwFse59kGb4XhUjQF2jr+Jtq+l/HsL1x+NHgzg3BFNX6ZwewB X-Gm-Gg: AeBDiesz31L++j9mRRy5r8BQiI9p6en3J8ZIPw62xgoW0uKeOBreUpdNerUuf41qQ5c O4e7fURP2xX0KfXIc/fHscKw4k1RUBuC+54Ua5xTaOliBF1qORIcX72KY5/pCE7VklO2SmAW4JF TEQYfk3/TrFRvTA1sqIFTUH26JvzooP6UN2/o5D1shu8YBMQvK78rGCfIUt2++4Zm1Zc7Pd9Syq TI35oJ/HxDD+BuX21iuQlBuV7lTE6PzNuRxszrDs6Oi9YjGzQRWP2RU0a5tg98tTgOvpqJsvnKo t9hJmxtWkTYEnWBEcuHjNoafcUsOc1bJ12JXD0cph+EwsRfS3VGUmaV10MMJ0ll9uti4BxfTFbL tFeXuG+jYAQeimmDdsuVx8OaFk+PaeSHnQqRWihzHIaFZtlWJtQtrnC9geICFcmpkRTPpQvwNeu WIESMvRkacyGAy3PNuvvWX0DCLz0Q= X-Received: by 2002:a17:90b:58cb:b0:362:bac0:1f54 with SMTP id 98e67ed59e1d1-36490cdb873mr2536931a91.6.1777385341011; Tue, 28 Apr 2026 07:09:01 -0700 (PDT) Received: from ser8.. ([221.156.231.192]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7fcade0f56sm2190526a12.21.2026.04.28.07.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2026 07:09:00 -0700 (PDT) From: DaeMyung Kang To: Namjae Jeon , Steve French Cc: Sergey Senozhatsky , Tom Talpey , Hyunchul Lee , Ronnie Sahlberg , linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, DaeMyung Kang Subject: [PATCH v2 0/3] ksmbd: fix connection and durable handle teardown 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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This series fixes lifetime bugs around ksmbd connection shutdown, session file-table teardown, and durable handle scavenging. Patch 1 centralizes the final struct ksmbd_conn release so every last putter runs ida_destroy() and transport cleanup. The release is queued to a dedicated workqueue because transport teardown can sleep, while one known last-putter is an RCU callback. Patch 2 hardens __close_file_table_ids() by taking a transient ksmbd_file reference, unpublishing from the session idr under ft->lock, and doing sleepable preserve/close work outside ft->lock. It also makes the FP_NEW window visible to the opener through ksmbd_update_fstate(). Patch 2 is scoped to file-table teardown and the FP_NEW publication window. It does not try to fix durable reconnect rollback on later smb2_open() error paths (and the related post-FP_INITED reference window in fresh smb2_open). Both already exist before this series and need either an explicit unpublish-on-error step or an extra session-owned reference. That is left as follow-up work. The FP_NEW -> FP_INITED failure reuses smb2_open()'s existing -ENOENT to STATUS_OBJECT_NAME_INVALID mapping to avoid changing wire behavior in this lifetime fix. Patch 3 closes two related races in the durable scavenger against any walker that iterates f_ci->m_fp_list (ksmbd_lookup_fd_inode() and the share-mode checks). The scavenger no longer reuses fp->node as a scavenger-private collect-list node, takes an explicit transient reference under global_ft.lock, and drops both the durable lifetime and transient refs with atomic_sub_and_test(2, ...) after the m_fp_list unlink so an in-flight m_fp_list walker that snatched fp owns the final close cleanly. fp->persistent_id is cleared inside __ksmbd_remove_durable_fd() so a delayed final close cannot re-issue idr_remove() on a slot that idr_alloc_cyclic() may have already re-handed to a new durable handle. __put_fd_final() bypasses the per-conn open_files_count decrement when fp is detached from any session table (fp->conn cleared by session_fd_check() at durable preserve, paired with the volatile_id clear at unpublish), since the walker that owns the final close in that case runs from an unrelated work->conn whose counter never tracked this durable fp. The series is intentionally scoped to lifetime/race fixes and the walker-final-putter regression that the durable scavenger handoff in patch 3 newly exposes. Pre-existing reconnect rollback and per-conn open_files_count accounting gaps are left as follow-up work so this series does not have to claim a full durable-reconnect or accounting cleanup. Validation: * abrupt-disconnect kmemleak/kprobe A/B for connection release * same-session two-tcon DEBUG_LIST/DEBUG_OBJECTS_WORK stress * forced durable-preserve sleep-path harness for session teardown * KASAN-enabled direct SMB2 coverage for session/tree teardown and durable-preserve paths * KASAN-enabled direct SMB2 coverage for durable scavenger expiry racing with m_fp_list lookups * checkpatch --strict for all patches * make -j$(nproc) M=fs/smb/server v1 -> v2: * Split the original change into bisectable patches: connection final release, session file-table teardown, and durable scavenger races. * Keep sleepable session preserve/close work out of ft->lock and make the FP_NEW publication race visible through a cleared volatile id. * Document that durable reconnect rollback on later smb2_open() error paths is a pre-existing follow-up item, and keep the existing -ENOENT to STATUS_OBJECT_NAME_INVALID wire mapping for this lifetime fix. * Avoid reusing fp->node as a temporary durable scavenger list node and take a transient reference in the durable scavenger so concurrent ksmbd_lookup_fd_inode() walkers cannot UAF on freed fp. These two fixes are folded into a single patch because the list-head-reuse fix alone leaves a deterministic UAF window for m_fp_list walkers; bisecting onto an intermediate state would land on a use-after-free that pre-patch chaos merely made less reproducible. * Clear fp->persistent_id in __ksmbd_remove_durable_fd() so a holder that owns the final close after a scavenger removal does not re-issue idr_remove() on a persistent id that may have already been handed out to a new durable handle. * Bypass the per-conn open_files_count decrement in __put_fd_final() when fp is detached from any session table, so an m_fp_list walker that owns the final close of a scavenged durable fp does not underflow an unrelated conn's stats counter. * Document the ksmbd_conn_wq lifetime invariant in ksmbd_conn_put() instead of guarding with WARN_ON_ONCE, so a violation surfaces as a NULL deref rather than a silent leak of the final release. DaeMyung Kang (3): ksmbd: centralize ksmbd_conn final release to plug transport leak ksmbd: harden file lifetime during session teardown ksmbd: close durable scavenger races against m_fp_list lookups fs/smb/server/connection.c | 101 +++++++++-- fs/smb/server/connection.h | 6 + fs/smb/server/oplock.c | 7 +- fs/smb/server/server.c | 12 ++ fs/smb/server/smb2pdu.c | 6 +- fs/smb/server/vfs_cache.c | 341 ++++++++++++++++++++++++++++++------- fs/smb/server/vfs_cache.h | 4 +- 7 files changed, 396 insertions(+), 81 deletions(-) -- 2.43.0