From patchwork Thu Nov 28 17:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 845951 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp376972wrp; Thu, 28 Nov 2024 09:39:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVd8sT76TCNsLPvK8KF48UrRPf5T2M7H6mZZNSbsWNrzxrkEPAj1Upy+pKg4X9GVsJgN5N70g==@linaro.org X-Google-Smtp-Source: AGHT+IEcPNW2atL+QcNXtf2gUjVwIzM9ZmBl8XVroUlMJyNj8t7swTZNRT1TWkGZjnbV31AyOG70 X-Received: by 2002:a05:622a:190c:b0:461:1c54:5bd5 with SMTP id d75a77b69052e-466b34d0c66mr96777971cf.9.1732815588334; Thu, 28 Nov 2024 09:39:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732815588; cv=pass; d=google.com; s=arc-20240605; b=SpIVTKKlVfD6rEPFR0PIRHuFicdUH+MFmD/IAPxtVT4QhPvWc+j1Iqukhzj/Lf4VBS 5y5/D9P/k9wG20GOUScV/opON1wo9ByczxvzP0i+hAO5snL2FxiyaDXZirzpAsrGpOWl EvMjLFurQRT8K8V8ewOdY39dx+CC7iBOXVcRT2RwdxowLcNNEqDHO3eWm9fjfvEbjwi3 x34PnrcpKirFN4No+Lm7lkWqEeSSp2lSLlOIj8KmTN406xBkaSyRsgcfgWRg6BJ/E2Kv laxrrkOFn+WRnRJXRVVxnZbZDX0fY94Weg72eH4kVU5cvJ5tLsV6LGXdGNQkCEBYz97r x0wA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=ukMExROWCFeI5moccZONnrqyhF8WcGwn/5A5w759xI4=; fh=5vlP+0ToNsZNUEx4IDYFBtVkL7R0+LPY9AvG1oUICyQ=; b=OWBO/BLPo6To/oUKYg0nbtDt2mW837nSgOhqZp3OwGbNz/pfiajjO0g6EvDXfVlSYy WQO0KrKcUa20d5RhnQFvjPTlvliXbNlhPBOpelj5XmLz56Drw1oUDWE0ZcW35LsV3nQm Hw1VCY1j3nwvJ5b3Zya/NcLvdxjwdOJ1t1jtqyoo8UuIGrcMrFFk+PLmBXqg7ubIDc4A dHjgM/Bi7mPwOWt8lZbSzvkPZy82DHwOHfHXlUC+wK8/u3okFuzHf9/SNCzSH0tOQGZy wJXqm11Qxnp2rueFwCYb8RQe7Qn1/FyqnwEa/9PALhC79uDSwXPqxlgFIksWFnC9FxGP DStQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pWr6u3Pl; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d75a77b69052e-466c4461f63si21112311cf.703.2024.11.28.09.39.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:39:48 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pWr6u3Pl; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D9CF73858D20 for ; Thu, 28 Nov 2024 17:39:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9CF73858D20 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=pWr6u3Pl X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by sourceware.org (Postfix) with ESMTPS id 47AEF3858C60 for ; Thu, 28 Nov 2024 17:38:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 47AEF3858C60 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 47AEF3858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::541 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815538; cv=none; b=qXzJfau1vpVN8HAegrohlx9fUIXFXHHL6LNDqSgblTHma+leaVMah+OgWkTO2/47b18iJPD+WOEcYxASE1QTrO29M5VdN3Wuh48vIhJESQ0PEY9s8uhh2oMV6zYxXBju3gIHQ0zEdHQZoc9vlbXda7YTG0PQSKuPtOiQN32XjNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815538; c=relaxed/simple; bh=9+5p+DVW+1ONj47gRsDFQzRhMMK5uKZTH4iuZwY6dZs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=XzOeMlXbx8tU6tgkPWyfQKcqQ0VdzUjWIeAu0jJCQYMoMuGL+rSXEkRdkUBCaWr4TlBaHdYmS9hVkNH1Zb60fwZb043SSKd82t6hzroeS030hW1G8ftKPMUHt1J8YKr9T1PcvedLyIuwqtSoRGJA3vjB4GqCeqNhdxK4Uoy8IlM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 47AEF3858C60 Received: by mail-pg1-x541.google.com with SMTP id 41be03b00d2f7-7f450f7f11dso701557a12.2 for ; Thu, 28 Nov 2024 09:38:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732815537; x=1733420337; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ukMExROWCFeI5moccZONnrqyhF8WcGwn/5A5w759xI4=; b=pWr6u3PllpI7tQnRnHW/DM8Bk+a3rkEhyc9XjwwjoxgPFTH6l475QNhFWBh9yvNjnj IY4VjQfPl0TEcyYiUbfJmptvEecKGiEZoaExsYoD0Y6g7u1mMM8iFQShcjlEx1f17njp VniHzmniHDQCBBy+lwvQ48k+YtStRoY8HeqcA5qsDfs2mlwIw5lT8FLhssRguJ5pyH8g ZLACvvpn2rTD0HfB4wfL04VMbRoHvZufsfD0K073orU/zYcO63T/UAjLkyAGmh+8w/Fi 7mjiZe11RhDMCDD78AsY/cLTWg0Xt0C6Ay7QjDaJNBvY9O+UPruXdSrJq8B2sKJiJJ+N qKOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732815537; x=1733420337; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ukMExROWCFeI5moccZONnrqyhF8WcGwn/5A5w759xI4=; b=n6klQxcinitQTxfdAG25dyTkwUIKM7vCOHFabnMQSnB1QEbPVJtsfw/dhDZlGQxD+V fFmTnGBo/+m3wTio+hnT3f6rpJ9ffHWc49ti2zK5WkHUp876+nqrZl501E2rCr1bmlWF cCFk2NSqangQjj09g485waAd4gXlhFLj16fMmE1QLkyAZb2v3RYOVVmECieJ2ytoArnD hbGev92POmsy2eseYuyWWq6/V1v+KWxI/JItT7H6C0rM9o92RrcoB3LixnJSmjl/pegX YHxsXKQDX7Pe3Du48rhsRFPmobAyK093bCg0REiHmrfwmI40A9X/fhdPPifVYluEtb0D 8WMA== X-Gm-Message-State: AOJu0YyFIE4cCE3F+016ArcvTaTM6VbKlqFFe/2BccppILosY0fPgElI 3FqtQvRE3WoSJ0Fyxh5epmJo3odo4SoUeXTRCmitUWO1n5hTXNW6SesTmEWD76pjOpiVAEywx9R Xi+N9hNMA X-Gm-Gg: ASbGncvDo5CpJm/TfuvItkV5j7p3JmxBptyBMOSeb13dI97c+BxDLuj2xs2JKGz8Jzr P0U1UT2qPnuWSsEMzXI38MVZx5Jt39CAXLCDtIDTWIghRNI3kb3grNQYRPHuWRk8+NaxlKcqdPe EmAJD/oCKljTwLma0kDx+4PNfyMrNnU90TYWwNhQsl9dZINv8W1ROnj94oY8PQj/v3sgBEKs8rC BVDT+Nj9MKi8GENKVpib4dVmnO7DFVc3wtgRh4m+y9lQa/mqLQrOS5LRn0r5gM= X-Received: by 2002:a05:6a20:6f8c:b0:1e0:cbcf:8917 with SMTP id adf61e73a8af0-1e0e0b0b329mr11082606637.21.1732815536855; Thu, 28 Nov 2024 09:38:56 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:68c8:2c85:3a76:728e:ead2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72541849d6csm1860356b3a.182.2024.11.28.09.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:38:56 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 1/4] elf: Consolidate stackinfo.h Date: Thu, 28 Nov 2024 14:36:42 -0300 Message-ID: <20241128173851.1920696-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> References: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org And use sane default the generic implementation. Reviewed-by: Florian Weimer --- sysdeps/aarch64/stackinfo.h | 33 --------------------- sysdeps/arc/stackinfo.h | 33 --------------------- sysdeps/csky/stackinfo.h | 29 ------------------ sysdeps/generic/stackinfo.h | 15 ++++++++-- sysdeps/loongarch/stackinfo.h | 33 --------------------- sysdeps/powerpc/{ => powerpc32}/stackinfo.h | 8 +---- sysdeps/riscv/stackinfo.h | 33 --------------------- 7 files changed, 13 insertions(+), 171 deletions(-) delete mode 100644 sysdeps/aarch64/stackinfo.h delete mode 100644 sysdeps/arc/stackinfo.h delete mode 100644 sysdeps/csky/stackinfo.h delete mode 100644 sysdeps/loongarch/stackinfo.h rename sysdeps/powerpc/{ => powerpc32}/stackinfo.h (82%) delete mode 100644 sysdeps/riscv/stackinfo.h diff --git a/sysdeps/aarch64/stackinfo.h b/sysdeps/aarch64/stackinfo.h deleted file mode 100644 index 5a4dce7309..0000000000 --- a/sysdeps/aarch64/stackinfo.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2001-2024 Free Software Foundation, Inc. - - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -/* This file contains a bit of information about the stack allocation - of the processor. */ - -#ifndef _STACKINFO_H -#define _STACKINFO_H 1 - -#include - -/* On AArch64 the stack grows down. */ -#define _STACK_GROWS_DOWN 1 - -/* Default to a non-executable stack. */ -#define DEFAULT_STACK_PERMS (PF_R|PF_W) - -#endif /* stackinfo.h */ diff --git a/sysdeps/arc/stackinfo.h b/sysdeps/arc/stackinfo.h deleted file mode 100644 index 99a7f56ea0..0000000000 --- a/sysdeps/arc/stackinfo.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Stack environment definitions for ARC. - Copyright (C) 2020-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -/* This file contains a bit of information about the stack allocation - of the processor. */ - -#ifndef _STACKINFO_H -#define _STACKINFO_H 1 - -#include - -/* On ARC the stack grows down. */ -#define _STACK_GROWS_DOWN 1 - -/* Default to a non-executable stack. */ -#define DEFAULT_STACK_PERMS (PF_R|PF_W) - -#endif /* stackinfo.h */ diff --git a/sysdeps/csky/stackinfo.h b/sysdeps/csky/stackinfo.h deleted file mode 100644 index ef22fa3249..0000000000 --- a/sysdeps/csky/stackinfo.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Stack environment definitions. C-SKY version. - Copyright (C) 2018-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -#ifndef _STACKINFO_H -#define _STACKINFO_H 1 - -#include - -/* On C-SKY the stack grows down. */ -#define _STACK_GROWS_DOWN 1 - -#define DEFAULT_STACK_PERMS (PF_R|PF_W) - -#endif /* stackinfo.h */ diff --git a/sysdeps/generic/stackinfo.h b/sysdeps/generic/stackinfo.h index bf752ce94d..51e5f92055 100644 --- a/sysdeps/generic/stackinfo.h +++ b/sysdeps/generic/stackinfo.h @@ -15,6 +15,15 @@ License along with the GNU C Library; if not, see . */ -/* This file contains a bit of information about the stack allocation - of the processor. Since there is no general truth we can't say - anything here. */ +/* This file contains a bit of information about the stack allocation of the + processor. Default to a non executable stack that grows downwards. */ + +#ifndef _STACKINFO_H +#define _STACKINFO_H 1 + +#include + +#define _STACK_GROWS_DOWN 1 +#define DEFAULT_STACK_PERMS (PF_R|PF_W) + +#endif diff --git a/sysdeps/loongarch/stackinfo.h b/sysdeps/loongarch/stackinfo.h deleted file mode 100644 index 6ee50552b7..0000000000 --- a/sysdeps/loongarch/stackinfo.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Stack environment definitions for LoongArch. - Copyright (C) 2022-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -/* This file contains a bit of information about the stack allocation - of the processor. */ - -#ifndef _STACKINFO_H -#define _STACKINFO_H 1 - -#include - -/* On LoongArch the stack grows down. */ -#define _STACK_GROWS_DOWN 1 - -/* Default to a non-executable stack. */ -#define DEFAULT_STACK_PERMS (PF_R | PF_W) - -#endif /* stackinfo.h */ diff --git a/sysdeps/powerpc/stackinfo.h b/sysdeps/powerpc/powerpc32/stackinfo.h similarity index 82% rename from sysdeps/powerpc/stackinfo.h rename to sysdeps/powerpc/powerpc32/stackinfo.h index 410689bc27..2ca360068a 100644 --- a/sysdeps/powerpc/stackinfo.h +++ b/sysdeps/powerpc/powerpc32/stackinfo.h @@ -26,13 +26,7 @@ /* On PPC the stack grows down. */ #define _STACK_GROWS_DOWN 1 -#if __WORDSIZE == 64 -/* PPC64 doesn't need an executable stack and doesn't need PT_GNU_STACK - * to make the stack nonexecutable. */ -# define DEFAULT_STACK_PERMS (PF_R|PF_W) -#else /* PF_X can be overridden if PT_GNU_STACK is present but is presumed absent. */ -# define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X) -#endif +#define DEFAULT_STACK_PERMS (PF_R|PF_W|PF_X) #endif /* stackinfo.h */ diff --git a/sysdeps/riscv/stackinfo.h b/sysdeps/riscv/stackinfo.h deleted file mode 100644 index a786d4f9b0..0000000000 --- a/sysdeps/riscv/stackinfo.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Stack environment definitions for RISC-V. - Copyright (C) 2011-2024 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library. If not, see - . */ - -/* This file contains a bit of information about the stack allocation - of the processor. */ - -#ifndef _STACKINFO_H -#define _STACKINFO_H 1 - -#include - -/* On RISC-V the stack grows down. */ -#define _STACK_GROWS_DOWN 1 - -/* Default to a non-executable stack. */ -#define DEFAULT_STACK_PERMS (PF_R | PF_W) - -#endif /* stackinfo.h */ From patchwork Thu Nov 28 17:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 845952 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp377058wrp; Thu, 28 Nov 2024 09:39:57 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU1TVW0+cLIutR9HoJYxEzHT4GntKL+huxi2ykICz28h8HH99/4FhhBmYH/B5Bu07r0c/4lUw==@linaro.org X-Google-Smtp-Source: AGHT+IFJsgAzZJDJMoslv0SUvwynb6NiGxXiFQe69W9h5JT6cCQtpwrLDxqAubxdUw0s12AqqbW1 X-Received: by 2002:a05:6214:2605:b0:6d4:e46:b43a with SMTP id 6a1803df08f44-6d864db421bmr142501636d6.45.1732815596874; Thu, 28 Nov 2024 09:39:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732815596; cv=pass; d=google.com; s=arc-20240605; b=JNm7SY6iGFqjlue4TySyK6dsI7cfNm1FbMFnl3FmjGsfwnNGZRhsHZI9rmzZICXcE+ IBdtPz7brvfxQAHxDClx/T4IOkFToZIsMARRnfQF+Ag8C+QmBy6jNAvsVJu4iQiNZFTR e26/tH8mitypeBBVAvNmY2QhAqZaAQObEt0dLREWBnmyYPQoCboTaouOJGrZkYY7vZlm v/k+4TkwGK3xjSCkjSgBipQWQbezhvqK0HKGQ6qS7YCurb+/KXVfQGgFLUivFA7ZOoEY x5t5AfZZ9AK7lWwG45wT+mR5aoEgqcW0/Nb+kYh3oOi0RndzjuCRgxc5RuNyJtISoggA TWcg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=05MFVFgeMvBqYdpaoNgsoYXGQfR8IqVOMNYKgyUlvvc=; fh=5vlP+0ToNsZNUEx4IDYFBtVkL7R0+LPY9AvG1oUICyQ=; b=VHEuXvBTFDHHzIY/geHIqXQnC3q/1PMerC0UwaSjjeXJqvB/rUiu+NZcJCOw1kYv+4 7e6WtytsS7XGJh9Rb+tdb0f5OlUnKJeMCcliCpVAL6+XRlsrmlw0Da9OWj0U6rp8h1wC dsD/neLikUJwZSx5DEQEn2OuCFLFvyquK6WJ52VKOcPY1LYVPHm0krM8hgHcsrZRbfGx P/aYogFPXgFSGsolMKUQAArDsuvzXwIuFB+tFn1rSYKJv8+p+gp8croyCWZyMO8N7QJx /DIkVlmIPd5/JU6d7bTFm2kCLZHG3CGXExyqm+3Jo8PyIYy3JkpftBDnbozrGmnlLVhX xbfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A+u7vMSQ; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 6a1803df08f44-6d880ea3998si4281376d6.272.2024.11.28.09.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:39:56 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A+u7vMSQ; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F7B03858CDB for ; Thu, 28 Nov 2024 17:39:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F7B03858CDB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=A+u7vMSQ X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id 296A03858C53 for ; Thu, 28 Nov 2024 17:39:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 296A03858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 296A03858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::441 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815540; cv=none; b=C1Pr500GeukrI3bdMvhSqotuOUbyodQ/wtheTm1ghCipSTy/IcTk3BRDx4y9X5luBRd4GdhcGlwiTUY6HIB4IVJ5g2xXDbBlPyeEu1R5+iHxlKtLdCRaYp17guAuzKeh9p2cPcm1ZzERNJlwYrIG9IWmjuap4qw4/X6l242iGCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815540; c=relaxed/simple; bh=aSxvVVO6Vga8HgJiogoeS3nLOAQVdw1CsUuE/gPe96c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Eu0RkN+aSP1z/Yc/g+VyUpEVUU8MTiA1pvvsMDRfb/qx1+UeAVAlCuwKNy+zme9sWODYDecBnryAhJWjLRaT8uCkWuaviEnM+VxqYBpj7BH4ofMxG6NPxoIJQDZTnc4jgSyFSSsYcnwS91vBVr3hltRJ3EfC5EtRjHN7GRcy78A= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 296A03858C53 Received: by mail-pf1-x441.google.com with SMTP id d2e1a72fcca58-724e14b90cfso1048576b3a.2 for ; Thu, 28 Nov 2024 09:39:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732815539; x=1733420339; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=05MFVFgeMvBqYdpaoNgsoYXGQfR8IqVOMNYKgyUlvvc=; b=A+u7vMSQ4phg3Ia25z2oETFW91PnlCfokQD75FIuMCxWD6Qx1KraK8SdEpbdNuqs18 pSwDFaKViPjqWZx95fkayRh0BIH5E1jEI4LxQJAqCs1e5CYX1A7Ee4QQbo3cBVBiqpVI Oe5nPn0hMchLdwyFGnPRw2Zxz9419Y+m7yVIn5+PsFPT1EFyqSXWO9NLpYN2auhYW2l1 itbnDtPb3uqSAQqJw+cp2LPbVm669LNk5kNzQaBE0CBQh1RMI+/fYcXWeNq/Tx9D5YdO iPO/z5Rv9KVxENGBTOW8dfcuIK/8gKx7o6WUlgd52emqo9gamlwebUKaTJbwbRT6e119 iHSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732815539; x=1733420339; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=05MFVFgeMvBqYdpaoNgsoYXGQfR8IqVOMNYKgyUlvvc=; b=JZ1w8mil5NCuvnX4bpZ/RkgHhkP93bxtm7tr+rft0lR42PCCoORhoBvENghGqemXRb GLS/ut1nNoBm4frbYslXQJoTwnX5cqmHSFuGFDcXP5i1KPKTaYNCyn1Ygnygce9/K+Bz 3FsfQc0urEFBu/+3KKSjTD1G4/Fq99/K7Lir3ov09glTFdSBzjfCYNi1AaDu0/VC+i5c OXzcm4wFOuzDhGs63+itu5T/rY3BtbtRpC2K32itoup2r8JdorVLQLayQW+ybXv0oGV8 Px7+MSzWj6H20suBxM0bjFtn4UTJYUAQ6v0Xy3x0pAwyncISxAQv7B1TP9mWJYghef4Q SzkQ== X-Gm-Message-State: AOJu0Yy7T29+lG0AsU76ECvlr/Ot5A3M/+r4himD76CL4W5zz3uzGUF5 I9FH/7MJIruP9neGKEvHhs5NkK9+BUEvqd90suJvyetaqVlJHrEzBNX/KP3xDoAUpYqheqvhqzP g9YLT4ein X-Gm-Gg: ASbGncuffvwyQ/gdNb2oOBXqP5j5wXGsk6KYmjiYpKni8XcB6f1DRgvG6Tj9TTLz1ZT RDIa0rEKTqD7577/KRs0rdyIaTv2KtduUlDWLDLvINnGOS+zSZlqP9UhHSWJXu4n4kG0ARh7avv ntqgUPKhXcxin57xRi9lueWK5NQ55O+Yp4zVTI7UE1qfgZl0L0E2Hmt5NGZZcHdapJLuhKm8L85 QOL0WSxNeUFZhInUjbsBHPuWyPxZNGTRLsrbPpWz4KVS922TwEA4UjhVsAqKOI= X-Received: by 2002:a05:6a00:1390:b0:71e:5a1d:ecdc with SMTP id d2e1a72fcca58-7253012f56dmr10609733b3a.17.1732815538414; Thu, 28 Nov 2024 09:38:58 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:68c8:2c85:3a76:728e:ead2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72541849d6csm1860356b3a.182.2024.11.28.09.38.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:38:58 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 2/4] elf: Do not change stack permission on dlopen/dlmopen Date: Thu, 28 Nov 2024 14:36:43 -0300 Message-ID: <20241128173851.1920696-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> References: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org If some shared library loaded with dlopen/dlmopen requires an executable stack, either implicitly because of a missing GNU_STACK ELF header (where the ABI default flags implies in the executable bit) or explicitly because of the executable bit from GNU_STACK; the loader will try to set the both the main thread and all thread stacks (from the pthread cache) as executable. Besides the issue where any __nptl_change_stack_perm failure does not undo the previous executable transition (meaning that if the library fails to load, there can be thread stacks with executable stacks), this behavior was used on recent CVE [1] as a vector for RCE. This patch changes that if a shared library requires an executable stack, and the current stack is not executable, dlopen fails. The change is done only for dynamically loaded modules, if the program or any dependency requires an executable stack, the loader will still change the main thread before program execution and any thread created with default stack configuration. [1] https://www.qualys.com/2023/07/19/cve-2023-38408/rce-openssh-forwarded-ssh-agent.txt Checked on x86_64-linux-gnu and i686-linux-gnu. --- NEWS | 6 ++ elf/dl-load.c | 13 +-- elf/dl-support.c | 4 - elf/rtld.c | 6 -- elf/tst-execstack.c | 142 ++++++++++--------------- nptl/allocatestack.c | 19 ---- sysdeps/generic/ldsodefs.h | 22 +--- sysdeps/mach/hurd/dl-execstack.c | 1 - sysdeps/nptl/pthreadP.h | 6 -- sysdeps/unix/sysv/linux/Versions | 3 - sysdeps/unix/sysv/linux/dl-execstack.c | 67 +----------- sysdeps/unix/sysv/linux/mips/Makefile | 7 ++ 12 files changed, 80 insertions(+), 216 deletions(-) diff --git a/NEWS b/NEWS index dae2332eab..8cb5597631 100644 --- a/NEWS +++ b/NEWS @@ -49,6 +49,12 @@ Deprecated and removed features, and other changes affecting compatibility: * The nios2*-*-linux-gnu configurations are no longer supported. +* dlopen and dlmopen no longer make the stack executable if a shared + library requires it, either implicitly because of a missing GNU_STACK ELF + header (and default ABI permission having the executable bit set) or + explicitly because of the executable bit in GNU_STACK, and the stack is + not already executable. + Changes to build and runtime requirements: * On recent Linux kernels with vDSO getrandom support, getrandom does not diff --git a/elf/dl-load.c b/elf/dl-load.c index e986d7faab..f525eec662 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1282,12 +1282,13 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, if (__glibc_unlikely ((stack_flags &~ GL(dl_stack_flags)) & PF_X)) { /* The stack is presently not executable, but this module - requires that it be executable. */ -#if PTHREAD_IN_LIBC - errval = _dl_make_stacks_executable (stack_endp); -#else - errval = (*GL(dl_make_stack_executable_hook)) (stack_endp); -#endif + requires that it be executable. Only tries to change the + stack protection during process startup. */ + if ((mode & __RTLD_DLOPEN) == 0) + errval = _dl_make_stack_executable (stack_endp); + else + errval = EINVAL; + if (errval) { errstring = N_("\ diff --git a/elf/dl-support.c b/elf/dl-support.c index ee590edf93..fe1f8c8f6a 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -178,10 +178,6 @@ size_t _dl_stack_cache_actsize; uintptr_t _dl_in_flight_stack; int _dl_stack_cache_lock; #else -/* If loading a shared object requires that we make the stack executable - when it was not, we do it by calling this function. - It returns an errno code or zero on success. */ -int (*_dl_make_stack_executable_hook) (void **) = _dl_make_stack_executable; void (*_dl_init_static_tls) (struct link_map *) = &_dl_nothread_init_static_tls; #endif struct dl_scope_free_list *_dl_scope_free_list; diff --git a/elf/rtld.c b/elf/rtld.c index b8cc3f605f..3b232f8525 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1335,12 +1335,6 @@ dl_main (const ElfW(Phdr) *phdr, __tls_pre_init_tp (); -#if !PTHREAD_IN_LIBC - /* The explicit initialization here is cheaper than processing the reloc - in the _rtld_local definition's initializer. */ - GL(dl_make_stack_executable_hook) = &_dl_make_stack_executable; -#endif - /* Process the environment variable which control the behaviour. */ skip_env = process_envvars (&state); diff --git a/elf/tst-execstack.c b/elf/tst-execstack.c index 560b353918..cd758c089e 100644 --- a/elf/tst-execstack.c +++ b/elf/tst-execstack.c @@ -9,6 +9,11 @@ #include #include +#include +#include +#include +#include + static void print_maps (void) { @@ -20,11 +25,21 @@ print_maps (void) #endif } -static void deeper (void (*f) (void)); +#ifndef DEFAULT_RWX_STACK +# define DEFAULT_RWX_STACK 0 +#else +static void +deeper (void (*f) (void)) +{ + char stack[1100 * 1024]; + explicit_bzero (stack, sizeof stack); + (*f) (); + memfrob (stack, sizeof stack); +} +#endif #if USE_PTHREADS -# include - +# if DEFAULT_RWX_STACK static void * tryme_thread (void *f) { @@ -32,16 +47,21 @@ tryme_thread (void *f) return 0; } +# endif static pthread_barrier_t startup_barrier, go_barrier; static void * waiter_thread (void *arg) { - void **f = arg; - pthread_barrier_wait (&startup_barrier); - pthread_barrier_wait (&go_barrier); + xpthread_barrier_wait (&startup_barrier); + xpthread_barrier_wait (&go_barrier); +# if DEFAULT_RWX_STACK + void **f = arg; (*((void (*) (void)) *f)) (); +# else + abort (); +# endif return 0; } @@ -83,52 +103,36 @@ do_test (void) printf ("executable stacks %sallowed\n", allow_execstack ? "" : "not "); +#if USE_PTHREADS || DEFAULT_RWX_STACK static void *f; /* Address of this is used in other threads. */ +#endif #if USE_PTHREADS /* Create some threads while stacks are nonexecutable. */ #define N 5 - pthread_t thr[N]; - pthread_barrier_init (&startup_barrier, NULL, N + 1); - pthread_barrier_init (&go_barrier, NULL, N + 1); + xpthread_barrier_init (&startup_barrier, NULL, N + 1); + xpthread_barrier_init (&go_barrier, NULL, N + 1); for (int i = 0; i < N; ++i) - { - int rc = pthread_create (&thr[i], NULL, &waiter_thread, &f); - if (rc) - error (1, rc, "pthread_create"); - } + xpthread_create (NULL, &waiter_thread, &f); /* Make sure they are all there using their stacks. */ - pthread_barrier_wait (&startup_barrier); + xpthread_barrier_wait (&startup_barrier); puts ("threads waiting"); #endif print_maps (); -#if USE_PTHREADS +#if USE_PTHREADS && DEFAULT_RWX_STACK void *old_stack_addr, *new_stack_addr; size_t stack_size; pthread_t me = pthread_self (); pthread_attr_t attr; - int ret = 0; - - ret = pthread_getattr_np (me, &attr); - if (ret) - { - printf ("before execstack: pthread_getattr_np returned error: %s\n", - strerror (ret)); - return 1; - } - ret = pthread_attr_getstack (&attr, &old_stack_addr, &stack_size); - if (ret) - { - printf ("before execstack: pthread_attr_getstack returned error: %s\n", - strerror (ret)); - return 1; - } + TEST_VERIFY_EXIT (pthread_getattr_np (me, &attr) == 0); + TEST_VERIFY_EXIT (pthread_attr_getstack (&attr, &old_stack_addr, + &stack_size) == 0); # if _STACK_GROWS_DOWN old_stack_addr += stack_size; # else @@ -143,18 +147,12 @@ do_test (void) const char *soname = "tst-execstack-mod.so"; #endif void *h = dlopen (soname, RTLD_LAZY); - if (h == NULL) - { - printf ("cannot load: %s\n", dlerror ()); - return allow_execstack; - } +#if !DEFAULT_RWX_STACK + TEST_VERIFY_EXIT (h == NULL); +#else + TEST_VERIFY_EXIT (h != NULL); - f = dlsym (h, "tryme"); - if (f == NULL) - { - printf ("symbol not found: %s\n", dlerror ()); - return 1; - } + f = xdlsym (h, "tryme"); /* Test if that really made our stack executable. The `tryme' function should crash if not. */ @@ -163,28 +161,15 @@ do_test (void) print_maps (); -#if USE_PTHREADS - ret = pthread_getattr_np (me, &attr); - if (ret) - { - printf ("after execstack: pthread_getattr_np returned error: %s\n", - strerror (ret)); - return 1; - } - - ret = pthread_attr_getstack (&attr, &new_stack_addr, &stack_size); - if (ret) - { - printf ("after execstack: pthread_attr_getstack returned error: %s\n", - strerror (ret)); - return 1; - } - -# if _STACK_GROWS_DOWN +# if USE_PTHREADS + TEST_VERIFY_EXIT (pthread_getattr_np (me, &attr) == 0); + TEST_VERIFY_EXIT (pthread_attr_getstack (&attr, &new_stack_addr, + &stack_size) == 0); +# if _STACK_GROWS_DOWN new_stack_addr += stack_size; -# else +# else new_stack_addr -= stack_size; -# endif +# endif /* It is possible that the dlopen'd module may have been mmapped just below the stack. The stack size is taken as MIN(stack rlimit size, end of last @@ -194,48 +179,29 @@ do_test (void) stacksize and stackaddr respectively. If the size changes due to the above, then both stacksize and stackaddr can change, but the stack bottom should remain the same, which is computed as stackaddr + stacksize. */ - if (old_stack_addr != new_stack_addr) - { - printf ("Stack end changed, old: %p, new: %p\n", - old_stack_addr, new_stack_addr); - return 1; - } + TEST_VERIFY_EXIT (old_stack_addr == new_stack_addr); printf ("Stack address remains the same: %p\n", old_stack_addr); -#endif +# endif /* Test that growing the stack region gets new executable pages too. */ deeper ((void (*) (void)) f); print_maps (); -#if USE_PTHREADS +# if USE_PTHREADS /* Test that a fresh thread now gets an executable stack. */ - { - pthread_t th; - int rc = pthread_create (&th, NULL, &tryme_thread, f); - if (rc) - error (1, rc, "pthread_create"); - } + xpthread_create (NULL, &tryme_thread, f); puts ("threads go"); /* The existing threads' stacks should have been changed. Let them run to test it. */ - pthread_barrier_wait (&go_barrier); + xpthread_barrier_wait (&go_barrier); pthread_exit ((void *) (long int) (! allow_execstack)); +# endif #endif return ! allow_execstack; } -static void -deeper (void (*f) (void)) -{ - char stack[1100 * 1024]; - explicit_bzero (stack, sizeof stack); - (*f) (); - memfrob (stack, sizeof stack); -} - - #include diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index d9adb5856c..9662b43afe 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -448,25 +448,6 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp, lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE); - - /* There might have been a race. Another thread might have - caused the stacks to get exec permission while this new - stack was prepared. Detect if this was possible and - change the permission if necessary. */ - if (__builtin_expect ((GL(dl_stack_flags) & PF_X) != 0 - && (prot & PROT_EXEC) == 0, 0)) - { - int err = __nptl_change_stack_perm (pd); - if (err != 0) - { - /* Free the stack memory we just allocated. */ - (void) __munmap (mem, size); - - return err; - } - } - - /* Note that all of the stack and the thread descriptor is zeroed. This means we do not have to initialize fields with initial value zero. This is specifically true for diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 91447a5e77..b897da7e7b 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -413,13 +413,6 @@ struct rtld_global #endif #include -#if !PTHREAD_IN_LIBC - /* If loading a shared object requires that we make the stack executable - when it was not, we do it by calling this function. - It returns an errno code or zero on success. */ - EXTERN int (*_dl_make_stack_executable_hook) (void **); -#endif - /* Prevailing state of the stack, PF_X indicating it's executable. */ EXTERN ElfW(Word) _dl_stack_flags; @@ -716,17 +709,10 @@ extern const ElfW(Phdr) *_dl_phdr; extern size_t _dl_phnum; #endif -#if PTHREAD_IN_LIBC -/* This function changes the permissions of all stacks (not just those - of the main stack). */ -int _dl_make_stacks_executable (void **stack_endp) attribute_hidden; -#else -/* This is the initial value of GL(dl_make_stack_executable_hook). - A threads library can change it. The ld.so implementation changes - the permissions of the main stack only. */ -extern int _dl_make_stack_executable (void **stack_endp); -rtld_hidden_proto (_dl_make_stack_executable) -#endif +/* This function changes the permission of the memory region pointed + by STACK_ENDP to executable and update the internal memory protection + flags for future thread stack creation. */ +int _dl_make_stack_executable (void **stack_endp) attribute_hidden; /* Variable pointing to the end of the stack (or close to it). This value must be constant over the runtime of the application. Some programs diff --git a/sysdeps/mach/hurd/dl-execstack.c b/sysdeps/mach/hurd/dl-execstack.c index 31371bc6e3..0222430131 100644 --- a/sysdeps/mach/hurd/dl-execstack.c +++ b/sysdeps/mach/hurd/dl-execstack.c @@ -47,4 +47,3 @@ _dl_make_stack_executable (void **stack_endp) return ENOSYS; #endif } -rtld_hidden_def (_dl_make_stack_executable) diff --git a/sysdeps/nptl/pthreadP.h b/sysdeps/nptl/pthreadP.h index c2db165052..a8e09bf754 100644 --- a/sysdeps/nptl/pthreadP.h +++ b/sysdeps/nptl/pthreadP.h @@ -289,12 +289,6 @@ extern _Noreturn void __syscall_do_cancel (void) attribute_hidden; extern void __nptl_free_tcb (struct pthread *pd); libc_hidden_proto (__nptl_free_tcb) -/* Change the permissions of a thread stack. Called from - _dl_make_stacks_executable and pthread_create. */ -int -__nptl_change_stack_perm (struct pthread *pd); -rtld_hidden_proto (__nptl_change_stack_perm) - /* longjmp handling. */ extern void __pthread_cleanup_upto (__jmp_buf target, char *targetframe); libc_hidden_proto (__pthread_cleanup_upto) diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index 213ff5f1fe..55d565545a 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -360,7 +360,4 @@ ld { __rseq_offset; __rseq_size; } - GLIBC_PRIVATE { - __nptl_change_stack_perm; - } } diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c b/sysdeps/unix/sysv/linux/dl-execstack.c index b986898598..68db6737f0 100644 --- a/sysdeps/unix/sysv/linux/dl-execstack.c +++ b/sysdeps/unix/sysv/linux/dl-execstack.c @@ -16,19 +16,10 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include -#include -#include -#include -#include -#include -#include -#include -static int -make_main_stack_executable (void **stack_endp) +int +_dl_make_stack_executable (void **stack_endp) { /* This gives us the highest/lowest page that needs to be changed. */ uintptr_t page = ((uintptr_t) *stack_endp @@ -52,57 +43,3 @@ make_main_stack_executable (void **stack_endp) return 0; } - -int -_dl_make_stacks_executable (void **stack_endp) -{ - /* First the main thread's stack. */ - int err = make_main_stack_executable (stack_endp); - if (err != 0) - return err; - - lll_lock (GL (dl_stack_cache_lock), LLL_PRIVATE); - - list_t *runp; - list_for_each (runp, &GL (dl_stack_used)) - { - err = __nptl_change_stack_perm (list_entry (runp, struct pthread, list)); - if (err != 0) - break; - } - - /* Also change the permission for the currently unused stacks. This - might be wasted time but better spend it here than adding a check - in the fast path. */ - if (err == 0) - list_for_each (runp, &GL (dl_stack_cache)) - { - err = __nptl_change_stack_perm (list_entry (runp, struct pthread, - list)); - if (err != 0) - break; - } - - lll_unlock (GL (dl_stack_cache_lock), LLL_PRIVATE); - - return err; -} - -int -__nptl_change_stack_perm (struct pthread *pd) -{ -#if _STACK_GROWS_DOWN - void *stack = pd->stackblock + pd->guardsize; - size_t len = pd->stackblock_size - pd->guardsize; -#elif _STACK_GROWS_UP - void *stack = pd->stackblock; - size_t len = (uintptr_t) pd - pd->guardsize - (uintptr_t) pd->stackblock; -#else -# error "Define either _STACK_GROWS_DOWN or _STACK_GROWS_UP" -#endif - if (__mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0) - return errno; - - return 0; -} -rtld_hidden_def (__nptl_change_stack_perm) diff --git a/sysdeps/unix/sysv/linux/mips/Makefile b/sysdeps/unix/sysv/linux/mips/Makefile index d5725c69d8..05ec9150b2 100644 --- a/sysdeps/unix/sysv/linux/mips/Makefile +++ b/sysdeps/unix/sysv/linux/mips/Makefile @@ -61,6 +61,7 @@ ifeq ($(subdir),elf) # this test is expected to fail. ifneq ($(mips-has-gnustack),yes) test-xfail-check-execstack = yes +CFLAGS-tst-execstack.c += -DDEFAULT_RWX_STACK=1 endif endif @@ -68,6 +69,12 @@ ifeq ($(subdir),stdlib) gen-as-const-headers += ucontext_i.sym endif +ifeq ($(subdir),nptl) +ifeq ($(mips-force-execstack),yes) +CFLAGS-tst-execstack-threads.c += -DDEFAULT_RWX_STACK=1 +endif +endif + ifeq ($(mips-force-execstack),yes) CFLAGS-.o += -Wa,-execstack CFLAGS-.os += -Wa,-execstack From patchwork Thu Nov 28 17:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 845954 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp379180wrp; Thu, 28 Nov 2024 09:44:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXWEyGrD7Eg1no5IRNY7hxBIKCHzxIukKF5Yy7DzothnfNqOmIBFKZtUuWXizJOo58W6UK9Yw==@linaro.org X-Google-Smtp-Source: AGHT+IFqW/VWA7YJc+t9bvyThd8iXvDlCH9dyYD5qbOBUxBY0kbGEongSaNLrdiL+AxsiGsX6Nim X-Received: by 2002:a05:6102:3708:b0:4af:4cd4:2923 with SMTP id ada2fe7eead31-4af4cd42b5emr8041192137.3.1732815858224; Thu, 28 Nov 2024 09:44:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732815858; cv=pass; d=google.com; s=arc-20240605; b=CY+6u7aw9SCvAGfiomNcdonbmQ7h3DEzN5lnHIVqHcocD2BrJTYH57nWObRA4nNfPd 0u2UEI2RlZls/G6C4G7tWMuJovVNjQ2K5C0j+f6vUzswL5p3NLJsx22Sm+OSVUCVhF5J ie39ASFvacZWhZXiNMWpI6jsZuxT7v12T2StGCVlE9ZJ24+t54FuZfaP4XMSWy5oGQ+5 Kq9OEeEhz7jyHNeML/lYhbD+x0HniEZljNLS43mMCHJ5w/o1DtVr6LdbsaO4BFZ238c0 CpYJqIIJKz3q0ZfO//qO4jtGVCyO2yDeBRNLW0eCvkTInOLSNmNostUJOIcSQ/vWEA0I ErKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=qcPXfGC7xd7XUl3EcMpXBmjQcyhiTXZ2yJEVUnb/y/A=; fh=5vlP+0ToNsZNUEx4IDYFBtVkL7R0+LPY9AvG1oUICyQ=; b=LbGxHRMI1B0NRFtA/cNTIu+LgV2msk+luU1UGQqw1WIurn1CIIsmR6NPQhN7oz5wVW AJIx/MrGFXHXW+4ioSabbMfLgRw728vqeR45dWY3cNk3Xn8K+BGDfuNaarTwgy8YGr73 Fqm+s3xed6BYgV97+3QjEr3Cca5nSz3yMIQun2H1h5xMVfiOJoLtem0EJxvPj4zB1c61 W1Tijp65+ZJW04R2kedkAsBZpW4ODdexzA/zQtsdgv3aZiT3HAAyaVxseyCkXVUCXH/f N78VA1X4W1rgVAQxaMjRvUv+DU60aT4wsoZvZo9XtwMIwsWQWB+0g3fyNnybwKhQZuUh FlLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F/mWhrm0"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ada2fe7eead31-4af593a1820si633530137.556.2024.11.28.09.44.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:44:18 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="F/mWhrm0"; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CB4283858C53 for ; Thu, 28 Nov 2024 17:44:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB4283858C53 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=F/mWhrm0 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 466EF3858C3A for ; Thu, 28 Nov 2024 17:39:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 466EF3858C3A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 466EF3858C3A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815541; cv=none; b=Pvi4YO1zUWpOnfb7A5BAQCOFfsF9wcHBmnF+MDG63IVQdFE9rdqFGnl5OjHdIiqjuf0hsF+58iO0J7s/DhRQNvoMtdedW6aOBGP4T8ACrFg/Dn30TmrsBMUvPOLswzCEuMTWo7X5cKtH/QmVySJGeHqFX4dpk3XoMzN4EWA8cKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815541; c=relaxed/simple; bh=K2oO4tXSzKSoK5XUBAefyG8djK9ADVBwbgREEEnWyDQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=fcbymGcjdPquxhuvTIZjynJJJGdMAlBN/8djoIHfZljAx2CWJ7Y9v2xJTS979kxOAdHI6BpF0PKkt6LgRQAREDqxN69T/VsYc6zbTygtIGZqNtIVuX+vLpatzpjgF5thePLqwLbb2EquU9VM3KHPbm6qCjw6qroFJLPs+3VCSDM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 466EF3858C3A Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-7251d20e7f2so1092878b3a.0 for ; Thu, 28 Nov 2024 09:39:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732815540; x=1733420340; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qcPXfGC7xd7XUl3EcMpXBmjQcyhiTXZ2yJEVUnb/y/A=; b=F/mWhrm0CkX113bwAOpHGYqGCZlQ2YFoDNG3tTkwnogbJLqc69cCkm8luL08YpdxCD IelbR4oc/hhhji7wVuYx0iBXjibZTMDVlryAlid5O4kAhcpNAfMw+HZVaIj2diBUgX4Z aWfdxATL913FT9LCQJhoG13gW2tH10N/DIK0U0oXOfiQ1xWmSXrgtDvUL9/fnxQL6zPT 09tQ1FHr+YNITnwMvRfX4hrubyvBEB2eZoRzO1T9YHcg3gN6OWB91Er2Tgh4ef2kiTs2 O/asB7ZtvgLJZ1X9uOGHxkJh6jxHPj7L5zLay/Y+0oPobPBTxrUIOgP9kKvxDGv10KqU z2eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732815540; x=1733420340; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qcPXfGC7xd7XUl3EcMpXBmjQcyhiTXZ2yJEVUnb/y/A=; b=a3nKFptO71cDA4kUt5WuHN3G8rOavNSVyiIDG0BCqHWZgeARMBhH+he87/gl10j4he 4KVTgXVLmy/2Wgp4OFma3bORKakIy3dGa2+cRfNZ37331xAcuQIHKStGzdDPjp4q2Jvz RcFUCH4a0pYyFql82dI/leKVO470i8JPlhMJ+eHo+gmWG+AFXBWufSUIEVO7uu1Poq5K W7Kf7Pp5Qc7Mtsposo2hUmq4O/FP+grACwpxx6nkyXIMxWGGEWeS0Fp0qn4KT4HyP2IN hAyAcXr/M/dS2Yp495qP7UwAKfjLVq4bNMSIIOMecCUBOWB+VPwWJ8MWt+FHkpwuKjFx ubNg== X-Gm-Message-State: AOJu0YyCj2VhmWLsUReYWRfxP3oqUH1y1fpqqrQvxETlZ7Ec/0gpfABx 5zBxrvxEFtVyrIWf03sA2aAN/n44aQlT1yi8XGbAtrqCDokz9akdDJz9EA+tlFw9Atk0Tnynv3V oMcq/5w== X-Gm-Gg: ASbGncsixpYxbUPKLAOA5sHcyozkux/cvLOcs+dGU61ResvWO+p1n+DnCk3kq+tUnPA NGlkfKQuvVWoMvav0tXvatV/nnQHjdo5RHvAKqydGsdaQsMw71ElCFhHiLIlHSnpbu8s4XbCBia y6NtfgXxELLhghh3In4q/asJ1J5TXwzJ50Iu5Dpp00xN3++5fL5M/W96vGqDoqUR6DjQ+qcmYG9 Xn6Vjge1oUmVwMnmVAQhdvY5uNxzbm9PPOg1h042IcvuN7AVQUaTcft+junwaA= X-Received: by 2002:a05:6a00:1390:b0:71e:5a1d:ecdc with SMTP id d2e1a72fcca58-7253012f56dmr10609866b3a.17.1732815540024; Thu, 28 Nov 2024 09:39:00 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:68c8:2c85:3a76:728e:ead2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72541849d6csm1860356b3a.182.2024.11.28.09.38.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:38:59 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 3/4] elf: Add tst-execstack-prog-static Date: Thu, 28 Nov 2024 14:36:44 -0300 Message-ID: <20241128173851.1920696-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> References: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org Similar to tst-execstack-prog, check if executable stacks works for statically linked programs. --- elf/Makefile | 7 +++++++ elf/tst-execstack-prog-static.c | 1 + 2 files changed, 8 insertions(+) create mode 100644 elf/tst-execstack-prog-static.c diff --git a/elf/Makefile b/elf/Makefile index ba6b022a2f..bdd169f4e8 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -553,6 +553,9 @@ tests-execstack-yes = \ tst-execstack-needed \ tst-execstack-prog \ # tests-execstack-yes +tests-execstack-static-yes = \ + tst-execstack-prog-static + # tests-execstack-static-yes endif ifeq ($(have-depaudit),yes) tests += \ @@ -647,6 +650,7 @@ $(objpfx)tst-rtld-dash-dash.out: tst-rtld-dash-dash.sh $(objpfx)ld.so $(evaluate-test) tests += $(tests-execstack-$(have-z-execstack)) +tests-static+= $(tests-execstack-static-$(have-z-execstack)) ifeq ($(run-built-tests),yes) tests-special += \ $(objpfx)tst-ldconfig-X.out \ @@ -1916,6 +1920,9 @@ LDFLAGS-tst-execstack-needed = -Wl,-z,noexecstack LDFLAGS-tst-execstack-prog = -Wl,-z,execstack CFLAGS-tst-execstack-prog.c += -Wno-trampolines CFLAGS-tst-execstack-mod.c += -Wno-trampolines + +LDFLAGS-tst-execstack-prog-static = -Wl,-z,execstack +CFLAGS-tst-execstack-prog-static.c += -Wno-trampolines endif LDFLAGS-tst-array2 = -Wl,--no-as-needed diff --git a/elf/tst-execstack-prog-static.c b/elf/tst-execstack-prog-static.c new file mode 100644 index 0000000000..328065dd9c --- /dev/null +++ b/elf/tst-execstack-prog-static.c @@ -0,0 +1 @@ +#include From patchwork Thu Nov 28 17:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 845953 Delivered-To: patch@linaro.org Received: by 2002:adf:f2c4:0:b0:382:43a8:7b94 with SMTP id d4csp378806wrp; Thu, 28 Nov 2024 09:43:28 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVxH9nO5aQDKP9EkwF1rSVOcKnD5UaRpCSBMyen+YsPegUtn89WIZFYzCoLQQtO/voC7SOGKg==@linaro.org X-Google-Smtp-Source: AGHT+IEzCoCslF93BBZDC3cVWASocXVAzdx14exZDEGdpPBRijrnpEYqCz9+H2DEwbC2v9WTULZg X-Received: by 2002:a05:620a:44c9:b0:7b1:800e:ef88 with SMTP id af79cd13be357-7b67c4b481emr1042410385a.60.1732815808130; Thu, 28 Nov 2024 09:43:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1732815808; cv=pass; d=google.com; s=arc-20240605; b=Ji+dYphWpSddJlRLds/a3WQcrY5ZkcI+aJ+t8r48Ha2AW8HNkIXn+uH90EFQGZlHGo s1x8lb2XU1oLvRexnn3FInz1ao65cw1GzOhuA3O6dYxva9i8LcomyQHowX6lFVQ7Vzet RnsINAGFaEjosuFWf+VKkIqD5hdycu/wXD1nel5+ofDnurRk/biGYUCy/CJwNVsLz3Ld L0v4IjCRMBNKKNDbPiCEA4MbJsascH6kYe742N6oqIDH+XAzxTeSco/Cdk6urQNNH0R/ pDwCXo1ZvKbUIjN37w0UptPKHh3iMW3vbpWBhCtGXg+wI+MTQHSoCTeFTFomDIWD14G6 EryA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dkim-filter:arc-filter:dmarc-filter :delivered-to:dkim-filter; bh=+8KrnfauYaJjYtrwZ1iNVu36eg0KTS2J4b7L0CcniRE=; fh=5vlP+0ToNsZNUEx4IDYFBtVkL7R0+LPY9AvG1oUICyQ=; b=Ze1jpUwoZ1KVWFL/q2yxb27xovzTA6c8DPtDznp57YdUhGEqsfeLGDXGXI6MlbBjnX CtZApFAZwO4CHr1MCgqzKkN4QmETzQ0xSNqYg2EpfRKFsEnWacX8Aza7nqLiALkaXFky C5CG8lZvLziQh4YNefBNkmrGPk68Wg3dTeGt5Jg6l7sa/5t5nNeWU49xmKiRnEZx3r1i Bz9oX16yAUh1frK0FEP6NNcNayg96acqWeI6s9UAq1s04LVz6T/QkvZEWWzaQ0WyoNBO CxEr/LYBlrF9phN6K58EXjH/Xbdx+KRRXn3ynwV5gn7ahcxjArIxrC26C4qAcZJ8Pd+N TuuA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rtYUDeKu; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id af79cd13be357-7b6849b2219si265264285a.264.2024.11.28.09.43.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:43:28 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rtYUDeKu; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F01EC3858C2B for ; Thu, 28 Nov 2024 17:43:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F01EC3858C2B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=rtYUDeKu X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id EFD283858D29 for ; Thu, 28 Nov 2024 17:39:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFD283858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFD283858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815543; cv=none; b=IHi/G8WpqRNBRJN9mHvtZf7kvD+ddtJqjfbZEl4feGT2QT7cim5ji7hoMYpjtgWyqot49MM8FjT53viOQamK1HEe85089YPL5nViwRBw19j4CmAMN2VDjPy+0QvhOLFDToUYgnEnJ90AeQ/0LBe6n97SBw/qZC6OX9oaESC1dTI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732815543; c=relaxed/simple; bh=pbufU+N9y0WOuCoUnB7vWE9b+KfpND/Oxhdtpjk71EY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KTnDP+rWp8eRvJrJ3qD5aeeiZcum/0rt5/RyBZ3n6uamUjjKMLerttOAN6TA1BVG+5v/dvgwW7wPqUv9fd2cd7RzeLdSykCvdJVFYjD+3FxgsAi7BryT4Oa9dP4hPaOxqROEp+e8kr/ld82BVzyQIuqjMYjoCyY/9ZdgHkO6QTc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFD283858D29 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-724d8422dbaso978526b3a.0 for ; Thu, 28 Nov 2024 09:39:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1732815541; x=1733420341; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+8KrnfauYaJjYtrwZ1iNVu36eg0KTS2J4b7L0CcniRE=; b=rtYUDeKuG7CHV9QaHFbgWED4V8mj2kfGWkI/oPnmxCrJD7Y3nuZKYyprZr45W4zDlO fXZhryPFH+yJtK5da/E6UAJ7rfSwRCxw1xyPVHCjGXTPmd5xApYHyalsE/xQBAV0a5U4 6ivpemYwy3aeMITeuV4Q9zHqQJKJMXlbTp3GwOmLgIPgIDIV6HBWqhGZoTxMzU/ALwGd tHZGrQ9eqJPj8YjNzX9vGaY9mH6l/o7vWdZbqSX6tIF+YXsZEXTVphHsRPoiHj0RdJjn fB6YRhkdrs+l/mXusb6KZZHUHT74nT55ZDtgCZwtY9dW6bvFvTU7REg/cfs51wzqcCGJ msBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732815541; x=1733420341; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+8KrnfauYaJjYtrwZ1iNVu36eg0KTS2J4b7L0CcniRE=; b=i7zEvl5rmyTaKw53CmnFCMxzh9lN8Jlfc+tHSpSSkj4aNo3AaGz+ZR2J+xbju+YyFc +BdO/pmbsgI21WdxRC4ZcQZRc6NPyksoj5mdvMX0RhSuXkPF7fMpIGeYLu4rBE/Fsywh ldry+lj4dmUdyh4dAvU1gbL3Jc+xNwnbfXbVCTmexagm7uu7/S1UP8RY9Rg6dGfjPz11 9v/X79uFO66DdUyVIMMwskfu0OxUvhDrrd8yQAUlPyoHEsLB3KhDqFy8r6B6NXpEBiBc 4MAqQ//5R6NbFja+vLH+4BjS4CCUCXI8cNVxp/tGbzyklDpNcopb2G3wRKdaFeyEvYS+ 8iYw== X-Gm-Message-State: AOJu0YzLLkRIYq2hu142ZOuo1GswAF/par7rWUFV3eGP/i9BY5ju1vf9 +6aUjnORlou8cwTqxOr7t9r1QVOsy8Qn6xjlujcvds7TZ2W1TMLL48/aHuVeNt0UHM6botTDpGU oHfsBdQ== X-Gm-Gg: ASbGncsYFB+gqPjTBx97ftziGqsxKJ3JnOIJxAkTWHGBXiyIkUwo5xNFgZ2qhyl3QS3 HapvilLlUKEgjaB1i4tAcJ2eLAgozUiNRmMG5Fbjb1Nw3yW6MsbGHT0h2AXwonoLhvoptncaBY1 zGwWdqM9orCGUeiWeft5qbvKof4j+Ezl7NJgborpQgsLoPRFGHa0p+WJZm0P7sFH0KOzGqexOz+ mruHdabnr3+hxfeXKpJfKz3lfqMcDFxz+CPA/zqG6V/JjdWB0F3i1JrtdN282k= X-Received: by 2002:a05:6a00:4f93:b0:71e:4786:98ee with SMTP id d2e1a72fcca58-7253015eecdmr10909457b3a.21.1732815541494; Thu, 28 Nov 2024 09:39:01 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c1:68c8:2c85:3a76:728e:ead2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72541849d6csm1860356b3a.182.2024.11.28.09.39.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2024 09:39:01 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 4/4] elf: Add glibc.rtld.execstack Date: Thu, 28 Nov 2024 14:36:45 -0300 Message-ID: <20241128173851.1920696-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> References: <20241128173851.1920696-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org The new tunable can be used to control whether executable stacks are allowed from either the main program or dependencies. The default is to allow executable stacks. The executable stacks default permission is checked agains the one provided by the PT_GNU_STACK from program headers (if present). The tunable also disables the stack permission change if any dependency requires an executable stack at loading time. Checked on x86_64-linux-gnu, i686-linux-gnu, and aarch64-linux-gnu. --- NEWS | 5 ++++ elf/Makefile | 44 ++++++++++++++++++++++++++++++++++ elf/dl-load.c | 4 +++- elf/dl-support.c | 5 ++++ elf/dl-tunables.list | 6 +++++ elf/rtld.c | 4 ++++ elf/tst-rtld-list-tunables.exp | 1 + manual/tunables.texi | 19 +++++++++++++++ 8 files changed, 87 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 8cb5597631..c2e8bf4b34 100644 --- a/NEWS +++ b/NEWS @@ -38,6 +38,11 @@ Major new features: liable to change. Features from C2Y are also enabled by _GNU_SOURCE, or by compiling with "gcc -std=gnu2y". +* A new tunable, glibc.rtld.execstack, can be used to control whether + executable stacks are allowed from main program, either implicitly due + a mising GNU_STACK ELF header or explicit explicitly because of the + executable bit in GNU_STACK. The default is to allow executable stacks. + Deprecated and removed features, and other changes affecting compatibility: * The big-endian ARC port (arceb-linux-gnu) has been removed. diff --git a/elf/Makefile b/elf/Makefile index bdd169f4e8..6dd15c63d9 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -556,6 +556,13 @@ tests-execstack-yes = \ tests-execstack-static-yes = \ tst-execstack-prog-static # tests-execstack-static-yes +ifeq (yes,$(run-built-tests)) +tests-execstack-special-yes = \ + $(objpfx)tst-execstack-needed-noexecstack.out \ + $(objpfx)tst-execstack-prog-noexecstack.out \ + $(objpfx)tst-execstack-prog-static-noexecstack.out \ + # tests-execstack-special-yes +endif # $(run-built-tests) endif ifeq ($(have-depaudit),yes) tests += \ @@ -651,6 +658,7 @@ $(objpfx)tst-rtld-dash-dash.out: tst-rtld-dash-dash.sh $(objpfx)ld.so tests += $(tests-execstack-$(have-z-execstack)) tests-static+= $(tests-execstack-static-$(have-z-execstack)) +tests-special += $(tests-execstack-special-$(have-z-execstack)) ifeq ($(run-built-tests),yes) tests-special += \ $(objpfx)tst-ldconfig-X.out \ @@ -1923,6 +1931,42 @@ CFLAGS-tst-execstack-mod.c += -Wno-trampolines LDFLAGS-tst-execstack-prog-static = -Wl,-z,execstack CFLAGS-tst-execstack-prog-static.c += -Wno-trampolines + +ifeq (yes,$(build-hardcoded-path-in-tests)) +tst-execstack-prog-noexecstack-msg = "Fatal glibc error: executable stack is not allowed$$" +else +tst-execstack-prog-noexecstack-msg = "error while loading shared libraries:.*cannot enable executable stack as shared object requires:" +endif + +$(objpfx)tst-execstack-prog-noexecstack.out: $(objpfx)tst-execstack-prog + $(test-program-cmd-before-env) \ + $(run-program-env) \ + GLIBC_TUNABLES=glibc.rtld.execstack=0 \ + $(test-program-cmd-after-env) $< \ + > $@ 2>&1; echo "status: $$?" >> $@; \ + grep -q $(tst-execstack-prog-noexecstack-msg) $@ \ + && grep -q '^status: 127$$' $@; \ + $(evaluate-test) + +$(objpfx)tst-execstack-needed-noexecstack.out: $(objpfx)tst-execstack-needed + $(test-program-cmd-before-env) \ + $(run-program-env) \ + GLIBC_TUNABLES=glibc.rtld.execstack=0 \ + $(test-program-cmd-after-env) $< \ + > $@ 2>&1; echo "status: $$?" >> $@; \ + grep -q 'error while loading shared libraries:.*cannot enable executable stack as shared object requires:' $@ \ + && grep -q '^status: 127$$' $@; \ + $(evaluate-test) + +$(objpfx)tst-execstack-prog-static-noexecstack.out: $(objpfx)tst-execstack-prog-static + $(test-program-cmd-before-env) \ + $(run-program-env) \ + GLIBC_TUNABLES=glibc.rtld.execstack=0 \ + $< \ + > $@ 2>&1; echo "status: $$?" >> $@; \ + grep -q 'Fatal glibc error: executable stack is not allowed$$' $@ \ + && grep -q '^status: 127$$' $@; \ + $(evaluate-test) endif LDFLAGS-tst-array2 = -Wl,--no-as-needed diff --git a/elf/dl-load.c b/elf/dl-load.c index f525eec662..0e402968ac 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -32,6 +32,7 @@ #include #include #include +#include /* Type for the buffer we put the ELF header and hopefully the program header. This buffer does not really have to be too large. In most @@ -1284,7 +1285,8 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, /* The stack is presently not executable, but this module requires that it be executable. Only tries to change the stack protection during process startup. */ - if ((mode & __RTLD_DLOPEN) == 0) + if ((mode & __RTLD_DLOPEN) == 0 + && TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL) == 1) errval = _dl_make_stack_executable (stack_endp); else errval = EINVAL; diff --git a/elf/dl-support.c b/elf/dl-support.c index fe1f8c8f6a..73fcd33892 100644 --- a/elf/dl-support.c +++ b/elf/dl-support.c @@ -45,6 +45,7 @@ #include #include #include +#include extern char *__progname; char **_dl_argv = &__progname; /* This is checked for some error messages. */ @@ -331,6 +332,10 @@ _dl_non_dynamic_init (void) break; } + if ((__glibc_unlikely (GL(dl_stack_flags)) & PF_X) + && TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL) == 0) + _dl_fatal_printf ("Fatal glibc error: executable stack is not allowed\n"); + call_function_static_weak (_dl_find_object_init); /* Setup relro on the binary itself. */ diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index 40ac5b3776..8e656296bb 100644 --- a/elf/dl-tunables.list +++ b/elf/dl-tunables.list @@ -135,6 +135,12 @@ glibc { maxval: 1 default: 0 } + execstack { + type: INT_32 + minval: 0 + maxval: 1 + default: 1 + } } mem { diff --git a/elf/rtld.c b/elf/rtld.c index 3b232f8525..baa39b3351 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1644,6 +1644,10 @@ dl_main (const ElfW(Phdr) *phdr, bool has_interp = rtld_setup_main_map (main_map); + if ((__glibc_unlikely (GL(dl_stack_flags)) & PF_X) + && TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL) == 0) + _dl_fatal_printf ("Fatal glibc error: executable stack is not allowed\n"); + /* If the current libname is different from the SONAME, add the latter as well. */ if (GL(dl_rtld_map).l_info[DT_SONAME] != NULL diff --git a/elf/tst-rtld-list-tunables.exp b/elf/tst-rtld-list-tunables.exp index db0e1c86e9..9f5990f340 100644 --- a/elf/tst-rtld-list-tunables.exp +++ b/elf/tst-rtld-list-tunables.exp @@ -13,5 +13,6 @@ glibc.malloc.top_pad: 0x20000 (min: 0x0, max: 0x[f]+) glibc.malloc.trim_threshold: 0x0 (min: 0x0, max: 0x[f]+) glibc.rtld.dynamic_sort: 2 (min: 1, max: 2) glibc.rtld.enable_secure: 0 (min: 0, max: 1) +glibc.rtld.execstack: 1 (min: 0, max: 1) glibc.rtld.nns: 0x4 (min: 0x1, max: 0x10) glibc.rtld.optional_static_tls: 0x200 (min: 0x0, max: 0x[f]+) diff --git a/manual/tunables.texi b/manual/tunables.texi index 0b1b2898c0..c3e894f4fe 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -355,6 +355,25 @@ tests for @code{AT_SECURE} programs and not meant to be a security feature. The default value of this tunable is @samp{0}. @end deftp +@deftp Tunable glibc.rtld.execstack +@theglibc{} will use either the default architecture ABI flags (that might +contain the executable bit) or the value of @code{PT_GNU_STACK} (if present) +to define whether to mark the stack non-executable, and if the program or +any shared library dependency require an executable stack the loader will +change the main stack permission if kernel starts with a non executable stack. + +The @code{glibc.rtld.execstack} tunable allows the user to control how +to proceed regarding the stack execution bit. Setting its value to @code{0} +disables executable stacks, where @code{1} enables it. The default value +is @code{1}. + +When executable stacks are not allowed, and if the main program requires an +executable stack, the loader will fail with an error message. +@strong{NB:} Trying to load a dynamic shared library with @code{dlopen} or +@code{dlmopen} that requires an executable stack will always fail if the +default flags does not contain the executable bit. +@end deftp + @node Elision Tunables @section Elision Tunables @cindex elision tunables