All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHSET 0/2] ext4: minor fixes to GETFSUUID ioctl
@ 2022-11-10 20:16 Darrick J. Wong
  2022-11-10 20:16 ` [PATCH 1/2] ext4: dont return EINVAL from GETFSUUID when reporting UUID length Darrick J. Wong
  2022-11-10 20:16 ` [PATCH 2/2] ext4: don't fail GETFSUUID when the caller provides a long buffer Darrick J. Wong
  0 siblings, 2 replies; 5+ messages in thread
From: Darrick J. Wong @ 2022-11-10 20:16 UTC (permalink / raw)
  To: djwong, tytso; +Cc: catherine.hoang, linux-ext4

Hi all,

Ted and I looked at the EXT4_IOC_GETFSUUID implementation on the ext4
concall this morning, and I pointed out that there were a couple of odd
things about the ioctl behavior.  Since Ted hasn't released a version of
e2fsprogs that uses this ioctl, let's tidy those things up before 6.1
comes out, eh?

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D
---
 fs/ext4/ioctl.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)


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

* [PATCH 1/2] ext4: dont return EINVAL from GETFSUUID when reporting UUID length
  2022-11-10 20:16 [PATCHSET 0/2] ext4: minor fixes to GETFSUUID ioctl Darrick J. Wong
@ 2022-11-10 20:16 ` Darrick J. Wong
  2022-11-11  1:11   ` Catherine Hoang
  2022-11-10 20:16 ` [PATCH 2/2] ext4: don't fail GETFSUUID when the caller provides a long buffer Darrick J. Wong
  1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-11-10 20:16 UTC (permalink / raw)
  To: djwong, tytso; +Cc: catherine.hoang, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

If userspace calls this ioctl with fsu_length (the length of the
fsuuid.fsu_uuid array) set to zero, ext4 copies the desired uuid length
out to userspace.  The kernel call returned a result from a valid input,
so the return value here should be zero, not EINVAL.

While we're at it, fix the copy_to_user call to make it clear that we're
only copying out fsu_len.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/ext4/ioctl.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)


diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 95dfea28bf4e..5f91f3ad3e50 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1153,9 +1153,10 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,
 
 	if (fsuuid.fsu_len == 0) {
 		fsuuid.fsu_len = UUID_SIZE;
-		if (copy_to_user(ufsuuid, &fsuuid, sizeof(fsuuid.fsu_len)))
+		if (copy_to_user(&ufsuuid->fsu_len, &fsuuid.fsu_len,
+					sizeof(fsuuid.fsu_len)))
 			return -EFAULT;
-		return -EINVAL;
+		return 0;
 	}
 
 	if (fsuuid.fsu_len != UUID_SIZE || fsuuid.fsu_flags != 0)


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

* [PATCH 2/2] ext4: don't fail GETFSUUID when the caller provides a long buffer
  2022-11-10 20:16 [PATCHSET 0/2] ext4: minor fixes to GETFSUUID ioctl Darrick J. Wong
  2022-11-10 20:16 ` [PATCH 1/2] ext4: dont return EINVAL from GETFSUUID when reporting UUID length Darrick J. Wong
@ 2022-11-10 20:16 ` Darrick J. Wong
  2022-11-11  1:13   ` Catherine Hoang
  1 sibling, 1 reply; 5+ messages in thread
From: Darrick J. Wong @ 2022-11-10 20:16 UTC (permalink / raw)
  To: djwong, tytso; +Cc: catherine.hoang, linux-ext4

From: Darrick J. Wong <djwong@kernel.org>

If userspace provides a longer UUID buffer than is required, we
shouldn't fail the call with EINVAL -- rather, we can fill the caller's
buffer with the bytes we /can/ fill, and update the length field to
reflect what we copied.  This doesn't break the UAPI since we're
enabling a case that currently fails, and so far Ted hasn't released a
version of e2fsprogs that uses the new ext4 ioctl.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/ext4/ioctl.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)


diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 5f91f3ad3e50..31e643795016 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -1159,14 +1159,16 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,
 		return 0;
 	}
 
-	if (fsuuid.fsu_len != UUID_SIZE || fsuuid.fsu_flags != 0)
+	if (fsuuid.fsu_len < UUID_SIZE || fsuuid.fsu_flags != 0)
 		return -EINVAL;
 
 	lock_buffer(sbi->s_sbh);
 	memcpy(uuid, sbi->s_es->s_uuid, UUID_SIZE);
 	unlock_buffer(sbi->s_sbh);
 
-	if (copy_to_user(&ufsuuid->fsu_uuid[0], uuid, UUID_SIZE))
+	fsuuid.fsu_len = UUID_SIZE;
+	if (copy_to_user(ufsuuid, &fsuuid, sizeof(fsuuid)) ||
+	    copy_to_user(&ufsuuid->fsu_uuid[0], uuid, UUID_SIZE))
 		return -EFAULT;
 	return 0;
 }


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

* Re: [PATCH 1/2] ext4: dont return EINVAL from GETFSUUID when reporting UUID length
  2022-11-10 20:16 ` [PATCH 1/2] ext4: dont return EINVAL from GETFSUUID when reporting UUID length Darrick J. Wong
@ 2022-11-11  1:11   ` Catherine Hoang
  0 siblings, 0 replies; 5+ messages in thread
From: Catherine Hoang @ 2022-11-11  1:11 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: tytso, linux-ext4

> On Nov 10, 2022, at 12:16 PM, Darrick J. Wong <djwong@kernel.org> wrote:
> 
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If userspace calls this ioctl with fsu_length (the length of the
> fsuuid.fsu_uuid array) set to zero, ext4 copies the desired uuid length
> out to userspace.  The kernel call returned a result from a valid input,
> so the return value here should be zero, not EINVAL.
> 
> While we're at it, fix the copy_to_user call to make it clear that we're
> only copying out fsu_len.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good
Reviewed-by: Catherine Hoang <catherine.hoang@oracle.com>
> ---
> fs/ext4/ioctl.c |    5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
> 
> 
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 95dfea28bf4e..5f91f3ad3e50 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1153,9 +1153,10 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,
> 
> 	if (fsuuid.fsu_len == 0) {
> 		fsuuid.fsu_len = UUID_SIZE;
> -		if (copy_to_user(ufsuuid, &fsuuid, sizeof(fsuuid.fsu_len)))
> +		if (copy_to_user(&ufsuuid->fsu_len, &fsuuid.fsu_len,
> +					sizeof(fsuuid.fsu_len)))
> 			return -EFAULT;
> -		return -EINVAL;
> +		return 0;
> 	}
> 
> 	if (fsuuid.fsu_len != UUID_SIZE || fsuuid.fsu_flags != 0)
> 


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

* Re: [PATCH 2/2] ext4: don't fail GETFSUUID when the caller provides a long buffer
  2022-11-10 20:16 ` [PATCH 2/2] ext4: don't fail GETFSUUID when the caller provides a long buffer Darrick J. Wong
@ 2022-11-11  1:13   ` Catherine Hoang
  0 siblings, 0 replies; 5+ messages in thread
From: Catherine Hoang @ 2022-11-11  1:13 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: tytso, linux-ext4

> On Nov 10, 2022, at 12:16 PM, Darrick J. Wong <djwong@kernel.org> wrote:
> 
> From: Darrick J. Wong <djwong@kernel.org>
> 
> If userspace provides a longer UUID buffer than is required, we
> shouldn't fail the call with EINVAL -- rather, we can fill the caller's
> buffer with the bytes we /can/ fill, and update the length field to
> reflect what we copied.  This doesn't break the UAPI since we're
> enabling a case that currently fails, and so far Ted hasn't released a
> version of e2fsprogs that uses the new ext4 ioctl.
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good
Reviewed-by: Catherine Hoang <catherine.hoang@oracle.com>
> ---
> fs/ext4/ioctl.c |    6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
> 
> 
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 5f91f3ad3e50..31e643795016 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1159,14 +1159,16 @@ static int ext4_ioctl_getuuid(struct ext4_sb_info *sbi,
> 		return 0;
> 	}
> 
> -	if (fsuuid.fsu_len != UUID_SIZE || fsuuid.fsu_flags != 0)
> +	if (fsuuid.fsu_len < UUID_SIZE || fsuuid.fsu_flags != 0)
> 		return -EINVAL;
> 
> 	lock_buffer(sbi->s_sbh);
> 	memcpy(uuid, sbi->s_es->s_uuid, UUID_SIZE);
> 	unlock_buffer(sbi->s_sbh);
> 
> -	if (copy_to_user(&ufsuuid->fsu_uuid[0], uuid, UUID_SIZE))
> +	fsuuid.fsu_len = UUID_SIZE;
> +	if (copy_to_user(ufsuuid, &fsuuid, sizeof(fsuuid)) ||
> +	    copy_to_user(&ufsuuid->fsu_uuid[0], uuid, UUID_SIZE))
> 		return -EFAULT;
> 	return 0;
> }
> 


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

end of thread, other threads:[~2022-11-11  1:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-10 20:16 [PATCHSET 0/2] ext4: minor fixes to GETFSUUID ioctl Darrick J. Wong
2022-11-10 20:16 ` [PATCH 1/2] ext4: dont return EINVAL from GETFSUUID when reporting UUID length Darrick J. Wong
2022-11-11  1:11   ` Catherine Hoang
2022-11-10 20:16 ` [PATCH 2/2] ext4: don't fail GETFSUUID when the caller provides a long buffer Darrick J. Wong
2022-11-11  1:13   ` Catherine Hoang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.