ksmbd: protect stream_del_pending with fp->f_lock
Subsystems (2)
PATCH 1/1 ksmbd: protect stream_del_pending with fp->f_lock
From: Gael Blivet <[email protected]>
Follow-up to commit 36442851a4d1 ("ksmbd: route stream FileDispositionInformation through stream delete flag"): fp's stream_del_pending is read and written from three call sites (ksmbd_inode_pending_delete(), ksmbd_fd_set_delete_pending()/ ksmbd_fd_clear_delete_pending(), and __ksmbd_inode_close()) with no locking at all, unlike every other piece of shared per-handle mutable state in this file, which uses fp->f_lock.
A FileDispositionInformation SET_INFO racing a concurrent close on the same handle can see a stale value and skip removing the stream's xattr even though the client asked for deletion.
Protect all three touch points with fp->f_lock, matching the existing convention (e.g. notify_pendings).
--- fs/smb/server/vfs_cache.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
fs/smb/server/vfs_cache.c +20 -6
@@ -236,8 +236,14 @@ bool ksmbd_inode_pending_delete(struct ksmbd_file *fp)* also incorrectly report a whole-file pending-delete as applying * to an unrelated stream handle on the same inode. */ -if (ksmbd_stream_fd (fp)) -return fp->stream_del_pending; +if (ksmbd_stream_fd (fp)) { +bool pending; + +spin_lock (&fp->f_lock); + pending = fp->stream_del_pending; +spin_unlock (&fp->f_lock); +return pending; + }down_read (&ci->m_lock); ret = (ci->m_flags &S_DEL_PENDING );
@@ -318,18 +324,24 @@ void ksmbd_fd_set_delete_on_close(struct ksmbd_file *fp,*/ void ksmbd_fd_set_delete_pending (struct ksmbd_file *fp) { -if (ksmbd_stream_fd (fp)) +if (ksmbd_stream_fd (fp)) { +spin_lock (&fp->f_lock); fp->stream_del_pending = true; -else +spin_unlock (&fp->f_lock); + }else {ksmbd_set_inode_pending_delete (fp); + } }void ksmbd_fd_clear_delete_pending (struct ksmbd_file *fp) { -if (ksmbd_stream_fd (fp)) +if (ksmbd_stream_fd (fp)) { +spin_lock (&fp->f_lock); fp->stream_del_pending = false; -else +spin_unlock (&fp->f_lock); + }else {ksmbd_clear_inode_pending_delete (fp); + } }static void ksmbd_inode_hash (struct ksmbd_inode *ci)
@@ -458,10 +470,12 @@ static void __ksmbd_inode_close(struct ksmbd_file *fp)* the inode-wide flag above, which only ever meant "some * stream on this file" with no way to say which one. */ +spin_lock (&fp->f_lock);if (fp->stream_del_pending) { fp->stream_del_pending = false; remove_stream_xattr = true; } +spin_unlock (&fp->f_lock);if (remove_stream_xattr) {const struct cred *saved_cred;
base-commit: 5e6eeafe46a4a19559808c5ef36ea36ea4f2a204
Signature · 1 line
2.43.0
PATCH v2 1/1 ksmbd: quiet mdssvc RPC log spam in create_smb2_pipe
From: Gael Blivet <[email protected]>
Follow-up to
commit bb682f1496f7 ("ksmbd: quiet mdssvc RPC log spam"), which silenced __rpc_method()'s own "Unsupported RPC: mdssvc" log line but missed that ksmbd_session_rpc_open() failing for that same, now-still-rejected pipe also trips a second, separate pr_err() here in its caller. macOS's routine mdssvc (Spotlight) probes still spam the kernel log via this second site on every single probe, defeating the original commit's stated purpose.
Suppress this specific case the same way the other site does; behavior is unchanged for every other RPC failure.
__rpc_method() (mgmt/user_session.c) returns -ENOENT for mdssvc, not -EINVAL.
---
v1 -> v2: Check -ENOENT instead of -EINVAL, matching what __rpc_method() actually returns for mdssvc.
fs/smb/server/smb2pdu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/smb/server/smb2pdu.c +10 -1
@@ -2655,7 +2655,16 @@ static noinline int create_smb2_pipe(struct ksmbd_work *work) id =ksmbd_session_rpc_open (work->sess, name);if (id <0 ) { -pr_err ("Unable to open RPC pipe: %d\n" , id); +/* +* mdssvc (Spotlight) is a routine, expected probe from macOS +* that we deliberately don't support -- it's disabled at the +* __rpc_method() level (mgmt/user_session.c), but this +* generic failure log would otherwise still fire on every +* single probe regardless. +*/ +if (!(id == -ENOENT && (!strcmp (name,"\\mdssvc" ) || + !strcmp (name,"mdssvc" )))) +pr_err ("Unable to open RPC pipe: %d\n" , id); err = id; goto out; }
base-commit: 5e6eeafe46a4a19559808c5ef36ea36ea4f2a204
Signature · 1 line
2.43.0
Re: [PATCH v2] ksmbd: quiet mdssvc RPC log spam in create_smb2_pipe
Quoted 12 lines · Gaël Blivet-Bailly
From: Gael Blivet <[email protected]>
Follow-up to
commitbb682f1496f7("ksmbd: quiet mdssvc RPC log spam"), which silenced __rpc_method()'s own "Unsupported RPC: mdssvc" log line but missed thatksmbd_session_rpc_open()failing for that same, now-still-rejected pipe also trips a second, separatepr_err()here in its caller. macOS's routine mdssvc (Spotlight) probes still spam the kernel log via this second site on every single probe, defeating the original commit's stated purpose.
Quoted 7 lines
Suppress this specific case the same way the other site does; behavior is unchanged for every other RPC failure.
__rpc_method()(mgmt/user_session.c) returns-ENOENTfor mdssvc, not-EINVAL.Signed-off-by Gael Blivet <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks!
PATCH v2 1/1 ksmbd: report actual xattr value length in stream enumeration
In reply to Gaël Blivet-BaillyFrom: Gael Blivet <[email protected]>
get_file_stream_info() (FileStreamInformation QUERY_INFO) reported each enumerated stream's StreamSize/StreamAllocationSize as stream_name_len -- the byte length of the stream's *name*, not its data. This is the same bug class already fixed for EndOfFile/ AllocationSize on an open stream handle (ksmbd_stream_eof()), just missed at this second site: a client enumerating streams sees a size derived from the name string length instead of the stream's actual content length, inconsistent with what querying the same stream by handle reports.
Compute the real value length the same way ksmbd_stream_eof() does, via ksmbd_vfs_casexattr_len() on the already-known xattr key.
---
v1 -> v2: Declare slen/ssize at the top of the function instead of a scoped block mid-function. Also pass the xattr name length including the null terminator to ksmbd_vfs_casexattr_len(), matching ksmbd_stream_eof()'s call -- without it, the lookup is a prefix match instead of an exact one.
fs/smb/server/smb2pdu.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fs/smb/server/smb2pdu.c +16 -2
@@ -5960,6 +5960,8 @@ static int get_file_stream_info(struct ksmbd_work *work,struct kstat stat;const struct path *path = &fp->filp->f_path;ssize_t xattr_list_len; +ssize_t slen; +loff_t ssize;int nbytes =0 , streamlen, stream_name_len, next, idx =0 ;int buf_free_len;int ret;
@@ -6021,8 +6023,20 @@ static int get_file_stream_info(struct ksmbd_work *work, streamlen *=2 ;kfree (stream_buf); file_info->StreamNameLength =cpu_to_le32 (streamlen); - file_info->StreamSize =cpu_to_le64 (stream_name_len); - file_info->StreamAllocationSize =cpu_to_le64 (stream_name_len); +/* +* stream_name_len is the byte length of the xattr's *name*, +* not its value -- same class of bug ksmbd_stream_eof() +* (smb2pdu.c) already fixes for EndOfFile/AllocationSize on +* a stream handle; this enumeration path needs the same +* real xattr value length, not the name length reused as a +* size. +*/ + slen =ksmbd_vfs_casexattr_len (file_mnt_idmap (fp->filp), + path->dentry, stream_name, +strlen (stream_name) +1 ); + ssize = slen <0 ?0 : (loff_t )slen; + file_info->StreamSize =cpu_to_le64 (ssize); + file_info->StreamAllocationSize =cpu_to_le64 (ssize); nbytes += next; buf_free_len -= next;
base-commit: 5e6eeafe46a4a19559808c5ef36ea36ea4f2a204
Signature · 1 line
2.43.0
Re: [PATCH v2] ksmbd: report actual xattr value length in stream enumeration
Quoted 13 lines · Gaël Blivet-Bailly
From: Gael Blivet <[email protected]>
get_file_stream_info()(FileStreamInformationQUERY_INFO) reported each enumerated stream's StreamSize/StreamAllocationSize asstream_name_len-- the byte length of the stream's *name*, not its data. This is the same bug class already fixed for EndOfFile/ AllocationSize on an open stream handle (ksmbd_stream_eof()), just missed at this second site: a client enumerating streams sees a size derived from the name string length instead of the stream's actual content length, inconsistent with what querying the same stream by handle reports.
Quoted 4 lines
Compute the real value length the same way
ksmbd_stream_eof()does, viaksmbd_vfs_casexattr_len()on the already-known xattr key.Signed-off-by Gael Blivet <[email protected]>
Applied it to #ksmbd-for-next-next.
Thanks!
Namjae Jeon
maintainerQuoted 11 lines · Gaël Blivet-Bailly
From: Gael Blivet <[email protected]>
Follow-up to commit
36442851a4d1("ksmbd: route stream FileDispositionInformation through stream delete flag"): fp'sstream_del_pendingis read and written from three call sites (ksmbd_inode_pending_delete(), ksmbd_fd_set_delete_pending()/ksmbd_fd_clear_delete_pending(), and__ksmbd_inode_close()) with no locking at all, unlike every other piece of shared per-handle mutable state in this file, which usesfp->f_lock.
Quoted 8 lines
A FileDispositionInformation
SET_INFOracing a concurrent close on the same handle can see a stale value and skip removing the stream's xattr even though the client asked for deletion.Protect all three touch points with
fp->f_lock, matching the existing convention (e.g.notify_pendings).Signed-off-by Gael Blivet <[email protected]>
This patch has been combined with the "ksmbd: route stream FileDispositionInformation through stream delete flag" patch.