From: Joe Perches <joe@perches.com>
To: Chao Yu <yuchao0@huawei.com>, jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org, chao@kernel.org
Subject: Re: [PATCH v4] f2fs: fix potential .flags overflow on 32bit architecture
Date: Sun, 22 Mar 2020 19:57:09 -0700 [thread overview]
Message-ID: <8d435607bd79f518bd9420d68894ddda521bac5a.camel@perches.com> (raw)
In-Reply-To: <20200323024109.60967-1-yuchao0@huawei.com>
On Mon, 2020-03-23 at 10:41 +0800, Chao Yu wrote:
> f2fs_inode_info.flags is unsigned long variable, it has 32 bits
> in 32bit architecture, since we introduced FI_MMAP_FILE flag
> when we support data compression, we may access memory cross
> the border of .flags field, corrupting .i_sem field, result in
> below deadlock.
[]
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
[]
> @@ -682,6 +682,47 @@ enum {
[]
> +/* used for f2fs_inode_info->flags */
> +enum {
[]
> + FI_MAX, /* max flag, never be used */
> +};
> +
> +/* f2fs_inode_info.flags array size */
> +#define FI_ARRAY_SIZE (BITS_TO_LONGS(FI_MAX))
Perhaps FI_ARRAY_SIZE isn't necessary.
> +
> struct f2fs_inode_info {
> struct inode vfs_inode; /* serve a vfs inode */
> unsigned long i_flags; /* keep an inode flags for ioctl */
> @@ -694,7 +735,7 @@ struct f2fs_inode_info {
> umode_t i_acl_mode; /* keep file acl mode temporarily */
>
> /* Use below internally in f2fs*/
> - unsigned long flags; /* use to pass per-file flags */
> + unsigned long flags[FI_ARRAY_SIZE]; /* use to pass per-file flags */
and BITS_TO_LONGS should be used here.
> diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
[]
> @@ -362,7 +363,8 @@ static int do_read_inode(struct inode *inode)
> fi->i_flags = le32_to_cpu(ri->i_flags);
> if (S_ISREG(inode->i_mode))
> fi->i_flags &= ~F2FS_PROJINHERIT_FL;
> - fi->flags = 0;
> + for (i = 0; i < FI_ARRAY_SIZE; i++)
> + fi->flags[i] = 0;
And this could become
bitmap_zero(fi->flags, BITS_TO_LONG(FI_MAX));
Is FI_ARRAY_SIZE used anywhere else?
next prev parent reply other threads:[~2020-03-23 2:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-23 2:41 [PATCH v4] f2fs: fix potential .flags overflow on 32bit architecture Chao Yu
2020-03-23 2:57 ` Joe Perches [this message]
2020-03-23 3:22 ` Chao Yu
2020-03-23 3:05 ` Ondřej Jirman
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=8d435607bd79f518bd9420d68894ddda521bac5a.camel@perches.com \
--to=joe@perches.com \
--cc=chao@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=yuchao0@huawei.com \
/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).