From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) by sourceware.org (Postfix) with ESMTPS id C6F54399C039 for ; Thu, 17 Jun 2021 23:07:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C6F54399C039 Received: by mail-qt1-x82b.google.com with SMTP id g12so6160111qtb.2 for ; Thu, 17 Jun 2021 16:07:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qiSdH6OH1+Pfbh8NoOy1wQ6ADrp2F8KoXLyvBNTNqD8=; b=oDrbHkc/WVyao7hxgUwQKc4zC6bVfq3u3/gQJ6b7woSlMtrERYNLNIm0rNUgMkN5AA /KTN0hjbuNtDs98+PCDQf7qi4COMP0vE5j/mfsSG9FOA1rWG/h7UmMnD9G+dJAhpUswR cOxKJ8gPmmhZFkPe1JrCCwrNPuxlHcpfAmAUIUFVTZT1kLvQhpx4uHizWgaZBvQJJDxe +Th93DodJ1MIHxMKz6cno2ItBSqnE4Qh/GRAeSl7hDFtUVRa5EmJxuaONWy5eEToeZ3s ml7d56vb3zZI4DJuthfzvP5qdSr0N2zeSbQP3Fo1pGeGD5gcOSs2c6uBes5EUb/wmCuP N+Qw== X-Gm-Message-State: AOAM533xO8rRIBxzlTF901MZwsbCiisI4ZAkx6nC12+psxq+1qmlKvmx nOI1LAreTIMquxVbAbHjbdZuxQ== X-Google-Smtp-Source: ABdhPJyiBMknBO+uKL0K5XP/BO8BSaXVOvFt5IoCp8S3K3dZMBXziAMWmZrpgwGdYPzVBGhxPRfEKw== X-Received: by 2002:ac8:5f88:: with SMTP id j8mr7585763qta.9.1623971223303; Thu, 17 Jun 2021 16:07:03 -0700 (PDT) Received: from [192.168.1.4] ([177.194.59.218]) by smtp.gmail.com with ESMTPSA id x5sm2708198qke.92.2021.06.17.16.07.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Jun 2021 16:07:02 -0700 (PDT) Subject: Re: A collection of LD_AUDIT bugs that are important for tools (with better formatting for this list) To: Florian Weimer Cc: John Mellor-Crummey , libc-alpha@sourceware.org, woodard@redhat.com References: <8A8FF420-8316-4A22-AC4D-DA1F2D5625A5@rice.edu> <2fc830b9-35da-9b94-369f-4df683078a5c@linaro.org> <8735tguubc.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella Message-ID: <75b2e838-a32e-6a2a-27b2-75bc06c01118@linaro.org> Date: Thu, 17 Jun 2021 20:06:59 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <8735tguubc.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 17 Jun 2021 23:07:07 -0000 On 17/06/2021 17:09, Florian Weimer wrote: > * Adhemerval Zanella: > >> I checked the issues you listed below with master (I can't really >> comment their status regarding the usual HPC distributions). > > Thank you for reviewing the status quo. > >>> ---------------------------------------------------------- >>> HIGH | la_symbind isn't always called when appropriate. >>> | We observed that glibc 2.26 calls la_symbind >>> | when appropriate; glibc 2.28 does not. >> >> I am not sure how to proper fix it, maybe an option is just to disable bind-now >> if we have any audit module enabled. We will need to discuss the possible >> implications. >> >> (btw your auditor-tests/symbind does not enable bind-now with either >> LD_BIND_NOW=1 or -Wl,-z,now). > > The issue is that the la_symbind interface is not very good at > communicating that PLT enter/exit hooks aren't available under these > circumstances. Maybe we can provide another flag and signal an error if > la_symbind requests enter/exit hooks in BIND_NOW mode. Another option is to provide such information on audit interface itself through an extension, maybe by adding an extra flag for la_activity() (LA_ACT_BINDNOW or likewise) or on la_symbind* itself. In both cases it will most likely require to bump LAV_CURRENT. > >>> ---------------------------------------------------------- >>> HIGH | glibc does not save all necessary registers >>> | (e.g. X8 - the indirect result register, truncated >>> | SIMD registers) when auditing on aarch64 since >>> | the beginning of time. >> >> This has been already discussed on the maillist: >> >> * NEON support: we have a proposed [1] patch that addresses it by extending the >> export struct used. Although the patch seems to fix the issue described by >> BZ#26643 it is still incomplete: it would required to bump LAV_CURRENT for >> aarch64 (and add a arch-specific way to override it), add tests, and check >> on how to handle possible incompatbilities. From a briefly chat with other >> glibc maintainer, we can just set that audit version lower LAV_CURRENT are >> just unsupported. >> >> * SVE support: as indicated by Szabolcs SVE calls are marked with the >> STO_AARCH64_VARIANT_PCS and thus explicit not supported by dynamic loader. >> To support SVE, it would require save/restore all registers (but pass down >> arg and retval registers to pltentry/exit callbacks according to the base >> PCS). Another option would be to use different LAV_CURRENT version, one for >> NEON and SVE with 128-bits and another for SVE larger than 256-bits. >> This also has performance implications. > > SVE support overlaps with the la_symbind issue quoted above because > those bindings are conceptually BIND_NOW. There is additional issues where we need to define whether we will use a hacky solution to work around the ABI limitation or if we can design something between. And it also has the performance implications, it will be hard not to notice potentially multiple KBs of load/store on each PLT call. > >> [1] https://patchwork.sourceware.org/project/glibc/patch/20200923160448.2321909-1-woodard@redhat.com/ >> [2] https://sourceware.org/pipermail/libc-alpha/2020-September/117822.html >> >>> ---------------------------------------------------------- >>> LOW | When auditing, a dlopen of a shared library >>> | that uses R_X86_64_TLSDESC causes a SEGV. This >>> | is reportedly fixed in glibc 2.34. >> >> It should be fixed by BZ#27137 (8f7e09f4dbdb5c815a18b8285fbc5d5d7bc17d86), >> however it has regressed by 03e187a41d9. We need the following fix and we >> definitely need a regression tests for this (I will probably use your >> auditor-test) as base: >> >> diff --git a/elf/dl-open.c b/elf/dl-open.c >> index d2240d8747..d2638ebf05 100644 >> --- a/elf/dl-open.c >> +++ b/elf/dl-open.c >> @@ -771,7 +771,7 @@ dl_open_worker (void *a) >> { >> struct link_map *libc_map = GL(dl_ns)[args->nsid].libc_map; >> #ifdef SHARED >> - bool initial = libc_map->l_ns == LM_ID_BASE; >> + bool initial = libc_map != NULL ? libc_map->l_ns == LM_ID_BASE : false; >> #else >> /* In the static case, there is only one namespace, but it >> contains a secondary libc (the primary libc is statically > > Hmm, I'm surprised that this doesn't crash more widely. Is it because > DT_NEEDED on ld.so preceeds libc.so if __tls_get_addr is used, or > something like that? I will need to check why we haven't see it with our own testcase. I in case I will prepare a patch to fix it. > >> And you are correct about your assessment on the document, we *really* need >> more extensible tests for audit interface. It would be really helpful if >> we could add more tests to exercise the real world usage from tools that >> rely on audit modules. > > Agreed. It would also be helpful to verify that the callbacks happened > in the expected order. This is always a troublesome aspect of a > callback-based interface. > >>> - We want to use LD_AUDIT’s la_symbind32 and la_symbind64 to interpose >>> wrappers around key functions, e.g. pthread_create. This enables a >>> tool to intercept functions invoked through pointers obtained with >>> dlsym, which preloaded wrappers can’t do. (Note: We don’t use >>> la_symbind for interposition yet, but we plan to when it works >>> everywhere.) >>> >>> - We need auditing to work when an application or a tool library (e.g., >>> Intel’s GT-Pin) opens a shared library with dlmopen. >>> >>> - We need auditing to work when opening a dynamic library with TLS >>> dialect gnu2 relocations on x86_64 (R_X86_64_TLSDESC). We don’t have >>> any special interest in such relocations; at present, they cause a >>> SEGV when auditing and that must be avoided. >> >> This should be fixed minus the regression above. > > pthread_create interception becomes more difficult in glibc 2.34 because > the pthread_create symbol is no longer interposable. > > We could make pthread_create interposable in the same we way do that > today for malloc. But it is only a handfull call internall (POSIX timer for instance). I don't think > > pthread_create interposition on glibc 2.0 architectures needs version > information in la_symbind. No 64-bit architecture except Alpha is that > old, so maybe this doesn't matter today. (libstdc++ currently binds to > the pthread_create compatibility symbol on these architectures, so the > issue is quite visible, but a rebuild of GCC against glibc 2.34 will fix > that, too. Then the default version will be used.) > > One caveat: We should be able to make la_symbind work on current > distributions with their hardened build defaults, *however* PLT > enter/exit hooks will not work. For the time being, you would have to > find a way to wrap the call yourself. This is theoretically fixable > even without run-time code generation (Madhavan T. Venkataraman from > Microsoft has submitted patches in this area for libffi), but it's > entirely vaporware at this point. This looks like a fairly isolated > project someone could work on without spending considerable time on > learning the internals of the dynamic loader. Is this what your are referring [1]? It is not clear to me how the v2 of this does not require a trip to the kernel, does it use a vDSO to place the trampolines (also the libffi.v2.txt link is broken)? In any case, do you think it should be fixable by adding trampolines on extra mmap memory? [1] https://lkml.org/lkml/2020/9/16/643 > >>> - We want to add an auditor to an application at link time, noted in the >>> DT_AUDIT entry of the dynamic section. Loading the DT_AUDIT entry as a >>> program is launched enables our profiler to be injected into an >>> application’s address space without a wrapper script that sets >>> LD_AUDIT and LD_PRELOAD. >> >> So if I understood correctly you are asking something like a DT_FILTER >> for DT_AUDIT? > > Indeed, please let us know if the existing DT_AUDIT support does not > work for you. > > Thanks, > Florian >