From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B509B38582AB; Fri, 17 Feb 2023 12:46:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B509B38582AB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676638012; bh=JMCrtjNC4/jYh3YLd1rJwMgam7aBCvb+/ob3awoN1Bc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=gCf8UcHJzgqu88uTDGa5dYWWOSHfOc2vCHrxNt5Wa52m9UVjjFCqwF5t8+mYX0RLU e7xU8NKTKGhTfstzP06ApvzL0T3Vwsy1JHO8NAOtyGPhD8EuPZL0Hm1fRtUgR1On/J WWRCEq8/25QxRMho5G2brgHUjwkCNOXmbNXI2WiY= From: "fweimer at redhat dot com" To: glibc-bugs@sourceware.org Subject: [Bug dynamic-link/30127] [rfe]: enable ld audit at run-time Date: Fri, 17 Feb 2023 12:46:52 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: dynamic-link X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: fweimer at redhat dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: security- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D30127 --- Comment #12 from Florian Weimer --- (In reply to Stas Sergeev from comment #11) > (In reply to Florian Weimer from comment #10) > > I think for experimentation, you can use the link map as a dlopen handle > > directly, and pass it to dlsym, for example. >=20 > That finally works, thank you. > So with that and the patches already posted to ML, > I can at least start prototyping some code. >=20 >=20 > > We need to gather consensus that this is the way to do it, and document= it. > > Presently, it's an undocumented implementation detail. > >=20 > > We also need to use a dedicated link map allocator which only reuses, b= ut > > not frees, the underlying storiage, so that it becomes safe to traverse= the > > _r_debug lists, despite concurrent dlopen/dlcose operation. >=20 > But I hope the traversal of _r_debug list > will not became the official solution, just > as well as using linkmap pointers directly. Why? The handles are void *, so there isn't any type-checking today, and i= t's hard to tell how many applications assume this undocumented equivalence. Maybe we shouldn't commit to the other direction of reuse (casting a dlopen handle to struct link_map *), that's a separate decision. > So maybe you don't need such an allocator, > but of course I am not aware of a use-case > you are referring to. There's no lock that synchronizes the traversal of _r_debug with concurrent dlopen/dlclose. Introducing that is difficult. Such locks are easily misuse= d, and there is no precedent for exposing glibc locks in this way. > > There should also be a way to obtain a stable handle from a link map > > pointer. Using dlopen with RTLD_NOLOAD seems about right for that. >=20 > So do you want this patch to get that working > right here right now: >=20 > --- a/elf/dl-open.c > +++ b/elf/dl-open.c > @@ -872,7 +872,8 @@ no more namespaces available for dlmopen()")); > DL_NNS is 1 and so any NSID !=3D 0 is invalid. */ > || DL_NNS =3D=3D 1 > || GL(dl_ns)[nsid]._ns_nloaded =3D=3D 0 > - || GL(dl_ns)[nsid]._ns_loaded->l_auditing)) > + || (GL(dl_ns)[nsid]._ns_loaded->l_auditing && > + !(mode & RTLD_NOLOAD)))) > _dl_signal_error (EINVAL, file, NULL, > N_("invalid target namespace in dlmopen()")); >=20=20 > I tested that patch and it works. > Test-suit shows no regressions. I think we need to do a pass first with pointer-comparison because the names are not unique per namespace. > Also what do you think about the aforementioned > void *dlaudit_load_module(const char *path, int flags); > void *dlopen_audit(const char *path, int flags, void *cookie); > extensions? They seem to have poor encapsulation. If more than one module uses them, the auditor registered in that way might see unexpected auditing events, with unrecognizable cookies. --=20 You are receiving this mail because: You are on the CC list for the bug.=