All of lore.kernel.org
 help / color / mirror / Atom feed
From: void0red <void0red@gmail.com>
To: dsterba@suse.com
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	void0red <void0red@gmail.com>, eriri <1527030098@qq.com>
Subject: [PATCH] btrfs: avoid use-after-free when return the error code
Date: Wed, 23 Nov 2022 22:39:45 +0800	[thread overview]
Message-ID: <20221123143945.2666-1-void0red@gmail.com> (raw)

free_extent_map(em) will free em->map_lookup, so it is
wrong to use it when return.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=216721
Signed-off-by: void0red <void0red@gmail.com>
Reported-by: eriri <1527030098@qq.com>
---
 fs/btrfs/volumes.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 635f45f1a2ef..dba087ad40ea 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -7241,8 +7241,9 @@ static int read_one_chunk(struct btrfs_key *key, struct extent_buffer *leaf,
 			map->stripes[i].dev = handle_missing_device(fs_info,
 								    devid, uuid);
 			if (IS_ERR(map->stripes[i].dev)) {
+				ret = PTR_ERR(map->stripes[i].dev);
 				free_extent_map(em);
-				return PTR_ERR(map->stripes[i].dev);
+				return ret;
 			}
 		}
 
-- 
2.34.1


             reply	other threads:[~2022-11-23 14:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 14:39 void0red [this message]
2022-11-23 15:40 ` [PATCH] btrfs: avoid use-after-free when return the error code 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=20221123143945.2666-1-void0red@gmail.com \
    --to=void0red@gmail.com \
    --cc=1527030098@qq.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.