From: Rustam Subkhankulov <subkhankulov@ispras.ru>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Rustam Subkhankulov <subkhankulov@ispras.ru>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>,
ldv-project@linuxtesting.org
Subject: [PATCH v2] fs/inode.c: change the order of initialization in inode_init_always()
Date: Mon, 29 Aug 2022 22:25:21 +0300 [thread overview]
Message-ID: <20220829192521.694631-1-subkhankulov@ispras.ru> (raw)
In-Reply-To: <20220829141517.bcjbdk5zb74mrhgu@wittgenstein>
If function security_inode_alloc() returns a nonzero value due to an
error (e.g. fail to allocate memory), then some of the fields, including
'i_private', will not be initialized.
After that, if the fs-specfic free_inode function is called in
i_callback(), the nonzero value of 'i_private' field can be interpreted
as initialized. As a result, this can cause dereferencing of random
value pointer (e.g. nilfs2).
In earlier versions, a similar situation could occur with the 'u' union
in 'inode' structure.
Found by Linux Verification Center (linuxtesting.org) with syzkaller.
Signed-off-by: Rustam Subkhankulov <subkhankulov@ispras.ru>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
fs/inode.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index ba1de23c13c1..a2892d85993d 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;
#endif
- if (security_inode_alloc(inode))
- goto out;
spin_lock_init(&inode->i_lock);
lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key);
@@ -228,6 +226,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
inode->i_fsnotify_mask = 0;
#endif
inode->i_flctx = NULL;
+
+ if (security_inode_alloc(inode))
+ goto out;
+
this_cpu_inc(nr_inodes);
return 0;
--
2.34.1
next prev parent reply other threads:[~2022-08-29 19:26 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-27 14:09 [PATCH] " Alexey Khoroshilov
2022-08-29 14:15 ` Christian Brauner
2022-08-29 19:25 ` Rustam Subkhankulov [this message]
2022-08-31 23:59 ` [PATCH v2] " Al Viro
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=20220829192521.694631-1-subkhankulov@ispras.ru \
--to=subkhankulov@ispras.ru \
--cc=khoroshilov@ispras.ru \
--cc=ldv-project@linuxtesting.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®