From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from hall.aurel32.net (hall.aurel32.net [IPv6:2001:bc8:30d7:100::1]) by sourceware.org (Postfix) with ESMTPS id B20563858409 for ; Tue, 18 Jan 2022 22:12:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B20563858409 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=aurel32.net Authentication-Results: sourceware.org; spf=none smtp.mailfrom=aurel32.net DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=aurel32.net ; s=202004.hall; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date: Subject:Cc:To:From:Content-Type:From:Reply-To:Subject:Content-ID: Content-Description:In-Reply-To:References:X-Debbugs-Cc; bh=mqMBkifsHp7+OxLKwkelAo55S8oyQ1B+oGMrfDLySkM=; b=tVGvqJIliKspzY8ZmOd2uD8TBL iweuFRcR+1g6vM7mFXTEnO+xWaa0n4VH4QtCPDcL2He50YCijGjyeJhiNJ2Z9Vs/bW6JX6sz2uy5l N2T9eg6dNeOdRInuk63wHKkADunDclmQBZh/Cvo17Kh0C3gRwloiJnnC4HKNufdGufdAgf2jAIAQJ L7wcFiruOpI8qzQJIEWyoLj3rV+KyMt+Xl4jQD/aBotSv7z8WZyaqXmhQqGzByk36tkja2g9T+n8S acpsNKI2D388tFJpy6lrldb2AE3n5jBJ6uPUfPwyxwPRbEoH+aSoPnW29ui8Wa9SI8xKsYbTEu4Fo wMsF2Yig==; Received: from [2a01:e34:ec5d:a741:8a4c:7c4e:dc4c:1787] (helo=ohm.rr44.fr) by hall.aurel32.net with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n9wiE-00BDoE-Us; Tue, 18 Jan 2022 23:12:23 +0100 Received: from aurel32 by ohm.rr44.fr with local (Exim 4.95) (envelope-from ) id 1n9wiE-0086TV-IS; Tue, 18 Jan 2022 23:12:22 +0100 From: Aurelien Jarno To: libc-stable@sourceware.org Cc: Florian Weimer , Szabolcs Nagy Subject: [COMMITTED 2.33] elf: Fix glibc-hwcaps priorities with cache flags mismatches [BZ #27046] Date: Tue, 18 Jan 2022 23:12:21 +0100 Message-Id: <20220118221221.1926142-1-aurelien@aurel32.net> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_PASS, SPF_NONE, 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-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 22:12:27 -0000 From: Florian Weimer If lib->flags (in the cache) did not match GLRO (dl_correct_cache_id), searching for further glibc-hwcaps entries did not happen, and it was possible that the best glibc-hwcaps was not found. By accident, this causes a test failure for elf/tst-glibc-hwcaps-prepend-cache on armv7l. This commit changes the cache lookup logic to continue searching if (a) no match has been found, (b) a named glibc-hwcaps match has been found(), or (c) non-glibc-hwcaps match has been found and the entry flags and cache default flags do not match. _DL_CACHE_DEFAULT_ID is used instead of GLRO (dl_correct_cache_id) because the latter is only written once on i386 if loading of libc.so.5 libraries is selected, so GLRO (dl_correct_cache_id) should probably removed in a future change. Reviewed-by: Szabolcs Nagy (cherry picked from commit 66db95b6e8264c5a6307f6a9e5285fec76907254) --- elf/dl-cache.c | 124 ++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 64 deletions(-) diff --git a/elf/dl-cache.c b/elf/dl-cache.c index 32f3bef5ea..2b8da8650d 100644 --- a/elf/dl-cache.c +++ b/elf/dl-cache.c @@ -269,81 +269,77 @@ search_cache (const char *string_table, uint32_t string_table_size, if (_dl_cache_check_flags (flags) && _dl_cache_verify_ptr (lib->value, string_table_size)) { - if (best == NULL || flags == GLRO (dl_correct_cache_id)) - { - /* Named/extension hwcaps get slightly different - treatment: We keep searching for a better - match. */ - bool named_hwcap = false; + /* Named/extension hwcaps get slightly different + treatment: We keep searching for a better + match. */ + bool named_hwcap = false; - if (entry_size >= sizeof (struct file_entry_new)) - { - /* The entry is large enough to include - HWCAP data. Check it. */ - struct file_entry_new *libnew - = (struct file_entry_new *) lib; + if (entry_size >= sizeof (struct file_entry_new)) + { + /* The entry is large enough to include + HWCAP data. Check it. */ + struct file_entry_new *libnew + = (struct file_entry_new *) lib; #ifdef SHARED - named_hwcap = dl_cache_hwcap_extension (libnew); - if (named_hwcap - && !dl_cache_hwcap_isa_level_compatible (libnew)) - continue; + named_hwcap = dl_cache_hwcap_extension (libnew); + if (named_hwcap + && !dl_cache_hwcap_isa_level_compatible (libnew)) + continue; #endif - /* The entries with named/extension hwcaps - have been exhausted. Return the best - match encountered so far if there is - one. */ - if (!named_hwcap && best != NULL) - break; + /* The entries with named/extension hwcaps have + been exhausted (they are listed before all + other entries). Return the best match + encountered so far if there is one. */ + if (!named_hwcap && best != NULL) + break; - if ((libnew->hwcap & hwcap_exclude) && !named_hwcap) - continue; - if (GLRO (dl_osversion) - && libnew->osversion > GLRO (dl_osversion)) - continue; - if (_DL_PLATFORMS_COUNT - && (libnew->hwcap & _DL_HWCAP_PLATFORM) != 0 - && ((libnew->hwcap & _DL_HWCAP_PLATFORM) - != platform)) - continue; + if ((libnew->hwcap & hwcap_exclude) && !named_hwcap) + continue; + if (GLRO (dl_osversion) + && libnew->osversion > GLRO (dl_osversion)) + continue; + if (_DL_PLATFORMS_COUNT + && (libnew->hwcap & _DL_HWCAP_PLATFORM) != 0 + && ((libnew->hwcap & _DL_HWCAP_PLATFORM) + != platform)) + continue; #ifdef SHARED - /* For named hwcaps, determine the priority - and see if beats what has been found so - far. */ - if (named_hwcap) - { - uint32_t entry_priority - = glibc_hwcaps_priority (libnew->hwcap); - if (entry_priority == 0) - /* Not usable at all. Skip. */ - continue; - else if (best == NULL - || entry_priority < best_priority) - /* This entry is of higher priority - than the previous one, or it is the - first entry. */ - best_priority = entry_priority; - else - /* An entry has already been found, - but it is a better match. */ - continue; - } -#endif /* SHARED */ + /* For named hwcaps, determine the priority and + see if beats what has been found so far. */ + if (named_hwcap) + { + uint32_t entry_priority + = glibc_hwcaps_priority (libnew->hwcap); + if (entry_priority == 0) + /* Not usable at all. Skip. */ + continue; + else if (best == NULL + || entry_priority < best_priority) + /* This entry is of higher priority + than the previous one, or it is the + first entry. */ + best_priority = entry_priority; + else + /* An entry has already been found, + but it is a better match. */ + continue; } +#endif /* SHARED */ + } - best = string_table + lib->value; + best = string_table + lib->value; - if (flags == GLRO (dl_correct_cache_id) - && !named_hwcap) - /* We've found an exact match for the shared - object and no general `ELF' release. Stop - searching, but not if a named (extension) - hwcap is used. In this case, an entry with - a higher priority may come up later. */ - break; - } + if (!named_hwcap && flags == _DL_CACHE_DEFAULT_ID) + /* With named hwcaps, we need to keep searching to + see if we find a better match. A better match + is also possible if the flags of the current + entry do not match the expected cache flags. + But if the flags match, no better entry will be + found. */ + break; } } while (++middle <= right); -- 2.34.1