From: Linus Torvalds <torvalds@linux-foundation.org>
To: Kirill Smelkov <kirr@nexedi.com>
Cc: Eric Dumazet <edumazet@google.com>,
Al Viro <viro@zeniv.linux.org.uk>,
Alan Stern <stern@rowland.harvard.edu>,
Marco Elver <elver@google.com>,
Eric Dumazet <eric.dumazet@gmail.com>,
syzbot <syzbot+3ef049d50587836c0606@syzkaller.appspotmail.com>,
linux-fsdevel <linux-fsdevel@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
Andrea Parri <parri.andrea@gmail.com>,
"Paul E. McKenney" <paulmck@kernel.org>,
LKMM Maintainers -- Akira Yokosawa <akiyks@gmail.com>
Subject: Re: KCSAN: data-race in __alloc_file / __alloc_file
Date: Tue, 12 Nov 2019 09:23:34 -0800 [thread overview]
Message-ID: <CAHk-=witx+fY-no_UTNhsxXvZnOaFLM80Q8so6Mvm6hUTjZdGg@mail.gmail.com> (raw)
In-Reply-To: <20191112165033.GA7905@deco.navytux.spb.ru>
On Tue, Nov 12, 2019 at 8:50 AM Kirill Smelkov <kirr@nexedi.com> wrote:
>
> The same logic applies if it is not 2 processes, but 2 threads:
> thread T2 adjusts file position racily to thread T1 while T1 is doing
> read syscall with the end result that T1 read could access file range
> that it should not be allowed to access.
Well, I think we actually always copy the file position before we pass
it down. So everybody always _uses_ their own private pointer, and the
race is only in the "read original value" vs "write new value back".
You had a patch that passed the address of file->f_pos down in your
original series iirc, but I NAK'ed that one. Exactly because it made
me nervous.
> By the way on "1" topic I suspect there is a race of how
> `N(file-users) > 1` check is done: file_count(file) is
> atomic_long_read(&file->f_count), but let's think on how that atomic
> read is positioned wrt another process creation: I did not studied in
> detail, so I might be wrong here, but offhand it looks like there is no
> synchronization.
Well, that's one reason to add the test for threads - it also gets rid
of that race. Because without threads, there's nothing else that could
access - or fork - a "N(file-users) == 1" file but us.
> So talking about the kernel I would also review the possibility of
> file_count wrt clone race once again.
See above. That goes away with the test for FDPUT_FPUT.
> About "2": I generally agree with the direction, but I think the kernel
> is not yet ready for this switch. Let me quote myself:
Hmm. I thought we already then applied all the patches that marked
things that didn't use f_pos as FMODE_STREAM. Including pipes and
sockets etc.
But if we didn't - and no, I didn't double-check now either - then
obviously that part of the patch can't be applied now.
Linus
next prev parent reply other threads:[~2019-11-12 17:23 UTC|newest]
Thread overview: 67+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAHk-=wjB61GNmqpX0BLA5tpL4tsjWV7akaTc2Roth7uGgax+mw@mail.gmail.com>
2019-11-10 16:09 ` KCSAN: data-race in __alloc_file / __alloc_file Alan Stern
2019-11-10 19:10 ` Marco Elver
2019-11-11 15:51 ` Alan Stern
2019-11-11 16:51 ` Linus Torvalds
2019-11-11 17:52 ` Eric Dumazet
2019-11-11 18:04 ` Linus Torvalds
2019-11-11 18:31 ` Eric Dumazet
2019-11-11 18:44 ` Eric Dumazet
2019-11-11 19:00 ` Linus Torvalds
2019-11-11 19:13 ` Eric Dumazet
2019-11-11 20:43 ` Linus Torvalds
2019-11-11 20:46 ` Linus Torvalds
2019-11-11 21:53 ` Eric Dumazet
2019-11-11 23:51 ` Linus Torvalds
2019-11-12 16:50 ` Kirill Smelkov
2019-11-12 17:23 ` Linus Torvalds [this message]
2019-11-12 17:36 ` Linus Torvalds
2019-11-17 18:56 ` Kirill Smelkov
2019-11-17 19:20 ` Linus Torvalds
2019-11-11 18:50 ` Linus Torvalds
2019-11-11 18:59 ` Marco Elver
2019-11-11 18:59 ` Eric Dumazet
2019-11-10 19:12 ` Linus Torvalds
2019-11-10 19:20 ` Linus Torvalds
2019-11-10 20:44 ` Paul E. McKenney
2019-11-10 21:10 ` Linus Torvalds
2019-11-10 21:31 ` Paul E. McKenney
2019-11-11 14:17 ` Marco Elver
2019-11-11 14:31 ` Paul E. McKenney
2019-11-11 15:10 ` Marco Elver
2019-11-13 0:25 ` Paul E. McKenney
2019-11-12 19:14 ` Alan Stern
2019-11-12 19:47 ` Linus Torvalds
2019-11-12 20:29 ` Alan Stern
2019-11-12 20:58 ` Linus Torvalds
2019-11-12 21:13 ` Linus Torvalds
2019-11-12 22:05 ` Marco Elver
2019-11-12 21:48 ` Alan Stern
2019-11-12 22:07 ` Eric Dumazet
2019-11-12 22:44 ` Alexei Starovoitov
2019-11-12 23:17 ` Eric Dumazet
2019-11-12 23:40 ` Linus Torvalds
2019-11-13 15:00 ` Marco Elver
2019-11-13 16:57 ` Linus Torvalds
2019-11-13 21:33 ` Marco Elver
2019-11-13 21:50 ` Alan Stern
2019-11-13 22:48 ` Marco Elver
2019-11-08 13:16 syzbot
2019-11-08 13:28 ` Eric Dumazet
2019-11-08 17:01 ` Linus Torvalds
2019-11-08 17:22 ` Eric Dumazet
2019-11-08 17:38 ` Linus Torvalds
2019-11-08 17:53 ` Eric Dumazet
2019-11-08 17:55 ` Eric Dumazet
2019-11-08 18:02 ` Eric Dumazet
2019-11-08 18:12 ` Linus Torvalds
2019-11-08 20:30 ` Linus Torvalds
2019-11-08 20:53 ` Eric Dumazet
2019-11-08 21:36 ` Linus Torvalds
2019-11-08 18:05 ` Linus Torvalds
2019-11-08 18:15 ` Marco Elver
2019-11-08 18:40 ` Linus Torvalds
2019-11-08 19:48 ` Marco Elver
2019-11-08 20:26 ` Linus Torvalds
2019-11-08 21:57 ` Alan Stern
2019-11-08 22:06 ` Linus Torvalds
2019-11-09 23:08 ` Alan Stern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHk-=witx+fY-no_UTNhsxXvZnOaFLM80Q8so6Mvm6hUTjZdGg@mail.gmail.com' \
--to=torvalds@linux-foundation.org \
--cc=akiyks@gmail.com \
--cc=edumazet@google.com \
--cc=elver@google.com \
--cc=eric.dumazet@gmail.com \
--cc=kirr@nexedi.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=parri.andrea@gmail.com \
--cc=paulmck@kernel.org \
--cc=stern@rowland.harvard.edu \
--cc=syzbot+3ef049d50587836c0606@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).