From: Linus Torvalds <torvalds@linux-foundation.org> To: Hillf Danton <hdanton@sina.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com>, Linux Kernel Mailing List <linux-kernel@vger.kernel.org>, Alexey Gladkov <legion@kernel.org> Subject: Re: [GIT PULL] ucount fix for v5.14-rc Date: Sat, 7 Aug 2021 18:00:23 -0700 [thread overview] Message-ID: <CAHk-=wh=CdjTFEsVb7wr+ZEyNKoM2JBdvdcTGJqW5EeQPqzFdw@mail.gmail.com> (raw) In-Reply-To: <20210808004243.2007-1-hdanton@sina.com> On Sat, Aug 7, 2021 at 5:42 PM Hillf Danton <hdanton@sina.com> wrote: > > Given the syzbot report, I doubt 3 is correct. I doubt your whole scenario. > If 3 is actually correct, however, the fix in this pull request is > incorrect. Why do you not accept the fact that the old code was buggy, and the bug was that the alloc->find didn't increment the count from 0 correctly under the lock? The fact is, the commit in question is ObviouslyCorrect(tm), and I don't understand any of your arguments against it. The old code would look up a uncounts entry, but then drop the lock, before incrementing it. That explains *everything*. It means that you have this basic race: Thread (a) on CPU1: starting out _without_ a reference to the uncounts, look up entry under the lock, but don't increment the count, release lock. Thread (b) on CPU2: have a reference, do a put_ucounts(). Count goes to zero, take the lock, unhash it, free the entry Thread (a) continues, increments the count on a UAF entry, triggers KASAN. Look, the fix in question _fixes_ exactly the above. The KASAN traces clearly show that alloc_ucounts() was involved. Now it does the right thing, and it does the count increment under the lock, and the put_ucounts() thing atomic_dec_and_lock_irqsave(). And this isn't even an interesting case. This was not a subtle bug. The ucounts code had an _obvious_ and unquestionable bug, and handled this wrong. The ucounts refcount code wasn't even doing anything unusual, it was just doing it BADLY and WRONG. This situation is _literally_ why atomic_dec_and_lock exists in the first place. The fact that the ucount code had missed this all was just a sad and pitiful bug, and it was just embarrassing that we hadn't noticed the obvious problem with commit b6c336528926 ("Use atomic_t for ucounts reference counting") earlier. What it is you claim happens that _isn't_ just due to this stupid and trivial bug? Because the scenario you outlined did not make sense, and I've pointed out _why_ it did not. Linus
next prev parent reply other threads:[~2021-08-08 1:01 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-05 17:15 Eric W. Biederman 2021-08-05 19:26 ` pr-tracker-bot [not found] ` <20210806021052.3013-1-hdanton@sina.com> 2021-08-06 3:38 ` Eric W. Biederman [not found] ` <20210806061458.3075-1-hdanton@sina.com> 2021-08-06 17:37 ` Linus Torvalds [not found] ` <20210807050314.1807-1-hdanton@sina.com> 2021-08-07 8:23 ` Linus Torvalds [not found] ` <20210807091128.1862-1-hdanton@sina.com> 2021-08-07 15:10 ` Linus Torvalds [not found] ` <20210808004243.2007-1-hdanton@sina.com> 2021-08-08 1:00 ` Linus Torvalds [this message] [not found] ` <20210808012056.2067-1-hdanton@sina.com> 2021-08-08 1:45 ` Linus Torvalds 2021-08-08 2:05 ` Linus Torvalds
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-=wh=CdjTFEsVb7wr+ZEyNKoM2JBdvdcTGJqW5EeQPqzFdw@mail.gmail.com' \ --to=torvalds@linux-foundation.org \ --cc=ebiederm@xmission.com \ --cc=hdanton@sina.com \ --cc=legion@kernel.org \ --cc=linux-kernel@vger.kernel.org \ --subject='Re: [GIT PULL] ucount fix for v5.14-rc' \ /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
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).