From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by sourceware.org (Postfix) with ESMTPS id E902D3858D28 for ; Fri, 17 Dec 2021 16:09:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E902D3858D28 Received: by mail-ua1-x932.google.com with SMTP id t13so5204459uad.9 for ; Fri, 17 Dec 2021 08:09:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=IgwTOKRg8TwQ2GrZ0It//koVLzGltuofSvKOepCZ0vM=; b=LzihEZeMbJ7uu1ozzDxfMalEtmtu0nQpFMo81ftbaR+AB4MvaeI91BNoCtoNnrc87D fhqRAgrVIYa3uOh6fEp/iuvpF53IfSoJh9O/OY0PbTb3lk3pP4vLBsJoIG37sBOotcR4 VhBWIL99my+zvrBwuEWj+0FMp6QdUCSinNAUAgRbOtcQFSuU6gH/QHaxadRVBkX9Ssv9 dsUg72xvc/8iUAE/P1WrlBDqMLj4jeDb65nA075doN/1z3+6vB41vDHhtNXSMbi1qoUU c2t0kH8ysNGlENXUyFgeYbVkZJeLKAOMgepsIyTgIetSRGPFGJuOQyviIfn5iB+YsI3B 6ozQ== X-Gm-Message-State: AOAM530GD2DgqMzBR2rmnLdaiYo6GOs41vGxe1IqoqfwvsiIMs0n99e+ pnpiro2q9yWrrmdN2SgpMq7bwElI4NUJMmj9 X-Google-Smtp-Source: ABdhPJz9dOgH/xeU3r0pa4J4Va5q62cxdXLNMtw2fUplazRt00r+Qxal9ZGycq/MZtG08RVSbOw3kA== X-Received: by 2002:a05:6102:363:: with SMTP id f3mr1330842vsa.22.1639757365451; Fri, 17 Dec 2021 08:09:25 -0800 (PST) Received: from ?IPV6:2804:431:c7ca:103f:7084:332e:7513:f115? ([2804:431:c7ca:103f:7084:332e:7513:f115]) by smtp.gmail.com with ESMTPSA id t20sm1865544vsj.27.2021.12.17.08.09.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 08:09:25 -0800 (PST) Message-ID: <77953f5e-e8f7-43c8-52ee-88fd8031bb64@linaro.org> Date: Fri, 17 Dec 2021 13:09:23 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v6 04/20] elf: Add _dl_audit_objsearch Content-Language: en-US To: Florian Weimer Cc: libc-alpha@sourceware.org, John Mellor-Crummey , Ben Woodard References: <20211115183734.531155-1-adhemerval.zanella@linaro.org> <20211115183734.531155-5-adhemerval.zanella@linaro.org> <87pmpvmngm.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87pmpvmngm.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Fri, 17 Dec 2021 16:09:27 -0000 On 17/12/2021 09:21, Florian Weimer wrote: > * Adhemerval Zanella: > >> diff --git a/elf/dl-audit.c b/elf/dl-audit.c >> index 5fbc76a36c..de85ef1ddd 100644 >> --- a/elf/dl-audit.c >> +++ b/elf/dl-audit.c >> @@ -42,6 +42,43 @@ _dl_audit_activity_nsid (Lmid_t nsid, int action) >> _dl_audit_activity_map (head, action); >> } >> >> +bool >> +_dl_audit_objsearch (const char **name, const char **origname, >> + struct link_map *l, unsigned int code) >> +{ >> + if (__glibc_likely (GLRO(dl_naudit) == 0) >> + || l == NULL || l->l_auditing >> + || code == 0) >> + return true; >> + >> + struct audit_ifaces *afct = GLRO(dl_audit); >> + for (unsigned int cnt = 0; cnt < GLRO(dl_naudit); ++cnt) >> + { >> + if (afct->objsearch != NULL) >> + { >> + const char *before = *name; >> + struct auditstate *state = link_map_audit_state (l, cnt); >> + *name = afct->objsearch (*name, &state->cookie, code); >> + if (*name == NULL) >> + return false; >> + >> + if (origname != NULL && before != *name >> + && strcmp (before, *name) != 0) >> + { >> + if (__glibc_unlikely (GLRO(dl_debug_mask) & DL_DEBUG_FILES)) >> + _dl_debug_printf ("audit changed filename %s -> %s\n", >> + before, *name); >> + >> + if (*origname == NULL) >> + *origname = before; >> + } >> + } >> + afct = afct->next; >> + } >> + >> + return true; >> +} > > Sorry, I find the interface rather confusing. *name is an in-out > parameter, and *origname is an out parameter. This is not really clear > from their names. > > I looked at the rest of elf/dl-load.c, and origname appears to be solely > used as an optimization, to avoid having to call add_name_to_object > twice. (add_name_to_object already filters out duplicate names.) > > I think this interface should work: > > const char *_dl_audit_objsearch (const char *name, struct link_map *l, > unsigned int code); > > Callers need to check for NULL return values and stop loading the > object. Otherwise they have to register both names with > add_name_to_object. > > What do you think? To replace the second command and keep the 'origname' update we will need to pass it as an out argument (or return as a tuple from _dl_audit_objsearch). Also, by just returning a 'const char *' there is no indication that audit modules are really handled, so we need to check on both sites if there are really enabled (which should be ok). if (__glibc_unlikely (GLRO(dl_naudit) > 0)) { [...] } What about: const char *_dl_audit_objsearch (const char *name, const char **origname, struct link_map *l, unsigned int code); Where 'origname' is updated if non NULL?