[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 11 Nov 2019 15:51:03 -0800
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Eric Dumazet <edumazet@...gle.com>,
Al Viro <viro@...iv.linux.org.uk>,
Kirill Smelkov <kirr@...edi.com>
Cc: Alan Stern <stern@...land.harvard.edu>,
Marco Elver <elver@...gle.com>,
Eric Dumazet <eric.dumazet@...il.com>,
syzbot <syzbot+3ef049d50587836c0606@...kaller.appspotmail.com>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
syzkaller-bugs <syzkaller-bugs@...glegroups.com>,
Andrea Parri <parri.andrea@...il.com>,
"Paul E. McKenney" <paulmck@...nel.org>,
LKMM Maintainers -- Akira Yokosawa <akiyks@...il.com>
Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file
On Mon, Nov 11, 2019 at 11:00 AM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> > if (ppos) {
> > pos = *ppos; // data-race
>
> That code uses "fdget_pos().
>
> Which does mutual exclusion _if_ the file is something we care about
> pos for, and if it has more than one process using it.
That said, the more I look at that code, the less I like it.
I have this feeling we really should get rid of FMODE_ATOMIC_POS
entirely, now that we have the much nicer FMODE_STREAM to indicate
that 'pos' really doesn't matter.
Also, the test for "file_count(file) > 1" really is wrong, in that it
means that we protect against other processes, but not other threads.
So maybe we really should do the attached thing. Adding Al and Kirill
to the cc for comments. Kirill did some fairly in-depth review of the
whole locking on f_pos, it might be good to get his comments.
Al? Note the change from
- if (file_count(file) > 1) {
+ if ((v & FDPUT_FPUT) || file_count(file) > 1) {
in __fdget_pos(). It basically says that the threaded case also does
the pos locking.
NOTE! This is entirely untested. It might be totally broken. It passes
my "LooksSuperficiallyFine(tm)" test, but that's all I'm going to say
about the patch.
Linus
View attachment "patch.diff" of type "text/x-patch" (1928 bytes)
Powered by blists - more mailing lists