Skip to content

Commit f9f0a53

Browse files
JungerBoyoKent Overstreet
authored andcommitted
bcachefs: Change OPT_STR max to be 1 less than the size of choices array
Change OPT_STR max value to be 1 less than the "ARRAY_SIZE" of "_choices" array. As a result, remove -1 from (opt->max-1) in bch2_opt_to_text. The "_choices" array is a null-terminated array, so computing the maximum using "ARRAY_SIZE" without subtracting 1 yields an incorrect result. Since bch2_opt_validate don't subtract 1, as bch2_opt_to_text does, values bigger than the actual maximum would pass through option validation. Reported-by: syzbot+bee87a0c3291c06aa8c6@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=bee87a0c3291c06aa8c6 Fixes: 63c4b25 ("bcachefs: Better superblock opt validation") Suggested-by: Kent Overstreet <kent.overstreet@linux.dev> Signed-off-by: Piotr Zalewski <pZ010001011111@proton.me> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent baefd3f commit f9f0a53

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/bcachefs/opts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const struct bch_option bch2_opt_table[] = {
226226
#define OPT_UINT(_min, _max) .type = BCH_OPT_UINT, \
227227
.min = _min, .max = _max
228228
#define OPT_STR(_choices) .type = BCH_OPT_STR, \
229-
.min = 0, .max = ARRAY_SIZE(_choices), \
229+
.min = 0, .max = ARRAY_SIZE(_choices) - 1, \
230230
.choices = _choices
231231
#define OPT_STR_NOLIMIT(_choices) .type = BCH_OPT_STR, \
232232
.min = 0, .max = U64_MAX, \
@@ -428,7 +428,7 @@ void bch2_opt_to_text(struct printbuf *out,
428428
prt_printf(out, "%lli", v);
429429
break;
430430
case BCH_OPT_STR:
431-
if (v < opt->min || v >= opt->max - 1)
431+
if (v < opt->min || v >= opt->max)
432432
prt_printf(out, "(invalid option %lli)", v);
433433
else if (flags & OPT_SHOW_FULL_LIST)
434434
prt_string_option(out, opt->choices, v);

0 commit comments

Comments
 (0)