Commit 65fbaf24 authored by sandeen@sandeen.net's avatar sandeen@sandeen.net Committed by Lachlan McIlroy

[XFS] Fix xfs_bulkstat_one size checks & error handling

The 32-bit xfs_blkstat_one handler was failing because
a size check checked whether the remaining (32-bit)
user buffer was less than the (64-bit) bulkstat buffer,
and failed with ENOMEM if so.  Move this check
into the respective handlers so that they check the
correct sizes.

Also, the formatters were returning negative errors
or positive bytes copied; this was odd in the positive
error value world of xfs, and handled wrong by at least
some of the callers, which treated the bytes returned
as an error value.  Move the bytes-used assignment
into the formatters.
Signed-off-by: default avatarEric Sandeen <sandeen@sandeen.net>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarLachlan McIlroy <lachlan@sgi.com>
parent 2ee4fa5c
...@@ -192,13 +192,19 @@ xfs_bstime_store_compat( ...@@ -192,13 +192,19 @@ xfs_bstime_store_compat(
return 0; return 0;
} }
/* Return 0 on success or positive error (to xfs_bulkstat()) */
STATIC int STATIC int
xfs_bulkstat_one_fmt_compat( xfs_bulkstat_one_fmt_compat(
void __user *ubuffer, void __user *ubuffer,
int ubsize,
int *ubused,
const xfs_bstat_t *buffer) const xfs_bstat_t *buffer)
{ {
compat_xfs_bstat_t __user *p32 = ubuffer; compat_xfs_bstat_t __user *p32 = ubuffer;
if (ubsize < sizeof(*p32))
return XFS_ERROR(ENOMEM);
if (put_user(buffer->bs_ino, &p32->bs_ino) || if (put_user(buffer->bs_ino, &p32->bs_ino) ||
put_user(buffer->bs_mode, &p32->bs_mode) || put_user(buffer->bs_mode, &p32->bs_mode) ||
put_user(buffer->bs_nlink, &p32->bs_nlink) || put_user(buffer->bs_nlink, &p32->bs_nlink) ||
...@@ -219,8 +225,10 @@ xfs_bulkstat_one_fmt_compat( ...@@ -219,8 +225,10 @@ xfs_bulkstat_one_fmt_compat(
put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) || put_user(buffer->bs_dmevmask, &p32->bs_dmevmask) ||
put_user(buffer->bs_dmstate, &p32->bs_dmstate) || put_user(buffer->bs_dmstate, &p32->bs_dmstate) ||
put_user(buffer->bs_aextents, &p32->bs_aextents)) put_user(buffer->bs_aextents, &p32->bs_aextents))
return -XFS_ERROR(EFAULT); return XFS_ERROR(EFAULT);
return sizeof(*p32); if (ubused)
*ubused = sizeof(*p32);
return 0;
} }
STATIC int STATIC int
......
...@@ -188,14 +188,21 @@ xfs_bulkstat_one_dinode( ...@@ -188,14 +188,21 @@ xfs_bulkstat_one_dinode(
} }
} }
/* Return 0 on success or positive error */
STATIC int STATIC int
xfs_bulkstat_one_fmt( xfs_bulkstat_one_fmt(
void __user *ubuffer, void __user *ubuffer,
int ubsize,
int *ubused,
const xfs_bstat_t *buffer) const xfs_bstat_t *buffer)
{ {
if (ubsize < sizeof(*buffer))
return XFS_ERROR(ENOMEM);
if (copy_to_user(ubuffer, buffer, sizeof(*buffer))) if (copy_to_user(ubuffer, buffer, sizeof(*buffer)))
return -EFAULT; return XFS_ERROR(EFAULT);
return sizeof(*buffer); if (ubused)
*ubused = sizeof(*buffer);
return 0;
} }
/* /*
...@@ -223,8 +230,6 @@ xfs_bulkstat_one_int( ...@@ -223,8 +230,6 @@ xfs_bulkstat_one_int(
if (!buffer || xfs_internal_inum(mp, ino)) if (!buffer || xfs_internal_inum(mp, ino))
return XFS_ERROR(EINVAL); return XFS_ERROR(EINVAL);
if (ubsize < sizeof(*buf))
return XFS_ERROR(ENOMEM);
buf = kmem_alloc(sizeof(*buf), KM_SLEEP); buf = kmem_alloc(sizeof(*buf), KM_SLEEP);
...@@ -239,15 +244,11 @@ xfs_bulkstat_one_int( ...@@ -239,15 +244,11 @@ xfs_bulkstat_one_int(
xfs_bulkstat_one_dinode(mp, ino, dip, buf); xfs_bulkstat_one_dinode(mp, ino, dip, buf);
} }
error = formatter(buffer, buf); error = formatter(buffer, ubsize, ubused, buf);
if (error < 0) { if (error)
error = EFAULT;
goto out_free; goto out_free;
}
*stat = BULKSTAT_RV_DIDONE; *stat = BULKSTAT_RV_DIDONE;
if (ubused)
*ubused = error;
out_free: out_free:
kmem_free(buf); kmem_free(buf);
......
...@@ -71,6 +71,8 @@ xfs_bulkstat_single( ...@@ -71,6 +71,8 @@ xfs_bulkstat_single(
typedef int (*bulkstat_one_fmt_pf)( /* used size in bytes or negative error */ typedef int (*bulkstat_one_fmt_pf)( /* used size in bytes or negative error */
void __user *ubuffer, /* buffer to write to */ void __user *ubuffer, /* buffer to write to */
int ubsize, /* remaining user buffer sz */
int *ubused, /* bytes used by formatter */
const xfs_bstat_t *buffer); /* buffer to read from */ const xfs_bstat_t *buffer); /* buffer to read from */
int int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment