From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 ED4453E3C5F for ; Thu, 23 Jul 2026 23:01:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784847672; cv=none; b=tvoRjvpFv3oW9Fkgxlz338r4g6XdvqWSVStopD7vdkFOt0IPQt8dQNQ+6kPd1KBhxsodkZFemHrgFbOnjJqhazcyoG/fy4ZhqSgEudjZzmLjYK0BBXum7EghVC+R/5EwEHuIV6Y8fY2LzwG8fiQUjBY9nTaovgRA6XUks8QanmM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784847672; c=relaxed/simple; bh=wnkam4gARZPimI6t3q6/gi53lYyin+NicZ/A9htdCU8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=k+dl1CXbKdMmx7fn9on7sD/U9CQeh6Yo3iiVFoOoysToiSm/311Bm4gMdqJ+Y79KddsPxBX90QTB0nckNWoSu9DCRbQlPcwuod+wUj5inzXP2CgzgBWxX8qiL2Luh/1nvjvQDHBvfw6AnOMclCeGsboLApS4Xfwb4JvPuWlA1Ic= 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=Y19sT8fE; arc=none smtp.client-ip=209.85.218.47 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="Y19sT8fE" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-c197e7e4e94so216582966b.2 for ; Thu, 23 Jul 2026 16:01:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784847668; x=1785452468; 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:content-type; bh=NkiiwKU0NKOWW0DOqWdWOWQ7VLeFhZ7u/mJhBXHCR5o=; b=Y19sT8fEkOIsL8IrKnzfW6BE0AvFo2eY9ikmiKCU3ZHRpEr08rDc5E4xUOAR4XbIl8 yzN9Eu52MnwaHm1mQ2Rl0xs8uTVy/2GJu6Vglq3fz7zwK/y1snJCh+cJkyuMbtLizMNT DuWAQM7S50332ckydxQHsY63k67WG/EHKG4bXRgqxws/M/vkgZ0Wa8mvklyznKQYkyIJ 4WdYtm5bqpbTKFS+0CTiL4PpYWvPXFS04b1+KTh3pjdsDeAwNK5NSPOZZCanledXDMMK n8rl9N2D1RB05ZtjJJbA/WYHcd0b4gRxpIG0hb5Njuyq77f3BX4W9Avw/zihEKG0tMxE zr6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784847668; x=1785452468; 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:content-type; bh=NkiiwKU0NKOWW0DOqWdWOWQ7VLeFhZ7u/mJhBXHCR5o=; b=nt8bnER0+ouvGMquRqXOeifqNAB+ZWX+72Iud4+hramMQTEVv4GvKulNs6+AlOCesK thEz8eh3cQteiOiO02crDcfo9z21tN5Eu4wsRjyIRyppfJpoQ+dEDUgrx+jpCyCS/ffd eoOqTrFgQKJ5t461bH1CcKC1AsLuZuL6fyPNk5H94XbhVBRvFoBySPbYWyfJFLu8Xo7/ Cg5RYt66mDISpdCtgXUePeJhSoPinOCJ7K9fLiLjClK7IqYpI7BtViTjJl6Co404tOQf NLi/907hA7JkGASUE0XKlXad5dSH0RwFXhhXqJ7z2S9mI4lDkirFXKw4ObdrRh+tufB/ uBEA== X-Forwarded-Encrypted: i=1; AHgh+RqYlxqDy8GJ7MXr0LSU8uGVX4kD/9U+Zb4j28PcTVoQddMlSqaPWT9yKW41jcB5XKDhXVNhd/zOOJxggLQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyUQyFV1w1Ookg5E50ekXy0iZdw6wtdrQG+XMtrVoi6pyNk36Ci NFZh3J6St6+rusk2nHqzwxlb+9/7PHBTBVcgO44JDtnv8uzWldbn+ZlD X-Gm-Gg: AR+sD124Z5Hnm4hIACT0SDvflIOunbjP6qFLzPuXJIPaQ/vkZX+MXEJHWsRDBuB30MY 0mLhjm1hK8xQcIRzMWG/IAKK6Jfte2oLIEx0PdeRBHaCigD3AjGDqCX5T2piCGGba9CBLl7CNKk vunUbmZSByeNiI6rymHmdydSTkkj33l0iccQK5fpckamLI4+r07nHFQO17zCxxEzJfYar3St3j8 swCXH64Qn7zfq2KqTeAbWD8bWol4ZjilRPqU0KQWCgJHcMYKMbBAyttLa/hVN1JLtxZxsx9HpBU tkSljTaKDT2OaNi1SOfNgrw0orYl9G9DwfcgnyBHaYA9psEPc3v21wobJ7rlleIfqBhK2pMHGiq LvavpNFmt28SADCuCMLD09O/SNK8Tzh4zZP8QRR1kYx82pd6GbtGgVwtPf6w3o+hIeyKPdg== X-Received: by 2002:a17:907:72d4:b0:c1c:4858:c19c with SMTP id a640c23a62f3a-c1c5098acf8mr214121066b.23.1784847667654; Thu, 23 Jul 2026 16:01:07 -0700 (PDT) Received: from beelink.. ([186.247.163.143]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32a78e0fsm277534766b.2.2026.07.23.16.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 16:01:06 -0700 (PDT) From: Your Name X-Google-Original-From: Your Name To: linux-cifs@vger.kernel.org Cc: linkinjeon@kernel.org, smfrench@gmail.com, senozhatsky@chromium.org, tom@talpey.com, linux-kernel@vger.kernel.org, Aldo Ariel Panzardo , stable@vger.kernel.org Subject: [PATCH] ksmbd: only rebind the reopened file's own oplock on durable reconnect Date: Thu, 23 Jul 2026 20:00:53 -0300 Message-ID: <20260723230053.684176-1-you@example.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 From: Aldo Ariel Panzardo ksmbd_reopen_durable_fd() walks the inode's m_op_list and rebinds every detached oplock to the reconnecting session: list_for_each_entry_rcu(op, &ci->m_op_list, op_entry, lockdep_is_held(&ci->m_lock)) { if (op->conn) continue; op->conn = ksmbd_conn_get(fp->conn); op->sess = work->sess; } The only key is op->conn == NULL, which every detached durable handle on that inode matches, not just the one owned by fp. When two sessions hold durable handles on the same file and both disconnect, reconnecting one of them adopts the other session's oplock: op->sess is overwritten with the reconnecting session without taking a reference on it, while op->conn pins the connection. The sibling teardown path, session_fd_check(), keys on the identity of the connection being torn down (op->conn == conn) rather than on shared state, and so does not have this problem. Once the adopting session is destroyed, ksmbd_session_destroy() frees it while the foreign oplock still points at it. The reader in ksmbd_close_fd_app_instance_id() validates only opinfo->conn, which is still live thanks to the reference taken above, and then dereferences the stale session: if (!opinfo->conn) { up_read(&fp->f_ci->m_lock); goto out; } ft = &opinfo->sess->file_table; write_lock(&ft->lock); BUG: KASAN: slab-use-after-free in _raw_write_lock+0x74/0xd0 Write of size 4 at addr ffff88810a970528 by task kworker/0:0/9 Workqueue: ksmbd-io handle_ksmbd_work Call Trace: _raw_write_lock+0x74/0xd0 ksmbd_close_fd_app_instance_id+0x183/0x410 smb2_open+0x1346/0x4430 handle_ksmbd_work+0x2bb/0x7b0 Reached from an authenticated session against a share with the default durable-handle and oplock configuration: two sessions open the same file with a durable-v2 handle and an RH lease under distinct AppInstanceIds, both log off, one reconnects with DH2C, and a later durable-v2 create carrying the other AppInstanceId walks into the freed session. Constrain the loop to the oplock owned by the file being reopened. Fixes: f363a0fb134a ("ksmbd: fix app-instance durable supersede session UAF") Cc: stable@vger.kernel.org Signed-off-by: Aldo Ariel Panzardo --- fs/smb/server/vfs_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index d95c405eab11..1e9d13344825 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -1720,7 +1720,7 @@ int ksmbd_reopen_durable_fd(struct ksmbd_work *work, struct ksmbd_file *fp) down_write(&ci->m_lock); list_for_each_entry_rcu(op, &ci->m_op_list, op_entry, lockdep_is_held(&ci->m_lock)) { - if (op->conn) + if (op->conn || op->o_fp != fp) continue; op->conn = ksmbd_conn_get(fp->conn); op->sess = work->sess; -- 2.43.0