stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 1/5] libfs: Return ENOSPC when the directory offset range is exhausted
       [not found] <20241220153314.5237-1-cel@kernel.org>
@ 2024-12-20 15:33 ` cel
  2024-12-23 16:28   ` Liam R. Howlett
  0 siblings, 1 reply; 3+ messages in thread
From: cel @ 2024-12-20 15:33 UTC (permalink / raw)
  To: Hugh Dickins, Christian Brauner, Al Viro
  Cc: linux-fsdevel, linux-mm, yukuai3, yangerkun, Chuck Lever, stable,
	Jeff Layton, Yang Erkun

From: Chuck Lever <chuck.lever@oracle.com>

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@vger.kernel.org> # v6.9+
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Yang Erkun <yangerkun@huawei.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/libfs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index 748ac5923154..3da58a92f48f 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -292,8 +292,8 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry)
 
 	ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN,
 				 LONG_MAX, &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;
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v6 1/5] libfs: Return ENOSPC when the directory offset range is exhausted
  2024-12-20 15:33 ` [PATCH v6 1/5] libfs: Return ENOSPC when the directory offset range is exhausted cel
@ 2024-12-23 16:28   ` Liam R. Howlett
  2024-12-23 17:54     ` Chuck Lever
  0 siblings, 1 reply; 3+ messages in thread
From: Liam R. Howlett @ 2024-12-23 16:28 UTC (permalink / raw)
  To: cel
  Cc: Hugh Dickins, Christian Brauner, Al Viro, linux-fsdevel, linux-mm,
	yukuai3, yangerkun, Chuck Lever, stable, Jeff Layton, Yang Erkun

* cel@kernel.org <cel@kernel.org> [241220 10:33]:
> From: Chuck Lever <chuck.lever@oracle.com>
> 
> 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.

Should the tree be returning ENOSPC in this case as apposed to
translating it here?

> 
> 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@vger.kernel.org> # v6.9+
> Reviewed-by: Jeff Layton <jlayton@kernel.org>
> Reviewed-by: Yang Erkun <yangerkun@huawei.com>
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>  fs/libfs.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 748ac5923154..3da58a92f48f 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -292,8 +292,8 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry)
>  
>  	ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN,
>  				 LONG_MAX, &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;
> -- 
> 2.47.0
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v6 1/5] libfs: Return ENOSPC when the directory offset range is exhausted
  2024-12-23 16:28   ` Liam R. Howlett
@ 2024-12-23 17:54     ` Chuck Lever
  0 siblings, 0 replies; 3+ messages in thread
From: Chuck Lever @ 2024-12-23 17:54 UTC (permalink / raw)
  To: Liam R. Howlett, cel, Hugh Dickins, Christian Brauner, Al Viro,
	linux-fsdevel, linux-mm, yukuai3, yangerkun, stable, Jeff Layton,
	Yang Erkun

On 12/23/24 11:28 AM, Liam R. Howlett wrote:
> * cel@kernel.org <cel@kernel.org> [241220 10:33]:
>> From: Chuck Lever <chuck.lever@oracle.com>
>>
>> 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.
> 
> Should the tree be returning ENOSPC in this case as apposed to
> translating it here?

ENOSPC means "No space left on device." which has a certain
filesystem-like ring to it. So translation in a filesystem caller
seems sensible to me.

If you change mtree_alloc_cyclic() wouldn't you also need to update
other mtree and xarray APIs as well, for consistency? That could be
a lot of bother.

But if you'd like to change the mtree API, I won't argue. It's not
a crazy idea.


>> 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@vger.kernel.org> # v6.9+
>> Reviewed-by: Jeff Layton <jlayton@kernel.org>
>> Reviewed-by: Yang Erkun <yangerkun@huawei.com>
>> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
>> ---
>>   fs/libfs.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/fs/libfs.c b/fs/libfs.c
>> index 748ac5923154..3da58a92f48f 100644
>> --- a/fs/libfs.c
>> +++ b/fs/libfs.c
>> @@ -292,8 +292,8 @@ int simple_offset_add(struct offset_ctx *octx, struct dentry *dentry)
>>   
>>   	ret = mtree_alloc_cyclic(&octx->mt, &offset, dentry, DIR_OFFSET_MIN,
>>   				 LONG_MAX, &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;
>> -- 
>> 2.47.0
>>
>>


-- 
Chuck Lever

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-12-23 17:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20241220153314.5237-1-cel@kernel.org>
2024-12-20 15:33 ` [PATCH v6 1/5] libfs: Return ENOSPC when the directory offset range is exhausted cel
2024-12-23 16:28   ` Liam R. Howlett
2024-12-23 17:54     ` Chuck Lever

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).