Message ID | 20221023163945.39920-5-yin31149@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | fs: fix possible null-ptr-deref when parsing param | expand |
Am So., 23. Okt. 2022 um 18:46 Uhr schrieb Hawkins Jiawei <yin31149@gmail.com>: > According to commit "vfs: parse: deal with zero length string value", > kernel will set the param->string to null pointer in vfs_parse_fs_string() > if fs string has zero length. > > Yet the problem is that, gfs2_parse_param() will dereferences the > param->string, without checking whether it is a null pointer, which may > trigger a null-ptr-deref bug. > > This patch solves it by adding sanity check on param->string > in gfs2_parse_param(). Yes, but then it dereferences param->string in the error message. That won't help. > Reported-by: syzbot+da97a57c5b742d05db51@syzkaller.appspotmail.com > Tested-by: syzbot+da97a57c5b742d05db51@syzkaller.appspotmail.com > Cc: agruenba@redhat.com > Cc: cluster-devel@redhat.com > Cc: linux-kernel@vger.kernel.org > Cc: rpeterso@redhat.com > Cc: syzkaller-bugs@googlegroups.com > Signed-off-by: Hawkins Jiawei <yin31149@gmail.com> > --- > fs/gfs2/ops_fstype.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c > index c0cf1d2d0ef5..934746f18c25 100644 > --- a/fs/gfs2/ops_fstype.c > +++ b/fs/gfs2/ops_fstype.c > @@ -1446,12 +1446,18 @@ static int gfs2_parse_param(struct fs_context *fc, struct fs_parameter *param) > > switch (o) { > case Opt_lockproto: > + if (!param->string) > + goto bad_val; > strscpy(args->ar_lockproto, param->string, GFS2_LOCKNAME_LEN); > break; > case Opt_locktable: > + if (!param->string) > + goto bad_val; > strscpy(args->ar_locktable, param->string, GFS2_LOCKNAME_LEN); > break; > case Opt_hostdata: > + if (!param->string) > + goto bad_val; > strscpy(args->ar_hostdata, param->string, GFS2_LOCKNAME_LEN); > break; > case Opt_spectator: > @@ -1535,6 +1541,10 @@ static int gfs2_parse_param(struct fs_context *fc, struct fs_parameter *param) > return invalfc(fc, "invalid mount option: %s", param->key); > } > return 0; > + > +bad_val: > + return invalfc(fc, "Bad value '%s' for mount option '%s'\n", > + param->string, param->key); > } > > static int gfs2_reconfigure(struct fs_context *fc) > -- > 2.25.1 > Thanks, Andreas
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c index c0cf1d2d0ef5..934746f18c25 100644 --- a/fs/gfs2/ops_fstype.c +++ b/fs/gfs2/ops_fstype.c @@ -1446,12 +1446,18 @@ static int gfs2_parse_param(struct fs_context *fc, struct fs_parameter *param) switch (o) { case Opt_lockproto: + if (!param->string) + goto bad_val; strscpy(args->ar_lockproto, param->string, GFS2_LOCKNAME_LEN); break; case Opt_locktable: + if (!param->string) + goto bad_val; strscpy(args->ar_locktable, param->string, GFS2_LOCKNAME_LEN); break; case Opt_hostdata: + if (!param->string) + goto bad_val; strscpy(args->ar_hostdata, param->string, GFS2_LOCKNAME_LEN); break; case Opt_spectator: @@ -1535,6 +1541,10 @@ static int gfs2_parse_param(struct fs_context *fc, struct fs_parameter *param) return invalfc(fc, "invalid mount option: %s", param->key); } return 0; + +bad_val: + return invalfc(fc, "Bad value '%s' for mount option '%s'\n", + param->string, param->key); } static int gfs2_reconfigure(struct fs_context *fc)