The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Jann Horn <jannh@google.com>, Rik van Riel <riel@surriel.com>,
	syzbot <syzbot+084b6e5bc1016723a9c4@syzkaller.appspotmail.com>,
	bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com,
	linux-kernel@vger.kernel.org, luto@kernel.org, mingo@redhat.com,
	neeraj.upadhyay@kernel.org, paulmck@kernel.org,
	peterz@infradead.org, syzkaller-bugs@googlegroups.com,
	x86@kernel.org, kernel-team <kernel-team@meta.com>,
	David Hildenbrand <david@redhat.com>
Subject: Re: [syzbot] [kernel?] KASAN: slab-use-after-free Write in flush_tlb_func
Date: Wed, 2 Jul 2025 13:44:34 -0400	[thread overview]
Message-ID: <aGVwAtUi8eKNT8Jy@yury> (raw)
In-Reply-To: <874ivuldog.ffs@tglx>

On Wed, Jul 02, 2025 at 07:12:31PM +0200, Thomas Gleixner wrote:
> On Wed, Jul 02 2025 at 19:00, Jann Horn wrote:
> > On Wed, Jul 2, 2025 at 6:53 PM Jann Horn <jannh@google.com> wrote:
> >> TLB flushes via IPIs on x86 are always synchronous, right?
> >> flush_tlb_func is only referenced from native_flush_tlb_multi() in
> >> calls to on_each_cpu_mask() (with wait=true) or
> >> on_each_cpu_cond_mask() (with wait=1).
> >> So I think this is not an issue, unless you're claiming that we call
> >> native_flush_tlb_multi() with an already-freed info->mm?
> >>
> >> And I think the bisected commit really is the buggy one: It looks at
> >> "nr_cpus", which tracks *how many CPUs we have to IPI*, but assumes
> >> that "nr_cpus" tracks *how many CPUs we posted work to*. Those numbers
> >> are not the same: If we post work to a CPU that already had IPI work
> >> pending, we just add a list entry without sending another IPI.
> >
> > Or in other words: After that blamed commit, if CPU 1 posts a TLB
> > flush to CPU 3, and then CPU 2 also quickly posts a TLB flush to CPU
> > 3, then CPU 2 will erroneously not wait for the TLB flush to complete
> > before reporting flush completion, which AFAICS means we can get both
> > stale TLB entries and (less often) UAF.
> 
> Right you are. Well analyzed and I missed it when taking the lot.
> 
> > I think the correct version of that commit would be to revert that
> > commit and instead just move the "run_remote = true;" line down, below
> > the cond_func() check.
> 
> I remove it from the relevant tip branch

Thank you guys for explaining that and sorry for the buggy patch.
I was actually under impression that run_remote duplicates nr_cpus !=0,
and even have a patch that removes run_remote.

Maybe worth to add a comment on what run_remote and nr_cpus track?

Thanks,
Yury

  reply	other threads:[~2025-07-02 17:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-02 13:50 [syzbot] [kernel?] KASAN: slab-use-after-free Write in flush_tlb_func syzbot
2025-07-02 15:20 ` Rik van Riel
2025-07-02 16:53   ` Jann Horn
2025-07-02 17:00     ` Jann Horn
2025-07-02 17:12       ` Thomas Gleixner
2025-07-02 17:44         ` Yury Norov [this message]
2025-07-02 17:59           ` [PATCH] smp: Wait for enqueued work regardless of IPI sent Rik van Riel
2025-07-03 13:52             ` Yury Norov
2025-07-03 16:56             ` Thomas Gleixner
2025-07-04  0:30               ` [PATCH v2] " Rik van Riel
2025-07-06 10:01                 ` [tip: smp/core] smp: Wait only if work was enqueued tip-bot2 for Rik van Riel
2025-07-02 17:09     ` [syzbot] [kernel?] KASAN: slab-use-after-free Write in flush_tlb_func Rik van Riel
2025-07-02 17:23       ` Jann Horn

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=aGVwAtUi8eKNT8Jy@yury \
    --to=yury.norov@gmail.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jannh@google.com \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=neeraj.upadhyay@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=riel@surriel.com \
    --cc=syzbot+084b6e5bc1016723a9c4@syzkaller.appspotmail.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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