Return-Path: Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41687 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752931AbeBKEeH (ORCPT ); Sat, 10 Feb 2018 23:34:07 -0500 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Colin Ian King" , "David Sterba" Date: Sun, 11 Feb 2018 04:31:11 +0000 Message-ID: Subject: [PATCH 3.16 037/136] btrfs: avoid null pointer dereference on fs_info when calling btrfs_crit In-Reply-To: Sender: stable-owner@vger.kernel.org List-ID: 3.16.54-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit 3993b112dac968612b0b213ed59cb30f50b0015b upstream. 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") Fixes: efe120a067c8 ("Btrfs: convert printk to btrfs_ and fix BTRFS prefix") Signed-off-by: Colin Ian King Reviewed-by: David Sterba Signed-off-by: David Sterba [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- fs/btrfs/super.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -185,7 +185,6 @@ static const char * const logtypes[] = { void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) { - struct super_block *sb = fs_info->sb; char lvl[4]; struct va_format vaf; va_list args; @@ -207,7 +206,8 @@ void btrfs_printk(const struct btrfs_fs_ vaf.fmt = fmt; vaf.va = &args; - 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 : "", &vaf); va_end(args); }