public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] libfs: Return ENOSPC when the directory offset range is exhausted
       [not found] <20241117213206.1636438-1-cel@kernel.org>
@ 2024-11-17 21:32 ` cel
  2024-11-18 19:55   ` Jeff Layton
  0 siblings, 1 reply; 2+ messages in thread
From: cel @ 2024-11-17 21:32 UTC (permalink / raw)
  To: linux-mm, linux-fsdevel, Hugh Dickens
  Cc: yukuai3, yangerkun, Chuck Lever, stable

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+
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/libfs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/libfs.c b/fs/libfs.c
index 46966fd8bcf9..bf67954b525b 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -288,7 +288,9 @@ 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)
+	if (unlikely(ret == -EBUSY))
+		return -ENOSPC;
+	if (unlikely(ret < 0))
 		return ret;
 
 	offset_set(dentry, offset);
-- 
2.47.0


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

* Re: [RFC PATCH 1/2] libfs: Return ENOSPC when the directory offset range is exhausted
  2024-11-17 21:32 ` [RFC PATCH 1/2] libfs: Return ENOSPC when the directory offset range is exhausted cel
@ 2024-11-18 19:55   ` Jeff Layton
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Layton @ 2024-11-18 19:55 UTC (permalink / raw)
  To: cel, linux-mm, linux-fsdevel, Hugh Dickens
  Cc: yukuai3, yangerkun, Chuck Lever, stable

On Sun, 2024-11-17 at 16:32 -0500, cel@kernel.org wrote:
> 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+
> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
> ---
>  fs/libfs.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/libfs.c b/fs/libfs.c
> index 46966fd8bcf9..bf67954b525b 100644
> --- a/fs/libfs.c
> +++ b/fs/libfs.c
> @@ -288,7 +288,9 @@ 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)
> +	if (unlikely(ret == -EBUSY))
> +		return -ENOSPC;
> +	if (unlikely(ret < 0))
>  		return ret;
>  
>  	offset_set(dentry, offset);

Reviewed-by: Jeff Layton <jlayton@kernel.org>

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

end of thread, other threads:[~2024-11-18 19:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20241117213206.1636438-1-cel@kernel.org>
2024-11-17 21:32 ` [RFC PATCH 1/2] libfs: Return ENOSPC when the directory offset range is exhausted cel
2024-11-18 19:55   ` Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox