* [PATCH] Fix wrong max check in bch2_opt_validate
@ 2024-10-31 23:22 Piotr Zalewski
2024-11-06 8:11 ` Piotr Zalewski
0 siblings, 1 reply; 5+ messages in thread
From: Piotr Zalewski @ 2024-10-31 23:22 UTC (permalink / raw)
To: kent.overstreet, linux-bcachefs, linux-kernel
Cc: skhan, Piotr Zalewski, syzbot+bee87a0c3291c06aa8c6
Use opt->max-1 in bch2_opt_validate when option type is BCH_OPT_STR. When
option type is BCH_OPT_STR, real option's max is one less than the max
value stored in option structure.
Reported-by: syzbot+bee87a0c3291c06aa8c6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=bee87a0c3291c06aa8c6
Fixes: 63c4b2545382 ("bcachefs: Better superblock opt validation")
Signed-off-by: Piotr Zalewski <pZ010001011111@proton.me>
---
fs/bcachefs/opts.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index 83f55cf99d46..bffcbe6a6fd0 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -290,6 +290,8 @@ static int bch2_mount_opt_lookup(const char *name)
int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)
{
+ const u64 opt_max = opt->type == BCH_OPT_STR ? opt->max - 1 : opt->max;
+
if (v < opt->min) {
if (err)
prt_printf(err, "%s: too small (min %llu)",
@@ -297,10 +299,10 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)
return -BCH_ERR_ERANGE_option_too_small;
}
- if (opt->max && v >= opt->max) {
+ if (opt->max && v >= opt_max) {
if (err)
prt_printf(err, "%s: too big (max %llu)",
- opt->attr.name, opt->max);
+ opt->attr.name, opt_max);
return -BCH_ERR_ERANGE_option_too_big;
}
--
2.47.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix wrong max check in bch2_opt_validate
2024-10-31 23:22 [PATCH] Fix wrong max check in bch2_opt_validate Piotr Zalewski
@ 2024-11-06 8:11 ` Piotr Zalewski
2024-11-06 17:52 ` Kent Overstreet
0 siblings, 1 reply; 5+ messages in thread
From: Piotr Zalewski @ 2024-11-06 8:11 UTC (permalink / raw)
To: Piotr Zalewski
Cc: kent.overstreet, linux-bcachefs, linux-kernel, skhan,
syzbot+bee87a0c3291c06aa8c6
Hi Kent,
Did you see this?
Best regards
On Friday, November 1st, 2024 at 12:22 AM, Piotr Zalewski <pZ010001011111@proton.me> wrote:
> Use opt->max-1 in bch2_opt_validate when option type is BCH_OPT_STR. When
>
> option type is BCH_OPT_STR, real option's max is one less than the max
> value stored in option structure.
>
> Reported-by: syzbot+bee87a0c3291c06aa8c6@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=bee87a0c3291c06aa8c6
> Fixes: 63c4b2545382 ("bcachefs: Better superblock opt validation")
> Signed-off-by: Piotr Zalewski pZ010001011111@proton.me
>
> ---
> fs/bcachefs/opts.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
> index 83f55cf99d46..bffcbe6a6fd0 100644
> --- a/fs/bcachefs/opts.c
> +++ b/fs/bcachefs/opts.c
> @@ -290,6 +290,8 @@ static int bch2_mount_opt_lookup(const char *name)
>
> int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)
> {
> + const u64 opt_max = opt->type == BCH_OPT_STR ? opt->max - 1 : opt->max;
>
> +
> if (v < opt->min) {
>
> if (err)
> prt_printf(err, "%s: too small (min %llu)",
> @@ -297,10 +299,10 @@ int bch2_opt_validate(const struct bch_option *opt, u64 v, struct printbuf *err)
> return -BCH_ERR_ERANGE_option_too_small;
> }
>
> - if (opt->max && v >= opt->max) {
>
> + if (opt->max && v >= opt_max) {
>
> if (err)
> prt_printf(err, "%s: too big (max %llu)",
> - opt->attr.name, opt->max);
>
> + opt->attr.name, opt_max);
>
> return -BCH_ERR_ERANGE_option_too_big;
> }
>
> --
> 2.47.0
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix wrong max check in bch2_opt_validate
2024-11-06 8:11 ` Piotr Zalewski
@ 2024-11-06 17:52 ` Kent Overstreet
2024-11-06 18:58 ` Piotr Zalewski
0 siblings, 1 reply; 5+ messages in thread
From: Kent Overstreet @ 2024-11-06 17:52 UTC (permalink / raw)
To: Piotr Zalewski
Cc: linux-bcachefs, linux-kernel, skhan, syzbot+bee87a0c3291c06aa8c6
On Wed, Nov 06, 2024 at 08:11:13AM +0000, Piotr Zalewski wrote:
> Hi Kent,
>
> Did you see this?
Whoops, I did miss it the first time.
I think it'd be better to fix it in the OPT_STR() macro though.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix wrong max check in bch2_opt_validate
2024-11-06 17:52 ` Kent Overstreet
@ 2024-11-06 18:58 ` Piotr Zalewski
2024-11-06 19:34 ` Kent Overstreet
0 siblings, 1 reply; 5+ messages in thread
From: Piotr Zalewski @ 2024-11-06 18:58 UTC (permalink / raw)
To: Kent Overstreet
Cc: linux-bcachefs, linux-kernel, skhan, syzbot+bee87a0c3291c06aa8c6
Sent with Proton Mail secure email.
On Wednesday, November 6th, 2024 at 6:52 PM, Kent Overstreet <kent.overstreet@linux.dev> wrote:
> On Wed, Nov 06, 2024 at 08:11:13AM +0000, Piotr Zalewski wrote:
>
> > Hi Kent,
> >
> > Did you see this?
>
>
> Whoops, I did miss it the first time.
np
> I think it'd be better to fix it in the OPT_STR() macro though.
If changed in OPT_STR() macro it would also require a change in
bch2_opt_to_text:434 (it also does -1 there).
Best regards
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix wrong max check in bch2_opt_validate
2024-11-06 18:58 ` Piotr Zalewski
@ 2024-11-06 19:34 ` Kent Overstreet
0 siblings, 0 replies; 5+ messages in thread
From: Kent Overstreet @ 2024-11-06 19:34 UTC (permalink / raw)
To: Piotr Zalewski
Cc: linux-bcachefs, linux-kernel, skhan, syzbot+bee87a0c3291c06aa8c6
On Wed, Nov 06, 2024 at 06:58:04PM +0000, Piotr Zalewski wrote:
>
>
>
>
>
> Sent with Proton Mail secure email.
>
> On Wednesday, November 6th, 2024 at 6:52 PM, Kent Overstreet <kent.overstreet@linux.dev> wrote:
>
> > On Wed, Nov 06, 2024 at 08:11:13AM +0000, Piotr Zalewski wrote:
> >
> > > Hi Kent,
> > >
> > > Did you see this?
> >
> >
> > Whoops, I did miss it the first time.
>
> np
>
> > I think it'd be better to fix it in the OPT_STR() macro though.
>
> If changed in OPT_STR() macro it would also require a change in
> bch2_opt_to_text:434 (it also does -1 there).
*nod*
I think we should do it that way then, we don't want opt->max meaning
different things in different contexts if we can avoid it
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-06 19:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-31 23:22 [PATCH] Fix wrong max check in bch2_opt_validate Piotr Zalewski
2024-11-06 8:11 ` Piotr Zalewski
2024-11-06 17:52 ` Kent Overstreet
2024-11-06 18:58 ` Piotr Zalewski
2024-11-06 19:34 ` Kent Overstreet
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox