linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <josef@toxicpanda.com>
To: linux-btrfs@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 09/13] btrfs: modify the new_root highest_objectid under a ref count
Date: Wed, 16 Dec 2020 11:22:13 -0500	[thread overview]
Message-ID: <db3b68c826ae28684100195170a913b13a23b567.1608135557.git.josef@toxicpanda.com> (raw)
In-Reply-To: <cover.1608135557.git.josef@toxicpanda.com>

Qu pointed out a bug in one of my error handling patches, which made me
notice that we modify the new_root->highest_objectid _after_ we've
dropped the ref to the new_root.  This could lead to a possible UAF, fix
this by modifying the ->highest_objectid before we drop our reference to
the new_root.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ioctl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index dde49a791f3e..af8d01659562 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -717,6 +717,12 @@ static noinline int create_subvol(struct inode *dir,
 	btrfs_record_root_in_trans(trans, new_root);
 
 	ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid);
+	if (!ret) {
+		mutex_lock(&new_root->objectid_mutex);
+		new_root->highest_objectid = new_dirid;
+		mutex_unlock(&new_root->objectid_mutex);
+	}
+
 	btrfs_put_root(new_root);
 	if (ret) {
 		/* We potentially lose an unused inode item here */
@@ -724,10 +730,6 @@ static noinline int create_subvol(struct inode *dir,
 		goto fail;
 	}
 
-	mutex_lock(&new_root->objectid_mutex);
-	new_root->highest_objectid = new_dirid;
-	mutex_unlock(&new_root->objectid_mutex);
-
 	/*
 	 * insert the directory item
 	 */
-- 
2.26.2


  parent reply	other threads:[~2020-12-16 16:23 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 16:22 [PATCH 00/13] Serious fixes for different error paths Josef Bacik
2020-12-16 16:22 ` [PATCH 01/13] btrfs: don't get an EINTR during drop_snapshot for reloc Josef Bacik
2021-01-11 21:56   ` David Sterba
2020-12-16 16:22 ` [PATCH 02/13] btrfs: initialize test inodes location Josef Bacik
2020-12-18 10:30   ` Nikolay Borisov
2020-12-21 16:58     ` David Sterba
2020-12-16 16:22 ` [PATCH 03/13] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Josef Bacik
2020-12-16 16:22 ` [PATCH 04/13] btrfs: splice remaining dirty_bg's onto the transaction dirty bg list Josef Bacik
2021-01-11 22:09   ` David Sterba
2020-12-16 16:22 ` [PATCH 05/13] btrfs: do not WARN_ON() if we can't find the reloc root Josef Bacik
2021-01-11 22:14   ` David Sterba
2020-12-16 16:22 ` [PATCH 06/13] btrfs: add ASSERT()'s for deleting backref cache nodes Josef Bacik
2021-01-11 22:18   ` David Sterba
2020-12-16 16:22 ` [PATCH 07/13] btrfs: do not double free backref nodes on error Josef Bacik
2020-12-16 16:22 ` [PATCH 08/13] btrfs: abort the transaction if we fail to inc ref in btrfs_copy_root Josef Bacik
2021-01-11 22:20   ` David Sterba
2020-12-16 16:22 ` Josef Bacik [this message]
2020-12-18 11:18   ` [PATCH 09/13] btrfs: modify the new_root highest_objectid under a ref count Nikolay Borisov
2020-12-16 16:22 ` [PATCH 10/13] btrfs: fix lockdep splat in btrfs_recover_relocation Josef Bacik
2020-12-16 16:22 ` [PATCH 11/13] btrfs: keep track of the root owner for relocation reads Josef Bacik
2021-01-11 22:23   ` David Sterba
2021-01-14 18:03     ` David Sterba
2020-12-16 16:22 ` [PATCH 12/13] btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node Josef Bacik
2020-12-16 16:22 ` [PATCH 13/13] btrfs: don't clear ret in btrfs_start_dirty_block_groups Josef Bacik
2021-01-08 16:44 ` [PATCH 00/13] Serious fixes for different error paths David Sterba
2021-01-14 18:20   ` 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=db3b68c826ae28684100195170a913b13a23b567.1608135557.git.josef@toxicpanda.com \
    --to=josef@toxicpanda.com \
    --cc=kernel-team@fb.com \
    --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 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).