{"id":2218983,"url":"http://patchwork.ozlabs.org/api/patches/2218983/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260402083912.457676-1-munanevil@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":"<20260402083912.457676-1-munanevil@gmail.com>","list_archive_url":null,"date":"2026-04-02T08:39:12","name":"ksmbd: fix use-after-free in __ksmbd_close_fd() lock cleanup","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"3f2c746f5dea23e340c31b2cee15966340bd0750","submitter":{"id":93036,"url":"http://patchwork.ozlabs.org/api/people/93036/?format=json","name":"munan Huang","email":"munanevil@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-cifs-client/patch/20260402083912.457676-1-munanevil@gmail.com/mbox/","series":[{"id":498452,"url":"http://patchwork.ozlabs.org/api/series/498452/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-cifs-client/list/?series=498452","date":"2026-04-02T08:39:12","name":"ksmbd: fix use-after-free in __ksmbd_close_fd() lock cleanup","version":1,"mbox":"http://patchwork.ozlabs.org/series/498452/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2218983/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2218983/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-cifs+bounces-10624-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=K/FgGiS+;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=172.105.105.114; helo=tor.lore.kernel.org;\n envelope-from=linux-cifs+bounces-10624-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=\"K/FgGiS+\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=74.125.82.52","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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])\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 4fmb6l4jFXz1yFv\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 02 Apr 2026 19:46:07 +1100 (AEDT)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby tor.lore.kernel.org (Postfix) with ESMTP id 841703111EDE\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  2 Apr 2026 08:39:28 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 6BBB23C456F;\n\tThu,  2 Apr 2026 08:39:23 +0000 (UTC)","from mail-dl1-f52.google.com (mail-dl1-f52.google.com\n [74.125.82.52])\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 1D4283BBA15\n\tfor <linux-cifs@vger.kernel.org>; Thu,  2 Apr 2026 08:39:22 +0000 (UTC)","by mail-dl1-f52.google.com with SMTP id\n a92af1059eb24-126ea4e9694so2025145c88.1\n        for <linux-cifs@vger.kernel.org>;\n Thu, 02 Apr 2026 01:39:21 -0700 (PDT)","from ubuntu22-base.lan (104.194.93.216.16clouds.com.\n [104.194.93.216])\n        by smtp.gmail.com with ESMTPSA id\n a92af1059eb24-12bedd4e4e3sm1716646c88.1.2026.04.02.01.39.17\n        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n        Thu, 02 Apr 2026 01:39:20 -0700 (PDT)"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1775119163; cv=none;\n b=UDpurBA3h3BAIEYGcxarZkQrx8l8mVyElEbi1iF9eKxIOu1Hubd/FuUQ51pepUxLB8ap5i1z4Ubs6RQpIFD+0glyOI7sDk8SVE9XBfd/fNOcDSr0HbyR21ib2wiX9JPUzKiQgljfiiTZnifQ/+vsxU0rmdAKppwA5KVelT+8RvY=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1775119163; c=relaxed/simple;\n\tbh=cwiMGb+QvJPPbyOUbTGVlCDSVPPTs9vIaN+NXNJAVn8=;\n\th=From:To:Cc:Subject:Date:Message-Id:MIME-Version;\n b=hKpTHaLnaFSWazZEkN6uQ/oPoEMvi4oCUB7MoP7ug3FcV6X89FxukkSF/PGLrmqBc76DqliMYyh85cpU10UCfnbk35PqmP0OaLOYzn5hjhgq3ncOIYII06iFxdSmvl6BR0U0BQ4uwub92QJMJVUT57EIvUaQayhD/SToWC/dcq8=","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=K/FgGiS+; arc=none smtp.client-ip=74.125.82.52","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=gmail.com; s=20251104; t=1775119161; x=1775723961;\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=7eITVDgwa5tEdf7gs96GHN8iyQzNKskoC8moYtKLcKc=;\n        b=K/FgGiS+3PI2cFIE2N+jYPaP3BbsprXkLelxACmeih+ZJPGr6NWju/f1916TjbFFkf\n         hZe/o0+7Mi9Nh8LR39DkgNxuql0TvOgBtyNcn1eupfqiLol1ElVgjyYZR+Z8PlS4FUBE\n         7jRTE9z5OvIAyBmxLHB9M+3u5Q/wfYaqkcEvbBY70NJPMbUDyALNBmj/2rjWlr9+XU9s\n         oEZt77sdmJCjDlY3137MMUZLABPhV1KibPuvqW/3dyFG6aQuDsPk7Ocbx2P6e6QcOYNw\n         d+JugzOrlkOzt5+fw89gpYcKlXSuZDxFsSJX/CTvk7oDCSVYAXzPlMbzdiN6cfqaiK3N\n         292g==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n        d=1e100.net; s=20251104; t=1775119161; x=1775723961;\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=7eITVDgwa5tEdf7gs96GHN8iyQzNKskoC8moYtKLcKc=;\n        b=tRFfn/2Q/y5ebjN4g90pLOrrjsCfNcxmpDap1XpZMvi4z7bieu75jh30kNlNP4hUwl\n         5kT4mYb3dRFQeg0NvVBbvQz2gbTobTgBC9d6gVbrzaIVOxgtvPzLh1lLeHPQoqlxYUFR\n         9LvtJQmONMmLflMt/Vdnyv7/c8RFMOAuWu2pFUICnX7Py1yQyKjjVhsbhSatMCLdMnOW\n         B7lpa4NXSmu+4p8XWoQNs5eu8OYDqaQUHtCMgIPLcfpKcaIwOz5XdWSixN52yYoKtYVK\n         7Zi7jhSz5ehwSuO29P2302neT2rniQOMYV3m+h4W52nXiFeZmfHRbBzTEVPUciAHkk/z\n         dVmQ==","X-Gm-Message-State":"AOJu0YzsxLnziUZwn1cwj0raOTcyAJ3NGoNqRwJdx4VR0ysKzRnfGcNC\n\tgxQsf/lr8I0KCvSGpOYveGN2fdZMLGQgsPFJDND1PjwJvqHWUgCgU0BD","X-Gm-Gg":"ATEYQzy3qFtowAUeqyEtZphaKNAUb3loylUIIwPROEQD6Los456nx1n/jOvHbtkE6Tj\n\tIra07lkUiUnTb4nQGSoWCbsV/2ZosSfosrz8j/4uENc5XJmRkuuFG4G5rSCXZzsYRfLmKoE5/ak\n\tymABzbNiSuxGsxRnSY33Rm74FSNJKDfZnbFt+QS1kHWY/ZUouG4RyO4crNyZTPlLUc4fyDh75Jf\n\t+W5o3sS5jRy/OQoIUFY7YZjQgSPzeDw28rP/pzz9rDzHK8RPmQ0BhoHscb2wS5is+BkohmurbF1\n\tkrSXFPnx09m3G9oxC7LROAedhY/ZOA9p3rcsGuqX4I70NnEkEbqlGAAthR64j/mqthraMKSSSM8\n\toSG/UUtYJedALDN95PGW7zxgChVPLs6iL0Y3ZtxkMREmVG6s++AKrMIDGrRF9mcFk6pe1yS8uZB\n\t0Am/IfueKgrCXxU0RYKWACZ2PJ2/LUuGA4nVnlp58uvQ+OvZ0Sk/eY0wJoYg==","X-Received":"by 2002:a05:7022:f8e:b0:119:e56b:957c with SMTP id\n a92af1059eb24-12bee613f8cmr1450943c88.1.1775119161057;\n        Thu, 02 Apr 2026 01:39:21 -0700 (PDT)","From":"munan Huang <munanevil@gmail.com>","To":"linkinjeon@kernel.org,\n\tsmfrench@gmail.com,\n\tsenozhatsky@chromium.org,\n\ttom@talpey.com","Cc":"linux-cifs@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org,\n\tmunan Huang <munanevil@gmail.com>,\n\tstable@vger.kernel.org","Subject":"[PATCH] ksmbd: fix use-after-free in __ksmbd_close_fd() lock cleanup","Date":"Thu,  2 Apr 2026 08:39:12 +0000","Message-Id":"<20260402083912.457676-1-munanevil@gmail.com>","X-Mailer":"git-send-email 2.34.1","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":"In __ksmbd_close_fd(), when cleaning up byte-range locks on a durable\nfile handle closed by the scavenger, the lock cleanup loop\nunconditionally dereferences fp->conn->llist_lock to remove each lock\nfrom the connection's list:\n\n  list_for_each_entry_safe(smb_lock, tmp_lock, &fp->lock_list, flist) {\n      spin_lock(&fp->conn->llist_lock);\n      list_del(&smb_lock->clist);\n      spin_unlock(&fp->conn->llist_lock);\n  }\n\nHowever, when a client disconnects without SMB2 LOGOFF, ksmbd preserves\ndurable file handles via session_fd_check(), which sets fp->conn to\nNULL and arms the durable scavenger timeout, but does not detach the\nbyte-range locks from the dying connection's lock list.\n\nWhen the scavenger timeout expires, ksmbd_durable_scavenger() calls\n__ksmbd_close_fd(NULL, fp). At this point fp->conn is NULL and the\noriginal connection object has already been freed by ksmbd_conn_free(),\nso it would cause a use-after-free or NULL pointer dereference.\n\nFix by checking fp->conn for NULL before accessing fp->conn->llist_lock\nin the lock cleanup loop. \n\nFixes: c8efcc786146 (\"ksmbd: add support for durable handles v1/v2\")\nCc: stable@vger.kernel.org\nSigned-off-by: munan Huang <munanevil@gmail.com>\n---\n fs/smb/server/vfs_cache.c | 8 +++++---\n 1 file changed, 5 insertions(+), 3 deletions(-)","diff":"diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c\nindex 168f2dd7e200..772a84d95fe3 100644\n--- a/fs/smb/server/vfs_cache.c\n+++ b/fs/smb/server/vfs_cache.c\n@@ -463,9 +463,11 @@ static void __ksmbd_close_fd(struct ksmbd_file_table *ft, struct ksmbd_file *fp)\n \t * there are not accesses to fp->lock_list.\n \t */\n \tlist_for_each_entry_safe(smb_lock, tmp_lock, &fp->lock_list, flist) {\n-\t\tspin_lock(&fp->conn->llist_lock);\n-\t\tlist_del(&smb_lock->clist);\n-\t\tspin_unlock(&fp->conn->llist_lock);\n+\t\tif (fp->conn) {\n+\t\t\tspin_lock(&fp->conn->llist_lock);\n+\t\t\tlist_del(&smb_lock->clist);\n+\t\t\tspin_unlock(&fp->conn->llist_lock);\n+\t\t}\n \n \t\tlist_del(&smb_lock->flist);\n \t\tlocks_free_lock(smb_lock->fl);\n","prefixes":[]}