archive mirror
 help / color / mirror / Atom feed
From: Dongliang Mu <>
To: Alexander Viro <>
Cc: Dongliang Mu <>,
	butt3rflyh4ck <>,
	Hao Sun <>, Jiacheng Xu <>,,,
Subject: [PATCH v2] fs: fix UAF/GPF bug in nilfs_mdt_destroy
Date: Tue, 16 Aug 2022 12:08:58 +0800	[thread overview]
Message-ID: <> (raw)

From: Dongliang Mu <>

In alloc_inode, inode_init_always() could return -ENOMEM if
security_inode_alloc() fails, which causes inode->i_private
uninitialized. Then nilfs_is_metadata_file_inode() returns
true and nilfs_free_inode() wrongly calls nilfs_mdt_destroy(),
which frees the uninitialized inode->i_private
and leads to crashes(e.g., UAF/GPF).

Fix this by moving security_inode_alloc just prior to

Reported-by: butt3rflyh4ck <>
Reported-by: Hao Sun <>
Reported-by: Jiacheng Xu <>
Signed-off-by: Dongliang Mu <>
Cc: Al Viro <>
v1->v2: move security_inode_alloc at the very end according to Al Viro
	other than initializing i_private before security_inode_alloc.
 fs/inode.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/inode.c b/fs/inode.c
index 6462276dfdf0..49d1eb91728c 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -192,8 +192,6 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	inode->i_wb_frn_history = 0;
-	if (security_inode_alloc(inode))
-		goto out;
 	lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
@@ -228,6 +226,9 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
 	inode->i_fsnotify_mask = 0;
 	inode->i_flctx = NULL;
+	if (security_inode_alloc(inode))
+		goto out;
 	return 0;

             reply	other threads:[~2022-08-16  7:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16  4:08 Dongliang Mu [this message]
2022-08-16 10:46 ` [PATCH v2] fs: fix UAF/GPF bug in nilfs_mdt_destroy Christian Brauner
2022-08-25 19:45 ` Eric Sandeen

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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \

* 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).