[PATCH v2] ubifs: make ubifs_[get|set]xattr atomic

Richard Weinberger richard at nod.at
Sat Aug 8 13:34:03 PDT 2015


Am 07.08.2015 um 07:40 schrieb Dongsheng Yang:
> On 08/04/2015 04:27 AM, Richard Weinberger wrote:
>> Am 31.07.2015 um 03:12 schrieb Dongsheng Yang:
>>> This commit make the ubifs_[get|set]xattr protected by ui_mutex.
>>>
>>> Originally, there is a possibility that ubifs_getxattr to get
>>> a wrong value.
>>>
>>>      P1                    P2
>>> ----------            ----------
>>> ubifs_getxattr            ubifs_setxattr
>>>                    - kfree()
>>>     - memcpy()
>>>                    - kmemdup()
>>>
>>> Then ubifs_getxattr() would get a non-sense data. To solve this
>>> problem, this commit make the xattr of ubifs_inode updated in
>>> atomic.
>>
>> so, ui->data needs protection?
>> The comment in fs/ubifs/ubifs.h does not mention ->data.
>> I'm asking because I want to make sure that ui_mutex is the correct lock to take.
> 
> ui->data needs protection for sure, as I show above.
> Without protection, there is a problem to get wrong value.
> 
> And yes, the comment does not mention the ->data. But
> I think ui_mutex is a good choice for it. And not all fields
> which is being protected by ui_mutex are listed in the comment,
> such as xattr_names and xattr_cnt.

Yeah. ;-\
The comment needs an update. In UBI and UBIFS we try hard to document our locking.
Will you do a patch or shall I?

Thanks,
//richard



More information about the linux-mtd mailing list