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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 41CF43857815 for ; Thu, 7 Mar 2024 20:37:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41CF43857815 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 41CF43857815 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709843838; cv=none; b=O+LIEn0t9+FE/DMTZaxo2mcv9Rcb8OrzKHFGM32rJ0NIxW/wjzcTI7xijuVYWVL+kxb/r/my1K96AKS5pWYgxYfLDFb3RA5BdTjx9GuMQKKhmjFr7VW32W3i65ShE/UNZZPZHydcgSxbqOr1fApL+jdLyOkxcV4iwSuVI0e72cA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709843838; c=relaxed/simple; bh=VzZftTomy8/ib47My5HooHJeb3x3cAMNSnSaaq2ja0k=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=PXobka3x3fZevMgWsQwubr/9HxEiBsFCEMdNhQvY3+Sx95b7Ey3zicA8kIHyAeG8xZgzFOi2V3QoI6WDNJYXpdV7HUPJWWwVPpYV71v00K61riZ5f8mHv39gWU1izAap3ipjy7QiVtOxfyOQ0wcdYJbuLCBOnCijojJ7KD8vn8I= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709843835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uIkaj/NfVH637sssEg9eEbPY49sALQoDX6FIwlZqKBM=; b=J5rKFSL+PBamTDQdRzxT1szhC0hIBDxnfPNY5yItNp5nGpYfLNYdnE5yS2Kz/ue43K6VrK 4CL//R5vj8Eqr1Hiuxyq+0zh9bgx/4BtrsjGvPcxaynoLYJgQWA6gn45jL3AYRsViYxJZ1 ISMzouBMUAy9k0Y9otSMxyV0ghLbceE= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-133-pteHCb74O3iD3FMOdOSGGQ-1; Thu, 07 Mar 2024 15:37:14 -0500 X-MC-Unique: pteHCb74O3iD3FMOdOSGGQ-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-60832a48684so22756817b3.1 for ; Thu, 07 Mar 2024 12:37:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709843834; x=1710448634; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uIkaj/NfVH637sssEg9eEbPY49sALQoDX6FIwlZqKBM=; b=q5H+gClGD3BduyOfhg/486KwBqvufjTrMu/g2KUaT6qQbi11I32vcFVfWwZO3ZvAcw 5bgRtl66LhYc/KzC3edAwNur3fCsjYWb2YdkeNPhRX4ReaM7ERv1CywpuAkdpOH4OXR7 1/OdiDVwr3kYm3b2MKMOQZ00TlkQ2yRT1vLf5EzU+cXAKxCKo+pAhfwkAVhg7ebuE5Oe 81VICHo03N5RS+P7SzkL73Xy01fEPuP3BWIfvjZZiSqMnUTinWkBmKOGwP6RY7TQLNpo BKQmEMr6dX4i7zHazzYGhc6OR4fBoMrXBpmDojc702BMy3uWZXUJfGWBaMqMD3Ms4Z84 vh/Q== X-Forwarded-Encrypted: i=1; AJvYcCUg6kR0Rl73qV+8lSsZ/4tsfp9xe3qGybIWuyK0Fqv/L0HtjgzzScw36giWHM+Jjyxirrd9cLhln4pDLSY/fT2OAcejD0HmKVf1 X-Gm-Message-State: AOJu0YyFSzGiJ4Ob1pT/UNErwJXHzO5VqZhe+fLacowFLUtklNYfqdIS 4Q4+RyhmLCLlv1YAJzvlPzwk4Pq4RJu5KEhw4Tbk+ov2C+ybdF3tUu+BX+nwvcPj7+WU8l9/p9E zzHyDBBD15vb7/MLnn5F5Df6JF6MRqD5L/0Eq+oWE755YcyG5VvPmyIwZIg== X-Received: by 2002:a25:d602:0:b0:dc7:464c:e979 with SMTP id n2-20020a25d602000000b00dc7464ce979mr17820691ybg.28.1709843834159; Thu, 07 Mar 2024 12:37:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0kWy6C6H7PyYrYZSb1T9DuggU0UojW2sbboAY0hQMVqmk/n9mXKPOE9rDKvvTM6f1FwSurw== X-Received: by 2002:a25:d602:0:b0:dc7:464c:e979 with SMTP id n2-20020a25d602000000b00dc7464ce979mr17820680ybg.28.1709843833889; Thu, 07 Mar 2024 12:37:13 -0800 (PST) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id d17-20020ac85351000000b0042f148f6caasm1753613qto.78.2024.03.07.12.37.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 12:37:13 -0800 (PST) Message-ID: Date: Thu, 7 Mar 2024 15:37:12 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] duplocale: protect use of global locale (bug 23970) To: Andreas Schwab , libc-alpha@sourceware.org References: From: Carlos O'Donell Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 3/6/24 07:48, Andreas Schwab wrote: > Protect the global locale from being modified while we compute the size of > the locale category names. That allows the use of the global locale in a > single thread, while all other threads use the thread safe locale > functions. Agreed. Good catch, we should make this work. LGTM. Reviewed-by: Carlos O'Donell > --- > locale/duplocale.c | 14 ++++++++------ > 1 file changed, 8 insertions(+), 6 deletions(-) > > diff --git a/locale/duplocale.c b/locale/duplocale.c > index a755ac5c36..bad476700f 100644 > --- a/locale/duplocale.c > +++ b/locale/duplocale.c > @@ -43,6 +43,11 @@ __duplocale (locale_t dataset) > int cnt; > size_t names_len = 0; > > + /* If dataset points to _nl_global_locale, we need to prevent other > + threads from modifying it. We also modify global data below (the > + usage counts). */ > + __libc_rwlock_wrlock (__libc_setlocale_lock); > + > /* Calculate the total space we need to store all the names. */ > for (cnt = 0; cnt < __LC_LAST; ++cnt) > if (cnt != LC_ALL && dataset->__names[cnt] != _nl_C_name) > @@ -55,9 +60,6 @@ __duplocale (locale_t dataset) > { > char *namep = (char *) (result + 1); > > - /* We modify global data (the usage counts). */ > - __libc_rwlock_wrlock (__libc_setlocale_lock); > - > for (cnt = 0; cnt < __LC_LAST; ++cnt) > if (cnt != LC_ALL) > { > @@ -78,11 +80,11 @@ __duplocale (locale_t dataset) > result->__ctype_b = dataset->__ctype_b; > result->__ctype_tolower = dataset->__ctype_tolower; > result->__ctype_toupper = dataset->__ctype_toupper; > - > - /* It's done. */ > - __libc_rwlock_unlock (__libc_setlocale_lock); > } > > + /* It's done. */ > + __libc_rwlock_unlock (__libc_setlocale_lock); > + > return result; > } > weak_alias (__duplocale, duplocale) -- Cheers, Carlos.