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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YrB6R5uHQaz1adhK@qian>
Date:   Mon, 20 Jun 2022 09:46:47 -0400
From:   Qian Cai <quic_qiancai@...cinc.com>
To:     Miaohe Lin <linmiaohe@...wei.com>
CC:     Muchun Song <songmuchun@...edance.com>,
        "Huang, Ying" <ying.huang@...el.com>, <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 Mon, Jun 20, 2022 at 08:32:27PM +0800, Miaohe Lin wrote:
> >>>>> --- 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
> >>
> >> I think the fix 218209487c3d is incomplete. The write side in swap_range_free() should
> >> also be fixed. Otherwise, IIUC, it cannot stop KCSAN complaining.
> > 
> > I tend to agree with you. READ_ONCE() should be paired with WRITE_ONCE() theoretically. But WRITTE_ONCE()
> > is ignored while the commit is introduced. Add Qian Cai for helping verify it. It's very kind of @Qian Cai
> > if he could tell us whether WRITTE_ONCE() is ignored deliberately.

The write side should be protected by the lock swap_info_struct::lock. Is
that not the case here?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ