From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8F9EC43458 for ; Thu, 9 Jul 2026 02:34:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:CC:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y5gPTQlvZ5+PltKfyd7jsM9jOpB/L3Mods25ly3hUmU=; b=msVHxpbo/u0M8VsuuGTL+2uCEH HvztDrVF70T61LFmAv10uWpQUzsI794vdIW60St4V4Y8hM/auQh44U4/fvp06OutPTjRVuRrURDro l5vjlk92y2aNdV1MSEp7g8yiV1NtSIBHmO7mxv2a7sCNulZE8eRHh1bl7e2NtesHdjWoZ6zABY2Hp zJp7n9zkQhgpsNV7nAaf/VYajMFl8Z8cfJV3n+IVzaStiKcA4KAixfSf2VEznaaPDwXVOI6u/LS+S JAxAobcgo3qR448vYVBeK+++sG60l2eXv9GDk5V+66pL4VzAAezBOGyd3b3Wl0KeiarED0ngMY1qz Ftxl5MAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1whebC-00000000q8w-2hAf; Thu, 09 Jul 2026 02:34:50 +0000 Received: from [113.46.200.225] (helo=canpmsgout10.his.huawei.com) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wheb8-00000000q5e-0Svx; Thu, 09 Jul 2026 02:34:49 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=Y5gPTQlvZ5+PltKfyd7jsM9jOpB/L3Mods25ly3hUmU=; b=wLN4PuTDh2Bs3oUFfNRxSZSE7gCwmqjYG039d/qXSq1UpIOaCLhb2iezcdm336V58TY0kTXy4 szfWi9o5up7AY22Girs57z0q9Oi7TCvcfhRpAuei9Dgq6Q3rv8QoRLbJRWC1d+UazJf8zIhojgL pcWHZ91jG23KLVROOKeLeOw= Received: from mail.maildlp.com (unknown [172.19.163.15]) by canpmsgout10.his.huawei.com (SkyGuard) with ESMTPS id 4gwf2174NCz1K96m; Thu, 9 Jul 2026 10:25:13 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 387FB40586; Thu, 9 Jul 2026 10:34:27 +0800 (CST) Received: from [10.67.109.254] (10.67.109.254) by dggpemf500011.china.huawei.com (7.185.36.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 9 Jul 2026 10:34:24 +0800 Message-ID: <3fdebd1c-f7ea-4b49-808d-8dec99e68623@huawei.com> Date: Thu, 9 Jul 2026 10:34:22 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [patch 03/18] entry: Provide [syscall_]enter_from_user_mode_randomize_stack() To: Thomas Gleixner , LKML CC: Peter Zijlstra , Michael Ellerman , Shrikanth Hegde , , Kees Cook , Huacai Chen , , Paul Walmsley , Palmer Dabbelt , , Sven Schnelle , , , Mark Rutland , Andy Lutomirski , Oleg Nesterov , Richard Henderson , Russell King , Catalin Marinas , Guo Ren , Geert Uytterhoeven , Thomas Bogendoerfer , Helge Deller , Yoshinori Sato , Richard Weinberger , Chris Zankel , , , , , , , , , Arnd Bergmann , Vineet Gupta , Will Deacon , Brian Cain , Michal Simek , Dinh Nguyen , "David S. Miller" , Andreas Larsson , , , , , , =?UTF-8?Q?Michal_Such=C3=A1nek?= , Jonathan Corbet , References: <20260707181957.433213175@kernel.org> <20260707190253.816918647@kernel.org> From: Jinjie Ruan In-Reply-To: <20260707190253.816918647@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.109.254] X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To dggpemf500011.china.huawei.com (7.185.36.131) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260708_193446_770683_CFCE2942 X-CRM114-Status: GOOD ( 22.12 ) X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org On 7/8/2026 3:06 AM, 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; \ > +}) Reviewed-by: Jinjie Ruan > + > +/** > * syscall_enter_from_user_mode - Establish state and check and handle work > * before invoking a syscall > * @regs: Pointer to currents pt_regs >