From patchwork Fri Jan 25 20:20:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 31215 Received: (qmail 36533 invoked by alias); 25 Jan 2019 20:21:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 36489 invoked by uid 89); 25 Jan 2019 20:21:00 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Software X-HELO: mx1.redhat.com From: Florian Weimer To: Adhemerval Zanella Cc: Siddhesh Poyarekar , Carlos O'Donell , libc-alpha@sourceware.org Subject: Re: [PATCH] elf: Fix LD_AUDIT for modules with invalid version (BZ#24122) References: <20190123140740.27433-1-adhemerval.zanella@linaro.org> <7016cdf1-258d-b15e-9aeb-ac7381bcbad3@linaro.org> <4cae1215-d113-198d-ad1e-ec6c652ef4e2@linaro.org> <868a3870-5617-2d28-29cd-a568f821711f@gotplt.org> <87lg3a6xrl.fsf@oldenburg2.str.redhat.com> <2e2862af-a987-e694-646e-d4fe05071f52@linaro.org> <87d0om6vkz.fsf@oldenburg2.str.redhat.com> <87d0om5efo.fsf@oldenburg2.str.redhat.com> <4bfff6d6-0216-623a-19c8-cf17fe110509@linaro.org> <87pnskze06.fsf@oldenburg2.str.redhat.com> Date: Fri, 25 Jan 2019 21:20:51 +0100 In-Reply-To: <87pnskze06.fsf@oldenburg2.str.redhat.com> (Florian Weimer's message of "Fri, 25 Jan 2019 21:19:37 +0100") Message-ID: <87imyczdy4.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 * Florian Weimer: > * Adhemerval Zanella: > >>> No, the missing symbol case is covered earlier, where lookup_doit will >>> fail. This is really about a NULL symbol, a different error case. >>> Maybe this is so bizarre that we should drop this check? (You need an >>> SHN_ABS symbol or an IFUNC resolver that returns NULL to get this.) >> >> I tend to agree that we should just assert as Carlos suggested. > > Okay, I put in an assert, but maybe I shoul even drop that. > >>> This doesn't say that it's ignored as an audit module. >> >> Maybe as original patch "\nfile=%s cannot be loaded as audit interface; ignored.\n", name);? > > The new patch uses this: > > 6066: file=elf/tst-audit13mod1.so [1]; audit interface function la_version returned zero; ignored. > > It uses the l_name and l_ns, like must LD_DEBUG=files output. And I suggest to reinstantiate the test like this. Thanks, Florian From: Adhemerval Zanella Subject: elf: Test for LD_AUDIT module returning zero from la_version [BZ #24122] This includes the original test case from commit 8e889c5da3c5981c5a46a93fec02de40131ac5a6 ("elf: Fix LD_AUDIT for modules with invalid version (BZ#24122)). 2019-01-24 Adhemerval Zanella [BZ #24122] * elf/Makefile (tests): Add tst-audit13. (modules-names): Add tst-audit13mod1. (tst-audit13.out, LDFLAGS-tst-audit13mod1.so, tst-audit13-ENV): New rule. * elf/tst-audit13.c: New file. * elf/tst-audit13mod1.c: Likewise. diff --git a/elf/Makefile b/elf/Makefile index 9cf5cd8dfd..c24d765730 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -187,7 +187,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ tst-nodelete2 tst-audit11 tst-audit12 tst-dlsym-error tst-noload \ tst-latepthread tst-tls-manydynamic tst-nodelete-dlclose \ tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \ - tst-unwind-ctor tst-unwind-main + tst-unwind-ctor tst-unwind-main tst-audit13 # reldep9 tests-internal += loadtest unload unload2 circleload1 \ neededtest neededtest2 neededtest3 neededtest4 \ @@ -275,7 +275,8 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ tst-latepthreadmod $(tst-tls-many-dynamic-modules) \ tst-nodelete-dlclose-dso tst-nodelete-dlclose-plugin \ tst-main1mod tst-libc_dlvsym-dso tst-absolute-sym-lib \ - tst-absolute-zero-lib tst-big-note-lib tst-unwind-ctor-lib + tst-absolute-zero-lib tst-big-note-lib tst-unwind-ctor-lib \ + tst-audit13mod1 # Most modules build with _ISOMAC defined, but those filtered out # depend on internal headers. modules-names-tests = $(filter-out ifuncmod% tst-libc_dlvsym-dso tst-tlsmod%,\ @@ -1382,6 +1383,10 @@ tst-audit12-ENV = LD_AUDIT=$(objpfx)tst-auditmod12.so $(objpfx)tst-audit12mod1.so: $(objpfx)tst-audit12mod2.so LDFLAGS-tst-audit12mod2.so = -Wl,--version-script=tst-audit12mod2.map +$(objpfx)tst-audit13.out: $(objpfx)tst-audit13mod1.so +LDFLAGS-tst-audit13mod1.so = -Wl,-z,lazy +tst-audit13-ENV = LD_AUDIT=$(objpfx)tst-audit13mod1.so + # Override -z defs, so that we can reference an undefined symbol. # Force lazy binding for the same reason. LDFLAGS-tst-latepthreadmod.so = \ diff --git a/elf/tst-audit13.c b/elf/tst-audit13.c new file mode 100644 index 0000000000..6f587baf58 --- /dev/null +++ b/elf/tst-audit13.c @@ -0,0 +1,28 @@ +/* Check for invalid audit version (BZ#24122). + Copyright (C) 2019 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 + . */ + +#include + +static int +do_test (void) +{ + puts ("plt call"); + return 0; +} + +#include diff --git a/elf/tst-audit13mod1.c b/elf/tst-audit13mod1.c new file mode 100644 index 0000000000..cf017e235c --- /dev/null +++ b/elf/tst-audit13mod1.c @@ -0,0 +1,93 @@ +/* Check for invalid audit version (BZ#24122). + Copyright (C) 2019 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 + . */ + +#include +#include + +unsigned int +la_version (unsigned int version) +{ + /* The audit specification says that a version of 0 or a version + greater than any version supported by the dynamic loader shall + cause the module to be ignored. */ + return 0; +} + +void +la_activity (uintptr_t *cookie, unsigned int flag) +{ + exit (EXIT_FAILURE); +} + +char * +la_objsearch (const char *name, uintptr_t *cookie, unsigned int flag) +{ + exit (EXIT_FAILURE); +} + +unsigned int +la_objopen (struct link_map *map, Lmid_t lmid, uintptr_t * cookie) +{ + exit (EXIT_FAILURE); +} + +void +la_preinit (uintptr_t * cookie) +{ + exit (EXIT_FAILURE); +} + +uintptr_t +#if __ELF_NATIVE_CLASS == 32 +la_symbind32 (Elf32_Sym *sym, unsigned int ndx, uintptr_t *refcook, + uintptr_t *defcook, unsigned int *flags, const char *symname) +#else +la_symbind64 (Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook, + uintptr_t *defcook, unsigned int *flags, const char *symname) +#endif +{ + exit (EXIT_FAILURE); +} + +unsigned int +la_objclose (uintptr_t * cookie) +{ + exit (EXIT_FAILURE); +} + +#include +#if (!defined (pltenter) || !defined (pltexit) || !defined (La_regs) \ + || !defined (La_retval) || !defined (int_retval)) +# error "architecture specific code needed in sysdeps/CPU/tst-audit.h" +#endif + +ElfW(Addr) +pltenter (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook, + uintptr_t *defcook, La_regs *regs, unsigned int *flags, + const char *symname, long int *framesizep) +{ + exit (EXIT_FAILURE); +} + +unsigned int +pltexit (ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook, + uintptr_t *defcook, const La_regs *inregs, La_retval *outregs, + const char *symname) +{ + exit (EXIT_FAILURE); +}