From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 828864499B4 for ; Thu, 9 Jul 2026 20:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783628198; cv=none; b=Fk5FhawPDJQTEce5rqTZlnoTN9ZO2lEkcVoPeY/yX74Ckmz/PVLPCf+tHfnIm0RX3EPM4KM6YwhJ9d1ozaWEyD8mDXHxL6Rq0XvCH/PXXS18ze5Bb7G7/E6bId+zhe6pt9ucayMffOff+S2+xuenL7GkXmJmoJbNPf6eoqtcXQI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783628198; c=relaxed/simple; bh=sCIzHr6LIKs/1PVbD9pk77j9HIdph/3wuYTdeeKTPZI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=P151JW9zQEvKF9bh0194Ox2cMs8+vuD6lWrqkft+vU7IR+nvEN3Rjyo2wZfe8hQrdtHoA5/lTR8bGHS25GdqvR02Y9MajQ3MwhByh6S5TV5U1mHMHQ/Fdq+HAplKVim66tQplINZoGZQxAVQs7XYHJ1SlxkZi69KIVOZ1KlU87Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Xv8fN8OV; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Xv8fN8OV" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2cabc0a1ab6so2354315ad.0 for ; Thu, 09 Jul 2026 13:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783628197; x=1784232997; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=5lqgggpghOuMWXpzCLQ94POSykk42wtAfFSu9QYNYOQ=; b=Xv8fN8OVcr/eq9upfP6q/kHBx/eNyqd9PgmZ2UxQwwed7lJKpc3xnzqEkyRSa2xT3K iRK9YxMnVB+eztpJt7EbsmBvG18kqnVnsd1jxCg3KwCpcjNE3K7F1bRj5iPgLaKlumNN v3PzFzy4J9x5xJstZAb2ObA0Tr5M78TyR/535A+Scf4RqJSu6jkEUNBBiS0eJbPHfNeq eYGvBtQ6HLtY8r2lcHZrOLHB8q5QUz2av5PAhODgJq7NSOGM0HMGTYFgdPHULPfW14fB fFXuOq4R35mcU3QV0E4TMC2u9H7+7P6IKqumqsxffP48GRjjeNxbdEiBCQqBnIgbbvpG MNeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783628197; x=1784232997; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5lqgggpghOuMWXpzCLQ94POSykk42wtAfFSu9QYNYOQ=; b=DCbFmml5u9kvmhWTa6xqzkgYdHtyzpnItLTVSTiTBxH3Ujv/ENIGTBfZ6tKapcJ5nJ nZPtYIcIjkxiWQaRw6sNWpr8MCVWXuLiFW6FR6gaRiCunctQPtlf5nQC9QwHWsnsZ8bW yaBCTgVdLPPU5xAB90ksX4JA8CKTJBKpsvXkWdrg935gLq86+4x5rwm7UNhI02vgIToA TYyBZ9GWZQsHSqlljM9OK0TofC4CoQuMKgsyVmyhux1mX8pgQ/0UNQoB995g3XQ1lk+r jNU/VC9s4nf5Zengu6quUretBx7vz+SmNMoR4FMMSm0d75E4QInk1PFCNU/YJjOyqp7N ptVw== X-Gm-Message-State: AOJu0Yz2x6iCi1C4S2NJJWKq/HbR/qs1hgRhatDNeZLWNRpc/fZ9Rbw2 gz5esGQPuHKYqy49iJ834yt1Kghxk3lK5DsLd/g8IuEbLu4rrz0KN5KJ X-Gm-Gg: AfdE7clFK9DpWH2MimJ4KuOFHP9oXNBBUArl7+K+/8NwN6HToXsm3EsSu1gIQBSj1g6 ILIKYR12ciFtbr6fiKGRMevjDZAV/7PAzvYDL7m81WuBY9aNGvKFwnmby7nNitZ7LIrntdij+pu LSLQ//k3OFpEnH7rownvwvAsdddKZLqPcP4sBPHzCSlXiwGt3pGDYN4z4ZsqPhpDuebA1e45uXm a3zfyjEEfUoOVs218GeSWFRvjOzowSsTWSpXNJiUrsx2j9hiHYpAsvLa0TsFDDdXEEWYTdAvkPJ gmOp9OvUEydsTGG8xHsv/zD0pTs41vGFxQrin3/L5xxeJGVq7ubpSTJh0d8ibqwDyYfmoMu5r/a VgxY4E7CoKDd29EX/KfOwlXaNa4JLUkX7My1LDrUcPLXDtwUfArwrpqvBCGdCdFXRKV6skjE4l8 rrnnV+SlOCk/vz1KLCiH3mDdojwa8oOBrIMdD+7Jn5fUoPNUghxTezYGREDLg2 X-Received: by 2002:a05:6a20:12d0:b0:3b1:882a:607b with SMTP id adf61e73a8af0-3c0bc95630amr10563387637.22.1783628195005; Thu, 09 Jul 2026 13:16:35 -0700 (PDT) Received: from li-1a3e774c-28e4-11b2-a85c-acc9f2883e29.ibm.com ([106.51.160.236]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31174a583bcsm38446663eec.19.2026.07.09.13.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2026 13:16:34 -0700 (PDT) Date: Fri, 10 Jul 2026 01:46:15 +0530 From: Mukesh Kumar Chaurasiya To: Thomas Gleixner Cc: LKML , Peter Zijlstra , Michael Ellerman , Shrikanth Hegde , linuxppc-dev@lists.ozlabs.org, Kees Cook , Huacai Chen , loongarch@lists.linux.dev, Paul Walmsley , Palmer Dabbelt , linux-riscv@lists.infradead.org, Sven Schnelle , linux-s390@vger.kernel.org, x86@kernel.org, Mark Rutland , Jinjie Ruan , Andy Lutomirski , Oleg Nesterov , Richard Henderson , Russell King , Catalin Marinas , Guo Ren , Geert Uytterhoeven , Thomas Bogendoerfer , Helge Deller , Yoshinori Sato , Richard Weinberger , Chris Zankel , linux-arm-kernel@lists.infradead.org, linux-alpha@vger.kernel.org, linux-csky@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-um@lists.infradead.org, Arnd Bergmann , Vineet Gupta , Will Deacon , Brian Cain , Michal Simek , Dinh Nguyen , "David S. Miller" , Andreas Larsson , linux-snps-arc@lists.infradead.org, linux-hexagon@vger.kernel.org, linux-openrisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, Michal =?utf-8?B?U3VjaMOhbmVr?= , Jonathan Corbet , linux-doc@vger.kernel.org Subject: Re: [patch 03/18] entry: Provide [syscall_]enter_from_user_mode_randomize_stack() Message-ID: References: <20260707181957.433213175@kernel.org> <20260707190253.816918647@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260707190253.816918647@kernel.org> On Tue, Jul 07, 2026 at 09:06:07PM +0200, Thomas Gleixner wrote: > Randomizing the syscall stack can only happen after state is established > via enter_from_user_mode() or syscall_enter_from_user_mode(). The earlier > it happens the better. > > Provide two new macros to consolidate that: > > - enter_from_user_mode_randomize_stack() > enter_from_user_mode(); > add_random_kstack_offset_irqsoff(); > > - syscall_enter_from_user_mode_randomize_stack() > enter_from_user_mode_randomize_stack(); > syscall_enter_from_user_mode_work(); > > to reduce boiler plate code. > > Those are macros and not inline functions as the latter would limit the > stack randomization scope to the inline function itself. > > Signed-off-by: Thomas Gleixner > --- > include/linux/entry-common.h | 56 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 56 insertions(+) > > --- a/include/linux/entry-common.h > +++ b/include/linux/entry-common.h > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -150,6 +151,61 @@ static __always_inline long syscall_ente > } > > /** > + * enter_from_user_mode_randomize_stack - Establish state and add stack randomization > + * before invoking syscall_enter_from_user_mode_work() > + * @regs: Pointer to currents pt_regs > + * > + * Invoked from architecture specific syscall entry code with interrupts > + * disabled. The calling code has to be non-instrumentable. When the function > + * returns all state is correct, interrupts are still disabled and the > + * subsequent functions can be instrumented. > + * > + * Implemented as a macro so that the stack randomization is effective > + * throughout the function in which it is invoked. An inline would only make it > + * effective in the scope of the inline function. > + */ > +#define enter_from_user_mode_randomize_stack(regs) \ > +do { \ > + enter_from_user_mode(regs); \ > + instrumentation_begin(); \ > + add_random_kstack_offset_irqsoff(); \ > + instrumentation_end(); \ > +} while (0) > + > +/** > + * syscall_enter_from_user_mode_randomize_stack - Establish state and check and handle work > + * before invoking a syscall > + * @regs: Pointer to currents pt_regs > + * @syscall: The syscall number > + * > + * Invoked from architecture specific syscall entry code with interrupts > + * disabled. The calling code has to be non-instrumentable. When the > + * function returns all state is correct, interrupts are enabled and the > + * subsequent functions can be instrumented. > + * > + * This is the combination of enter_from_user_mode_randomize_stack() and > + * syscall_enter_from_user_mode_work() to be used when there is no > + * architecture specific work to be done between the two. > + * > + * Returns: The original or a modified syscall number. See > + * syscall_enter_from_user_mode_work() for further explanation. > + * > + * Implemented as a macro to make stack randomization effective in the calling > + * scope. > + */ > +#define syscall_enter_from_user_mode_randomize_stack(regs, syscall) \ > +({ \ > + enter_from_user_mode_randomize_stack(regs); \ > + \ > + instrumentation_begin(); \ > + local_irq_enable(); \ > + long _ret = syscall_enter_from_user_mode_work(regs, syscall); \ > + instrumentation_end(); \ > + \ > + _ret; \ > +}) > + > +/** > * syscall_enter_from_user_mode - Establish state and check and handle work > * before invoking a syscall > * @regs: Pointer to currents pt_regs > Reviewed-by: Mukesh Kumar Chaurasiya (IBM) > > _______________________________________________ > linux-snps-arc mailing list > linux-snps-arc@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-snps-arc