lkml.org 
[lkml]   [2020]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH v2] f2fs: fix potential .flags overflow on 32bit architecture
From
Date
On 2020/3/22 22:56, Joe Perches wrote:
> On Sun, 2020-03-22 at 21:56 +0800, Chao Yu wrote:
>> From: Chao Yu <yuchao0@huawei.com>
>>
>> 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.
>>
>> To fix this issue, let's expand .flags as an array to grab enough
>> space to store new flags.
> []
>> +static inline void __set_inode_flag(struct inode *inode, int flag)
>> +{
>> + if (!test_bit(flag % BITS_PER_LONG,
>> + &F2FS_I(inode)->flags[BIT_WORD(flag)]))
>> + set_bit(flag % BITS_PER_LONG,
>> + &F2FS_I(inode)->flags[BIT_WORD(flag)]);
>> +}
>
> I believe you don't need to do anything like this
> but just let test_bit and set_bit do the indexing.
>
> if (!test_bit(flg, F2FS_I(inode->flags)))
> set_bit(flag, F2FS_I(inode->flags));
>
> And there already is a function called test_and_set_bit()

Yup, I've cleaned up with test_and_{set,clear}_bit(), thanks for your
reminder.

Thanks,

>
>
> .
>

\
 
 \ /
  Last update: 2020-03-23 02:08    [W:0.050 / U:5.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site