All of lore.kernel.org
 help / color / mirror / Atom feed
From: fdmanana@kernel.org
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/3] btrfs: fix extent map leak in unexpected scenario at unpin_extent_cache()
Date: Wed, 13 Mar 2024 13:20:44 +0000	[thread overview]
Message-ID: <f3c7f68caa8f3568fbf2d561b35604823bb5985f.1710335452.git.fdmanana@suse.com> (raw)
In-Reply-To: <cover.1710335452.git.fdmanana@suse.com>

From: Filipe Manana <fdmanana@suse.com>

At unpin_extent_cache() if we happen to find an extent map with an
unexpected start offset, we jump to the 'out' label and never release the
reference we added to the extent map through the call to
lookup_extent_mapping(), therefore resulting in a leak. So fix this by
moving the free_extent_map() under the 'out' label.

Fixes: c03c89f821e5 ("btrfs: handle errors returned from unpin_extent_cache()")
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/extent_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c
index 347ca13d15a9..e03953dbcd5e 100644
--- a/fs/btrfs/extent_map.c
+++ b/fs/btrfs/extent_map.c
@@ -340,9 +340,9 @@ int unpin_extent_cache(struct btrfs_inode *inode, u64 start, u64 len, u64 gen)
 		em->mod_len = em->len;
 	}
 
-	free_extent_map(em);
 out:
 	write_unlock(&tree->lock);
+	free_extent_map(em);
 	return ret;
 
 }
-- 
2.43.0


  reply	other threads:[~2024-03-13 13:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-13 13:20 [PATCH 0/3] btrfs: some minor fixes around extent maps fdmanana
2024-03-13 13:20 ` fdmanana [this message]
2024-03-13 13:20 ` [PATCH 2/3] btrfs: fix warning messages not printing interval at unpin_extent_range() fdmanana
2024-03-13 13:20 ` [PATCH 3/3] btrfs: fix message not properly printing interval when adding extent map fdmanana
2024-03-13 17:28 ` [PATCH v2 0/4] btrfs: some minor fixes around extent maps fdmanana
2024-03-13 17:28   ` [PATCH v2 1/4] btrfs: fix extent map leak in unexpected scenario at unpin_extent_cache() fdmanana
2024-03-14 12:59     ` Anand Jain
2024-03-13 17:28   ` [PATCH v2 2/4] btrfs: fix warning messages not printing interval at unpin_extent_range() fdmanana
2024-03-13 17:28   ` [PATCH v2 3/4] btrfs: fix message not properly printing interval when adding extent map fdmanana
2024-03-13 17:28   ` [PATCH v2 4/4] btrfs: use btrfs_warn() to log message at btrfs_add_extent_mapping() fdmanana
2024-03-13 19:22   ` [PATCH v2 0/4] btrfs: some minor fixes around extent maps Qu Wenruo
2024-03-14 13:06   ` Anand Jain

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=f3c7f68caa8f3568fbf2d561b35604823bb5985f.1710335452.git.fdmanana@suse.com \
    --to=fdmanana@kernel.org \
    --cc=linux-btrfs@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.