ksmbd: rate limit the log for a failed security descriptor store
Subsystems (2)
PATCH 1/1 ksmbd: rate limit the log for a failed security descriptor store
ksmbd_vfs_set_sd_xattr() logs every failed store with pr_err(), with no rate limit and without the file name. A client can make the store fail at will. It only has to send a descriptor larger than the xattr space the filesystem has for the file. On the ext4 filesystem with 4 KiB blocks used in testing, a DACL of 86 ACEs was already too large. Each SET_INFO or CREATE that carries such a DACL then writes an error line to the kernel log.
When smb2_open() stores the default security descriptor of a new file, it logs the same failure a second time.
Log the failure with pr_warn_ratelimited() and include the file name. Drop the second message in smb2_open().
---
smb2_open() also logged two early returns of ksmbd_vfs_set_sd_xattr() that the new message does not cover. One is a length shorter than the descriptor header. That cannot happen here, because smb2_open() builds the descriptor itself. The other is a failed copy of the descriptor, which this path no longer logs. Callers do not usually log allocation failures, so the patch adds no message for it.
Tested on ksmbd-for-next 267029b35ad1 with KASAN. A run of forty SET_INFOs whose DACL does not fit now logs the first ten failures and reports the rest as suppressed. Each line names the file. smb2_open() no longer logs the failure a second time. smbtorture results match the base.
This patch was developed with LLM assistance.
fs/smb/server/smb2pdu.c | 10 ++-------- fs/smb/server/vfs.c | 3 ++- 2 files changed, 4 insertions(+), 9 deletions(-)
fs/smb/server/smb2pdu.c +2 -8
@@ -5271,15 +5271,9 @@ int smb2_open(struct ksmbd_work *work) goto err_out; } - rc =ksmbd_vfs_set_sd_xattr (conn, - idmap, - &path, - pntsd, - pntsd_size); +ksmbd_vfs_set_sd_xattr (conn, idmap, &path, + pntsd, pntsd_size);kvfree (pntsd); -if (rc) -pr_err ("failed to store ntacl in xattr : %d\n" , - rc); } } }
fs/smb/server/vfs.c +2 -1
@@ -1767,7 +1767,8 @@ int ksmbd_vfs_set_sd_xattr(struct ksmbd_conn *conn,XATTR_NAME_SD , sd_ndr.data, sd_ndr.offset, 0, true);if (rc <0 ) -pr_err ("Failed to store XATTR ntacl :%d\n" , rc); +pr_warn_ratelimited ("failed to store the security descriptor of %pd: %d\n" , + dentry, rc); out:kfree (sd_ndr.data);
Signature · 1 line
2.47.3
Quoted 9 lines · Ian Bridges
ksmbd_vfs_set_sd_xattr()logs every failed store withpr_err(), with no rate limit and without the file name. A client can make the store fail at will. It only has to send a descriptor larger than the xattr space the filesystem has for the file. On the ext4 filesystem with 4 KiB blocks used in testing, a DACL of 86 ACEs was already too large. EachSET_INFOor CREATE that carries such a DACL then writes an error line to the kernel log.
Quoted 7 lines
When
smb2_open()stores the default security descriptor of a new file, it logs the same failure a second time.Log the failure with
pr_warn_ratelimited()and include the file name. Drop the second message insmb2_open().Signed-off-by Ian Bridges <[email protected]>
Applied it to #ksmbd-for-next.
Thanks!