btrfs: avoid null pointer dereference on fs_info when calling btrfs_crit
Subsystems (2)
PATCH 1/1 btrfs: avoid null pointer dereference on fs_info when calling btrfs_crit
From: Colin Ian King <[email protected]>
There are checks on fs_info in __btrfs_panic to avoid dereferencing a null fs_info, however, there is a call to btrfs_crit that may also dereference a null fs_info. Fix this by adding a check to see if fs_info is null and only print the s_id if fs_info is non-null.
Detected by CoverityScan CID#401973 ("Dereference after null check")
--- fs/btrfs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/super.c +2 -2
@@ -202,7 +202,6 @@ static struct ratelimit_state printk_limits[] = {void btrfs_printk (const struct btrfs_fs_info *fs_info,const char *fmt, ...) { -struct super_block *sb = fs_info->sb;char lvl[PRINTK_MAX_SINGLE_HEADER_LEN +1 ] ="\0" ;struct va_format vaf;va_list args;
@@ -228,7 +227,8 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) vaf.va = &args;if (__ratelimit (ratelimit)) -printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, sb->s_id, &vaf); +printk ("%sBTRFS %s (device %s): %pV\n" , lvl, type, + fs_info ? fs_info->sb->s_id :"<unknown>" , &vaf);va_end (args); }
Signature · 1 line
2.14.1
Quoted 11 lines · Colin King
From: Colin Ian King <[email protected]>
There are checks on
fs_infoin__btrfs_panicto avoid dereferencing a nullfs_info, however, there is a call tobtrfs_critthat may also dereference a nullfs_info. Fix this by adding a check to see iffs_infois null and only print thes_idiffs_infois non-null.Detected by CoverityScan CID#401973 ("Dereference after null check")
Fixes efe120a067c8 ("Btrfs: convert printk to btrfs_ and fix BTRFS prefix")Signed-off-by Colin Ian King <[email protected]>