All of lore.kernel.org
 help / color / mirror / Atom feed
* [bug report] bcachefs: Add an ioctl for resizing journal on a device
@ 2023-09-14 15:03 Dan Carpenter
  2023-09-20  2:27 ` Kent Overstreet
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2023-09-14 15:03 UTC (permalink / raw)
  To: kent.overstreet; +Cc: linux-bcachefs

Hello Kent Overstreet,

The patch f9e4304e0562: "bcachefs: Add an ioctl for resizing journal
on a device" from Nov 16, 2020 (linux-next), leads to the following
(unpublished) Smatch static checker warning:

	fs/bcachefs/chardev.c:624 bch2_ioctl_disk_resize_journal()
	warn: truncating user data 'arg.nbuckets' '0-u64max'

fs/bcachefs/chardev.c
    607 static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
    608                                    struct bch_ioctl_disk_resize_journal arg)
    609 {
    610         struct bch_dev *ca;
    611         int ret;
    612 
    613         if (!capable(CAP_SYS_ADMIN))
    614                 return -EPERM;
    615 
    616         if ((arg.flags & ~BCH_BY_INDEX) ||
    617             arg.pad)
    618                 return -EINVAL;
    619 
    620         ca = bch2_device_lookup(c, arg.dev, arg.flags);
    621         if (IS_ERR(ca))
    622                 return PTR_ERR(ca);
    623 
--> 624         ret = bch2_set_nr_journal_buckets(c, ca, arg.nbuckets);

This is harmless.  arg.nbuckets is a u64 and bch2_set_nr_journal_buckets()
takes a u32.  However this u32 vs u64 inconsistency with ->nbuckets is
not just here but also in other places.  (struct journal_device)->nr is
a u32 for example.  It would be better if it were consistent everywhere.

    625 
    626         percpu_ref_put(&ca->ref);
    627         return ret;
    628 }

regards,
dan carpenter

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

* Re: [bug report] bcachefs: Add an ioctl for resizing journal on a device
  2023-09-14 15:03 [bug report] bcachefs: Add an ioctl for resizing journal on a device Dan Carpenter
@ 2023-09-20  2:27 ` Kent Overstreet
  0 siblings, 0 replies; 2+ messages in thread
From: Kent Overstreet @ 2023-09-20  2:27 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: kent.overstreet, linux-bcachefs

On Thu, Sep 14, 2023 at 06:03:08PM +0300, Dan Carpenter wrote:
> Hello Kent Overstreet,
> 
> The patch f9e4304e0562: "bcachefs: Add an ioctl for resizing journal
> on a device" from Nov 16, 2020 (linux-next), leads to the following
> (unpublished) Smatch static checker warning:
> 
> 	fs/bcachefs/chardev.c:624 bch2_ioctl_disk_resize_journal()
> 	warn: truncating user data 'arg.nbuckets' '0-u64max'
> 
> fs/bcachefs/chardev.c
>     607 static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
>     608                                    struct bch_ioctl_disk_resize_journal arg)
>     609 {
>     610         struct bch_dev *ca;
>     611         int ret;
>     612 
>     613         if (!capable(CAP_SYS_ADMIN))
>     614                 return -EPERM;
>     615 
>     616         if ((arg.flags & ~BCH_BY_INDEX) ||
>     617             arg.pad)
>     618                 return -EINVAL;
>     619 
>     620         ca = bch2_device_lookup(c, arg.dev, arg.flags);
>     621         if (IS_ERR(ca))
>     622                 return PTR_ERR(ca);
>     623 
> --> 624         ret = bch2_set_nr_journal_buckets(c, ca, arg.nbuckets);
> 
> This is harmless.  arg.nbuckets is a u64 and bch2_set_nr_journal_buckets()
> takes a u32.  However this u32 vs u64 inconsistency with ->nbuckets is
> not just here but also in other places.  (struct journal_device)->nr is
> a u32 for example.  It would be better if it were consistent everywhere.

applying this fix

From 1c0cfb0abe14594347fa0639fe728f068be92deb Mon Sep 17 00:00:00 2001
From: Kent Overstreet <kent.overstreet@linux.dev>
Date: Tue, 19 Sep 2023 22:26:18 -0400
Subject: [PATCH] bcachefs: bch2_ioctl_disk_resize_journal(): check for integer
 truncation

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>

diff --git a/fs/bcachefs/chardev.c b/fs/bcachefs/chardev.c
index 51d671267741..e8b6733e7f71 100644
--- a/fs/bcachefs/chardev.c
+++ b/fs/bcachefs/chardev.c
@@ -627,6 +627,9 @@ static long bch2_ioctl_disk_resize_journal(struct bch_fs *c,
 	    arg.pad)
 		return -EINVAL;
 
+	if (arg.nbuckets > U32_MAX)
+		return -EINVAL;
+
 	ca = bch2_device_lookup(c, arg.dev, arg.flags);
 	if (IS_ERR(ca))
 		return PTR_ERR(ca);

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

end of thread, other threads:[~2023-09-20  2:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-14 15:03 [bug report] bcachefs: Add an ioctl for resizing journal on a device Dan Carpenter
2023-09-20  2:27 ` Kent Overstreet

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.