From patchwork Mon Mar 7 18:27:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1602480 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=cdl0uoIz; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KC6RP0G5Tz9s5P for ; Tue, 8 Mar 2022 05:28:49 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KC6RM4HZDz3bd9 for ; Tue, 8 Mar 2022 05:28:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=cdl0uoIz; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::429; helo=mail-pf1-x429.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=cdl0uoIz; dkim-atps=neutral Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KC6Q85mF0z3bbB for ; Tue, 8 Mar 2022 05:27:43 +1100 (AEDT) Received: by mail-pf1-x429.google.com with SMTP id g19so3290174pfc.9 for ; Mon, 07 Mar 2022 10:27:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xLhzOZfiSqjqlwLqL5zd/t/2T3kyAguFpM7SN7VkuXA=; b=cdl0uoIzZQDfTEovBL2q8L8AAZLyfKd9TNGPfyDmgf6yUAgtIqzuW9kRhYEqcTnl1A p0U7jfdpi9eJ2sV/hpKZ6npqQsGjOO00qK1uF+8MP9oaw+c+IUyU3O87hedufpJIYKQu 6fJUquzV/tUofIlpEYobUUl/19SC+elWYyPLyzLAiofyQ9PUQzWFKaQkuQGdlbzT8Jnm pDm/13zcDW4zGtwfGOlFr6EslQoIp0fM89iKgajkyxpOVfSmWZa0U1KjQS1EqA8m9odU IdxGBHQe3NNULZThkuZEEfssi6FOWTtmB1XRveQjOJP6RmVWlSvoZI5KGbKmwS2rYov6 MbGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=xLhzOZfiSqjqlwLqL5zd/t/2T3kyAguFpM7SN7VkuXA=; b=PgoomyDr25Bi5pgCIWRv7j1GdjqmHxAUbhhZqIFAw0dBgX62QAvdufqA166IozneLQ MIPxXg+NbCOh1PkLyDzuRVs4YhUkbp8TCkbKK5misyTGIt+zoZVOf2afyM4aTV3b7QeI q0DEo50N8/hQppvfGKvGWGnR8pxWDZWxQ5COmpw38SMBjIYlaQ/tlau7L6uEQqWDItLJ 47AWefYsI600Km8OxdIdAHTF8kqPPwp3qPujcRE6N3CN4eWteCxOpO14m+lNbhRkE9p9 Tc6GipYFpxEFc+WH0nNj04cPWskihFwZC19B6uTf0/nASOpnrhC/ok0A3dA0p9N5zCI7 JKOg== X-Gm-Message-State: AOAM531R80fr6PQyrIuKUfdZb8w69Jvrm5AdKtzQ3a5ujNGKXBPAzYpP OwPCaSuwSBvujVUJLotHUDkvSJyxAIg= X-Google-Smtp-Source: ABdhPJyb+wng4BGrFYxQR7j4UOJwr0GQhQzPuMjg3QRUI/t0AIXKZ5jSe3qCioJoQgxK7VwFGcauTg== X-Received: by 2002:a63:c011:0:b0:378:74a6:9c31 with SMTP id h17-20020a63c011000000b0037874a69c31mr10860828pgg.585.1646677660505; Mon, 07 Mar 2022 10:27:40 -0800 (PST) Received: from bobo.ozlabs.ibm.com (61-68-211-196.tpgi.com.au. [61.68.211.196]) by smtp.gmail.com with ESMTPSA id v22-20020a17090ad59600b001b7deb42251sm68767pju.15.2022.03.07.10.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 10:27:40 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Date: Tue, 8 Mar 2022 04:27:33 +1000 Message-Id: <20220307182734.289289-1-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tulio Magno Quites Machado Filho , Nicholas Piggin , Alan Modra Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The sad tale of SIGSTKSZ and MINSIGSTKSZ is documented in glibc.git commit f7c399cff5bd ("PowerPC SIGSTKSZ"), which explains why glibc does not use the kernel defines for these constants. Since then in fact there has been a further expansion of the signal stack frame size on little-endian with linux commit 573ebfa6601f ("powerpc: Increase stack redzone for 64-bit userspace to 512 bytes"), which has caused it to exceed even the glibc defines. Increase MINSIGSTKSZ to 8192 which is double the current glibc value and fits the current stack frame with room to grow. SIGSTKSZ is set to 4x the minimum as convention. glibc will have to be updated as well. Cc: Alan Modra Cc: Tulio Magno Quites Machado Filho Signed-off-by: Nicholas Piggin --- arch/powerpc/include/uapi/asm/signal.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/powerpc/include/uapi/asm/signal.h b/arch/powerpc/include/uapi/asm/signal.h index 04873dd311c2..81fa9d90be80 100644 --- a/arch/powerpc/include/uapi/asm/signal.h +++ b/arch/powerpc/include/uapi/asm/signal.h @@ -62,8 +62,13 @@ typedef struct { #define SA_RESTORER 0x04000000U +#ifdef __powerpc64__ +#define MINSIGSTKSZ 8192 +#define SIGSTKSZ 32768 +#else #define MINSIGSTKSZ 2048 #define SIGSTKSZ 8192 +#endif #include From patchwork Mon Mar 7 18:27:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1602477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=i2BnqLMd; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KC6Qj4Lkzz9s5P for ; Tue, 8 Mar 2022 05:28:13 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KC6Qg2yRlz3bbN for ; Tue, 8 Mar 2022 05:28:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=i2BnqLMd; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=i2BnqLMd; dkim-atps=neutral Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4KC6Q85t3Rz3bbG for ; Tue, 8 Mar 2022 05:27:44 +1100 (AEDT) Received: by mail-pf1-x42f.google.com with SMTP id t5so14858334pfg.4 for ; Mon, 07 Mar 2022 10:27:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WlzGmKQkWzi6Qr+WywUOdHqH4PZoISUm1CwL1+MnnnQ=; b=i2BnqLMdrRJKcl5wqFruwNd/uPzX3h7Lts9Z0Ne4aqHEcF9FogZGotzwggDmhlI+04 fi2DCYALFrdM5PjmYVGAzvRkvTN5cD5F6cTkZxvzxUUPzzhJWvhaYyQzzjW6fTdYtZGF 7SV8HthxX+2qv62AaLI18nL2SFUqj2pWQVYdaYP9XXCVTHEKG7HPdIDaLilgQOZi9Q8C lirqN4PnVJZ3Hgr3P9zXDf/+WI0HHwD/9MeXtCLu0yrOjphIJKJU8eQ5K4hDX4V4Taz4 7BVxJNgYJ9S6jKP34oI4WPUN8bsibZYy8E20mHUYMBpfa0YuzPEW1J9EetIRuZcVI1KF 9fFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WlzGmKQkWzi6Qr+WywUOdHqH4PZoISUm1CwL1+MnnnQ=; b=tQuc6hvZ95RRzOChJd20JHBH0z/b74wVUR3szqqPswOi+zq/n7fLTvuAW4LuibhYBC LmZoP+XBCbWSYKA1APRFy5rlUiin1vhFoaXxxGZ2p8LNTIb8/0tPolR0eyRvezBfBsy5 BFV+6MZ6BP5h/RUa445t2moHeg1CtYqA06qdXN/rGLCO8oJFtb0C1xgSriYd1JvkaLDX XhGdryLv07IluGm2w6hgRi1/3n7VPMMO/+sHfdXIVhxuX+aMmQb/Lpo3HAc6P8s0Nz2y YZ6g7GIGRsSVyXrTj+z6crZacun4rWlZz0HEyYcBW2pp5FsD+fBPG9jpAGTh4c7XVZM3 ACfw== X-Gm-Message-State: AOAM532pe0h0UxWdM+jTMwSKbUFuroCsZUwZt4DfGX4uLy+1pjYLvE+G UrSEhMp37d5pnQIPm3+UWplfcLL78QA= X-Google-Smtp-Source: ABdhPJzAjnTW5FUKRBxdhht054Dd7PpdEbFf69k0eEn2QYLSGkMAyC1mlrSw353a6i4kpo7GIF6gsA== X-Received: by 2002:a63:8643:0:b0:37c:996c:ecd with SMTP id x64-20020a638643000000b0037c996c0ecdmr10849261pgd.416.1646677663087; Mon, 07 Mar 2022 10:27:43 -0800 (PST) Received: from bobo.ozlabs.ibm.com (61-68-211-196.tpgi.com.au. [61.68.211.196]) by smtp.gmail.com with ESMTPSA id v22-20020a17090ad59600b001b7deb42251sm68767pju.15.2022.03.07.10.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Mar 2022 10:27:42 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ Date: Tue, 8 Mar 2022 04:27:34 +1000 Message-Id: <20220307182734.289289-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220307182734.289289-1-npiggin@gmail.com> References: <20220307182734.289289-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tulio Magno Quites Machado Filho , Nicholas Piggin , Alan Modra Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Implement the AT_MINSIGSTKSZ AUXV entry, allowing userspace to dynamically size stack allocations in a manner forward-compatible with new processor state saved in the signal frame For now these statically find the maximum signal frame size rather than doing any runtime testing of features to minimise the size. glibc 2.34 will take advantage of this, as will applications that use use _SC_MINSIGSTKSZ and _SC_SIGSTKSZ. Cc: Alan Modra Cc: Tulio Magno Quites Machado Filho References: 94b07c1f8c39 ("arm64: signal: Report signal frame size to userspace via auxv") Signed-off-by: Nicholas Piggin Reviewed-by: Tulio Magno Quites Machado Filho --- arch/powerpc/include/asm/elf.h | 14 +++++++++++++- arch/powerpc/include/asm/signal.h | 5 +++++ arch/powerpc/include/uapi/asm/auxvec.h | 4 +++- arch/powerpc/kernel/signal.c | 15 +++++++++++++++ arch/powerpc/kernel/signal_32.c | 6 ++++++ arch/powerpc/kernel/signal_64.c | 5 +++++ 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h index b8425e3cfd81..19d5c798c566 100644 --- a/arch/powerpc/include/asm/elf.h +++ b/arch/powerpc/include/asm/elf.h @@ -160,7 +160,7 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm, * even if DLINFO_ARCH_ITEMS goes to zero or is undefined. * update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes */ -#define ARCH_DLINFO \ +#define COMMON_ARCH_DLINFO \ do { \ /* Handle glibc compatibility. */ \ NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \ @@ -173,6 +173,18 @@ do { \ ARCH_DLINFO_CACHE_GEOMETRY; \ } while (0) +#define ARCH_DLINFO \ +do { \ + COMMON_ARCH_DLINFO; \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size()); \ +} while (0) + +#define COMPAT_ARCH_DLINFO \ +do { \ + COMMON_ARCH_DLINFO; \ + NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size_compat()); \ +} while (0) + /* Relocate the kernel image to @final_address */ void relocate(unsigned long final_address); diff --git a/arch/powerpc/include/asm/signal.h b/arch/powerpc/include/asm/signal.h index 99e1c6de27bc..922d43700fb4 100644 --- a/arch/powerpc/include/asm/signal.h +++ b/arch/powerpc/include/asm/signal.h @@ -9,4 +9,9 @@ struct pt_regs; void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags); +unsigned long get_min_sigframe_size_32(void); +unsigned long get_min_sigframe_size_64(void); +unsigned long get_min_sigframe_size(void); +unsigned long get_min_sigframe_size_compat(void); + #endif /* _ASM_POWERPC_SIGNAL_H */ diff --git a/arch/powerpc/include/uapi/asm/auxvec.h b/arch/powerpc/include/uapi/asm/auxvec.h index 7af21dc0e320..aa7c16215453 100644 --- a/arch/powerpc/include/uapi/asm/auxvec.h +++ b/arch/powerpc/include/uapi/asm/auxvec.h @@ -48,6 +48,8 @@ #define AT_L3_CACHESIZE 46 #define AT_L3_CACHEGEOMETRY 47 -#define AT_VECTOR_SIZE_ARCH 14 /* entries in ARCH_DLINFO */ +#define AT_MINSIGSTKSZ 51 /* stack needed for signal delivery */ + +#define AT_VECTOR_SIZE_ARCH 15 /* entries in ARCH_DLINFO */ #endif diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c index b93b87df499d..b3c458db2b8d 100644 --- a/arch/powerpc/kernel/signal.c +++ b/arch/powerpc/kernel/signal.c @@ -141,6 +141,21 @@ unsigned long copy_ckvsx_from_user(struct task_struct *task, int show_unhandled_signals = 1; +unsigned long get_min_sigframe_size(void) +{ + if (IS_ENABLED(CONFIG_PPC64)) + return get_min_sigframe_size_64(); + else + return get_min_sigframe_size_32(); +} + +#ifdef CONFIG_COMPAT +unsigned long get_min_sigframe_size_compat(void) +{ + return get_min_sigframe_size_32(); +} +#endif + /* * Allocate space for the signal frame */ diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c index d84c434b2b78..157a7403e3eb 100644 --- a/arch/powerpc/kernel/signal_32.c +++ b/arch/powerpc/kernel/signal_32.c @@ -233,6 +233,12 @@ struct rt_sigframe { int abigap[56]; }; +unsigned long get_min_sigframe_size_32(void) +{ + return max(sizeof(struct rt_sigframe) + __SIGNAL_FRAMESIZE + 16, + sizeof(struct sigframe) + __SIGNAL_FRAMESIZE); +} + /* * Save the current user registers on the user stack. * We only save the altivec/spe registers if the process has used diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c index d1e1fc0acbea..7c5317e07169 100644 --- a/arch/powerpc/kernel/signal_64.c +++ b/arch/powerpc/kernel/signal_64.c @@ -66,6 +66,11 @@ struct rt_sigframe { char abigap[USER_REDZONE_SIZE]; } __attribute__ ((aligned (16))); +unsigned long get_min_sigframe_size_64(void) +{ + return sizeof(struct rt_sigframe) + __SIGNAL_FRAMESIZE; +} + /* * This computes a quad word aligned pointer inside the vmx_reserve array * element. For historical reasons sigcontext might not be quad word aligned,