From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C7DC2DECBF for ; Tue, 24 Mar 2026 19:25:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774380345; cv=none; b=j8MwbrQ5O9f65QONWM3ZF11mLNdDtQ6BUtcVkoj/+YenKom4Ca0P5htlkZcNvxqXJd+m8NhGAWZS3TvueuQyiMEj+lXfzPezLMYyFE7ZA+oGj3UlQ4ScM+pMelb69SllzjXAteyOGbJJGI7tM4cZ7LJQhg1uN0mYzBRvcpNDJs4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774380345; c=relaxed/simple; bh=i7rPO7vJ0iMIhXdIA5JbBJbypaa0ZTSBnbMplVZXRa4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=uv4vhNAPSUMfa0a1iMd6J4eMgUHBgjuHWp7/rWNIjVu0XNnjfcppqA67AF/wZoEynmyzhMpqp3KtPJTxdFhgDqym8xZNodcOxOLp0Q9yDatBOYKHss0c8kD5YvIFs3tD0b+4wDcLAhw8GToN3i9QwT+Qmm6s/AQiH17EZHWgFUU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NUIN27Zc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NUIN27Zc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D6B9C19424; Tue, 24 Mar 2026 19:25:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774380345; bh=i7rPO7vJ0iMIhXdIA5JbBJbypaa0ZTSBnbMplVZXRa4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=NUIN27ZcKuNYOfYaRtrqCVW5R8ocr6UKZ9Q7eRmeK/Mer+lFKudGrW4Cio+tO31BN B+5h3I7dQNHoR5Lsa1fV7UhcnFuCZjt45pwkq90SB5kSktwjl7t86r5Xr3aZ3oy23F 80LSejXGPp3+C2Cp2DiRRpogfzd6IDAJx6yrovu3e6gO6bbkz5HVUlMG9DI0nP5vCV IxFlmGehCGXSoSOysg69v+zrppfr7GS1PdlOEdDq5KxbWjwoRe5Mm/1C5b599JzK6i 5MB8bd6zoJ6HQmCZJo3xKGsOE5DZxuH4JJaE1N+medG41vM7n/T24jNlphmoz1HZg6 lftUVVUhYvSpg== From: Thomas Gleixner To: Peter Zijlstra Cc: Hao-Yu Yang , mingo@redhat.com, linux-kernel@vger.kernel.org, Andrew Morton , David Hillenbrand , Eric Dumazet , linux-mm@kvack.org Subject: Re: [PATCH v2] futex: Use-after-free between futex_key_to_node_opt and vma_replace_policy In-Reply-To: <20260324174418.GB1850007@noisy.programming.kicks-ass.net> References: <20260313124756.52461-1-naup96721@gmail.com> <87a4vyihlx.ffs@tglx> <20260324140019.GE3738010@noisy.programming.kicks-ass.net> <87fr5pgp5x.ffs@tglx> <20260324174418.GB1850007@noisy.programming.kicks-ass.net> Date: Tue, 24 Mar 2026 20:25:41 +0100 Message-ID: <87a4vxghca.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Tue, Mar 24 2026 at 18:44, Peter Zijlstra wrote: > On Tue, Mar 24, 2026 at 05:36:42PM +0100, Thomas Gleixner wrote: >> On Tue, Mar 24 2026 at 15:00, Peter Zijlstra wrote: >> > On Mon, Mar 23, 2026 at 06:24:42PM +0100, Thomas Gleixner wrote: >> > Not to mention we don't actually need any of that here, because: >> > >> >> Especially the writer side is required so that the proper memory >> >> barriers are inserted for architectures with a weakly ordered memory >> >> model. >> > >> > The vma->vm_policy thing is written under mmap_lock held for writing, >> > and the futex consumer is a speculative read lock. Specifically the >> > ordering is through the associated seqcount. >> >> Duh. Yes. >> >> > All that is really needed is to extend the lifetime of the mpol to the >> > associated RCU period. Which is exactly what this patch does. >> > >> > Want me to go write up a better Changelog? >> >> And a comment in the code explaining the RCU magic perhaps? > > Does this work for you? Perfect > --- > Subject: futex: Fix UaF between futex_key_to_node_opt() and vma_replace_policy() > From: Hao-Yu Yang > Date: Fri, 13 Mar 2026 20:47:56 +0800 > > From: Hao-Yu Yang > > During futex_key_to_node_opt() execution, vma->vm_policy is read under > speculative mmap lock and RCU. Concurrently, mbind() may call > vma_replace_policy() which frees the old mempolicy immediately via > kmem_cache_free(). > > This creates a race where __futex_key_to_node() dereferences a freed > mempolicy pointer, causing a use-after-free read of mpol->mode. > > [ 151.412631] BUG: KASAN: slab-use-after-free in __futex_key_to_node (kernel/futex/core.c:349) > [ 151.414046] Read of size 2 at addr ffff888001c49634 by task e/87 > > [ 151.415969] Call Trace: > > [ 151.416732] __asan_load2 (mm/kasan/generic.c:271) > [ 151.416777] __futex_key_to_node (kernel/futex/core.c:349) > [ 151.416822] get_futex_key (kernel/futex/core.c:374 kernel/futex/core.c:386 kernel/futex/core.c:593) > > Fix by adding rcu to __mpol_put(). > > Fixes: c042c505210d ("futex: Implement FUTEX2_MPOL") > Reported-by: Hao-Yu Yang > Suggested-by: Eric Dumazet > Signed-off-by: Hao-Yu Yang > Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Thomas Gleixner I think there was also a Reviewed-by from Eric in one of the previous threads. Thanks, tglx