From nobody Fri Dec 19 11:16:01 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 3B67014AD20; Sat, 12 Apr 2025 18:46:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744483621; cv=none; b=YWZK145sgbNvOHvwJDbsdtfSF9dzEM92WG6j+6H5CbVGi0wpL4UfHIEcy2+/O1wcO0FRTbxrdoLIbrguSooiHFnwqpdJxzI2H4fxal+hx2vXW0FGHBe2U7gAHWsl2CCdLKHRqTqjjXHaiA/IPoHR4Qqk96ObsMNqvU3Yodr6Xo0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744483621; c=relaxed/simple; bh=j46hwc/Vjomt/pqHJ6Fr1IMoW9Ufx5YOej65KLQ5tpY=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=fHfA11X8SRPlwk/0YtjQ230iCnKQxxHJXO46qoAYnLYVDp2uBn874VpnQb8c97FP7aGMljFIdKMpu5Kd7pahVRGcLRFguj131HUO2tUPUmd6wIdEO2YVEE6i1YGZiEEjaKYFEzboQ9Tr/wBxlRaUJYyRxgRBaPtPUaMBECyxzN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=2rYdaY5+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3MibZVl6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="2rYdaY5+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3MibZVl6" Date: Sat, 12 Apr 2025 18:46:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744483618; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UuYiJ7p7letDCh7223xHHWSfo+zFdmWmcwBhRUywMFQ=; b=2rYdaY5+f547/iCq2i6VKRv/AmhTPD49FnxZsQlhfbhc3SxtZMQ8hSC+5Ju/DtNKhTOnSp 0XgZ7DoYWBjYjnJr0q6Ds6dx/gClqYj/JvId6p7PMhzURcrLnvldYBmwisMn/8y8NgN/tR DLNK/kheeDsbLXS80KrpT/YU0dZrH2foY1LjFezvABmcqNVDAPrBx1UkzRHR30/WGsfGbA yX7/Sfm2MkoKjGQAoO3+Y/Y7Q9Ti0mziHWs5+3o6JpZQ9y8PBKUuVN1EyF2w4NX37Q+IXo pJuR5LXR3cyDWmd/xpnd1PNVbAOe+P0WfKmNljq/4L5+sjMyu4nBTlvIoElVKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744483618; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UuYiJ7p7letDCh7223xHHWSfo+zFdmWmcwBhRUywMFQ=; b=3MibZVl6W533egfVdErdYHFpfD8ifzexVLS4O+lsfIyR5t1AL5Afro/Sib8WtKAYQdAztP Hsse732Enny2xODQ== From: "tip-bot2 for Andy Lutomirski" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/alternatives] x86/events, x86/insn-eval: Remove incorrect current->active_mm references Cc: Andy Lutomirski , "Peter Zijlstra (Intel)" , Ingo Molnar , Rik van Riel , "H. Peter Anvin" , Linus Torvalds , Andrew Morton , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20250402094540.3586683-3-mingo@kernel.org> References: <20250402094540.3586683-3-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <174448361789.31282.10406016673269368609.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the x86/alternatives branch of ti= p: Commit-ID: 81e3cbdef230fd9adfa8569044b07290afd66708 Gitweb: https://git.kernel.org/tip/81e3cbdef230fd9adfa8569044b07290a= fd66708 Author: Andy Lutomirski AuthorDate: Wed, 02 Apr 2025 11:45:35 +02:00 Committer: Ingo Molnar CommitterDate: Sat, 12 Apr 2025 10:05:46 +02:00 x86/events, x86/insn-eval: Remove incorrect current->active_mm references When decoding an instruction or handling a perf event that references an LDT segment, if we don't have a valid user context, trying to access the LDT by any means other than SLDT is racy. Certainly, using current->active_mm is wrong, as active_mm can point to a real user mm when CR3 and LDTR no longer reference that mm. Clean up the code. If nmi_uaccess_okay() says we don't have a valid context, just fail. Otherwise use current->mm. Signed-off-by: Andy Lutomirski Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Cc: Rik van Riel Cc: "H. Peter Anvin" Cc: Linus Torvalds Cc: Andrew Morton Link: https://lore.kernel.org/r/20250402094540.3586683-3-mingo@kernel.org --- arch/x86/events/core.c | 9 ++++++++- arch/x86/lib/insn-eval.c | 13 ++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 6866cc5..95118b5 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2803,8 +2803,15 @@ static unsigned long get_segment_base(unsigned int s= egment) #ifdef CONFIG_MODIFY_LDT_SYSCALL struct ldt_struct *ldt; =20 + /* + * If we're not in a valid context with a real (not just lazy) + * user mm, then don't even try. + */ + if (!nmi_uaccess_okay()) + return 0; + /* IRQs are off, so this synchronizes with smp_store_release */ - ldt =3D READ_ONCE(current->active_mm->context.ldt); + ldt =3D smp_load_acquire(¤t->mm->context.ldt); if (!ldt || idx >=3D ldt->nr_entries) return 0; =20 diff --git a/arch/x86/lib/insn-eval.c b/arch/x86/lib/insn-eval.c index 98631c0..f786401 100644 --- a/arch/x86/lib/insn-eval.c +++ b/arch/x86/lib/insn-eval.c @@ -631,14 +631,21 @@ static bool get_desc(struct desc_struct *out, unsigne= d short sel) /* Bits [15:3] contain the index of the desired entry. */ sel >>=3D 3; =20 - mutex_lock(¤t->active_mm->context.lock); - ldt =3D current->active_mm->context.ldt; + /* + * If we're not in a valid context with a real (not just lazy) + * user mm, then don't even try. + */ + if (!nmi_uaccess_okay()) + return false; + + mutex_lock(¤t->mm->context.lock); + ldt =3D current->mm->context.ldt; if (ldt && sel < ldt->nr_entries) { *out =3D ldt->entries[sel]; success =3D true; } =20 - mutex_unlock(¤t->active_mm->context.lock); + mutex_unlock(¤t->mm->context.lock); =20 return success; }