Re: [syzbot] general protection fault in prt_str

syzbot
2024-09-16T21:11:27Z

Author: djahchankoike@gmail.com

#syz test

syzbot reported a null ptr deref when printing mount options [1].

This happens because syzbot can pass options such as ',appraise,'
with no value associated with it, since it is a unknown option and
is not in the 'noopt' form it does not check for null values.
Change so that unknown options with invalid values are reported.

Signed-off-by: Diogo Jahchan Koike <djahchankoike@gmail.com>
---
fs/bcachefs/opts.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/fs/bcachefs/opts.c b/fs/bcachefs/opts.c
index e10fc1da71b1..1ccaed5c340b 100644
--- a/fs/bcachefs/opts.c
+++ b/fs/bcachefs/opts.c
@@ -482,6 +482,10 @@ int bch2_parse_one_mount_opt(struct bch_fs *c, struct bch_opts *opts,
val = "0";
}

+ /* Unknown options with invalid values are reported */
+ if (id < 0 && !val)
+ goto bad_val;
+
/* Unknown options are ignored: */
if (id < 0)
return 0;
--
2.43.0