From nobody Sat Jul 25 23:05:42 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 2266C3B14B2; Sun, 12 Jul 2026 12:44:16 +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=1783860258; cv=none; b=E8CWl+zO69h1if3GIU8uyW8asLGNBFiryz4ORXCVY5A3KewMYHcJzB/Ir+NWCzVKGoJ/bLAlkKAH3J1dsuS61kFaES68hm1HdZp/Pr0skMQgXwfpsvBIh//NAWgycTLASklwaBSTxTVT3+qdOesAbqHKakMNdLMnkXetNklioO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783860258; c=relaxed/simple; bh=HmFZHUbrXk/r9oqBelKv7JLgQZM06k9xFDUAa5iQGCc=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=OSDo+QZtBNx3BkS87Q9ozUxZOVp1i/6zPVtFEep06b20xkOejv1SxlOUjijDxKIB6QKAxROWTo2mfqGhAeaHPrBrkN2ki6WyHJD8HGutJHNZDu6USqHQW8PdXzK5P9u9eBKuJiurx97DwgtYUXPs9K2bZotR+aBrwVA01AykImc= 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=EHfIA7Nq; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=iSQviZhy; 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="EHfIA7Nq"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iSQviZhy" Date: Sun, 12 Jul 2026 12:44:13 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1783860254; 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=3IgpumUkdiSVBmkoTKIZDLJGm98SyCmVFazRxBveWdc=; b=EHfIA7NqLYsfughG+VmkvJ5sCAkmJA5VPzCBJdLuZ+smKf5j9SvZufoMGTeulTOOpFgm5h 5zDKc2LYg6kimKh4vAxCAw3ifPKro449CsWYRyzQnxwcpG1DVo9izWbqfBHgpwIo7zaP/D uxh74XB0wrlqAItyXX1S/ziSfHzYP7URm1OxDdne7Ancf0PM8ZbR7rCKkrAl4bg68yzcV8 TCfflIzM8OSd7jyLRMPeXcwISHF4FGBBihILZPu9+aZBYcZQETagFf7NaezhwnZYlm6OXm +BC+R7bTy9WnqAFRa0TCyH3PsPFuavJsaik1s/B7WsMT04cTsv1v7dzDjOrnJA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1783860254; 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=3IgpumUkdiSVBmkoTKIZDLJGm98SyCmVFazRxBveWdc=; b=iSQviZhyVONlOIuxU5ZYdO/u9Oy7jwBVEya7Z/N+VIiYJOy6IeGbfHMSlOw/Sekj8JSiT2 0joixohQkd46wIBg== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: core/entry] randomize_kstack: Provide add_random_kstack_offset_irqsoff() Cc: Thomas Gleixner , Radu Rendec , Kees Cook , "Mukesh Kumar Chaurasiya (IBM)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260707190253.768842729@kernel.org> References: <20260707190253.768842729@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <178386025333.1844600.69129570837205203.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 core/entry branch of tip: Commit-ID: 0b9a3057530cc1c3f87ce2ab9d1278164e81990f Gitweb: https://git.kernel.org/tip/0b9a3057530cc1c3f87ce2ab9d1278164= e81990f Author: Thomas Gleixner AuthorDate: Tue, 07 Jul 2026 21:06:02 +02:00 Committer: Thomas Gleixner CommitterDate: Sun, 12 Jul 2026 12:38:00 +02:00 randomize_kstack: Provide add_random_kstack_offset_irqsoff() add_random_kstack_offset() uses get/put_cpu_var() which is pointless overhead when it is invoked from low level entry code with interrupts disabled. Provide a irqsoff() variant, which avoids that. Signed-off-by: Thomas Gleixner Reviewed-by: Radu Rendec Reviewed-by: Kees Cook Reviewed-by: Mukesh Kumar Chaurasiya (IBM) Link: https://patch.msgid.link/20260707190253.768842729@kernel.org --- include/linux/randomize_kstack.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/include/linux/randomize_kstack.h b/include/linux/randomize_kst= ack.h index 024fc20..d8b939f 100644 --- a/include/linux/randomize_kstack.h +++ b/include/linux/randomize_kstack.h @@ -77,8 +77,27 @@ static __always_inline u32 get_kstack_offset(void) } \ } while (0) =20 +/** + * add_random_kstack_offset_irqsoff - Increase stack utilization by a rand= om offset. + * + * This should be used in the syscall entry path after user registers have= been + * stored to the stack. Interrupts must be still disabled. + */ +#define add_random_kstack_offset_irqsoff() \ +do { \ + lockdep_assert_irqs_disabled(); \ + if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \ + &randomize_kstack_offset)) { \ + u32 offset =3D prandom_u32_state(raw_cpu_ptr(&kstack_rnd_state)); \ + u8 *ptr =3D __kstack_alloca(KSTACK_OFFSET_MAX(offset)); \ + /* Keep allocation even after "ptr" loses scope. */ \ + asm volatile("" :: "r"(ptr) : "memory"); \ + } \ +} while (0) + #else /* CONFIG_RANDOMIZE_KSTACK_OFFSET */ #define add_random_kstack_offset() do { } while (0) +#define add_random_kstack_offset_irqsoff() do { } while (0) #endif /* CONFIG_RANDOMIZE_KSTACK_OFFSET */ =20 #endif