bcachefs: avoid copy from NULL printbuf
PATCH 1/1 bcachefs: avoid copy from NULL printbuf
printbuf.buf may be NULL if allocation_failure is set. Check for this prior to using it as a seq_puts() source.
---
test test
fs/bcachefs/fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/bcachefs/fs.c +5 -2
@@ -1931,13 +1931,16 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root) {struct bch_fs *c = root->d_sb->s_fs_info;struct printbuf buf =PRINTBUF ; +int ret =0 ;bch2_opts_to_text (&buf, c->opts, c, c->disk_sb.sb,OPT_MOUNT ,OPT_HIDDEN ,OPT_SHOW_MOUNT_STYLE );printbuf_nul_terminate (&buf); -seq_puts (seq, buf.buf); +if (buf.allocation_failure) + ret = -ENOMEM ; +else +seq_puts (seq, buf.buf); -int ret = buf.allocation_failure ? -ENOMEM :0 ;printbuf_exit (&buf);return ret; }
Signature · 1 line
2.46.1
Quoted 20 lines · David Disseldorp
printbuf.buf may be NULL if
allocation_failureis set. Check for this prior to using it as aseq_puts()source.Fixes fa8e94faeece1 ("bcachefs: Heap allocate printbufs")Signed-off-by David Disseldorp <[email protected]>---
test testfs/bcachefs/fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/bcachefs/fs.c +1
-0@@ -1931,13 +1931,16 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root) {struct bch_fs *c = root->d_sb->s_fs_info;struct printbuf buf =PRINTBUF ; +int ret =0 ;
fs/bcachefs/fs.c static int bch2_show_options(struct seq_file *seq, struct dentry *root) · line 1943
Quoted 10 lines
fs/bcachefs/fs.c +4
-1bch2_opts_to_text (&buf, c->opts, c, c->disk_sb.sb,OPT_MOUNT ,OPT_HIDDEN ,OPT_SHOW_MOUNT_STYLE );printbuf_nul_terminate (&buf); -seq_puts (seq, buf.buf); +if (buf.allocation_failure) + ret = -ENOMEM ; +else +seq_puts (seq, buf.buf);
May I fix here in the last patch "bcachefs: fix incorrect show_options results" in v2, and add you as co-author?
Thanks,
Hongbo
Quoted 4 lines
fs/bcachefs/fs.c +0
-1-int ret = buf.allocation_failure ? -ENOMEM :0 ;printbuf_exit (&buf);return ret; }
Quoted 22 lines · Hongbo Li
Quoted 21 lines · David Disseldorp
printbuf.buf may be NULL if
allocation_failureis set. Check for this prior to using it as aseq_puts()source.Fixes fa8e94faeece1 ("bcachefs: Heap allocate printbufs")Signed-off-by David Disseldorp <[email protected]>---
test testfs/bcachefs/fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/bcachefs/fs.c +1
-0@@ -1931,13 +1931,16 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root) {struct bch_fs *c = root->d_sb->s_fs_info;struct printbuf buf =PRINTBUF ; +int ret =0 ;
Quoted 11 lines
fs/bcachefs/fs.c static int bch2_show_options(struct seq_file *seq, struct dentry *root) · line 1943
Quoted 9 lines
fs/bcachefs/fs.c +4
-1bch2_opts_to_text (&buf, c->opts, c, c->disk_sb.sb,OPT_MOUNT ,OPT_HIDDEN ,OPT_SHOW_MOUNT_STYLE );printbuf_nul_terminate (&buf); -seq_puts (seq, buf.buf); +if (buf.allocation_failure) + ret = -ENOMEM ; +else +seq_puts (seq, buf.buf);May I fix here in the last patch "bcachefs: fix incorrect
show_optionsresults" in v2, and add you as co-author?
I'm fine with this being squashed in with or without a co-author tag. However, I think they deserve separate commits given that they address separate regressions, and fixing show_options is more critical.
Thanks, David
Quoted 36 lines · David Disseldorp
Quoted 22 lines · Hongbo Li
Quoted 21 lines · David Disseldorp
printbuf.buf may be NULL if
allocation_failureis set. Check for this prior to using it as aseq_puts()source.Fixes fa8e94faeece1 ("bcachefs: Heap allocate printbufs")Signed-off-by David Disseldorp <[email protected]>---
test testfs/bcachefs/fs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/bcachefs/fs.c +1
-0@@ -1931,13 +1931,16 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root) {struct bch_fs *c = root->d_sb->s_fs_info;struct printbuf buf =PRINTBUF ; +int ret =0 ;Quoted 11 lines
fs/bcachefs/fs.c static int bch2_show_options(struct seq_file *seq, struct dentry *root) · line 1943
Quoted 9 lines
fs/bcachefs/fs.c +4
-1bch2_opts_to_text (&buf, c->opts, c, c->disk_sb.sb,OPT_MOUNT ,OPT_HIDDEN ,OPT_SHOW_MOUNT_STYLE );printbuf_nul_terminate (&buf); -seq_puts (seq, buf.buf); +if (buf.allocation_failure) + ret = -ENOMEM ; +else +seq_puts (seq, buf.buf);May I fix here in the last patch "bcachefs: fix incorrect
show_optionsresults" in v2, and add you as co-author?
Quoted 4 lines
I'm fine with this being squashed in with or without a co-author tag. However, I think they deserve separate commits given that they address separate regressions, and fixing
show_optionsis more critical.
I collect these two patch in [1] with separated commits. :)
[1] https://lore.kernel.org/linux-bcachefs/[email protected]/T/#t
Thanks,
Hongbo
Quoted 1 line
Thanks, David