From nobody Thu Feb 12 09:01:49 2026 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 EEC671D3631; Tue, 8 Oct 2024 11:05:17 +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=1728385519; cv=none; b=Sg3EMdHjCOa4EOZHx4wKaoo1Res5TqVJwHe4jMvQKg1oHSUh27mKgGhkyfT1HzlCA7r5r1BhgXQJZmfxIN+E6eYb6fYtE665fnhzPXmPuHaH8FEK4lR0uupvs4llNkvaZwXJEmolVJy/mvNMeg7plpSXtW9X12kZ6Zjnp1jtaTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728385519; c=relaxed/simple; bh=4x5D9E3micXOrZJr+A60Gt3XIvpKEUqfXqExAEdTShQ=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=SGK9nNnmFyrbtVXwvYlJ6rlqGPzBMNwGjioMhEv1ccdwk3T0Uoa8r/WC05WK0swoucfxLoqfCiih1yMUVE4b0og0qcLeEqYhCC4gZussHhhV72aJjSPcil4a5iSzN2lj+v5wxPB2B/x88b3AIIrttxPRHsMJESaB+Ts68eHGeZs= 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=Ften/Lk5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hhTW0H+B; 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="Ften/Lk5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hhTW0H+B" Date: Tue, 08 Oct 2024 11:05:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1728385516; 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=cherZcoR+rme32+x63HrLvfBnpzGjjZogGDCCx7c2hk=; b=Ften/Lk5W2CX321yiCfj00taESe9dQTGn6mEzPF62L2EKdTZkxrgKB/569YLqVv+4JGOgq MAHCeyl9KY2DygciMRlu0XVNPyPtNwpc1o0AoYXnRyujjvA5rip7bPxctZkPH5fmcSLykp Z+6OgmowDzW6u2IZoT7byjh3QSLq17vl5XGv7zCXvtMjFOMTyYB4ID6D2sOsIAwyfDmB9I ZmJLP8VwRMzeTOS6L7ZUqL+ItuxvgooqPAhca5eAWIbIa2vZz96FoK+PonLDWA1lhcn+Kc m9RQd342rxR84ZxSCyhHWQcNLp3NEc/HixSeW8sfMKH24EOj4VFb/t4bYx9IEA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1728385516; 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=cherZcoR+rme32+x63HrLvfBnpzGjjZogGDCCx7c2hk=; b=hhTW0H+B3mIqDIWnAaJ+vYhnxSeIXcMWE0mx96crJwkru2V6jYWP9/jIugEWOZwe1DlnbG 0oGJQIs2pnhn/VCA== From: "tip-bot2 for Oleg Nesterov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] uprobes: sanitiize xol_free_insn_slot() Cc: Oleg Nesterov , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240929144235.GA9471@redhat.com> References: <20240929144235.GA9471@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <172838551507.1442.6275116358937013583.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 perf/core branch of tip: Commit-ID: c7b4133c48445dde789ed30b19ccb0448c7593f7 Gitweb: https://git.kernel.org/tip/c7b4133c48445dde789ed30b19ccb0448= c7593f7 Author: Oleg Nesterov AuthorDate: Sun, 29 Sep 2024 16:42:35 +02:00 Committer: Peter Zijlstra CommitterDate: Mon, 07 Oct 2024 09:28:44 +02:00 uprobes: sanitiize xol_free_insn_slot() 1. Clear utask->xol_vaddr unconditionally, even if this addr is not valid, xol_free_insn_slot() should never return with utask->xol_vaddr !=3D NULL. 2. Add a comment to explain why do we need to validate slot_addr. 3. Simplify the validation above. We can simply check offset < PAGE_SIZE, unsigned underflows are fine, it should work if slot_addr < area->vaddr. 4. Kill the unnecessary "slot_nr >=3D UINSNS_PER_PAGE" check, slot_nr must be valid if offset < PAGE_SIZE. The next patches will cleanup this function even more. Signed-off-by: Oleg Nesterov Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20240929144235.GA9471@redhat.com --- kernel/events/uprobes.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 15e91a3..3f38be1 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -1680,8 +1680,8 @@ static unsigned long xol_get_insn_slot(struct uprobe = *uprobe) static void xol_free_insn_slot(struct task_struct *tsk) { struct xol_area *area; - unsigned long vma_end; unsigned long slot_addr; + unsigned long offset; =20 if (!tsk->mm || !tsk->mm->uprobes_state.xol_area || !tsk->utask) return; @@ -1690,24 +1690,21 @@ static void xol_free_insn_slot(struct task_struct *= tsk) if (unlikely(!slot_addr)) return; =20 + tsk->utask->xol_vaddr =3D 0; area =3D tsk->mm->uprobes_state.xol_area; - vma_end =3D area->vaddr + PAGE_SIZE; - if (area->vaddr <=3D slot_addr && slot_addr < vma_end) { - unsigned long offset; - int slot_nr; - - offset =3D slot_addr - area->vaddr; - slot_nr =3D offset / UPROBE_XOL_SLOT_BYTES; - if (slot_nr >=3D UINSNS_PER_PAGE) - return; + offset =3D slot_addr - area->vaddr; + /* + * slot_addr must fit into [area->vaddr, area->vaddr + PAGE_SIZE). + * This check can only fail if the "[uprobes]" vma was mremap'ed. + */ + if (offset < PAGE_SIZE) { + int slot_nr =3D offset / UPROBE_XOL_SLOT_BYTES; =20 clear_bit(slot_nr, area->bitmap); atomic_dec(&area->slot_count); smp_mb__after_atomic(); /* pairs with prepare_to_wait() */ if (waitqueue_active(&area->wq)) wake_up(&area->wq); - - tsk->utask->xol_vaddr =3D 0; } }