linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian <sebastian.scherbel@fau.de>
To: clm@fb.com
Cc: josef@toxicpanda.com, dsterba@suse.com,
	linux-btrfs@vger.kernel.org, linux-kernel@i4.cs.fau.de,
	Sebastian Scherbel <sebastian.scherbel@fau.de>,
	Ole Wiedemann <ole.wiedemann@fau.de>
Subject: [PATCH 2/2] btrfs: Move dereference behind null check in check volumes
Date: Sat,  7 Dec 2019 23:18:18 +0100	[thread overview]
Message-ID: <20191207221818.3641-3-sebastian.scherbel@fau.de> (raw)
In-Reply-To: <20191207221818.3641-1-sebastian.scherbel@fau.de>

From: Sebastian Scherbel <sebastian.scherbel@fau.de>

Regarding Bug 205003, point 2
The struct "tgtdev" is currently dereferenced before being checked
for null later on. This patch moves the derefernce after the null
check to avoid a possible null pointer dereference.
Furthermore WARN_ON is replaced by BUG_ON to prevent the subsequent
dereference of the null pointer.

Signed-off-by: Sebastian Scherbel <sebastian.scherbel@fau.de>
Co-developed-by: Ole Wiedemann <ole.wiedemann@fau.de>
Signed-off-by: Ole Wiedemann <ole.wiedemann@fau.de>
---
 fs/btrfs/volumes.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d8e5560db285..12015f60f50d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2128,9 +2128,11 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_device *srcdev)
 
 void btrfs_destroy_dev_replace_tgtdev(struct btrfs_device *tgtdev)
 {
-	struct btrfs_fs_devices *fs_devices = tgtdev->fs_info->fs_devices;
+	struct btrfs_fs_devices *fs_devices;
+
+	BUG_ON(!tgtdev);
+	fs_devices = tgtdev->fs_info->fs_devices;
 
-	WARN_ON(!tgtdev);
 	mutex_lock(&fs_devices->device_list_mutex);
 
 	btrfs_sysfs_rm_device_link(fs_devices, tgtdev);
-- 
2.20.1


  parent reply	other threads:[~2019-12-07 22:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-07 22:18 [PATCH 0/2] btrfs: Move dereference behind null checks Sebastian
2019-12-07 22:18 ` [PATCH 1/2] btrfs: Move dereference behind null check in check integrity Sebastian
2019-12-07 22:18 ` Sebastian [this message]
2019-12-09  9:30 ` [PATCH 0/2] btrfs: Move dereference behind null checks Johannes Thumshirn
2019-12-09 16:11   ` David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191207221818.3641-3-sebastian.scherbel@fau.de \
    --to=sebastian.scherbel@fau.de \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@i4.cs.fau.de \
    --cc=ole.wiedemann@fau.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).