From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.147 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796015649; b=5RXiWcDFWh+N/QjDoBiZSuWiWl5qQeeMLZxTMF9gQHISM8Oa/06O+Vrzykqd1kSuqctq B+dlWeZP+fHMqu3Aj1elIJCInkQwghSATyMKnrZ33qeqfTqrF19d27YBltCd9dgy4gPoI 3UnA0vgi5oq+LH8oXZWMe9HUMtITuv90GA+3VS2GvIOUXl90tZI/S7TGN1u0vHPwK8O9H xBZKDRX4PfgxpozTp7VVVRGpl1/jPu86cAcHAQwk/SCRXyGECanBwVHuqR7zxOyqKS5vE KjiJ0TZngWs/F/3+thwjKxxYJQN+lpetK83q4QVuK2NjmuLPdD7U9cwpshmWhgTRArg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796015649; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=WvMBuPRD53nelBWBwF6SHk4lhO8R+78gpMyq3nyx29c=; b=KRBU2iomPOEGf50RVOo9SfzTMncAnwvsEw2eo8ZAV63pPwh2TJZ9+VzMXwY8Q/txIA0x JA7NcEcqCz4wkjRsyeOayA18593yFQmwLaTR4btyqasynzUnjsZP9sVlaXfJhvFh6obUj CWbG/bCRYOYKaR1AdkAbIOEx5PAE/OCapA4QwL79umVLty4mP5CVk7D0OVxr+hKcLIov2 pmEbukwrSkyL1xsJ+x+HreerdoJPDqic50t4bseQRS/WpD2WJB50PQKNTkvU25fokcN71 9gjHq3Htrq30hPRUvcF0xS1kpenE4tO1xS05GfWva4tytVNarBsgS16PrnB23ObiUow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fastmail.org; spf=pass smtp.mailfrom=fastmail.org; dkim=pass header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=r+4J5gln; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=uDDaBkKt; arc=none smtp.remote-ip=103.168.172.147 Received: from fout-a4-smtp.messagingengine.com (fout-a4-smtp.messagingengine.com [103.168.172.147]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E575606A31C for ; Mon, 30 Nov 2026 05:14:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9E575606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fastmail.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastmail.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=r+4J5gln; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=uDDaBkKt Received: from phl-compute-05.internal (phl-compute-05.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id AE50AEC1D63 for ; Mon, 30 Nov 2026 00:14:07 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-05.internal (MEProxy); Mon, 30 Nov 2026 00:14:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1796015647; x= 1796102047; bh=WvMBuPRD53nelBWBwF6SHk4lhO8R+78gpMyq3nyx29c=; b=r +4J5glnpH4TKeGS2djP1RrD0Stmfmwq00rfkdI+wCq7L1bKX6WKIo4pcaOhc/mOP ZgzZx2dfSMTp4IOvMBVVRqwy5BDusvdE9z6wsShm9A3vW/GuLH12t+SW657WmV5O /7L0M63IAn9YGBb3h04XiHLyHyXz038NQ1DjfRJazuBI68PxFhdylkFLl30+usbM +kWkX/3O+6Ugy+69lxmMGHk+Mgav7dxZBO4vErnwxVx8amiKZQ/GiVAOjD8u8woI DW4+mfQf+4YAvIjvIzpVADOplj7Q0RO8cSxPuHiGGRYIno96/fU+bW/WjLNJswc8 lkh2lNJJc/n7O62n0NKvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796015647; x=1796102047; bh=W vMBuPRD53nelBWBwF6SHk4lhO8R+78gpMyq3nyx29c=; b=uDDaBkKtYfDxXAmvA MrEiLzruAPACRPReXysxUnGXgz45Gn+f52ukvS7oPcWV4PQRIZycOFS5AoK19URv xIXJvgZey7pQsKVQ7VvBLHN41qrkB5mKLk/xjRqWLwOvsZWfQhThur904WkIzyIs C0z0Ia/sUnC/7ZdVzH5Wy/mXLJXPxcKMuTOVRbTZrsWIz6OOK6Uiv7qLrFoy2Zwu C7Ycm3tG71FB5q+spGwkQeDyFsgyJGLZ+Gf13ou/mL9HiLfxomdSJbQUQl6J28ef nfIoQ4q+qUH2kX9GQUink/RInF2vltpc9xcohYv2C57M0H+Dd6C8bIR6/S98t0HT lk42A== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=fastmail.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796015647; d=fastmail.org; mf=PGljYkBmYXN0bWFpbC5vcmc+; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:FaqYesSSzZykUynwT3MgW/8VBe2f79g9AIL6k8oYpklKQBM ZRpFwe2Xbo6qxD7fJVjQpbLqG+IfnrE/N6sI7ox861cA05isLz5jlKXLnWlXmBK4 QFtIovosgEGHeS7t3yapWItmk/bBaz10wMBDuqxWy2h2G9JYSzVXwQRL5Jn6WPL3 asUz5iUJWQ8ahga/Y7yFQf734T/3l4DYPAa45/fO8k0lBW80qAsFpG9/z5DUGipU KMUOoY6oIAQbC2U62fPLGT+RuaJjGD9pCQOMuK03CtZ6nzNl5KsXgzbt8DQegaKf WFftcHH2J046Ju3vu7I/mPq965X4yPXl0hbYNsg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:E+21dNHH4ZZlQ0b8gzigJGbzuDL4piy7ptecbEnNUXU=:JlxHTqhw3sNiHIn8HrWLdoAYc9iP83xWiYDuPZVHn04=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFnvEwJcLNFL3v+XxtNo06Kn9V1oRT37IXYiiqIQs8Usw8a8SL6Nc4y/bsRsHzat7 Q94nV3DLxy7pRW8ELkydRcx22lwYJucUYGODdCTtXF8oG8IassMeekScTZ1FCXL6+KfXe6 98hnsnQ6lUuhxq3gu8p2ya4fgcZV7pftbbP7pqBAgXQGRsCg7y+4nzxW3nC+4vUfJ+2r4t +uWeMEzgs5RxSzTKfWPEGsI90aSD8PG6q+cNvxeN7uMllgeYiThQhoD1vdeElVWos8HRj8 T6NbiWaBuTXexGnkkRrru6z8d/PLVjASakIWGvJvSR7OUlvxJkW1Hxp7FoRxAAznDyt2CX 8Xh5iLgquUucPgc/MqQNqdn7eRSw29sPyXVFeg9GomECyK7zLGYbn/OEX9yBt60cOohZCg AJyr6TTQLGluusvyDGP+8byirguDvgxmK5pR/aYGL+ZvdaehRqGzMQOZHZkq0hhVz9DsPq K8UuNkZzFdy4Wv/1mEesZwgd2NVF9LY4C3uTqpPFz8z0NOFPWIw8w06H4mHHZ4BwDZBr0K 3ZC/dfaU4Mpjx2BnmLqZGWBv798e8ARPpCK1ATHy5coI8tSYNt7+UBM2Dx5wrdyGzG6m1d UjSbn7goRKpMwbaa2IxJoxlpKrf2i1XgmODvY0r7MMua4zVXapDo76jVImjg X-ME-Proxy: Feedback-ID: ib53e4b78:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 30 Nov 2026 00:14:06 -0500 (EST) From: Ian Bridges To: linkinjeon@kernel.org Cc: senozhatsky@chromium.org, tom@talpey.com, chenxiaosong@chenxiaosong.com, linux-cifs@vger.kernel.org, linux-kernel@vger.kernel.org, Ian Bridges Subject: [PATCH 1/4] ksmbd: check the cached read-only attribute for delete-on-close Date: Sun, 29 Nov 2026 23:13:46 -0600 Message-ID: <0b59bc735ec6399e7f034717f4c432389f19029f.1796015315.git.icb@fastmail.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On a share that does not store DOS attributes, SET_INFO can mark an open file read-only in the inode cache. While a handle keeps that entry alive, queries report the attribute and SET_INFO refuses to mark the file for deletion. A second delete-on-close open ignores the attribute and can delete the file. Check the attributes in memory when no stored attributes can be read. Named streams and POSIX opens keep the old check. The check now comes after the checks of the file type and the name. So a delete-on-close open with FILE_CREATE of an existing read-only file now fails with STATUS_OBJECT_NAME_COLLISION. FileDispositionInformation checks the read-only attribute before it looks at the request. So clearing delete pending on a read-only file fails, and a handle without DELETE gets STATUS_CANNOT_DELETE instead of STATUS_ACCESS_DENIED. Check the read-only attribute only when delete pending is set, after the check for DELETE. Signed-off-by: Ian Bridges --- fs/smb/server/smb2pdu.c | 71 +++++++++++++++++++++++++++------------ fs/smb/server/vfs_cache.c | 23 +++++++++++++ fs/smb/server/vfs_cache.h | 1 + 3 files changed, 74 insertions(+), 21 deletions(-) diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index 38326db8da40..3818d003e47a 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -3914,6 +3914,26 @@ static void smb2_update_xattrs(struct ksmbd_tree_connect *tcon, } } +/* + * Return the DOS attributes of an existing file. On a share that stores DOS + * attributes, read the stored attributes first, because an open copies the + * stored attributes into the inode cache only after adding the file to the + * cache. If no stored attributes can be read, return the cached attributes + * when @cached is set, and zero otherwise. + */ +static __le32 smb2_file_attributes(struct ksmbd_tree_connect *tcon, + const struct path *path, bool cached) +{ + struct xattr_dos_attrib da; + + if (test_share_config_flag(tcon->share_conf, + KSMBD_SHARE_FLAG_STORE_DOS_ATTRS) && + ksmbd_vfs_get_dos_attrib_xattr(mnt_idmap(path->mnt), path->dentry, + &da) > 0) + return cpu_to_le32(da.attr); + return cached ? ksmbd_inode_fattr(path->dentry) : 0; +} + static int smb2_creat(struct ksmbd_work *work, struct path *path, char *name, int open_flags, umode_t posix_mode, bool is_dir) @@ -4554,7 +4574,7 @@ int smb2_open(struct ksmbd_work *work) int share_ret, need_truncate = 0; u64 time, alloc_size = 0; umode_t posix_mode = 0; - __le32 daccess, maximal_access = 0; + __le32 daccess, maximal_access = 0, file_attrs = 0; u32 dos_attr; int iov_len = 0; @@ -4900,8 +4920,6 @@ int smb2_open(struct ksmbd_work *work) file_present = true; if (req->CreateOptions & FILE_DELETE_ON_CLOSE_LE) { - struct xattr_dos_attrib da; - /* * If file exists with under flags, return access * denied error. @@ -4918,16 +4936,6 @@ int smb2_open(struct ksmbd_work *work) rc = -EACCES; goto err_out; } - - if (test_share_config_flag(tcon->share_conf, - KSMBD_SHARE_FLAG_STORE_DOS_ATTRS) && - ksmbd_vfs_get_dos_attrib_xattr(mnt_idmap(path.mnt), - path.dentry, &da) > 0 && - da.attr & FILE_ATTRIBUTE_READONLY) { - rsp->hdr.Status = STATUS_CANNOT_DELETE; - rc = -EACCES; - goto err_out; - } } else if (d_is_symlink(path.dentry)) { rc = -EACCES; goto err_out; @@ -5007,6 +5015,25 @@ int smb2_open(struct ksmbd_work *work) daccess = smb_map_generic_desired_access(req->DesiredAccess); + /* + * Read the existing file's attributes once for the checks below. A + * named stream is looked up only later, and the POSIX extensions do + * not refuse delete-on-close of a read-only file in the same way. So + * for a named stream or a POSIX open, read only the stored attributes, + * as before. + */ + if (file_present && req->CreateOptions & FILE_DELETE_ON_CLOSE_LE) + file_attrs = smb2_file_attributes(tcon, &path, + !stream_name && !posix_ctxt); + + /* A read-only file is not deleted on close */ + if (file_present && req->CreateOptions & FILE_DELETE_ON_CLOSE_LE && + file_attrs & FILE_ATTRIBUTE_READONLY_LE) { + rsp->hdr.Status = STATUS_CANNOT_DELETE; + rc = -EACCES; + goto err_out; + } + if (file_present && !(req->CreateOptions & FILE_DELETE_ON_CLOSE_LE)) { rc = smb_check_perm_dacl(conn, &path, &daccess, req->DesiredAccess, @@ -9232,11 +9259,17 @@ static int set_file_disposition_info(struct ksmbd_work *work, return -EACCES; } - if (fp->f_ci->m_fattr & FILE_ATTRIBUTE_READONLY_LE) - return -EACCES; - inode = file_inode(fp->filp); if (file_info->DeletePending) { + if (fp->f_ci->m_fattr & FILE_ATTRIBUTE_READONLY_LE) { + struct smb2_set_info_req *req; + struct smb2_set_info_rsp *rsp; + + WORK_BUFFERS(work, req, rsp); + rsp->hdr.Status = STATUS_CANNOT_DELETE; + return -EACCES; + } + if (ksmbd_has_stream_without_delete_share(fp)) return -ESHARE; @@ -9520,11 +9553,7 @@ int smb2_set_info(struct ksmbd_work *work) err_out: if (rc == -EACCES || rc == -EPERM || rc == -EXDEV) { - if (fp && req->InfoType == SMB2_O_INFO_FILE && - req->FileInfoClass == FILE_DISPOSITION_INFORMATION && - fp->f_ci->m_fattr & FILE_ATTRIBUTE_READONLY_LE) - rsp->hdr.Status = STATUS_CANNOT_DELETE; - else + if (!rsp->hdr.Status) rsp->hdr.Status = STATUS_ACCESS_DENIED; } else if (rc == -EINVAL) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index c846023e5ada..7db0a52dd4ae 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -345,6 +345,29 @@ struct ksmbd_inode *ksmbd_inode_lookup_lock(struct dentry *d) return ci; } +/* + * No reference is taken. The inode is freed only after it is unhashed under + * the write lock, so it stays valid under the read lock. + */ +__le32 ksmbd_inode_fattr(struct dentry *d) +{ + struct hlist_head *head = inode_hashtable + + inode_hash(d_inode(d)->i_sb, (unsigned long)d); + struct ksmbd_inode *ci; + __le32 fattr = 0; + + read_lock(&inode_hash_lock); + hlist_for_each_entry(ci, head, m_hash) { + if (ci->m_de == d) { + if (atomic_read(&ci->m_count)) + fattr = READ_ONCE(ci->m_fattr); + break; + } + } + read_unlock(&inode_hash_lock); + return fattr; +} + int ksmbd_query_inode_status(struct dentry *dentry) { struct ksmbd_inode *ci; diff --git a/fs/smb/server/vfs_cache.h b/fs/smb/server/vfs_cache.h index 57c81287efe6..bc1955b87855 100644 --- a/fs/smb/server/vfs_cache.h +++ b/fs/smb/server/vfs_cache.h @@ -218,6 +218,7 @@ int ksmbd_vfs_set_durable_owner(struct ksmbd_file *fp, struct ksmbd_file *ksmbd_file_get(struct ksmbd_file *fp); void ksmbd_fd_put(struct ksmbd_work *work, struct ksmbd_file *fp); struct ksmbd_inode *ksmbd_inode_lookup_lock(struct dentry *d); +__le32 ksmbd_inode_fattr(struct dentry *d); void ksmbd_inode_put(struct ksmbd_inode *ci); bool ksmbd_close_disconnected_durable_delete_on_close(struct dentry *dentry); struct ksmbd_file *ksmbd_lookup_global_fd(unsigned long long id); -- 2.47.3