Skip to content

Commit 903dc9c

Browse files
chuckleverbrauner
authored andcommitted
libfs: Return ENOSPC when the directory offset range is exhausted
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: 6faddda ("libfs: Add directory operations for stable offsets") Cc: [email protected] # v6.9+ Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: Yang Erkun <[email protected]> Signed-off-by: Chuck Lever <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 40384c8 commit 903dc9c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/libfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,8 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry)
292292

293293
ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN,
294294
LONG_MAX, &octx->next_offset, GFP_KERNEL);
295-
if (ret < 0)
296-
return ret;
295+
if (unlikely(ret < 0))
296+
return ret == -EBUSY ? -ENOSPC : ret;
297297

298298
offset_set(dentry, offset);
299299
return 0;

0 commit comments

Comments
 (0)