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 303C6C44506 for ; Thu, 9 Jul 2026 02:45:13 +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=dcBLjAZIuOcKQn3MTY+bY4X711wnRwuwnS+wCIvAotY=; b=JKcXuK6IN58AusJpux95bYIHGj OTFCyKkDlyDIvaQNkA8vJ9ZOOthMmWTnPY9g7KSSEznkBClMZwHMEdV7PqNpvtGAJ/OuKYIl1cC8L NyzSk02b7GtKiQo/A2IutYmiFlKxOQI+ji1LKgTkx6wqUS92CXFBMdRg3piivTQtuaKfN4EL3QOsc OFOiUfSVTX7AWes2sa/tkizeR9Suq5+szx+AaBLaJO2LLlmJsGND4RlyEgFgwdGZduTHwMxdYImAp e6jfiW1MLE4zN593UiKvrxCbikPKCT/to5qL32GVe9mnv7yDCK9+FjwCpdzo3hglQ3ujyUl26g/8Q q2IWN8Ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1whelE-00000000rTa-0Agv; Thu, 09 Jul 2026 02:45:12 +0000 Received: from canpmsgout08.his.huawei.com ([113.46.200.223]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1whel9-00000000rSr-07CJ; Thu, 09 Jul 2026 02:45:09 +0000 dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=dcBLjAZIuOcKQn3MTY+bY4X711wnRwuwnS+wCIvAotY=; b=vWAJv97fd4j7v7LNzsA1jn7LpDaj1qwxvv/Lzs0LqF+U5jdju4uyIQO/9pQ/LJxYukNVEgr9E NQoEi0lQj6z3nWKyFlljAYQcLzbsWESODoQ516BnoreEQp50kC1pN6GxxIn6she9WscRAAZsS6n UHY+SgzEAjANoQ5JULImdXU= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4gwfG3311mzmVZr; Thu, 9 Jul 2026 10:35:39 +0800 (CST) Received: from dggpemf500011.china.huawei.com (unknown [7.185.36.131]) by mail.maildlp.com (Postfix) with ESMTPS id 14A5440563; Thu, 9 Jul 2026 10:44:54 +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:44:50 +0800 Message-ID: Date: Thu, 9 Jul 2026 10:44:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [patch 08/18] x86/syscall: Use [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> <20260707190254.079478122@kernel.org> From: Jinjie Ruan In-Reply-To: <20260707190254.079478122@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_194507_691148_86D2EC2C X-CRM114-Status: GOOD ( 20.59 ) 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: > These functions integrate the stack randomization. > > syscall_enter_from_user_mode_randomize_stack() has the advantage that the > randomization happens early right after enter_from_user_mode(). > > In both cases also the overhead of get/put_cpu_var() in > add_random_kstack_offset() is avoided. > > No functional change. > > Signed-off-by: Thomas Gleixner > Cc: x86@kernel.org > --- > arch/x86/entry/syscall_32.c | 19 +++++-------------- > arch/x86/entry/syscall_64.c | 3 +-- > arch/x86/include/asm/entry-common.h | 1 - > 3 files changed, 6 insertions(+), 17 deletions(-) Reviewed-by: Jinjie Ruan > > --- a/arch/x86/entry/syscall_32.c > +++ b/arch/x86/entry/syscall_32.c > @@ -142,10 +142,9 @@ static __always_inline bool int80_is_ext > * int80_is_external() below which calls into the APIC driver. > * Identical for soft and external interrupts. > */ > - enter_from_user_mode(regs); > + enter_from_user_mode_randomize_stack(regs); > > instrumentation_begin(); > - add_random_kstack_offset(); > > /* Validate that this is a soft interrupt to the extent possible */ > if (unlikely(int80_is_external())) > @@ -210,11 +209,9 @@ DEFINE_FREDENTRY_RAW(int80_emulation) > { > int nr; > > - enter_from_user_mode(regs); > + enter_from_user_mode_randomize_stack(regs); > > instrumentation_begin(); > - add_random_kstack_offset(); > - > /* > * FRED pushed 0 into regs::orig_ax and regs::ax contains the > * syscall number. > @@ -252,10 +249,10 @@ DEFINE_FREDENTRY_RAW(int80_emulation) > * orig_ax, the int return value truncates it. This matches > * the semantics of syscall_get_nr(). > */ > - nr = syscall_enter_from_user_mode(regs, nr); > + nr = syscall_enter_from_user_mode_randomize_stack(regs, nr); > + > instrumentation_begin(); > > - add_random_kstack_offset(); > do_syscall_32_irqs_on(regs, nr); > > instrumentation_end(); > @@ -268,15 +265,9 @@ static noinstr bool __do_fast_syscall_32 > int nr = syscall_32_enter(regs); > int res; > > - /* > - * This cannot use syscall_enter_from_user_mode() as it has to > - * fetch EBP before invoking any of the syscall entry work > - * functions. > - */ > - enter_from_user_mode(regs); > + enter_from_user_mode_randomize_stack(regs); > > instrumentation_begin(); > - add_random_kstack_offset(); > local_irq_enable(); > /* Fetch EBP from where the vDSO stashed it. */ > if (IS_ENABLED(CONFIG_X86_64)) { > --- a/arch/x86/entry/syscall_64.c > +++ b/arch/x86/entry/syscall_64.c > @@ -86,10 +86,9 @@ static __always_inline bool do_syscall_x > /* Returns true to return using SYSRET, or false to use IRET */ > __visible noinstr bool do_syscall_64(struct pt_regs *regs, int nr) > { > - nr = syscall_enter_from_user_mode(regs, nr); > + nr = syscall_enter_from_user_mode_randomize_stack(regs, nr); > > instrumentation_begin(); > - add_random_kstack_offset(); > > if (!do_syscall_x64(regs, nr) && !do_syscall_x32(regs, nr) && nr != -1) { > /* Invalid system call, but still a system call. */ > --- a/arch/x86/include/asm/entry-common.h > +++ b/arch/x86/include/asm/entry-common.h > @@ -2,7 +2,6 @@ > #ifndef _ASM_X86_ENTRY_COMMON_H > #define _ASM_X86_ENTRY_COMMON_H > > -#include > #include > > #include >