* [PATCH v2] fs: Fix uninitialized value issue in from_kuid and from_kgid
@ 2024-10-17 12:05 Alessandro Zanni
2024-10-17 13:06 ` Jan Kara
2024-10-17 13:32 ` Christian Brauner
0 siblings, 2 replies; 3+ messages in thread
From: Alessandro Zanni @ 2024-10-17 12:05 UTC (permalink / raw)
To: viro, brauner, jack
Cc: Alessandro Zanni, linux-fsdevel, linux-kernel, skhan,
anupnewsmail, alessandrozanni.dev, syzbot+6c55f725d1bdc8c52058
ocfs2_setattr() uses attr->ia_mode, attr->ia_uid and attr->ia_gid in
a trace point even though ATTR_MODE, ATTR_UID and ATTR_GID aren't set.
Initialize all fields of newattrs to avoid uninitialized variables, by
checking if ATTR_MODE, ATTR_UID, ATTR_GID are initialized, otherwise 0.
Reported-by: syzbot+6c55f725d1bdc8c52058@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6c55f725d1bdc8c52058
Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
---
Notes:
v2: fix ocfs2_setattr to avoid similar issues; improved commit description
fs/ocfs2/file.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index ad131a2fc58e..58887456e3c5 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1129,9 +1129,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
trace_ocfs2_setattr(inode, dentry,
(unsigned long long)OCFS2_I(inode)->ip_blkno,
dentry->d_name.len, dentry->d_name.name,
- attr->ia_valid, attr->ia_mode,
- from_kuid(&init_user_ns, attr->ia_uid),
- from_kgid(&init_user_ns, attr->ia_gid));
+ attr->ia_valid,
+ attr->ia_valid & ATTR_MODE ? attr->ia_mode : 0,
+ attr->ia_valid & ATTR_UID ?
+ from_kuid(&init_user_ns, attr->ia_uid) : 0,
+ attr->ia_valid & ATTR_GID ?
+ from_kgid(&init_user_ns, attr->ia_gid) : 0);
/* ensuring we don't even attempt to truncate a symlink */
if (S_ISLNK(inode->i_mode))
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] fs: Fix uninitialized value issue in from_kuid and from_kgid
2024-10-17 12:05 [PATCH v2] fs: Fix uninitialized value issue in from_kuid and from_kgid Alessandro Zanni
@ 2024-10-17 13:06 ` Jan Kara
2024-10-17 13:32 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2024-10-17 13:06 UTC (permalink / raw)
To: Alessandro Zanni
Cc: viro, brauner, jack, linux-fsdevel, linux-kernel, skhan,
anupnewsmail, alessandrozanni.dev, syzbot+6c55f725d1bdc8c52058
On Thu 17-10-24 14:05:51, Alessandro Zanni wrote:
> ocfs2_setattr() uses attr->ia_mode, attr->ia_uid and attr->ia_gid in
> a trace point even though ATTR_MODE, ATTR_UID and ATTR_GID aren't set.
>
> Initialize all fields of newattrs to avoid uninitialized variables, by
> checking if ATTR_MODE, ATTR_UID, ATTR_GID are initialized, otherwise 0.
>
> Reported-by: syzbot+6c55f725d1bdc8c52058@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=6c55f725d1bdc8c52058
> Signed-off-by: Alessandro Zanni <alessandro.zanni87@gmail.com>
Thanks! The patch looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> Notes:
> v2: fix ocfs2_setattr to avoid similar issues; improved commit description
>
> fs/ocfs2/file.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
> index ad131a2fc58e..58887456e3c5 100644
> --- a/fs/ocfs2/file.c
> +++ b/fs/ocfs2/file.c
> @@ -1129,9 +1129,12 @@ int ocfs2_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
> trace_ocfs2_setattr(inode, dentry,
> (unsigned long long)OCFS2_I(inode)->ip_blkno,
> dentry->d_name.len, dentry->d_name.name,
> - attr->ia_valid, attr->ia_mode,
> - from_kuid(&init_user_ns, attr->ia_uid),
> - from_kgid(&init_user_ns, attr->ia_gid));
> + attr->ia_valid,
> + attr->ia_valid & ATTR_MODE ? attr->ia_mode : 0,
> + attr->ia_valid & ATTR_UID ?
> + from_kuid(&init_user_ns, attr->ia_uid) : 0,
> + attr->ia_valid & ATTR_GID ?
> + from_kgid(&init_user_ns, attr->ia_gid) : 0);
>
> /* ensuring we don't even attempt to truncate a symlink */
> if (S_ISLNK(inode->i_mode))
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] fs: Fix uninitialized value issue in from_kuid and from_kgid
2024-10-17 12:05 [PATCH v2] fs: Fix uninitialized value issue in from_kuid and from_kgid Alessandro Zanni
2024-10-17 13:06 ` Jan Kara
@ 2024-10-17 13:32 ` Christian Brauner
1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2024-10-17 13:32 UTC (permalink / raw)
To: Alessandro Zanni
Cc: Christian Brauner, linux-fsdevel, linux-kernel, skhan,
anupnewsmail, alessandrozanni.dev, syzbot+6c55f725d1bdc8c52058,
viro, jack
On Thu, 17 Oct 2024 14:05:51 +0200, Alessandro Zanni wrote:
> ocfs2_setattr() uses attr->ia_mode, attr->ia_uid and attr->ia_gid in
> a trace point even though ATTR_MODE, ATTR_UID and ATTR_GID aren't set.
>
> Initialize all fields of newattrs to avoid uninitialized variables, by
> checking if ATTR_MODE, ATTR_UID, ATTR_GID are initialized, otherwise 0.
>
>
> [...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] fs: Fix uninitialized value issue in from_kuid and from_kgid
https://git.kernel.org/vfs/vfs/c/eeb1277262f8
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-17 13:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-17 12:05 [PATCH v2] fs: Fix uninitialized value issue in from_kuid and from_kgid Alessandro Zanni
2024-10-17 13:06 ` Jan Kara
2024-10-17 13:32 ` Christian Brauner
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).