From patchwork Tue May 20 15:55:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 112702 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AE6F385843D for ; Tue, 20 May 2025 15:58:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AE6F385843D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=V/ms+w/s X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id A1A78385800F for ; Tue, 20 May 2025 15:55:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A1A78385800F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A1A78385800F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747756558; cv=none; b=SMhptgigaOzciMf1GkZs1Vs0AdlNl0RcDHodVEUOg31QBJYl3Tz/WNwTc2SWvNovMXO5PY6y5enUGVpzJN+cC4dpuncOgBweRQ0tTFxwJS4x3ZI4gwEHBU34kPvMMoMOV8+dw++Ta8DkxrSt/ImsCyM3MNvxxSnGMT2VZG3eou0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747756558; c=relaxed/simple; bh=W5aWqL0kTO9bX270zToKyKWKMsQAS8dTyUePWY2s3gY=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=qDNxK1eMUd1e1MgOgm7TjEYfB1EttYs5FP6yetc38G4AiUkdAXpyz10mp/ClNrAqfFkTYTp6PjfVqdS0r0lpo6YMo9enxHGKZ/ptR8lwndMA0+7FXuUvNw6z1zadxXQeFFhlN3nWucWMsaSFCBml17jPyPdK7gsy/iC/lfUUz6I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1A78385800F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747756558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=M24MPJTLkvRyMYELNRoiyyW3n4e+PJSO2eeQgijxbk8=; b=V/ms+w/sobSz4LyX+FVNlIcR68SWA6lIChDJikCB65cP5RxzRjGeiq5jFGVRS9VG/cJapW thMset/mhWp5N7BM82TF0B389ybH05GvokrJrt7nFuz43JHrkEvU2kzA3bJLsWMLmIKmAw zRgOfwAblBS7Qc01mWzgPfRCS+hfuVI= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-16-mu0qaE5nMvOTSrWYjvMCkA-1; Tue, 20 May 2025 11:55:57 -0400 X-MC-Unique: mu0qaE5nMvOTSrWYjvMCkA-1 X-Mimecast-MFC-AGG-ID: mu0qaE5nMvOTSrWYjvMCkA_1747756556 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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 mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28C0B19560A0 for ; Tue, 20 May 2025 15:55:56 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.247]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6BF2119560A3 for ; Tue, 20 May 2025 15:55:55 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 1/2] support: Use const char * argument in support_capture_subprogram_self_sgid Message-ID: X-From-Line: d6ba7e599b3f8d587771a5ef5972d28f228f21bc Mon Sep 17 00:00:00 2001 Date: Tue, 20 May 2025 17:55:52 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: YETohCHwnw42P35hD2McU7t_v1QQPeIi-_4Flpi1BQ8_1747756556 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org The function does not modify the passed-in string, so make this clear via the prototype. Reviewed-by: Carlos O'Donell --- support/capture_subprocess.h | 3 +-- support/support_capture_subprocess.c | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) base-commit: 2071666d0387c3723db3141ee026e963ac840a4e diff --git a/support/capture_subprocess.h b/support/capture_subprocess.h index 91d75e5d6b..77140430d2 100644 --- a/support/capture_subprocess.h +++ b/support/capture_subprocess.h @@ -45,8 +45,7 @@ struct support_capture_subprocess support_capture_subprogram /* Copy the running program into a setgid binary and run it with CHILD_ID argument. If execution is successful, return the exit status of the child program, otherwise return a non-zero failure exit code. */ -int support_capture_subprogram_self_sgid - (char *child_id); +int support_capture_subprogram_self_sgid (const char *child_id); /* Deallocate the subprocess data captured by support_capture_subprocess. */ diff --git a/support/support_capture_subprocess.c b/support/support_capture_subprocess.c index c3ef478d17..d99aafd370 100644 --- a/support/support_capture_subprocess.c +++ b/support/support_capture_subprocess.c @@ -110,7 +110,7 @@ support_capture_subprogram (const char *file, char *const argv[], safely make it SGID with the TARGET group ID. Then runs the executable. */ static int -copy_and_spawn_sgid (char *child_id, gid_t gid) +copy_and_spawn_sgid (const char *child_id, gid_t gid) { char *dirname = xasprintf ("%s/tst-tunables-setuid.%jd", test_dir, (intmax_t) getpid ()); @@ -182,7 +182,7 @@ copy_and_spawn_sgid (char *child_id, gid_t gid) ret = 0; infd = outfd = -1; - char * const args[] = {execname, child_id, NULL}; + char * const args[] = {execname, (char *) child_id, NULL}; status = support_subprogram_wait (args[0], args); @@ -211,7 +211,7 @@ err: } int -support_capture_subprogram_self_sgid (char *child_id) +support_capture_subprogram_self_sgid (const char *child_id) { gid_t target = 0; const int count = 64; From patchwork Tue May 20 15:56:12 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 112701 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B7AD3858C62 for ; Tue, 20 May 2025 15:57:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B7AD3858C62 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EW0ffHpt X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id B2DB03858C42 for ; Tue, 20 May 2025 15:56:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2DB03858C42 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B2DB03858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747756578; cv=none; b=GKj0mrbg1fcLL1T7Jcpr325UG9K6pXJZVLYJBWi5693PdhQ7QNe22no5gQql2ook/DfMVwdTPJYXwMB2selJE2iI8IyymeFhz2Ug9/WlmJO5NLz3PaANlGSflJNQKzY4LxfXKJlqjIBdhqaZiZLindCuM3CN7l/fT+63rU9m238= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747756578; c=relaxed/simple; bh=hDR2PzKNGxcmYyi3u/gW+33E2FLt1dSUbQ1wz7EeZRY=; h=DKIM-Signature:From:To:Subject:Message-ID:Date:MIME-Version; b=JQQlZc/SWaBw4ohHwg5VS7QO12AXrtlKZByqsTlgG7I5W3HUbd1BEy0q6/opINeJZQxzpqT97NNPSIgqOHieWQL3u8AuApnc3cNywR9miHxfw0On+l0tT4HroUvsmvE2J+DdosumBVkF+v9d42wEyQEn7HYuxdjTT0qK8gYrFik= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2DB03858C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747756578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BF76A2yz1SxHXcQcLOPzwPZAijn0R024ptXbrLr1Gfo=; b=EW0ffHptxRD4QgvU0+szwT3tAViCG7THUWCNCg42Sio6whqGRYPKMOjun8XPRNgcBSj2UY 8bqzt4ivMw2LuRJrGCxuSqPeXTBgQMFei5wMQc/hVqFaMbBmjnpYJ3S6shM5teuaSMXoNZ N2SLbVNkjKpJj2w8m1+b7P2PnV3bUiY= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-uA3EhLy4OUKxCpHRnfFUeg-1; Tue, 20 May 2025 11:56:16 -0400 X-MC-Unique: uA3EhLy4OUKxCpHRnfFUeg-1 X-Mimecast-MFC-AGG-ID: uA3EhLy4OUKxCpHRnfFUeg_1747756575 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B29C81800877 for ; Tue, 20 May 2025 15:56:15 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.247]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0452618004A7 for ; Tue, 20 May 2025 15:56:14 +0000 (UTC) From: Florian Weimer To: libc-alpha@sourceware.org Subject: [PATCH 2/2] elf: Test case for bug 32976 (CVE-2025-4802) In-Reply-To: Message-ID: <610de38037af616049bd94c3436033b1611fb55a.1747756521.git.fweimer@redhat.com> References: X-From-Line: 610de38037af616049bd94c3436033b1611fb55a Mon Sep 17 00:00:00 2001 Date: Tue, 20 May 2025 17:56:12 +0200 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: VG_9gelt21Tozst3dl4q6hjdYQufmVCF487ZqaVNH2Y_1747756575 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org Check that LD_LIBRARY_PATH is ignored for AT_SECURE statically linked binaries, using support_capture_subprogram_self_sgid. Reviewed-by: Carlos O'Donell --- elf/Makefile | 4 ++ elf/tst-dlopen-sgid-mod.c | 1 + elf/tst-dlopen-sgid.c | 104 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 elf/tst-dlopen-sgid-mod.c create mode 100644 elf/tst-dlopen-sgid.c diff --git a/elf/Makefile b/elf/Makefile index ed1b0223da..f8f015b907 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -268,6 +268,7 @@ tests-static-normal := \ tst-array1-static \ tst-array5-static \ tst-dl-iter-static \ + tst-dlopen-sgid \ tst-dst-static \ tst-env-setuid-static \ tst-getauxval-static \ @@ -923,6 +924,7 @@ modules-names += \ tst-dlopen-auditdupmod \ tst-dlopen-constructor-null-mod1 \ tst-dlopen-constructor-null-mod2 \ + tst-dlopen-sgid-mod \ tst-dlopen-tlsreinitmod1 \ tst-dlopen-tlsreinitmod2 \ tst-dlopen-tlsreinitmod3 \ @@ -3488,3 +3490,5 @@ $(objpfx)tst-origin.out: tst-origin.sh $(objpfx)tst-origin liborigin-mod.so \ > $@; \ $(evaluate-test) + +$(objpfx)tst-dlopen-sgid.out: $(objpfx)tst-dlopen-sgid-mod.so diff --git a/elf/tst-dlopen-sgid-mod.c b/elf/tst-dlopen-sgid-mod.c new file mode 100644 index 0000000000..5eb79eef48 --- /dev/null +++ b/elf/tst-dlopen-sgid-mod.c @@ -0,0 +1 @@ +/* Opening this object should not succeed. */ diff --git a/elf/tst-dlopen-sgid.c b/elf/tst-dlopen-sgid.c new file mode 100644 index 0000000000..47829a405e --- /dev/null +++ b/elf/tst-dlopen-sgid.c @@ -0,0 +1,104 @@ +/* Test case for ignored LD_LIBRARY_PATH in static startug (bug 32976). + 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 +#include +#include +#include +#include +#include +#include + +/* This is the name of our test object. Use a custom module for + testing, so that this object does not get picked up from the system + path. */ +static const char dso_name[] = "tst-dlopen-sgid-mod.so"; + +/* Used to mark the recursive invocation. */ +static const char magic_argument[] = "run-actual-test"; + +static int +do_test (void) +{ +/* Pathname of the directory that receives the shared objects this + test attempts to load. */ + char *libdir = support_create_temp_directory ("tst-dlopen-sgid-"); + + /* This is supposed to be ignored and stripped. */ + TEST_COMPARE (setenv ("LD_LIBRARY_PATH", libdir, 1), 0); + + /* Copy of libc.so.6. */ + { + char *from = xasprintf ("%s/%s", support_objdir_root, LIBC_SO); + char *to = xasprintf ("%s/%s", libdir, LIBC_SO); + add_temp_file (to); + support_copy_file (from, to); + free (to); + free (from); + } + + /* Copy of the test object. */ + { + char *from = xasprintf ("%s/elf/%s", support_objdir_root, dso_name); + char *to = xasprintf ("%s/%s", libdir, dso_name); + add_temp_file (to); + support_copy_file (from, to); + free (to); + free (from); + } + + TEST_COMPARE (support_capture_subprogram_self_sgid (magic_argument), 0); + + free (libdir); + + return 0; +} + +static void +alternative_main (int argc, char **argv) +{ + if (argc == 2 && strcmp (argv[1], magic_argument) == 0) + { + if (getgid () == getegid ()) + /* This can happen if the file system is mounted nosuid. */ + FAIL_UNSUPPORTED ("SGID failed: GID and EGID match (%jd)\n", + (intmax_t) getgid ()); + + /* Should be removed due to SGID. */ + TEST_COMPARE_STRING (getenv ("LD_LIBRARY_PATH"), NULL); + + TEST_VERIFY (dlopen (dso_name, RTLD_NOW) == NULL); + { + const char *message = dlerror (); + TEST_COMPARE_STRING (message, + "tst-dlopen-sgid-mod.so:" + " cannot open shared object file:" + " No such file or directory"); + } + + support_record_failure_barrier (); + exit (EXIT_SUCCESS); + } +} + +#define PREPARE alternative_main +#include