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: AS17314 8.43.84.0/22 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, PDS_RDNS_DYNAMIC_FP,RCVD_IN_DNSWL_MED,RDNS_DYNAMIC,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 B51D11F8C6 for ; Fri, 30 Jul 2021 19:57:14 +0000 (UTC) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E49183983045 for ; Fri, 30 Jul 2021 19:57:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E49183983045 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1627675033; bh=/SC7uS/+NHVu6zDqyDQqL1f7VVvWF+ouJ05IGfuMP9U=; 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=rPKZfIA/72kcicxdWRbBfITV1dsFtEIP0rzfAtsGby2iXWyWSjag/1V0EN0bVm50J Y847v1gMjMQ/k+m7qTTNmRI9Bjs/M/RjVqA/trPOLx4FDHO+xJKDD5bkUI3dZgHwJx nZueRjbUhNPusRHt29T/D1axYbFn2k/v4IExHuqM= Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id B9DE5398202E for ; Fri, 30 Jul 2021 19:47:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B9DE5398202E Received: by mail-pl1-x62d.google.com with SMTP id u2so4061653plg.10 for ; Fri, 30 Jul 2021 12:47:47 -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=/SC7uS/+NHVu6zDqyDQqL1f7VVvWF+ouJ05IGfuMP9U=; b=MEfV7NlkXOte+4wp8OdvUEb84Xq/qG5l3wL68p85iG4POqWM1dUO9lKD/K+kj5psv0 0sv65YW/rloZAFAtE7PP3TbhZ8vWDREV/ZpqZZ41Zz5vipjGB0cW335Z+HAwDBicUbKk iSCrDMorJrRR1q84mQc9WBA+mbagnUE3Dz/qCgaxKJhWkA0lz3VemlurBTwszit9ElL8 OWbR8cTbPGV3xA0lbbxFGN7sDX+EYDLeQaGe86s1ndn4f6fZli7X/BVHh3sX5QhMSuwQ stES1u/DxcSHzjWGGH4mJrlqROqeUzWJhSeE28HygU6aMEyYyDsCnTK1U9Z657ag+KdH 4raw== X-Gm-Message-State: AOAM533MO/GFRDiCkFCC4k6O0XlKwBwwnZ+Dm1xEnDY1SiEBJv/5rK44 gj5LzCV0w5acwuvWNJM+bvgZ6mAVzf8a2w== X-Google-Smtp-Source: ABdhPJxIO2On2JtzZwFlUXsH6k73DIKOCdCqupMWPpgXcaP4M891AnfSbemI/e6AsMeUxvWYnnKxxg== X-Received: by 2002:a65:41c7:: with SMTP id b7mr3140419pgq.81.1627674466627; Fri, 30 Jul 2021 12:47:46 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jul 2021 12:47:46 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v3 12/20] elf: Add _dl_audit_pltenter Date: Fri, 30 Jul 2021 16:47:07 -0300 Message-Id: <20210730194715.881900-13-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_pltenter() audit callback. No function change, checked on x86_64-linux-gnu. --- elf/dl-audit.c | 77 ++++++++++++++++++++++++++++++++++++++ elf/dl-runtime.c | 73 +----------------------------------- sysdeps/generic/ldsodefs.h | 8 ++++ 3 files changed, 86 insertions(+), 72 deletions(-) diff --git a/elf/dl-audit.c b/elf/dl-audit.c index a968cbde16..7d410bc128 100644 --- a/elf/dl-audit.c +++ b/elf/dl-audit.c @@ -17,7 +17,9 @@ . */ #include +#include #include +#include #ifdef SHARED void @@ -257,4 +259,79 @@ _dl_audit_symbind (struct link_map *l, struct reloc_result *reloc_result, reloc_result->flags = flags; *value = DL_FIXUP_ADDR_VALUE (sym.st_value); } + +void +_dl_audit_pltenter (struct link_map *l, struct reloc_result *reloc_result, + DL_FIXUP_VALUE_TYPE *value, void *regs, long int *framesize) +{ + /* Don't do anything if no auditor wants to intercept this call. */ + if (GLRO(dl_naudit) == 0 + || (reloc_result->enterexit & LA_SYMB_NOPLTENTER)) + return; + + /* Sanity check: DL_FIXUP_VALUE_CODE_ADDR (value) should have been + initialized earlier in this function or in another thread. */ + assert (DL_FIXUP_VALUE_CODE_ADDR (*value) != 0); + ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound, + l_info[DT_SYMTAB]) + + reloc_result->boundndx); + + /* Set up the sym parameter. */ + ElfW(Sym) sym = *defsym; + sym.st_value = DL_FIXUP_VALUE_ADDR (*value); + + /* Get the symbol name. */ + const char *strtab = (const void *) D_PTR (reloc_result->bound, + l_info[DT_STRTAB]); + const char *symname = strtab + sym.st_name; + + /* Keep track of overwritten addresses. */ + unsigned int flags = reloc_result->flags; + + struct audit_ifaces *afct = GLRO(dl_audit); + for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) + { + if (afct->ARCH_LA_PLTENTER != NULL + && (reloc_result->enterexit + & (LA_SYMB_NOPLTENTER << (2 * (cnt + 1)))) == 0) + { + long int new_framesize = -1; + struct auditstate *l_state = link_map_audit_state (l, cnt); + struct auditstate *bound_state + = link_map_audit_state (reloc_result->bound, cnt); + uintptr_t new_value + = afct->ARCH_LA_PLTENTER (&sym, reloc_result->boundndx, + &l_state->cookie, &bound_state->cookie, + regs, &flags, symname, &new_framesize); + if (new_value != (uintptr_t) sym.st_value) + { + flags |= LA_SYMB_ALTVALUE; + sym.st_value = new_value; + } + + /* Remember the results for every audit library and store a summary + in the first two bits. */ + reloc_result->enterexit |= ((flags & (LA_SYMB_NOPLTENTER + | LA_SYMB_NOPLTEXIT)) + << (2 * (cnt + 1))); + + if ((reloc_result->enterexit & (LA_SYMB_NOPLTEXIT + << (2 * (cnt + 1)))) + == 0 && new_framesize != -1 && *framesize != -2) + { + /* If this is the first call providing information, use it. */ + if (*framesize == -1) + *framesize = new_framesize; + /* If two pltenter calls provide conflicting information, use + the larger value. */ + else if (new_framesize != *framesize) + *framesize = MAX (new_framesize, *framesize); + } + } + + afct = afct->next; + } + + *value = DL_FIXUP_ADDR_VALUE (sym.st_value); +} #endif diff --git a/elf/dl-runtime.c b/elf/dl-runtime.c index 680e66a6d6..4d16957c08 100644 --- a/elf/dl-runtime.c +++ b/elf/dl-runtime.c @@ -351,78 +351,7 @@ _dl_profile_fixup ( #ifdef SHARED /* Auditing checkpoint: report the PLT entering and allow the auditors to change the value. */ - if (GLRO(dl_naudit) > 0 - /* Don't do anything if no auditor wants to intercept this call. */ - && (reloc_result->enterexit & LA_SYMB_NOPLTENTER) == 0) - { - /* Sanity check: DL_FIXUP_VALUE_CODE_ADDR (value) should have been - initialized earlier in this function or in another thread. */ - assert (DL_FIXUP_VALUE_CODE_ADDR (value) != 0); - ElfW(Sym) *defsym = ((ElfW(Sym) *) D_PTR (reloc_result->bound, - l_info[DT_SYMTAB]) - + reloc_result->boundndx); - - /* Set up the sym parameter. */ - ElfW(Sym) sym = *defsym; - sym.st_value = DL_FIXUP_VALUE_ADDR (value); - - /* Get the symbol name. */ - const char *strtab = (const void *) D_PTR (reloc_result->bound, - l_info[DT_STRTAB]); - const char *symname = strtab + sym.st_name; - - /* Keep track of overwritten addresses. */ - unsigned int flags = reloc_result->flags; - - struct audit_ifaces *afct = GLRO(dl_audit); - for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) - { - if (afct->ARCH_LA_PLTENTER != NULL - && (reloc_result->enterexit - & (LA_SYMB_NOPLTENTER << (2 * (cnt + 1)))) == 0) - { - long int new_framesize = -1; - struct auditstate *l_state = link_map_audit_state (l, cnt); - struct auditstate *bound_state - = link_map_audit_state (reloc_result->bound, cnt); - uintptr_t new_value - = afct->ARCH_LA_PLTENTER (&sym, reloc_result->boundndx, - &l_state->cookie, - &bound_state->cookie, - regs, &flags, symname, - &new_framesize); - if (new_value != (uintptr_t) sym.st_value) - { - flags |= LA_SYMB_ALTVALUE; - sym.st_value = new_value; - } - - /* Remember the results for every audit library and - store a summary in the first two bits. */ - reloc_result->enterexit - |= ((flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT)) - << (2 * (cnt + 1))); - - if ((reloc_result->enterexit & (LA_SYMB_NOPLTEXIT - << (2 * (cnt + 1)))) - == 0 && new_framesize != -1 && framesize != -2) - { - /* If this is the first call providing information, - use it. */ - if (framesize == -1) - framesize = new_framesize; - /* If two pltenter calls provide conflicting information, - use the larger value. */ - else if (new_framesize != framesize) - framesize = MAX (new_framesize, framesize); - } - } - - afct = afct->next; - } - - value = DL_FIXUP_ADDR_VALUE (sym.st_value); - } + _dl_audit_pltenter (l, reloc_result, &value, regs, &framesize); #endif /* Store the frame size information. */ diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 4d39888a7b..32a621ae99 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1379,6 +1379,14 @@ void _dl_audit_symbind_alt (struct link_map *l, const ElfW(Sym) *ref, /* Call the la_preinit() from audit modules for the link_map L. */ void _dl_audit_preinit (struct link_map *l); rtld_hidden_proto (_dl_audit_symbind_alt) +/* Call the la_pltenter() arch specific from audit modules for the link_map L. + The RELOC_RESULT is the entry from link_map::l_reloc_result used to keep + track of the binding actions set by the audit modules, while VALUE is the + relocation result value, and REGS is the arch-specific register state + saved, and FRAMESIZE is the frame size pointer passed on the callback. */ +void _dl_audit_pltenter (struct link_map *l, struct reloc_result *reloc_result, + DL_FIXUP_VALUE_TYPE *value, void *regs, + long int *framesize); #endif /* SHARED */ #if PTHREAD_IN_LIBC && defined SHARED -- 2.30.2