From patchwork Tue Jun 11 15:27:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 1946405 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=aFHIJLDQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzCPW5Rtbz20Py for ; Wed, 12 Jun 2024 01:33:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11C4D385DDFB for ; Tue, 11 Jun 2024 15:33:34 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id CC43E385DDE6 for ; Tue, 11 Jun 2024 15:32:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CC43E385DDE6 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 CC43E385DDE6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718119965; cv=none; b=IVhr4IUevXb7QhW83QOV62cmVlg6BzClX1LR/VORaM9EYB3PXa0YZqnr0GUdedbiDac6i18F3FVuoquRZmR7DM92zT7L2Namjfce1JURxUzqHecVT6aww4O5aEAnfAutwCWsHm834k7iChmCbDEzqn1tO9xkA9mfKDmKWwqUDWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718119965; c=relaxed/simple; bh=FhBU3T+zdv3Xj88T1ncqfgOT2bZ06o7xH3vFHAKYFeQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=J3TdC8otBqqIyMsR/ZaEGruGmoDdGelt81NEnYxbIAipvuV/gonmOr2YG/8KazzlOiaHITc3Y5j9UDwPqL8zdX8RJX1aKxfHeoKjQU9xSGuc3ry6w1G0U0OuMsZ1fiMaezaoG5BeTmwgCaEMj2F8H33vN/8u38r2dc5WFUNEntU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-70109d34a16so5390920b3a.2 for ; Tue, 11 Jun 2024 08:32:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718119961; x=1718724761; 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=Xmphwhr+iTAJGwS9wSN4vGADMl6gfC25KCNXJlSglXU=; b=aFHIJLDQvoQb/aHA2k9RhLw05xCyoersQenvYNGaG4o8a42rfVsTumigqOfuX+xC7c Bim7pSRLWx7gVLPjoee3e+hxty/iSTbdjSk81KbS7d0yYy+13QetFfTP7Dsid/fsstwp 7hkXB6VLSS9KFymFdN9vD/AJ1rqr+6bQS75rujRmRGIRMxikmI8PA+uP3vcw/5sxh9gD d0BTBrOiOnkUOfUj2Emge83mdbz6HJnKNjVda6Y/f580BQf+U8W+fROmOkGIkyawrrxh +slqcaMd5DThAhlncmUUGw0WyGVrWn5Pj5ni971pFkeFrI/PBfkNFXlBXAfz4EfHuFSy M13Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718119961; x=1718724761; 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=Xmphwhr+iTAJGwS9wSN4vGADMl6gfC25KCNXJlSglXU=; b=sXXWOhi2Vmr50LiJnNw2RaGozVziMh0pHQGTX+QCMUZzUp8dgNAbFY7Akg47qLUjDM WF0GuNcljC19vu20IHyzlkPfZIIDXtBYxbSFIhMsWiQROyuWLmupVfi2bzCIiRb9r9iL oZgpbRPqLdgf/bLn+fBjIrbQiZmZeO3/wMwwYk42Ld1t1p5pbtSoG931Z7DOeuZnyNjc zv4rVsSf3jVeZGor8Jn1tNoTSEu4cBwFncLG6ZHYX7xGIL7dI2E5g7Xrjms6COWzmmpE ywB15kc8LSWonntl31WOtzxKLcRtLjn0kFhKgh5/J9cZWEVxos+m4hHmxtcmDrf6Pyln nvVg== X-Gm-Message-State: AOJu0YzyqOqNYZHpcZxqtxSdyST+BQNpiB/mHD8IfqH47BO9qzRzXpM6 Gtr6duny3xqd94151nhJnMkMDJD/A5dDOvf5Y3bZRVhejT2j5xEjgGAq7IpQERNi7gaLEEwhKMY i X-Google-Smtp-Source: AGHT+IFa6qrpFe7kuXrXjJNlGm+7AfXV4Q/iZZuiC9MG82o2i0CilYDpUrRy1vAvPmJDBYYJKzAk2w== X-Received: by 2002:a05:6a00:2e11:b0:704:3491:d753 with SMTP id d2e1a72fcca58-7043491dec3mr8184188b3a.16.1718119961054; Tue, 11 Jun 2024 08:32:41 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:c5fb:1cf6:d480:34ef:aedf]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70422c977dasm6023811b3a.62.2024.06.11.08.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 08:32:40 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Stephen Roettger , jeffxu@chromium.org, Carlos O'Donell , Florian Weimer Subject: [RFC 5/5] elf: Add support to memory sealing for audit modules Date: Tue, 11 Jun 2024 12:27:08 -0300 Message-ID: <20240611153220.165430-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611153220.165430-1-adhemerval.zanella@linaro.org> References: <20240611153220.165430-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org The memory sealing is done after library loading and sanity check since an inexistent or wrong la_version might unload the library. Checked on x86_64-linux-gnu and aarch64-linux-gnu. --- elf/rtld.c | 4 ++++ manual/tunables.texi | 3 +++ sysdeps/unix/sysv/linux/Makefile | 2 ++ .../unix/sysv/linux/tst-dl_mseal-auditmod.c | 23 +++++++++++++++++++ sysdeps/unix/sysv/linux/tst-dl_mseal.c | 7 ++++-- 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c diff --git a/elf/rtld.c b/elf/rtld.c index 174389e205..62ad1272a4 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1044,6 +1044,10 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d); /* Mark the DSO as being used for auditing. */ dlmargs.map->l_auditing = 1; + + /* Seal the audit modules and their dependencies. */ + dlmargs.map->l_seal = lt_seal_toseal; + _dl_mseal_map (dlmargs.map, true); } /* Load all audit modules. */ diff --git a/manual/tunables.texi b/manual/tunables.texi index be36d52cf9..63445d74c2 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -385,6 +385,9 @@ Any library loaded with @code{dlopen} with @code{RTLD_NODELETE} flag. @item Any runtime library used for process unwind (such as required by @code{backtrace} or @code{pthread_exit}). + +@item +All audit modules and their dependencies. @end itemize The tunable accepts three diferent values: @samp{0} where sealing is disabled, diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 922511b4a1..f11aff84f5 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -656,9 +656,11 @@ modules-names += \ lib-tst-dl_mseal-dlopen-2 \ lib-tst-dl_mseal-dlopen-2-1 \ lib-tst-dl_mseal-preload \ + tst-dl_mseal-auditmod \ # modules-names $(objpfx)tst-dl_mseal.out: \ + $(objpfx)tst-dl_mseal-auditmod.so \ $(objpfx)lib-tst-dl_mseal-preload.so \ $(objpfx)lib-tst-dl_mseal-1.so \ $(objpfx)lib-tst-dl_mseal-2.so \ diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c b/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c new file mode 100644 index 0000000000..d909a1561c --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-dl_mseal-auditmod.c @@ -0,0 +1,23 @@ +/* Audit module for tst-dl_mseal test. + Copyright (C) 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 + . */ + +unsigned int +la_version (unsigned int v) +{ + return v; +} diff --git a/sysdeps/unix/sysv/linux/tst-dl_mseal.c b/sysdeps/unix/sysv/linux/tst-dl_mseal.c index da1a3ebe5a..ac60d7342a 100644 --- a/sysdeps/unix/sysv/linux/tst-dl_mseal.c +++ b/sysdeps/unix/sysv/linux/tst-dl_mseal.c @@ -35,6 +35,7 @@ #include #define LIB_PRELOAD "lib-tst-dl_mseal-preload.so" +#define LIB_AUDIT "tst-dl_mseal-auditmod.so" #define LIB_NEEDED_1 "lib-tst-dl_mseal-1.so" #define LIB_NEEDED_2 "lib-tst-dl_mseal-2.so" @@ -68,6 +69,7 @@ static const char *expected_sealed_libs[] = "ld.so", "tst-dl_mseal", LIB_PRELOAD, + LIB_AUDIT, LIB_NEEDED_1, LIB_NEEDED_2, LIB_DLOPEN_NODELETE, @@ -247,11 +249,12 @@ do_test (int argc, char *argv[]) spargv[i++] = (char *) "--restart"; spargv[i] = NULL; - char *envvarss[3]; + char *envvarss[4]; envvarss[0] = (char *) "GLIBC_TUNABLES=glibc.rtld.seal=2"; #ifndef TEST_STATIC envvarss[1] = (char *) "LD_PRELOAD=" LIB_PRELOAD; - envvarss[2] = NULL; + envvarss[2] = (char *) "LD_AUDIT=" LIB_AUDIT, + envvarss[3] = NULL; #else envvarss[1] = NULL; #endif