* [PATCH] fs/inode.c: change the order of initialization in inode_init_always()
@ 2022-08-27 14:09 Alexey Khoroshilov
2022-08-29 14:15 ` Christian Brauner
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Khoroshilov @ 2022-08-27 14:09 UTC (permalink / raw)
To: Alexander Viro
Cc: Rustam Subkhankulov, linux-fsdevel, linux-kernel,
Alexey Khoroshilov, ldv-project
From: Rustam Subkhankulov <subkhankulov@ispras.ru>
If function 'security_inode_alloc()' returns a nonzero value at
[fs/inode.c: 195] 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 | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index bd4da9c5207e..08d093737e8c 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);
@@ -230,9 +228,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
inode->i_flctx = NULL;
this_cpu_inc(nr_inodes);
+ if (security_inode_alloc(inode))
+ return -ENOMEM;
+
return 0;
-out:
- return -ENOMEM;
}
EXPORT_SYMBOL(inode_init_always);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] fs/inode.c: change the order of initialization in inode_init_always()
2022-08-27 14:09 [PATCH] fs/inode.c: change the order of initialization in inode_init_always() Alexey Khoroshilov
@ 2022-08-29 14:15 ` Christian Brauner
2022-08-29 19:25 ` [PATCH v2] " Rustam Subkhankulov
0 siblings, 1 reply; 4+ messages in thread
From: Christian Brauner @ 2022-08-29 14:15 UTC (permalink / raw)
To: Alexey Khoroshilov
Cc: Alexander Viro, Rustam Subkhankulov, linux-fsdevel, linux-kernel,
ldv-project
On Sat, Aug 27, 2022 at 05:09:26PM +0300, Alexey Khoroshilov wrote:
> From: Rustam Subkhankulov <subkhankulov@ispras.ru>
>
> If function 'security_inode_alloc()' returns a nonzero value at
> [fs/inode.c: 195] 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 | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/fs/inode.c b/fs/inode.c
> index bd4da9c5207e..08d093737e8c 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);
>
> @@ -230,9 +228,10 @@ int inode_init_always(struct super_block *sb, struct inode *inode)
> inode->i_flctx = NULL;
> this_cpu_inc(nr_inodes);
>
> + if (security_inode_alloc(inode))
> + return -ENOMEM;
This should probably be before this_cpu_inc(nr_inodes).
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] fs/inode.c: change the order of initialization in inode_init_always()
2022-08-29 14:15 ` Christian Brauner
@ 2022-08-29 19:25 ` Rustam Subkhankulov
2022-08-31 23:59 ` Al Viro
0 siblings, 1 reply; 4+ messages in thread
From: Rustam Subkhankulov @ 2022-08-29 19:25 UTC (permalink / raw)
To: Alexander Viro
Cc: Rustam Subkhankulov, linux-fsdevel, linux-kernel,
Alexey Khoroshilov, ldv-project
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] fs/inode.c: change the order of initialization in inode_init_always()
2022-08-29 19:25 ` [PATCH v2] " Rustam Subkhankulov
@ 2022-08-31 23:59 ` Al Viro
0 siblings, 0 replies; 4+ messages in thread
From: Al Viro @ 2022-08-31 23:59 UTC (permalink / raw)
To: Rustam Subkhankulov
Cc: linux-fsdevel, linux-kernel, Alexey Khoroshilov, ldv-project
On Mon, Aug 29, 2022 at 10:25:21PM +0300, Rustam Subkhankulov wrote:
> 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.
See vfs.git#work.inode (included into #for-next); I agree that your
commit message looks better, but...
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-01 0:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-27 14:09 [PATCH] fs/inode.c: change the order of initialization in inode_init_always() Alexey Khoroshilov
2022-08-29 14:15 ` Christian Brauner
2022-08-29 19:25 ` [PATCH v2] " Rustam Subkhankulov
2022-08-31 23:59 ` Al Viro
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).