[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8d435607bd79f518bd9420d68894ddda521bac5a.camel@perches.com>
Date: Sun, 22 Mar 2020 19:57:09 -0700
From: Joe Perches <joe@...ches.com>
To: Chao Yu <yuchao0@...wei.com>, jaegeuk@...nel.org
Cc: linux-f2fs-devel@...ts.sourceforge.net,
linux-kernel@...r.kernel.org, chao@...nel.org
Subject: Re: [PATCH v4] f2fs: fix potential .flags overflow on 32bit
architecture
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?
Powered by blists - more mailing lists