From: Chuck Lever <chuck.lever@xxxxxxxxxx> [ Upstream commit 903dc9c43a155e0893280c7472d4a9a3a83d75a6 ] Testing shows that the EBUSY error return from mtree_alloc_cyclic() leaks into user space. The ERRORS section of "man creat(2)" says: > EBUSY O_EXCL was specified in flags and pathname refers > to a block device that is in use by the system > (e.g., it is mounted). ENOSPC is closer to what applications expect in this situation. Note that the normal range of simple directory offset values is 2..2^63, so hitting this error is going to be rare to impossible. Fixes: 6faddda69f62 ("libfs: Add directory operations for stable offsets") Cc: stable@xxxxxxxxxxxxxxx # v6.9+ Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx> Reviewed-by: Yang Erkun <yangerkun@xxxxxxxxxx> Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx> Link: https://lore.kernel.org/r/20241228175522.1854234-2-cel@xxxxxxxxxx Signed-off-by: Christian Brauner <brauner@xxxxxxxxxx> [ cel: adjusted to apply to origin/linux-6.6.y ] Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/libfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/libfs.c +++ b/fs/libfs.c @@ -287,8 +287,8 @@ int simple_offset_add(struct offset_ctx ret = xa_alloc_cyclic(&octx->xa, &offset, dentry, limit, &octx->next_offset, GFP_KERNEL); - if (ret < 0) - return ret; + if (unlikely(ret < 0)) + return ret == -EBUSY ? -ENOSPC : ret; offset_set(dentry, offset); return 0; Patches currently in stable-queue which might be from cel@xxxxxxxxxx are queue-6.6/libfs-replace-simple_offset-end-of-directory-detection.patch queue-6.6/libfs-re-arrange-locking-in-offset_iterate_dir.patch queue-6.6/libfs-add-simple_offset_empty.patch queue-6.6/shmem-fix-shmem_rename2.patch queue-6.6/revert-libfs-add-simple_offset_empty.patch queue-6.6/libfs-use-d_children-list-to-iterate-simple_offset-directories.patch queue-6.6/libfs-define-a-minimum-directory-offset.patch queue-6.6/libfs-return-enospc-when-the-directory-offset-range-is-exhausted.patch queue-6.6/libfs-fix-simple_offset_rename_exchange.patch queue-6.6/libfs-add-simple_offset_rename-api.patch