From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Status: No, score=-4.2 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id B5A471F8C6 for ; Fri, 30 Jul 2021 19:53:23 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED7E3398242A for ; Fri, 30 Jul 2021 19:53:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED7E3398242A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627674803; bh=Um1/+d8J9jrXyPSXflhKBY2tpC9WPBhc7hXxH34fWE8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=a3KDr5z6jwIl9hkIzmSBcOCOQW/Z64RNVcTEiQS8UWBXeTmbDFaRmzF2DMSB/OK8V wHL9zAD3oH1MPV7BcdlNGejKOdhVHH+2TRnA8sxax+NfTUXiBdlb2V8oiu3Vvkamyf DPaKBQ4leWhRcxwbQ4wf8y5WpfrBZtRNN6QLN+Dk= Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 89D7D384F00D for ; Fri, 30 Jul 2021 19:47:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 89D7D384F00D Received: by mail-pl1-x630.google.com with SMTP id e5so12322186pld.6 for ; Fri, 30 Jul 2021 12:47:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Um1/+d8J9jrXyPSXflhKBY2tpC9WPBhc7hXxH34fWE8=; b=CVigHfEG6uiNvBHBwxhfyjRK0gPpwU+jtTF+nuo4Xs/8jH4ideOpJZRFOLg0NIw05k UGrr43J3p6fFr0PLwIk0EVD8a9Sfm8K6ZTvDNo1jgTn+IX5BgAhtW7aM0KdyWmsguiq2 KlIVLedeOy/eFAMciuW5XLdtwi5zdnduIv8CHqcFprSggJYez1wQgs8JQ9OkC397FRhk jPIGFxzdmnwIIEhFo3xRxMxxHcvqcPbFoYjZFDWiUZ6oV9oN8dqJl+v6Ak+2fCfxDzIE AeqrU/H4xh3eIcJTGIn8u7bKpBZcAbiUzOr3pubbyTyBZIXRBI01Qc0dzqyG6UUvvVAP axFw== X-Gm-Message-State: AOAM531rD8/qrOu005IPMuJCn6btmdeeSF+mgDSGf0XrkMZVFlUIfRmA VEH/UtKvUtlvi6u/AX/WL4a/uqqNFLrBRQ== X-Google-Smtp-Source: ABdhPJzicsCVM9iv8Bu/Vrbyim+R8NMI4EX7lw1L9b2eZRStNdH1yTHIbEzNgifR5SjoEZ6qciS2fQ== X-Received: by 2002:a05:6a00:b46:b029:334:54db:af17 with SMTP id p6-20020a056a000b46b029033454dbaf17mr4199642pfo.26.1627674458423; Fri, 30 Jul 2021 12:47:38 -0700 (PDT) Received: from birita.. ([2804:431:c7cb:43e2:6c33:fd81:e602:d33]) by smtp.gmail.com with ESMTPSA id c12sm3041426pfl.56.2021.07.30.12.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 12:47:38 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 07/20] elf: Add _dl_audit_activity_map and _dl_audit_activity_nsid Date: Fri, 30 Jul 2021 16:47:02 -0300 Message-Id: <20210730194715.881900-8-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210730194715.881900-1-adhemerval.zanella@linaro.org> References: <20210730194715.881900-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Adhemerval Zanella via Libc-alpha Reply-To: Adhemerval Zanella Cc: John Mellor-Crummey Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org Sender: "Libc-alpha" It consolidates the code required to call la_activity() audit callback. No function change, checked on x86_64-linux-gnu. --- elf/dl-audit.c | 23 ++++++++++++++++ elf/dl-close.c | 54 +++++++------------------------------- elf/dl-load.c | 28 +++++--------------- elf/dl-open.c | 20 +------------- elf/rtld.c | 31 ++-------------------- sysdeps/generic/ldsodefs.h | 7 +++++ 6 files changed, 48 insertions(+), 115 deletions(-) diff --git a/elf/dl-audit.c b/elf/dl-audit.c index 24d8557f18..5fbc76a36c 100644 --- a/elf/dl-audit.c +++ b/elf/dl-audit.c @@ -19,6 +19,29 @@ #include #ifdef SHARED +void +_dl_audit_activity_map (struct link_map *l, int action) +{ + struct audit_ifaces *afct = GLRO(dl_audit); + for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) + { + if (afct->activity != NULL) + afct->activity (&link_map_audit_state (l, cnt)->cookie, action); + afct = afct->next; + } +} + +void +_dl_audit_activity_nsid (Lmid_t nsid, int action) +{ + struct link_map *head = GL(dl_ns)[nsid]._ns_loaded; + if (__glibc_likely (GLRO(dl_naudit) == 0) + || head == NULL || head->l_auditing) + return; + + _dl_audit_activity_map (head, action); +} + void _dl_audit_objopen (struct link_map *l, Lmid_t nsid, bool check_audit) { diff --git a/elf/dl-close.c b/elf/dl-close.c index f39001cab9..744621b11f 100644 --- a/elf/dl-close.c +++ b/elf/dl-close.c @@ -478,25 +478,7 @@ _dl_close_worker (struct link_map *map, bool force) #ifdef SHARED /* Auditing checkpoint: we will start deleting objects. */ - if (__glibc_unlikely (do_audit)) - { - struct link_map *head = ns->_ns_loaded; - struct audit_ifaces *afct = GLRO(dl_audit); - /* Do not call the functions for any auditing object. */ - if (head->l_auditing == 0) - { - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->activity != NULL) - { - struct auditstate *state = link_map_audit_state (head, cnt); - afct->activity (&state->cookie, LA_ACT_DELETE); - } - - afct = afct->next; - } - } - } + _dl_audit_activity_nsid (nsid, LA_ACT_DELETE); #endif /* Notify the debugger we are about to remove some loaded objects. */ @@ -785,32 +767,14 @@ _dl_close_worker (struct link_map *map, bool force) } #ifdef SHARED - /* Auditing checkpoint: we have deleted all objects. */ - if (__glibc_unlikely (do_audit)) - { - struct link_map *head = ns->_ns_loaded; - /* If head is NULL, the namespace has become empty, and the - audit interface does not give us a way to signal - LA_ACT_CONSISTENT for it because the first loaded module is - used to identify the namespace. - - Furthermore, do not notify auditors of the cleanup of a - failed audit module loading attempt. */ - if (head != NULL && head->l_auditing == 0) - { - struct audit_ifaces *afct = GLRO(dl_audit); - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->activity != NULL) - { - struct auditstate *state = link_map_audit_state (head, cnt); - afct->activity (&state->cookie, LA_ACT_CONSISTENT); - } - - afct = afct->next; - } - } - } + /* Auditing checkpoint: we have deleted all objects. If head is NULL, the + namespace has become empty, and the audit interface does not give us a + way to signal LA_ACT_CONSISTENT for it because the first loaded module + is used to identify the namespace. + + Furthermore, do not notify auditors of the cleanup of a failed audit + module loading attempt. */ + _dl_audit_activity_nsid (nsid, LA_ACT_CONSISTENT); #endif if (__builtin_expect (ns->_ns_loaded == NULL, 0) diff --git a/elf/dl-load.c b/elf/dl-load.c index c0b68638c0..ecd64d2400 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1057,28 +1057,12 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, if (r->r_state == RT_CONSISTENT) { #ifdef SHARED - /* Auditing checkpoint: we are going to add new objects. */ - if ((mode & __RTLD_AUDIT) == 0 - && __glibc_unlikely (GLRO(dl_naudit) > 0)) - { - struct link_map *head = GL(dl_ns)[nsid]._ns_loaded; - /* Do not call the functions for any auditing object and also do not - try to call auditing functions if the namespace is currently - empty. This happens when opening the first DSO in a new - namespace. */ - if (head != NULL && head->l_auditing == 0) - { - struct audit_ifaces *afct = GLRO(dl_audit); - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->activity != NULL) - afct->activity (&link_map_audit_state (head, cnt)->cookie, - LA_ACT_ADD); - - afct = afct->next; - } - } - } + /* Auditing checkpoint: we are going to add new objects. Do not call + the functions for any auditing object and also do not try to call + auditing functions if the namespace is currently empty. This + happens when opening the first DSO in a new namespace. */ + if ((mode & __RTLD_AUDIT) == 0) + _dl_audit_activity_nsid (nsid, LA_ACT_ADD); #endif /* Notify the debugger we have added some objects. We need to diff --git a/elf/dl-open.c b/elf/dl-open.c index f25340968f..dba36f2c10 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -608,25 +608,7 @@ dl_open_worker (void *a) #ifdef SHARED /* Auditing checkpoint: we have added all objects. */ - if (__glibc_unlikely (GLRO(dl_naudit) > 0)) - { - struct link_map *head = GL(dl_ns)[new->l_ns]._ns_loaded; - /* Do not call the functions for any auditing object. */ - if (head->l_auditing == 0) - { - struct audit_ifaces *afct = GLRO(dl_audit); - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->activity != NULL) - { - struct auditstate *state = link_map_audit_state (head, cnt); - afct->activity (&state->cookie, LA_ACT_CONSISTENT); - } - - afct = afct->next; - } - } - } + _dl_audit_activity_nsid (new->l_ns, LA_ACT_CONSISTENT); #endif /* Notify the debugger all new objects are now ready to go. */ diff --git a/elf/rtld.c b/elf/rtld.c index 8008570f82..1cbaaa2124 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1760,18 +1760,7 @@ dl_main (const ElfW(Phdr) *phdr, /* Auditing checkpoint: we are ready to signal that the initial map is being constructed. */ - if (__glibc_unlikely (GLRO(dl_naudit) > 0)) - { - struct audit_ifaces *afct = GLRO(dl_audit); - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->activity != NULL) - afct->activity (&link_map_audit_state (main_map, cnt)->cookie, - LA_ACT_ADD); - - afct = afct->next; - } - } + _dl_audit_activity_map (main_map, LA_ACT_ADD); /* We have two ways to specify objects to preload: via environment variable and via the file /etc/ld.so.preload. The latter can also @@ -2452,23 +2441,7 @@ dl_main (const ElfW(Phdr) *phdr, #ifdef SHARED /* Auditing checkpoint: we have added all objects. */ - if (__glibc_unlikely (GLRO(dl_naudit) > 0)) - { - struct link_map *head = GL(dl_ns)[LM_ID_BASE]._ns_loaded; - /* Do not call the functions for any auditing object. */ - if (head->l_auditing == 0) - { - struct audit_ifaces *afct = GLRO(dl_audit); - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->activity != NULL) - afct->activity (&link_map_audit_state (head, cnt)->cookie, - LA_ACT_CONSISTENT); - - afct = afct->next; - } - } - } + _dl_audit_activity_nsid (LM_ID_BASE, LA_ACT_CONSISTENT); #endif /* Notify the debugger all new objects are now ready to go. We must re-get diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 3432bcd693..013f62c415 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1347,6 +1347,13 @@ link_map_audit_state (struct link_map *l, size_t index) } } +/* Call the la_activity() from the audit modules from the link map L + and issues the ACTION argument. */ +void _dl_audit_activity_map (struct link_map *l, int action) + attribute_hidden; +/* Call the la_activity() from the audit modules from the link map + from the namespace NSSID and issues the ACTION argument. */ +void _dl_audit_activity_nsid (Lmid_t nsid, int action); /* Call the la_objopen() from the audit modules for the link_map L on the namespace identification NSID. If CHECK_AUDIT is set it will also check if main mapping of the namespace is an audit modules. */ -- 2.30.2