From patchwork Mon Feb 10 19:29:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 863820 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e42:0:b0:385:e875:8a9e with SMTP id r2csp1764691wrt; Mon, 10 Feb 2025 11:31:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU6/1IhMbSrvZwwVv7QOJsGB3kkscaAYu/UFhd9V8QraOjwU76UVDohoUmPgoF8fwwVV/rcMg==@linaro.org X-Google-Smtp-Source: AGHT+IFPTTYcwayb9jWc07Aj/vYcDzVmtA0Zd77J5RVLQY9vXxxRI8pnRNXE40zgHIoncS68r1+Q X-Received: by 2002:a05:6902:2783:b0:e5b:f5f:5960 with SMTP id 3f1490d57ef6-e5b461662f3mr13037525276.1.1739215862453; Mon, 10 Feb 2025 11:31:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1739215862; cv=pass; d=google.com; s=arc-20240605; b=G3DhhGjgon844YoWsLEOIWoNBYXG7hCoJShjnW637Pc0kWjOhvYBm9dWtHgY3JCYz7 9PH5eQUxoPzZhJskdu/MHOU/3wpnVm6+i6knFGrDJw5KPuzcI+TQ/RMnG47Ibd5BTcDa QJEOjBBL6z56I6pDcS1oQ2SFvmzkEICtDNmfMeLJNoYzyBQPJbBA9N0cYWOYPjy/CHpK XRt1A5s6HzkD66qWwOmhIC2PHj1RRUyQM2kJkTsaprRO1eqfAqmjr6DOhGjAoGfW/Jsz mGLyKkhnmoXnK60G6zdCNfG8FWYMIBUAhmawAr7KLANLBQ2Vg48hXe6HDzs86CHZm/Da 1zUA== 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:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=EHP+gsJXV+LWFXCmxYUKA35BozlI7iL/2L6aFAlVM84=; fh=rCa3ppVe5iCiIg2hlr/ZWmuMjHCO35lkvmJd+GFan0o=; b=jzjSaHPck/v8N/RpRfjXFMOfIvSfkEhUqgn+DVRTNGoKgZcou4YHonrei7fi6Wb+nd 93qDv54t3Z4QACOxpHDMTM6KSZ2jxwY7I608PG9aD3YiVuorNS8Z/S+cluPiL7Umrkvs EfKZussN9N9IKQ8mxRmrEJ+GNVvu1iKOSAztJSWXMv2Hzo5PwLVFOhq8bxKrOCmJLPp1 ZCkiuld5RjAUYbuM4ogjj83lx3aszP9w1k4lLTsBOUKrNXe7tL9AWtl7TAOKKOVyjrob 9kiqhnkonlD8wwANUg7DpQlEErO0uHvY9LyMGkHMl49Wzp+5VtMB+Q13DsF7X5dxHbZl IKrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a6K7u5xD; 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 3f1490d57ef6-e5b3a485026si9415969276.474.2025.02.10.11.31.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 11:31:02 -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=a6K7u5xD; 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 DEAF53858435 for ; Mon, 10 Feb 2025 19:31:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DEAF53858435 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=a6K7u5xD X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 5A73A385841D for ; Mon, 10 Feb 2025 19:30:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A73A385841D 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 5A73A385841D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::632 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739215833; cv=none; b=VFyos3D/H9PhDKj6msS80kQNquQVihwGbq+tAxXuUlYftSCdXB5mV+SzezOTWzQmKGUBfPuy8RgV8oIaXFM5zI5L5h5Hq3bjIBtiVePiSi/vo6Emqh4on/R/LxomtnuKaUin/jx1w8wUwPa5lMDIyXCweYIYnYnfZVFYtRPnZ4M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739215833; c=relaxed/simple; bh=EqRhTMjc0qgIRXm4DUX5LMgVVr1F7be1Vt2vHePAgCo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=k8NCrRN4+lm3eueYBmaAS/piJ0wDGr9fdVBPk226yf+2KuOI5URqRbHS5oXMQLGQrmdFXb3DfSDJF3kAepBmTzaU9DJApc2CjpTtFQ/LMmvba1CLdD/7kgPRHtUDQm7nrQkgrBtkUnN2dDvCKyrupRwM/q2nN9gbQneF+MZwb1g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A73A385841D Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-21f44e7eae4so76900385ad.2 for ; Mon, 10 Feb 2025 11:30:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1739215832; x=1739820632; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EHP+gsJXV+LWFXCmxYUKA35BozlI7iL/2L6aFAlVM84=; b=a6K7u5xD2X0fyo6/fKe6o2E44Y+WSXTaN6pwBCU6b0fR/0lG6x0zoUPUhRs27sAIFR FVglv1R6vMOQ835Q9g6jowiLc4pbkkZPfPUnFmL+YDWDEUiQlgkiSw4tmOdQtu4Iuo/6 qnnAF6EDL4ToxzgurCJkar2mmwhKRHEB1/SWUEBE72DPAcm5Ln0s2pyVtI59qGp7Ki6U dlNtA8XIgTNm1s/Du0MGJ2DzZEEHUh7nIyo/6vslDGTEeFR5wD5wJZrZVrZ0EMpB61yV 8petY0BLnnrpwnujyUsWemTYlFsdahDOGamNzzPrtRi1uhE7qgO3DZAQb6Ro1LuCt1cp SN7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739215832; x=1739820632; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EHP+gsJXV+LWFXCmxYUKA35BozlI7iL/2L6aFAlVM84=; b=d9a8xB7tLQ2GQeqeEw0ABfmuQfLYNd4XoM1vEOxu1oNdXuXvXyosdhf/vDEwHdIv3U Fp3B0rAVlTjo8bm6ONcXtCLuRRwaUJwtNJmloxV0kXOYuNGSyf0mwAyEsMOqwzEqwMK3 5A4ZNZVzgEJwtZN/Ivafy55WhzRbplPG6jkcxh9cX7u1PjuhMWmRl7PDQWolQeOaHvri mIZfDPK02BdBmVzyJY1z4X9cMtXdPsyZlF9CS5hg5vIlNBKJjWxvv+DrKTaw821Y1T+u FyYiMDzHjQjR9EGkhJ1qtCuNLe2pWv8VokN07yRIQW3E9BLxepst55HnqEauPSDPChF4 db4A== X-Gm-Message-State: AOJu0YxHrJhVH2ZV+J96npKcJVP+FJPd+f1LPi9pmuizs3LJozmFOTdk uRCobWd0wBS5JrfyxStJ7/QpVpho45OVViwMEajYlB1meuUAWdMMQHN4g8DboMkaWT/2naqyfba P X-Gm-Gg: ASbGncssO3sjxTbipVcOAwvNTjWKpluVxsSdtjukDOXaX+BphKo/Nxc+Y++/H5qVD7J c3/bj/JDYHpwemPNv014k3kcX83BCOVoPzEPAkyjQHYuyq7eBjXd7hLZ1n1t+oiJE4neLr03vYP aTutZP2Sz/3S7MZ7O3WumJfA+bw0FRvexuc9AM2DilhCQj2GrIv6RGWHn1BphvvDVRiBd1FYz0W pR9qwCOluAkJlrRy4q1esxm8cTPZKPKLodGVzongwMiCqqs4VnMdz0DHMDRPZdX8LgH6yYs0pHn uIGamEIBP4xMz1fpHjGmPLeqRZkf X-Received: by 2002:a05:6a21:2d0b:b0:1e1:b44f:cff1 with SMTP id adf61e73a8af0-1ee03b4227bmr25952915637.33.1739215831804; Mon, 10 Feb 2025 11:30:31 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:c933:6ede:a43f:9b59:5001]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ad54a066811sm3200855a12.8.2025.02.10.11.30.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Feb 2025 11:30:31 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Sam James , Florian Weimer , Ethan Lee Subject: [PATCH] elf: Extend glibc.rtld.execstack tunable to force executable stack (BZ 32653) Date: Mon, 10 Feb 2025 16:29:30 -0300 Message-ID: <20250210193026.3387809-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 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 >From the bug report [1], multiple programs still require to dlopen shared libraries with either missing PT_GNU_STACK or with the executable bit set. Although, in some cases, it seems to be a hard-craft assembly source without the required PT_GNU_STACK mark (so the loader is forced to set an RWE), other cases seem that the library uses trampolines [2]. Unfortunately, READ_IMPLIES_EXEC is not an option since on some ABIs (x86_64), the kernel clears the bit, making it unsupported. To avoid reinstating the broken code that changes stack permission on dlopen (0ca8785a28), this patch extends the glibc.rtld.execstack tunable to allow an option to force an executable stack at the program startup. The tunable is a security issue because it defeats the PT_GNU_STACK hardening. It has the slight advantage of making it explicit by the caller, and, as for other tunables, this is disabled for setuid binaries. A tunable also allows us to eventually remove it, but from previous experiences, it would require some time. Checked on x86_64-linux-gnu and i686-linux-gnu. [1] https://sourceware.org/bugzilla/show_bug.cgi?id=32653 [2] https://github.com/conda-forge/ctng-compiler-activation-feedstock/issues/143 --- I am marking this a RFC because I am not about the security implications. The glibc 2.41 with 0ca8785a28 fixed a long standing security issue where some security guarantee were being change during process execution, while still enforcing the PT_GNU_STACK during process execution. This compatibility patch removes the enforcement, since user may override the PT_GNU_STACK with an environment variable. This in theory is a hardening drowgrade, but this is also what users seems to be doing with execstack to override the binary PT_GNU_STACK header. --- csu/libc-start.c | 3 ++ elf/dl-tunables.list | 2 +- elf/rtld.c | 1 + elf/tst-rtld-list-tunables.exp | 2 +- manual/tunables.texi | 10 +++-- sysdeps/generic/ldsodefs.h | 4 ++ sysdeps/unix/sysv/linux/Makefile | 12 ++++++ sysdeps/unix/sysv/linux/dl-execstack.c | 29 ++++++++++++-- .../unix/sysv/linux/include/sys/personality.h | 12 ++++++ .../linux/tst-execstack-tunable-execstack.c | 1 + .../linux/tst-execstack-tunable-skeleton.c | 39 +++++++++++++++++++ .../unix/sysv/linux/tst-execstack-tunable.c | 39 +++++++++++++++++++ 12 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/include/sys/personality.h create mode 100644 sysdeps/unix/sysv/linux/tst-execstack-tunable-execstack.c create mode 100644 sysdeps/unix/sysv/linux/tst-execstack-tunable-skeleton.c create mode 100644 sysdeps/unix/sysv/linux/tst-execstack-tunable.c diff --git a/csu/libc-start.c b/csu/libc-start.c index 6f3d52e223..7a13961b18 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -307,6 +307,9 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), #endif /* !SHARED */ + /* Make the thread executable if required. */ + GLRO(dl_check_executable_stack) (); + /* Register the destructor of the dynamic linker if there is any. */ if (__glibc_likely (rtld_fini != NULL)) __cxa_atexit ((void (*) (void *)) rtld_fini, NULL, NULL); diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index 0b6721bc51..c03c9967f0 100644 --- a/elf/dl-tunables.list +++ b/elf/dl-tunables.list @@ -138,7 +138,7 @@ glibc { execstack { type: INT_32 minval: 0 - maxval: 1 + maxval: 2 default: 1 } } diff --git a/elf/rtld.c b/elf/rtld.c index 115f1da37f..573197a484 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -372,6 +372,7 @@ struct rtld_global_ro _rtld_global_ro attribute_relro = ._dl_error_free = _dl_error_free, ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft, ._dl_libc_freeres = __rtld_libc_freeres, + ._dl_check_executable_stack = _dl_check_executable_stack, }; /* If we would use strong_alias here the compiler would see a non-hidden definition. This would undo the effect of the previous diff --git a/elf/tst-rtld-list-tunables.exp b/elf/tst-rtld-list-tunables.exp index 9f5990f340..8df6f5906e 100644 --- a/elf/tst-rtld-list-tunables.exp +++ b/elf/tst-rtld-list-tunables.exp @@ -13,6 +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.execstack: 1 (min: 0, max: 2) 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 7f0246c789..5c96fae769 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -365,8 +365,11 @@ change the main stack permission if kernel starts with a non-executable stack. The @code{glibc.rtld.execstack} can be used to control whether an executable stack is allowed from the main program. Setting the value to @code{0} disables the ABI auto-negotiation (meaning no executable stacks even if the ABI or ELF -header requires it), while @code{1} enables auto-negotiation (although the -program might not need an executable stack). +header requires it), @code{1} enables auto-negotiation (although the program +might not need an executable stack), while @code{2} forces and executable +stack during initialization (this is provide for compatibility reasons, where +the program requires to dynamically load modules with executable stacks with +@code{dlopen}). When executable stacks are not allowed, and if the main program requires it, the loader will fail with an error message. @@ -380,7 +383,8 @@ of hardware capabilities and kernel configuration. @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 main program does not require an executable stack at loading time. This -is enforced regardless of the tunable value. +can be disable by setting the tunable to @code{2}, where the stack is +always executable. @end deftp @node Elision Tunables diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 8465cbaa9b..caed31e17f 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -671,6 +671,8 @@ struct rtld_global_ro /* Called from __libc_shared to deallocate malloc'ed memory. */ void (*_dl_libc_freeres) (void); + int (*_dl_check_executable_stack) (void); + /* Implementation of _dl_find_object. The public entry point is in libc, and this is patched by __rtld_static_init to support static dlopen. */ @@ -707,6 +709,8 @@ extern const ElfW(Phdr) *_dl_phdr; extern size_t _dl_phnum; #endif +int _dl_check_executable_stack (void) attribute_hidden; + /* 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. */ diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 395d2d6593..364fd66aab 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -681,6 +681,18 @@ tests-special += \ $(objpfx)tst-nolink-libc-2.out \ # tests-special endif + +ifeq ($(have-z-execstack),yes) +tests += \ + tst-execstack-tunable \ + # tests + +# Re-use the module with an executable stack from elf/Makefile +$(objpfx)tst-execstack.out: $(objpfx)tst-execstack-mod.so + +tst-execstack-tunable-ENV = GLIBC_TUNABLES=glibc.rtld.execstack=2 +endif + endif # $(subdir) == elf ifeq ($(subdir),rt) diff --git a/sysdeps/unix/sysv/linux/dl-execstack.c b/sysdeps/unix/sysv/linux/dl-execstack.c index 9791b339ca..a8fa21dfda 100644 --- a/sysdeps/unix/sysv/linux/dl-execstack.c +++ b/sysdeps/unix/sysv/linux/dl-execstack.c @@ -17,9 +17,10 @@ . */ #include +#include -int -_dl_make_stack_executable (void **stack_endp) +static int +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 @@ -35,11 +36,31 @@ _dl_make_stack_executable (void **stack_endp) ) != 0) return errno; + /* Remember that we changed the permission. */ + GL(dl_stack_flags) |= PF_X; + + return 0; +} + +int +_dl_make_stack_executable (void **stack_endp) +{ + int r = make_stack_executable (stack_endp); + if (r != 0) + return r; + /* Clear the address. */ *stack_endp = NULL; - /* Remember that we changed the permission. */ - GL(dl_stack_flags) |= PF_X; + return r; +} +int +_dl_check_executable_stack (void) +{ + if (TUNABLE_GET (glibc, rtld, execstack, int32_t, NULL) == 2) + /* We can't clean the __libc_stack_end because it is marked as RO + when this function is called. */ + return make_stack_executable (&__libc_stack_end); return 0; } diff --git a/sysdeps/unix/sysv/linux/include/sys/personality.h b/sysdeps/unix/sysv/linux/include/sys/personality.h new file mode 100644 index 0000000000..794047a488 --- /dev/null +++ b/sysdeps/unix/sysv/linux/include/sys/personality.h @@ -0,0 +1,12 @@ +#ifndef _INCLUDE_SYS_PERSONALITY_H +#define _INCLUDE_SYS_PERSONALITY_H 1 + +#include_next + +# ifndef _ISOMAC + +extern __typeof (personality) __personality __THROW; +hidden_proto (__personality) + +# endif /* _ISOMAC */ +#endif /* sys/sysinfo.h */ diff --git a/sysdeps/unix/sysv/linux/tst-execstack-tunable-execstack.c b/sysdeps/unix/sysv/linux/tst-execstack-tunable-execstack.c new file mode 100644 index 0000000000..50e4fa5299 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-execstack-tunable-execstack.c @@ -0,0 +1 @@ +#include "tst-execstack-tunable-skeleton.c" diff --git a/sysdeps/unix/sysv/linux/tst-execstack-tunable-skeleton.c b/sysdeps/unix/sysv/linux/tst-execstack-tunable-skeleton.c new file mode 100644 index 0000000000..e91f85edb7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-execstack-tunable-skeleton.c @@ -0,0 +1,39 @@ +/* Check glibc.rtld.execstack=2 makes the stack executable. + + Copyright (C) 2025 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 + . */ + +#include +#include +#include + +#include +#include + +static int +do_test (void) +{ + void *h = dlopen ("tst-execstack-mod.so", RTLD_LAZY); + TEST_VERIFY (h != NULL); + + void (*f)(void) = xdlsym (h, "tryme"); + f (); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/tst-execstack-tunable.c b/sysdeps/unix/sysv/linux/tst-execstack-tunable.c new file mode 100644 index 0000000000..7a5954ad9c --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-execstack-tunable.c @@ -0,0 +1,39 @@ +/* Check if READ_IMPLIES_EXEC makes the initial stack executable (BZ#32653) + + Copyright (C) 2025 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 + . */ + +#include +#include +#include + +#include +#include + +static int +do_test (void) +{ + void *h = dlopen ("tst-execstack-mod.so", RTLD_LAZY); + TEST_VERIFY (h != NULL); + + void (*f)(void) = xdlsym (h, "tryme"); + f (); + + return 0; +} + +#include