lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <13414d6a-9e72-fb6c-f0a8-8b83ba0455de@huawei.com>
Date:   Mon, 20 Jun 2022 17:04:50 +0800
From:   Miaohe Lin <linmiaohe@...wei.com>
To:     "Huang, Ying" <ying.huang@...el.com>
CC:     <akpm@...ux-foundation.org>, <david@...hat.com>,
        <linux-mm@...ck.org>, <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v2 2/3] mm/swapfile: fix possible data races of
 inuse_pages

On 2022/6/20 15:54, Huang, Ying wrote:
> Miaohe Lin <linmiaohe@...wei.com> writes:
> 
>> si->inuse_pages could still be accessed concurrently now. The plain reads
>> outside si->lock critical section, i.e. swap_show and si_swapinfo, which
>> results in data races. But these should be ok because they're just used
>> for showing swap info.
>>
>> Signed-off-by: Miaohe Lin <linmiaohe@...wei.com>
>> Reviewed-by: David Hildenbrand <david@...hat.com>
>> ---
>>  mm/swapfile.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index d2bead7b8b70..3fa26f6971e9 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -2646,7 +2646,7 @@ static int swap_show(struct seq_file *swap, void *v)
>>  	}
>>  
>>  	bytes = si->pages << (PAGE_SHIFT - 10);
>> -	inuse = si->inuse_pages << (PAGE_SHIFT - 10);
>> +	inuse = READ_ONCE(si->inuse_pages) << (PAGE_SHIFT - 10);
>>  
>>  	file = si->swap_file;
>>  	len = seq_file_path(swap, file, " \t\n\\");
>> @@ -3265,7 +3265,7 @@ void si_swapinfo(struct sysinfo *val)
>>  		struct swap_info_struct *si = swap_info[type];
>>  
>>  		if ((si->flags & SWP_USED) && !(si->flags & SWP_WRITEOK))
>> -			nr_to_be_unused += si->inuse_pages;
>> +			nr_to_be_unused += READ_ONCE(si->inuse_pages);
>>  	}
>>  	val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
>>  	val->totalswap = total_swap_pages + nr_to_be_unused;
> 
> READ_ONCE() should be paired with WRITE_ONCE().  So, change the writer
> side too?

READ_ONCE() is used to fix the complaint of concurrent accessing to si->inuse_pages from KCSAN here.
The similar commit is 218209487c3d ("mm/swapfile: fix data races in try_to_unuse()"). IMHO, it's fine
to see a not-uptodate value of si->inuse_pages because it's just used for showing swap info. So
WRITE_ONCE() is not obligatory. Or am I miss something?

> 
> Best Regards,
> Huang, Ying

Thanks!

> .
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ