From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id DAFB3385829E for ; Fri, 16 Feb 2024 13:24:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DAFB3385829E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DAFB3385829E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708089874; cv=none; b=qSLEjX5bhxRrfaWFznJl6AJcY9rqryDk/2PJc9wF8GsItzxoiRWZE3sIribRmlCsIwStrFJvG640IkgsiNe7SQJOBV98vrDXTVzcpGWTKCMGZvGeDB+kWXA4p6Ot1WbdWTiSUBP5xI/EE8p+f9DSrSPmZEbKf/eL3b9juB6n214= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708089874; c=relaxed/simple; bh=FQWKQn4cCgPHdGgw46/q2+LJQzb4W3tI2brArs1JDSY=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Txz1DaWJn2+uC6RPPcoaduBcuiFK8WyrUNi/EIakqY99g5FpvQoTewjl1aolG8iA5EV0gLjsoXzaQtwiSBmtwa4BtfdsRUkqq/hIuPnT4U/IYpfa95O32Gw2xt5H5/zYshr+/QRasGSyZJZtB4WP0agS+soTRPlc/c5un8FSJsk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1d7354ba334so18192585ad.1 for ; Fri, 16 Feb 2024 05:24:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708089870; x=1708694670; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=ANU/m8nnXwDA8wm8JegH4rMpJnd/YEa5nU7QSpj06NA=; b=df8bRTwiH6ks9btNMf43n3Mz2hWkrmQnmmBZ3cND2t/S4zYaRCvuXM5tR/DYNhZRP/ VQ24f1mdfL79JzhDizTdbgwJ8cO4/guoo4J/GB6Uz9fC0m649erJSYn4F7cQU8BUwPPc Tu/fZJE6JfpvbWQdgkE+uGkkuyTrLyKRuIflY18IqfM7aRjywl9DoPVsghNMLrsu+TxX HAYSML78iQ4aLy2hgf1QqetislSQQcUnoA7IQ+QLChR5hrgsn3GYPh+xTXfhv5GnFroX culIEAVPx7Wq7kGnQqJctDEI52eoU9ghLXBDZRZYJ9AcYID+R0ca+k8SJ7a9NUfQLuhY 5dWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708089870; x=1708694670; h=content-transfer-encoding:in-reply-to:organization:from:references :cc: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=ANU/m8nnXwDA8wm8JegH4rMpJnd/YEa5nU7QSpj06NA=; b=kmgjNvFgh/xKCQJOpZkcamBsHjq9JuLEzE/H1UjpjgBn3vDYOrT59H+51+UUZDWlcP XoUCwVK/JD+7fk5ewJLqfQwSWHI33jIYxOplSJ/KVmBjLp8ZYsT5/iC8ltJ/gV49aj+a 9AP+hltzTgvsdqYKaYnJeZS9xHR9zb6/FXC/BtQklVIvFth/mDHgphvi+SWWDe0ZC7ka WxmTi7roxkSuQxq6seJqI+7tgMnVxB4WR7H0JZIgEKr5sbCY5rgyMJ9JuFqrPfb0sNRQ mW3m1iwlCIUvsNFhwSUqR33t7t+xJW4h5bwngAdODuu3DVAO23/ZJlznsgWSKlapNnqk 2dFw== X-Forwarded-Encrypted: i=1; AJvYcCX/BFoOrqjfuPmZ1Gw3FSDBbrlwzi6W55XSQlG1vLGXZIFDAGD1Cu6UH0InnvWVFZPVgmkUyFmqfOhCZBtvs0Z5sgYMccL4E6jI X-Gm-Message-State: AOJu0YwHxWPUxdAv0L+NgraddZ73v0rcxO4EkGnEnuGoWR309eMFkAdV 1PelCB1XXmH4AtHE5LL0TTjtdtOCFvaotQMw1auulLNHWPoflRicp+390XQG//w= X-Google-Smtp-Source: AGHT+IEkpF4wJw75kHapTKJIHg0mCSLRjnO+Tg2fKUsLXnyeQ7Wnaqypf6WY2YXq/Pej6ZyT3/gnkQ== X-Received: by 2002:a17:902:f70c:b0:1db:a2a1:713b with SMTP id h12-20020a170902f70c00b001dba2a1713bmr3308950plo.25.1708089870588; Fri, 16 Feb 2024 05:24:30 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c0:8177:542a:9f26:15a9:5ce4? ([2804:1b3:a7c0:8177:542a:9f26:15a9:5ce4]) by smtp.gmail.com with ESMTPSA id j16-20020a170902759000b001d913992d8csm2959121pll.242.2024.02.16.05.24.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Feb 2024 05:24:29 -0800 (PST) Message-ID: <479d0338-46e9-439d-8b95-110ff84e07bb@linaro.org> Date: Fri, 16 Feb 2024 10:24:26 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/2] x86: Update _dl_tlsdesc_dynamic to preserve caller-saved registers Content-Language: en-US To: "H.J. Lu" Cc: Florian Weimer , libc-alpha@sourceware.org, Fangrui Song , Carlos O'Donell References: <20240213041501.2494232-1-hjl.tools@gmail.com> <20240213041501.2494232-3-hjl.tools@gmail.com> <871q9d7wra.fsf@oldenburg.str.redhat.com> <87mss061s0.fsf@oldenburg.str.redhat.com> <984b51c6-920a-40c5-aa1f-182efdd1af92@linaro.org> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK 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 16/02/24 09:58, H.J. Lu wrote: > On Fri, Feb 16, 2024 at 4:47 AM Adhemerval Zanella Netto > wrote: >> >> >> >> On 16/02/24 09:37, H.J. Lu wrote: >>> On Fri, Feb 16, 2024 at 4:20 AM H.J. Lu wrote: >>>> >>>> On Fri, Feb 16, 2024 at 4:18 AM Florian Weimer wrote: >>>>> >>>>> * H. J. Lu: >>>>> >>>>>> On Thu, Feb 15, 2024 at 10:23 PM Florian Weimer wrote: >>>>>>> >>>>>>> * Adhemerval Zanella Netto: >>>>>>> >>>>>>>>> diff --git a/elf/malloc-for-test.map b/elf/malloc-for-test.map >>>>>>>>> new file mode 100644 >>>>>>>>> index 0000000000..8437cf4346 >>>>>>>>> --- /dev/null >>>>>>>>> +++ b/elf/malloc-for-test.map >>>>>>>>> @@ -0,0 +1,6 @@ >>>>>>>>> +GLIBC_2.0 { >>>>>>>> >>>>>>>> You need to use the correct version to override the malloc: >>>>>>>> >>>>>>>> $ gdb --args tst-gnu2-tls2 --direct >>>>>>>> [...] >>>>>>>> (gdb) b apply_tls >>>>>>>> (gdb) r >>>>>>>> Thread 2 "tst-gnu2-tls2" hit Breakpoint 1, apply_tls (p=0x7ffff7bfee80) at tst-gnu2-tls2mod1.c:25 >>>>>>>> 25 { >>>>>>>> (gdb) b malloc >>>>>>>> Breakpoint 2 at 0x7ffff7ca8ad0: malloc. (3 locations) >>>>>>>> (gdb) c >>>>>>>> Continuing. >>>>>>> >>>>>>> Why do we need to set a symbol version here? I think this can be >>>>>>> removed. >>>>>> >>>>>> malloc-for-test.so provides a fake malloc to clobber caller-save >>>>>> registers. Since malloc in ld.so has a symbol version, >>>>>> >>>>>> struct r_found_version version; >>>>>> version.name = symbol_version_string (libc, GLIBC_2_0); >>>>>> version.hidden = 0; >>>>>> version.hash = _dl_elf_hash (version.name); >>>>>> version.filename = NULL; >>>>>> >>>>>> void *new_calloc = lookup_malloc_symbol (main_map, "calloc", &version); >>>>>> void *new_free = lookup_malloc_symbol (main_map, "free", &version); >>>>>> void *new_malloc = lookup_malloc_symbol (main_map, "malloc", &version); >>>>>> void *new_realloc = lookup_malloc_symbol (main_map, "realloc", &version); >>>>>> >>>>>> malloc in malloc-for-test.so must have the same version. Otherwise, >>>>>> it won't be used in the test. >>>>> >>>>> I thought that unversioned symbols interpose all versioned symbols. Has >>>>> this changed in the dynamic linker? >>>> >>>> Only for this case. >>>> >>> >>> I was wrong. Version isn't needed. Will fix it. >>> >> >> Indeed, but I think we also improve the register check testing since just clobbering >> on malloc does not really provide much coverage. > > Why? The slow path will always call malloc in malloc-for-test.so. > We can clobber any caller-save registers we need. Without > malloc-for-test.so, the test doesn't fail for i386 since malloc in libc.so > doesn't use any vector registers. > The idea is to check whether _dl_tlsdesc_dynamic call does preserve any possible caller-saved register and since this test is generic and afaik all affected ABIs follow the same idea (compiler won't save/restore such register), clobbering the register will only trigger a possible issue iff the thread that actually issue the TLS usage does actually use any possible register. That's why I think a better coverage would to also clobber the register before the TLS access, and check if their values does not change over the TLS access.