From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua1-x936.google.com (mail-ua1-x936.google.com [IPv6:2607:f8b0:4864:20::936]) by sourceware.org (Postfix) with ESMTPS id E77B83857C7E for ; Thu, 11 Nov 2021 14:09:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E77B83857C7E Received: by mail-ua1-x936.google.com with SMTP id o26so12137528uab.5 for ; Thu, 11 Nov 2021 06:09:56 -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=IWwIUexGOjBUkwopQhv2r/tl/vi3018DO6tY0HVhE4g=; b=OKV1nbYMHUgDMh2fmEFdAdRIa+CIg8404RMTdO+YrRnNaNswl4Frtoo4hH96ObugaY SHkLp6l97iUsduRPtt+rvJrnhcr7RY+SkbRNd40zSZ8aLeLCHM8T6IYDD2uX0B9jEdTs UgDeBlWudoKSDbO4mfShifSw+5843Huzpc2lcIJTVk/EgG6KVfsZM5DuarjSN3Tn8AkS jVFP1kNgCkA3Htmj8GoMutL1SPxDZeNroy2GHD3K3TFcRYYkXNFRy9KdPu/hPg3zv8Yv GyuiIEcs6MT+vaYHNV6t+4ogfuwb/9nQ6NytvOR15sCbw56fajP7HeiidgWZpT5BSxJm +ymA== X-Gm-Message-State: AOAM5301CrhgW0PkE18aS5IWWev35/6yLLzs5b8BfUnIYeOWxvW9haUa mAOb8N2Vxq97WR5gWI0bhmvSqQ== X-Google-Smtp-Source: ABdhPJxapTFG83R6hdYQB98lWAhb9xKnwcVWK/791gXhlvEWRQh3Na2vYaIjxqMvoCS5EcOkpVtksw== X-Received: by 2002:a67:d58f:: with SMTP id m15mr10490974vsj.34.1636639794963; Thu, 11 Nov 2021 06:09:54 -0800 (PST) Received: from ?IPV6:2804:431:c7cb:55a:48f2:1d0b:8ae8:643a? ([2804:431:c7cb:55a:48f2:1d0b:8ae8:643a]) by smtp.gmail.com with ESMTPSA id g187sm2042340vsc.10.2021.11.11.06.09.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 11 Nov 2021 06:09:54 -0800 (PST) Message-ID: Date: Thu, 11 Nov 2021 11:09:51 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH 1/3] inet: Fix getnameinfo (NI_NOFQDN) race condition (BZ#28566) Content-Language: en-US To: Florian Weimer Cc: Adhemerval Zanella via Libc-alpha , leonardo.macchia@gmail.com References: <20211110185832.1931688-1-adhemerval.zanella@linaro.org> <20211110185832.1931688-2-adhemerval.zanella@linaro.org> <87r1bn150g.fsf@oldenburg.str.redhat.com> <27605b2b-cde0-9b1a-fc97-882d30e30b49@linaro.org> <87czn6yf0d.fsf@oldenburg.str.redhat.com> From: Adhemerval Zanella In-Reply-To: <87czn6yf0d.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-15.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: Thu, 11 Nov 2021 14:09:58 -0000 On 11/11/2021 10:54, Florian Weimer wrote: > * Adhemerval Zanella: > >> On 11/11/2021 05:16, Florian Weimer wrote: >>> * Adhemerval Zanella via Libc-alpha: >>> >>>> diff --git a/inet/getnameinfo.c b/inet/getnameinfo.c >>>> index 8380d85783..58ebbb1154 100644 >>>> --- a/inet/getnameinfo.c >>>> +++ b/inet/getnameinfo.c >>>> @@ -86,55 +86,75 @@ libc_freeres_ptr (static char *domain); >>>> static char * >>>> nrl_domainname (void) >>>> { >>>> + __libc_lock_define_initialized (static, lock); >>>> + __libc_lock_lock (lock); >>>> >>>> + static bool not_first = false; >>>> if (! not_first) >>> >>>> + done: >>>> + scratch_buffer_free (&tmpbuf); >>>> + not_first = true; >>> >>> This is missing the acquire/release pairing for the double-checked >>> locking idiom. You can probably use the domain variable directly. >> >> But it is done now within the lock, different than current implementation >> which does outside. I moved to be within the lock exactly to avoid the >> double-checked locking idiom. > > Ah, sorry, I had missed that. > >> I think now that we might be moving to a more optimized lll_lock internally >> using a acquire-load+CAS instead of just CAS we can get it without need >> to code it explicitly. > > The double-checked locking idiom avoids the CAS after initialization. > With the lll_lock change, an atomic read-modify-write operation still > happens on the lock in all cases (prior to the eventual return to the > caller). I meant H.J internal lock optimization [1], where the lll_lock int this case will be mostly a relaxed load instead of a CAS (since once 'domain' is properly initialized, there is no need to take the lock). [1] https://sourceware.org/pipermail/libc-alpha/2021-November/132899.html