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: 803247 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:e87:b0:35b:5a80:51b4 with SMTP id dz7csp367872wrb; Tue, 11 Jun 2024 08:33:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX9QqM7s0sDD+XkGsGPTHoV54oT+lAJORffWsPn1fyHy+YOZ9ldhTy+YarI/Wrnb9RNPezL67zx7LWeVuiMi/Xg X-Google-Smtp-Source: AGHT+IHMqTk6n/lRNZU1IYvdrBPUaTPVvDA7dF8hPKDx76JMQ1mFmazORTYuZuC2AbXbIWtd7iKh X-Received: by 2002:a05:6214:4598:b0:6b0:6650:f9ca with SMTP id 6a1803df08f44-6b06650faa5mr109432416d6.10.1718120007164; Tue, 11 Jun 2024 08:33:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718120007; cv=pass; d=google.com; s=arc-20160816; b=wKjFRAGoDEwSKgVzdV7VQrwzOsQ2I1g1UoW4AsVuOQyrpUuUBq9FQRnZ+L++efoSfr iHlp+vVa8JEhGajemOSXY0H6ieq2kL8/HcLb/wFlzHe2LOJd1IrDxkyQVjsGe0twV0KQ QFpAJze48tkdN0UOSW4CJ3l5vycqnaKclPs2oi+vBOdJWefb9QMyJfBBRhw3rSiEX5cQ j5qmwXm21+/wKgn/gGQcIfWAqY2rtHWpmb4+bGiPBs9RSUhXa9dCUj76+QKHL5kZ6rgB /S+tOuQQOC0jhbL924PTvvRhpTHA85r8xLpo5ybgCHU9PmS5GJrZxCkeamlEKTCzZBfa GRZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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:arc-filter:dmarc-filter:delivered-to; bh=Xmphwhr+iTAJGwS9wSN4vGADMl6gfC25KCNXJlSglXU=; fh=Xe8CcRFBQpY3WaKalMJwtTjJfhW8yymKb7+oOheBL8A=; b=EH4F7hcAnuVU/iLkMtLbvKasqq2Q+YilHb+e+Nz6xc3q/MWda32DmmCZy/CXAbyofa Q/AIPvPTudkP5Jo07aBMCljoC+25S3wYQ500F1moiAyg7lYvk29HPogH0V+/OL8v5C5g K/QIfU9qjFEh4NtmaWVASy5vC/MfVnpLLHBvckjT5bIUfKc03cmi6JV4RKn4PMGkgCDh RNe3NhZyjjLIIcduOhCjAi/VoFuBKOWo7nqy6MSDpJoNjwszAS0Hsjk6P6zQFyyoZZUK Rl19G0gAvFWi5rNfGt8FgSl5oK7vq4HQRur9qtN0e2OT/gyJxozlE0MgFvdIJqOOBJA0 0bEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aFHIJLDQ; 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-6b08ade6b8csi23183006d6.255.2024.06.11.08.33.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jun 2024 08:33:27 -0700 (PDT) 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=aFHIJLDQ; 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 CBDEA385DDEB for ; Tue, 11 Jun 2024 15:33:26 +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-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+patch=linaro.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