From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 02BCC3857030 for ; Thu, 24 Sep 2020 01:30:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 02BCC3857030 Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-JxJI0TxaMT-4kIaoyvpDYA-1; Wed, 23 Sep 2020 21:30:26 -0400 X-MC-Unique: JxJI0TxaMT-4kIaoyvpDYA-1 Received: by mail-qk1-f198.google.com with SMTP id o28so972150qkm.23 for ; Wed, 23 Sep 2020 18:30:26 -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:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=I96QA6skXAeUoVraJL4FZBGK1rX5FMtM4hBBvWhO+/w=; b=SMh5E8LDudKnDwEUu0wA8BCNgIGs/Q+RuYnmhYJewICBTN+JG2oKKnbppmyhfSwGTe G50Tb73bClmM+VxaNoSKMppAAyvtOokN9LZWP5ynQjUlxu9yuH056pFXxQs/g46MONiC ZxTQaFlfSLHrb7Mix0r0GLgRCEqQcNRoXMF2tpV+yayUcw1Oqc2Hz7+RyPcVTxhEUhN/ 5RJcFdP3nq9pSAixTxZw8fUINZfyKCAlV/ouPwqp0BC7KAsmvSSV/96M3U5tBR9UAnCM De7t4+qvlMYvpyzoIf7TDMDYvFIkEoq4sw2pLr2QaAPUjzsJkepZ2T1aXg9U9rNPlOrm Au0A== X-Gm-Message-State: AOAM533Z0WDffoAVqJp1qCS8i6Iwb7rqqm6oxPhoYnePQKCVlfgcRgnK kMbJg42hCXPHR15LeK+ZdY073PPxT2SqL0LFYbYF6gqnUFtRRrLfz3rO3zaOKC3ZKHSyYOyPMwJ 0IMOoP5qJuvNXB/Ea6dWg X-Received: by 2002:a05:620a:7f6:: with SMTP id k22mr2678905qkk.337.1600911025571; Wed, 23 Sep 2020 18:30:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2nny+uNhPo3s2QXoUgtNQKqtQqwP4VG7YdDYfzhT0SNth54zazuLd4OAzXszHLEhV3uQo7g== X-Received: by 2002:a05:620a:7f6:: with SMTP id k22mr2678886qkk.337.1600911025292; Wed, 23 Sep 2020 18:30:25 -0700 (PDT) Received: from [192.168.1.16] (198-84-214-74.cpe.teksavvy.com. [198.84.214.74]) by smtp.gmail.com with ESMTPSA id e1sm1165894qtb.0.2020.09.23.18.30.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Sep 2020 18:30:24 -0700 (PDT) Subject: Re: [PATCH] rtld-audit.7: Clarify la_version handshake To: Florian Weimer , linux-man@vger.kernel.org, =?UTF-8?Q?Ludovic_Court=c3=a8s?= Cc: libc-alpha@sourceware.org References: <874knosoyq.fsf@oldenburg2.str.redhat.com> From: Carlos O'Donell Organization: Red Hat Message-ID: Date: Wed, 23 Sep 2020 21:30:23 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <874knosoyq.fsf@oldenburg2.str.redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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, 24 Sep 2020 01:30:33 -0000 On 9/23/20 7:38 AM, Florian Weimer via Libc-alpha wrote: > Returning its argument without further checks is almost always > wrong for la_version. What you write here is the way I understand the interface to work. As Andreas noted there is one typo. I suggest changing the example to match, otherwise people might keep cribbing that code ;-) > Signed-off-by: Florian Weimer > I agree that la_version should return LAV_CURRENT, that is the expected way to implement the function, and returning less than LAV_CURRENT is required to implement older interfaces and be more compatible with older releases. As an example I encouraged Ludovic to solve a Guix path problem with LD_AUDIT and you can see it here: https://issues.guix.gnu.org/41189 +unsigned int +la_version (unsigned int v) +{ + if (v != LAV_CURRENT) + error (1, 0, "cannot handle interface version %u", v); + ... + return v; +} While this is OK, in that if it's not an exact match the audit module errors out, or if it is a match returns v which is LAV_CURRENT. It could have been more relaxed: if (v < LAV_CURRENT) error (...) ... return LAV_CURRENT; Your changes here int he man page would have clarified that to some extent. > --- > man7/rtld-audit.7 | 31 ++++++++++++++++++++++--------- > 1 file changed, 22 insertions(+), 9 deletions(-) > > diff --git a/man7/rtld-audit.7 b/man7/rtld-audit.7 > index b1b7dfebc..ca8afa752 100644 > --- a/man7/rtld-audit.7 > +++ b/man7/rtld-audit.7 > @@ -70,17 +70,30 @@ the auditing library. > When invoking this function, the dynamic linker passes, in > .IR version , > the highest version of the auditing interface that the linker supports. > -If necessary, the auditing library can check that this version > -is sufficient for its requirements. > .PP > -As its function result, > -this function should return the version of the auditing interface > -that this auditing library expects to use (returning > +A typical implementation of this function simply returns the constant > +.BR LAV_CURRENT , > +which indicates the version of > +.I > +that was used to build the audit module. If the dynamic linker does > +not support this version of the audit interface, it will refuse to > +activate this audit module. If the function returns zero, the dynamic > +linker also does not activate this audit module. > +.PP > +In order to enable backwards compatibility with older dynamic linkers, > +an audit module can examine the > +.I version > +argument and return an earlier version than > +.BR LAV_CURRENT , > +assuming the module can adjust its implement to match the requirements s/implement/implementation/g (Andreas caught this in his review) > +of the previous version of the audit interface. The > +.B la_version > +function should not return the value of > .I version > -is acceptable). > -If the returned value is 0, > -or a version that is greater than that supported by the dynamic linker, > -then the audit library is ignored. > +without further checks because it could correspond to an interface > +that does not match the > +.I > +definitions used to build the audit module. > .SS la_objsearch() > \& > .nf > May I additionally suggest something like this to the example? diff --git a/man7/rtld-audit.7 b/man7/rtld-audit.7 index b1b7dfebc..8a4008b2a 100644 --- a/man7/rtld-audit.7 +++ b/man7/rtld-audit.7 @@ -510,7 +510,11 @@ la_version(unsigned int version) { printf("la_version(): %u\en", version); - return version; + if (version > LAV_CURRENT) + printf ("la_version(): rtld supports newer interfaces.\n"); + + /* Request the version we knew about at compile time. */ + return LAV_CURRENT; } char * --- Post a v2? -- Cheers, Carlos.