diff --git a/0001-add-loongarch-suopport-for-abseil-cpp.patch b/0001-add-loongarch-suopport-for-abseil-cpp.patch index 0e28a69cbad910268efdefb608243f2fd3ba990f..2a90469ea9a8ab30644b92b3429c1140a01a418a 100644 --- a/0001-add-loongarch-suopport-for-abseil-cpp.patch +++ b/0001-add-loongarch-suopport-for-abseil-cpp.patch @@ -1,34 +1,37 @@ -From a8c98703c8b7b1fc3ae104dce0bfd05dc92a1d7d Mon Sep 17 00:00:00 2001 -From: Wenlong Zhang Huang Yang -Date: Mon, 14 Nov 2022 11:48:49 +0000 +From 560380189ff29687e011eada93774af59452f2c5 Mon Sep 17 00:00:00 2001 +From: Wenlong Zhang +Date: Wed, 6 Mar 2024 03:28:59 +0000 Subject: [PATCH] add loongarch suopport for abseil-cpp -Signed-off-by: Wenlong Zhang --- - absl/base/internal/direct_mmap.h | 3 ++- - 1 file changed, 2 insertions(+), 1 deletion(-) + absl/base/internal/direct_mmap.h | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/absl/base/internal/direct_mmap.h b/absl/base/internal/direct_mmap.h -index e492bb0..d11a64e 100644 +index 1beb2ee..80fcbbb 100644 --- a/absl/base/internal/direct_mmap.h +++ b/absl/base/internal/direct_mmap.h -@@ -79,6 +79,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd, - (defined(__mips__) && _MIPS_SIM == _MIPS_SIM_ABI32) || \ +@@ -80,7 +80,8 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd, (defined(__PPC__) && !defined(__PPC64__)) || \ (defined(__riscv) && __riscv_xlen == 32) || \ -+ defined(__loongarch64) || \ (defined(__s390__) && !defined(__s390x__)) || \ - (defined(__sparc__) && !defined(__arch64__)) +- (defined(__sparc__) && !defined(__arch64__)) ++ (defined(__sparc__) && !defined(__arch64__)) || \ ++ defined(__loongarch64) // On these architectures, implement mmap with mmap2. -@@ -100,7 +101,7 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd, - return __mmap2(start, length, prot, flags, fd, offset / pagesize); + static int pagesize = 0; + if (pagesize == 0) { +@@ -99,6 +100,10 @@ inline void* DirectMmap(void* start, size_t length, int prot, int flags, int fd, + // Workaround by invoking __mmap2() instead. + return __mmap2(start, length, prot, flags, fd, + static_cast(offset / pagesize)); ++#elif defined(__loongarch64) ++ return reinterpret_cast( ++ syscall(SYS_mmap, start, length, prot, flags, fd, ++ static_cast(offset / pagesize))); // NOLINT #else return reinterpret_cast( -- syscall(SYS_mmap2, start, length, prot, flags, fd, -+ syscall(SYS_mmap, start, length, prot, flags, fd, - static_cast(offset / pagesize))); - #endif - #elif defined(__s390x__) + syscall(SYS_mmap2, start, length, prot, flags, fd, -- -2.33.0 +2.43.0 diff --git a/0002-PR-1644-unscaledcycleclock-remove-RISC-V-support.patch b/0002-PR-1644-unscaledcycleclock-remove-RISC-V-support.patch new file mode 100644 index 0000000000000000000000000000000000000000..f9adc5d6752b688fb0e6f802219af8f1c43b48e6 --- /dev/null +++ b/0002-PR-1644-unscaledcycleclock-remove-RISC-V-support.patch @@ -0,0 +1,81 @@ +From 7335a36d0b5c1c597566f9aa3f458a5b6817c3b4 Mon Sep 17 00:00:00 2001 +From: aurel32 +Date: Fri, 22 Mar 2024 14:21:13 -0700 +Subject: [PATCH] PR #1644: unscaledcycleclock: remove RISC-V support + +Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1644 + +Starting with Linux 6.6 [1], RDCYCLE is a privileged instruction on RISC-V and can't be used directly from userland. There is a sysctl option to change that as a transition period, but it will eventually disappear. + +The RDTIME instruction is another less accurate alternative, however its frequency varies from board to board, and there is currently now way to get its frequency from userland [2]. + +Therefore this patch just removes the code for unscaledcycleclock on RISC-V. Without processor specific implementation, abseil relies on std::chrono::steady_clock::now().time_since_epoch() which is basically a wrapper around clock_gettime (CLOCK_MONOTONIC), which in turns use __vdso_clock_gettime(). On RISC-V this VDSO is just a wrapper around RDTIME correctly scaled to use nanoseconds units. + +This fixes the testsuite on riscv64, tested on a VisionFive 2 board. + +[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=cc4c07c89aada16229084eeb93895c95b7eabaa3 +[2] https://github.com/abseil/abseil-cpp/pull/1631 +Merge 43356a2548cfde76e164d446cb69004b488c6a71 into 76f8011beabdaee872b5fde7546e02407b220cb1 + +Merging this change closes #1644 + +COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1644 from aurel32:rv64-no-unscaledcycleclock 43356a2548cfde76e164d446cb69004b488c6a71 +PiperOrigin-RevId: 618286262 +Change-Id: Ie4120a727e7d0bb185df6e06ea145c780ebe6652 +--- + absl/base/internal/unscaledcycleclock.cc | 12 ------------ + absl/base/internal/unscaledcycleclock_config.h | 8 ++++---- + 2 files changed, 4 insertions(+), 16 deletions(-) + +diff --git a/absl/base/internal/unscaledcycleclock.cc b/absl/base/internal/unscaledcycleclock.cc +index 05e0e7ba..a0bf3a65 100644 +--- a/absl/base/internal/unscaledcycleclock.cc ++++ b/absl/base/internal/unscaledcycleclock.cc +@@ -121,18 +121,6 @@ double UnscaledCycleClock::Frequency() { + return aarch64_timer_frequency; + } + +-#elif defined(__riscv) +- +-int64_t UnscaledCycleClock::Now() { +- int64_t virtual_timer_value; +- asm volatile("rdcycle %0" : "=r"(virtual_timer_value)); +- return virtual_timer_value; +-} +- +-double UnscaledCycleClock::Frequency() { +- return base_internal::NominalCPUFrequency(); +-} +- + #elif defined(_M_IX86) || defined(_M_X64) + + #pragma intrinsic(__rdtsc) +diff --git a/absl/base/internal/unscaledcycleclock_config.h b/absl/base/internal/unscaledcycleclock_config.h +index 24b324ac..43a3dabe 100644 +--- a/absl/base/internal/unscaledcycleclock_config.h ++++ b/absl/base/internal/unscaledcycleclock_config.h +@@ -21,8 +21,8 @@ + + // The following platforms have an implementation of a hardware counter. + #if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \ +- defined(__powerpc__) || defined(__ppc__) || defined(__riscv) || \ +- defined(_M_IX86) || (defined(_M_X64) && !defined(_M_ARM64EC)) ++ defined(__powerpc__) || defined(__ppc__) || defined(_M_IX86) || \ ++ (defined(_M_X64) && !defined(_M_ARM64EC)) + #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1 + #else + #define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 0 +@@ -53,8 +53,8 @@ + #if ABSL_USE_UNSCALED_CYCLECLOCK + // This macro can be used to test if UnscaledCycleClock::Frequency() + // is NominalCPUFrequency() on a particular platform. +-#if (defined(__i386__) || defined(__x86_64__) || defined(__riscv) || \ +- defined(_M_IX86) || defined(_M_X64)) ++#if (defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || \ ++ defined(_M_X64)) + #define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY + #endif + #endif +-- +2.39.2 + diff --git a/abseil-cpp-20210324.2-sw.patch b/abseil-cpp-20210324.2-sw.patch old mode 100755 new mode 100644 diff --git a/abseil-cpp-20220623.1.tar.gz b/abseil-cpp-20220623.1.tar.gz deleted file mode 100644 index 492bcbc40c043e3a2a8388ac0e38008f7840fd93..0000000000000000000000000000000000000000 Binary files a/abseil-cpp-20220623.1.tar.gz and /dev/null differ diff --git a/abseil-cpp-20230802.1.tar.gz b/abseil-cpp-20230802.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..397f6515d73a0678bbdb0db3051a451541d783ab Binary files /dev/null and b/abseil-cpp-20230802.1.tar.gz differ diff --git a/abseil-cpp.spec b/abseil-cpp.spec index 2428a53b49e29a614d25f4761232bfe87bc78a11..eef3e20ba54808d7ce252841941f8b95e1925d5e 100644 --- a/abseil-cpp.spec +++ b/abseil-cpp.spec @@ -2,27 +2,23 @@ %undefine __cmake_in_source_build # Installed library version -%global lib_version 2206.0.0 +%global lib_version 2308.0.0 Name: abseil-cpp -Version: 20220623.1 -Release: 6 +Version: 20230802.1 +Release: 1 Summary: C++ Common Libraries -License: ASL 2.0 +License: Apache-2.0 URL: https://abseil.io Source0: https://github.com/abseil/abseil-cpp/archive/%{version}/%{name}-%{version}.tar.gz -Patch0: backport-Do-not-leak-maes-msse4.1-into-pkgconfig.patch Patch1: abseil-cpp-20210324.2-sw.patch -Patch2: backport-Add-missing-include-for-std-unique_ptr.patch -Patch3: backport-CVE-2025-0838.patch - -%ifarch loongarch64 Patch100: 0001-add-loongarch-suopport-for-abseil-cpp.patch -%endif +Patch101: 0002-PR-1644-unscaledcycleclock-remove-RISC-V-support.patch +Patch102: backport-CVE-2025-0838.patch -BuildRequires: cmake +BuildRequires: cmake ninja-build BuildRequires: gcc-c++ BuildRequires: make @@ -53,15 +49,107 @@ Development headers for %{name} %autosetup -p1 %build -%cmake +%cmake -S %{_vpath_srcdir} -B %{_vpath_builddir} -GNinja \ + -DCMAKE_BUILD_TYPE:STRING=None \ + -DCMAKE_CXX_STANDARD:STRING=17 \ + -DCMAKE_SHARED_LINKER_FLAGS="-Wl,--as-needed" \ + -DCMAKE_BUILD_TYPE=RelWithDebInfo + +%__cmake --build %{_vpath_builddir} %{?_smp_mflags} --verbose %install -%make_install +DESTDIR="%{buildroot}" %__cmake --install "%{_vpath_builddir}" %files %license LICENSE %doc FAQ.md README.md UPGRADES.md -%{_libdir}/libabsl_*.so.%{lib_version} +# All shared libraries except installed TESTONLY libraries; see the %%files +# list for the -testing subpackage for those. +%{_libdir}/libabsl_bad_any_cast_impl.so.%{lib_version} +%{_libdir}/libabsl_bad_optional_access.so.%{lib_version} +%{_libdir}/libabsl_bad_variant_access.so.%{lib_version} +%{_libdir}/libabsl_base.so.%{lib_version} +%{_libdir}/libabsl_city.so.%{lib_version} +%{_libdir}/libabsl_civil_time.so.%{lib_version} +%{_libdir}/libabsl_cord.so.%{lib_version} +%{_libdir}/libabsl_cord_internal.so.%{lib_version} +%{_libdir}/libabsl_cordz_functions.so.%{lib_version} +%{_libdir}/libabsl_cordz_handle.so.%{lib_version} +%{_libdir}/libabsl_cordz_info.so.%{lib_version} +%{_libdir}/libabsl_cordz_sample_token.so.%{lib_version} +%{_libdir}/libabsl_crc32c.so.%{lib_version} +%{_libdir}/libabsl_crc_cord_state.so.%{lib_version} +%{_libdir}/libabsl_crc_cpu_detect.so.%{lib_version} +%{_libdir}/libabsl_crc_internal.so.%{lib_version} +%{_libdir}/libabsl_debugging_internal.so.%{lib_version} +%{_libdir}/libabsl_demangle_internal.so.%{lib_version} +%{_libdir}/libabsl_die_if_null.so.%{lib_version} +%{_libdir}/libabsl_examine_stack.so.%{lib_version} +%{_libdir}/libabsl_exponential_biased.so.%{lib_version} +%{_libdir}/libabsl_failure_signal_handler.so.%{lib_version} +%{_libdir}/libabsl_flags.so.%{lib_version} +%{_libdir}/libabsl_flags_commandlineflag.so.%{lib_version} +%{_libdir}/libabsl_flags_commandlineflag_internal.so.%{lib_version} +%{_libdir}/libabsl_flags_config.so.%{lib_version} +%{_libdir}/libabsl_flags_internal.so.%{lib_version} +%{_libdir}/libabsl_flags_marshalling.so.%{lib_version} +%{_libdir}/libabsl_flags_parse.so.%{lib_version} +%{_libdir}/libabsl_flags_private_handle_accessor.so.%{lib_version} +%{_libdir}/libabsl_flags_program_name.so.%{lib_version} +%{_libdir}/libabsl_flags_reflection.so.%{lib_version} +%{_libdir}/libabsl_flags_usage.so.%{lib_version} +%{_libdir}/libabsl_flags_usage_internal.so.%{lib_version} +%{_libdir}/libabsl_graphcycles_internal.so.%{lib_version} +%{_libdir}/libabsl_hash.so.%{lib_version} +%{_libdir}/libabsl_hashtablez_sampler.so.%{lib_version} +%{_libdir}/libabsl_int128.so.%{lib_version} +%{_libdir}/libabsl_kernel_timeout_internal.so.%{lib_version} +%{_libdir}/libabsl_leak_check.so.%{lib_version} +%{_libdir}/libabsl_log_entry.so.%{lib_version} +%{_libdir}/libabsl_log_flags.so.%{lib_version} +%{_libdir}/libabsl_log_globals.so.%{lib_version} +%{_libdir}/libabsl_log_initialize.so.%{lib_version} +%{_libdir}/libabsl_log_internal_check_op.so.%{lib_version} +%{_libdir}/libabsl_log_internal_conditions.so.%{lib_version} +%{_libdir}/libabsl_log_internal_format.so.%{lib_version} +%{_libdir}/libabsl_log_internal_globals.so.%{lib_version} +%{_libdir}/libabsl_log_internal_log_sink_set.so.%{lib_version} +%{_libdir}/libabsl_log_internal_message.so.%{lib_version} +%{_libdir}/libabsl_log_internal_nullguard.so.%{lib_version} +%{_libdir}/libabsl_log_internal_proto.so.%{lib_version} +%{_libdir}/libabsl_log_severity.so.%{lib_version} +%{_libdir}/libabsl_log_sink.so.%{lib_version} +%{_libdir}/libabsl_low_level_hash.so.%{lib_version} +%{_libdir}/libabsl_malloc_internal.so.%{lib_version} +%{_libdir}/libabsl_periodic_sampler.so.%{lib_version} +%{_libdir}/libabsl_random_distributions.so.%{lib_version} +%{_libdir}/libabsl_random_internal_distribution_test_util.so.%{lib_version} +%{_libdir}/libabsl_random_internal_platform.so.%{lib_version} +%{_libdir}/libabsl_random_internal_pool_urbg.so.%{lib_version} +%{_libdir}/libabsl_random_internal_randen.so.%{lib_version} +%{_libdir}/libabsl_random_internal_randen_hwaes.so.%{lib_version} +%{_libdir}/libabsl_random_internal_randen_hwaes_impl.so.%{lib_version} +%{_libdir}/libabsl_random_internal_randen_slow.so.%{lib_version} +%{_libdir}/libabsl_random_internal_seed_material.so.%{lib_version} +%{_libdir}/libabsl_random_seed_gen_exception.so.%{lib_version} +%{_libdir}/libabsl_random_seed_sequences.so.%{lib_version} +%{_libdir}/libabsl_raw_hash_set.so.%{lib_version} +%{_libdir}/libabsl_raw_logging_internal.so.%{lib_version} +%{_libdir}/libabsl_scoped_set_env.so.%{lib_version} +%{_libdir}/libabsl_spinlock_wait.so.%{lib_version} +%{_libdir}/libabsl_stacktrace.so.%{lib_version} +%{_libdir}/libabsl_status.so.%{lib_version} +%{_libdir}/libabsl_statusor.so.%{lib_version} +%{_libdir}/libabsl_str_format_internal.so.%{lib_version} +%{_libdir}/libabsl_strerror.so.%{lib_version} +%{_libdir}/libabsl_strings.so.%{lib_version} +%{_libdir}/libabsl_strings_internal.so.%{lib_version} +%{_libdir}/libabsl_string_view.so.%{lib_version} +%{_libdir}/libabsl_symbolize.so.%{lib_version} +%{_libdir}/libabsl_synchronization.so.%{lib_version} +%{_libdir}/libabsl_throw_delegate.so.%{lib_version} +%{_libdir}/libabsl_time.so.%{lib_version} +%{_libdir}/libabsl_time_zone.so.%{lib_version} %files devel %{_includedir}/absl @@ -70,6 +158,9 @@ Development headers for %{name} %{_libdir}/pkgconfig/*.pc %changelog +* Mon Apr 7 2025 fuanan - 20230802.1-1 +- Update version to 20230802.1 + * Mon Feb 24 2025 xinghe - 20220623.1-6 - Type:cves - CVE:CVE-2025-0838 diff --git a/backport-Add-missing-include-for-std-unique_ptr.patch b/backport-Add-missing-include-for-std-unique_ptr.patch deleted file mode 100644 index 09a64bb19c84bcdd086d8e5ec4c264ad3086a2f8..0000000000000000000000000000000000000000 --- a/backport-Add-missing-include-for-std-unique_ptr.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 701185dbce17a2f49334027ca3cb5788a5d06c6d Mon Sep 17 00:00:00 2001 -From: Abseil Team -Date: Fri, 22 Jul 2022 12:41:32 -0700 -Subject: [PATCH] Add missing include for std::unique_ptr - -PiperOrigin-RevId: 462681925 -Change-Id: Ic5610cb4124b7f60a00817ca2f1d52674b27c168 - -Conflict: NA -Reference: https://github.com/abseil/abseil-cpp/commit/701185dbce17a2f49334027ca3cb5788a5d06c6d ---- - absl/status/internal/status_internal.h | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/absl/status/internal/status_internal.h b/absl/status/internal/status_internal.h -index 19a4a7aaa09..873eb5c245d 100644 ---- a/absl/status/internal/status_internal.h -+++ b/absl/status/internal/status_internal.h -@@ -14,6 +14,7 @@ - #ifndef ABSL_STATUS_INTERNAL_STATUS_INTERNAL_H_ - #define ABSL_STATUS_INTERNAL_STATUS_INTERNAL_H_ - -+#include - #include - #include - diff --git a/backport-CVE-2025-0838.patch b/backport-CVE-2025-0838.patch index 5332026a8d6f7c38b5f6b705dd398595a02884e4..aac5033fffaefd7f48070b74da9cf7e48baea256 100644 --- a/backport-CVE-2025-0838.patch +++ b/backport-CVE-2025-0838.patch @@ -1,110 +1,110 @@ -From 3c4b18dc14949d1c6dac8bae2e459c71b21e3416 Mon Sep 17 00:00:00 2001 -From: Derek Mauro -Date: Wed, 22 Jan 2025 15:58:56 -0500 -Subject: [PATCH] Fix potential integer overflow in hash container - create/resize - -The sized constructors, reserve(), and rehash() methods of -absl::{flat,node}_hash_{set,map} did not impose an upper bound on -their size argument. As a result, it was possible for a caller to pass -a very large size that would cause an integer overflow when computing -the size of the container's backing store. Subsequent accesses to the -container might then access out-of-bounds memory. - -The fix is in two parts: - -1) Update max_size() to return the maximum number of items that can be -stored in the container - -2) Validate the size arguments to the constructors, reserve(), and -rehash() methods, and abort the program when the argument is invalid - -We've looked at uses of these containers in Google codebases like -Chrome, and determined this vulnerability is likely to be difficult to -exploit. This is primarily because container sizes are rarely -attacker-controlled. - -The bug was discovered by Dmitry Vyukov . - -Conflict: remove absl/base/config.h and context adapt -Reference: https://github.com/abseil/abseil-cpp/commit/3c4b18dc14949d1c6dac8bae2e459c71b21e3416 ---- - absl/container/internal/raw_hash_set.h | 15 ++++++++++++++- - absl/container/internal/raw_hash_set_test.cc | 8 ++++++++ - 2 files changed, 22 insertions(+), 1 deletion(-) - -diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h -index ea912f8..40c2c67 100644 ---- a/absl/container/internal/raw_hash_set.h -+++ b/absl/container/internal/raw_hash_set.h -@@ -745,6 +745,12 @@ inline size_t NormalizeCapacity(size_t n) { - return n ? ~size_t{} >> countl_zero(n) : 1; - } - -+template -+size_t MaxValidCapacity() { -+ return NormalizeCapacity((std::numeric_limits::max)() / 4 / -+ kSlotSize); -+} -+ - // General notes on capacity/growth methods below: - // - We use 7/8th as maximum load factor. For 16-wide groups, that gives an - // average of two empty slots per group. -@@ -1148,6 +1154,8 @@ class raw_hash_set { - : ctrl_(EmptyGroup()), - settings_(0, HashtablezInfoHandle(), hash, eq, alloc) { - if (bucket_count) { -+ ABSL_RAW_CHECK(bucket_count <= MaxValidCapacity(), -+ "Hash table size overflow"); - capacity_ = NormalizeCapacity(bucket_count); - initialize_slots(); - } -@@ -1341,7 +1349,9 @@ class raw_hash_set { - bool empty() const { return !size(); } - size_t size() const { return size_; } - size_t capacity() const { return capacity_; } -- size_t max_size() const { return (std::numeric_limits::max)(); } -+ size_t max_size() const { -+ return CapacityToGrowth(MaxValidCapacity()); -+ } - - ABSL_ATTRIBUTE_REINITIALIZES void clear() { - // Iterating over this container is O(bucket_count()). When bucket_count() -@@ -1678,6 +1688,8 @@ class raw_hash_set { - auto m = NormalizeCapacity(n | GrowthToLowerboundCapacity(size())); - // n == 0 unconditionally rehashes as per the standard. - if (n == 0 || m > capacity_) { -+ ABSL_RAW_CHECK(m <= MaxValidCapacity(), -+ "Hash table size overflow"); - resize(m); - - // This is after resize, to ensure that we have completed the allocation -@@ -1688,6 +1700,7 @@ class raw_hash_set { - - void reserve(size_t n) { - if (n > size() + growth_left()) { -+ ABSL_RAW_CHECK(n <= max_size(), "Hash table size overflow"); - size_t m = GrowthToLowerboundCapacity(n); - resize(NormalizeCapacity(m)); - -diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc -index f77ffbc..078bbad 100644 ---- a/absl/container/internal/raw_hash_set_test.cc -+++ b/absl/container/internal/raw_hash_set_test.cc -@@ -2181,6 +2181,14 @@ TEST(Table, AlignOne) { - } - } - -+TEST(Table, MaxSizeOverflow) { -+ size_t overflow = (std::numeric_limits::max)(); -+ EXPECT_DEATH_IF_SUPPORTED(IntTable t(overflow), "Hash table size overflow"); -+ IntTable t; -+ EXPECT_DEATH_IF_SUPPORTED(t.reserve(overflow), "Hash table size overflow"); -+ EXPECT_DEATH_IF_SUPPORTED(t.rehash(overflow), "Hash table size overflow"); -+} -+ - } // namespace - } // namespace container_internal - ABSL_NAMESPACE_END --- -2.43.0 \ No newline at end of file +From 3c4b18dc14949d1c6dac8bae2e459c71b21e3416 Mon Sep 17 00:00:00 2001 +From: Derek Mauro +Date: Wed, 22 Jan 2025 15:58:56 -0500 +Subject: [PATCH] Fix potential integer overflow in hash container + create/resize + +The sized constructors, reserve(), and rehash() methods of +absl::{flat,node}_hash_{set,map} did not impose an upper bound on +their size argument. As a result, it was possible for a caller to pass +a very large size that would cause an integer overflow when computing +the size of the container's backing store. Subsequent accesses to the +container might then access out-of-bounds memory. + +The fix is in two parts: + +1) Update max_size() to return the maximum number of items that can be +stored in the container + +2) Validate the size arguments to the constructors, reserve(), and +rehash() methods, and abort the program when the argument is invalid + +We've looked at uses of these containers in Google codebases like +Chrome, and determined this vulnerability is likely to be difficult to +exploit. This is primarily because container sizes are rarely +attacker-controlled. + +The bug was discovered by Dmitry Vyukov . + +Conflict: remove absl/base/config.h +Reference: https://github.com/abseil/abseil-cpp/commit/3c4b18dc14949d1c6dac8bae2e459c71b21e3416 +--- + absl/base/config.h | 2 +- + absl/container/internal/raw_hash_set.h | 16 +++++++++++++++- + absl/container/internal/raw_hash_set_test.cc | 8 ++++++++ + 3 files changed, 24 insertions(+), 2 deletions(-) + +diff --git a/absl/container/internal/raw_hash_set.h b/absl/container/internal/raw_hash_set.h +index 5f89d8efee6..92b93453314 100644 +--- a/absl/container/internal/raw_hash_set.h ++++ b/absl/container/internal/raw_hash_set.h +@@ -1076,6 +1076,12 @@ inline size_t NormalizeCapacity(size_t n) { + return n ? ~size_t{} >> countl_zero(n) : 1; + } + ++template ++size_t MaxValidCapacity() { ++ return NormalizeCapacity((std::numeric_limits::max)() / 4 / ++ kSlotSize); ++} ++ + // General notes on capacity/growth methods below: + // - We use 7/8th as maximum load factor. For 16-wide groups, that gives an + // average of two empty slots per group. +@@ -1717,6 +1723,8 @@ class raw_hash_set { + const allocator_type& alloc = allocator_type()) + : settings_(CommonFields{}, hash, eq, alloc) { + if (bucket_count) { ++ ABSL_RAW_CHECK(bucket_count <= MaxValidCapacity(), ++ "Hash table size overflow"); + common().set_capacity(NormalizeCapacity(bucket_count)); + initialize_slots(); + } +@@ -1916,7 +1924,10 @@ class raw_hash_set { + bool empty() const { return !size(); } + size_t size() const { return common().size(); } + size_t capacity() const { return common().capacity(); } +- size_t max_size() const { return (std::numeric_limits::max)(); } ++ size_t max_size() const { ++ return CapacityToGrowth(MaxValidCapacity()); ++ } ++ + + ABSL_ATTRIBUTE_REINITIALIZES void clear() { + // Iterating over this container is O(bucket_count()). When bucket_count() +@@ -2266,6 +2277,8 @@ class raw_hash_set { + auto m = NormalizeCapacity(n | GrowthToLowerboundCapacity(size())); + // n == 0 unconditionally rehashes as per the standard. + if (n == 0 || m > capacity()) { ++ ABSL_RAW_CHECK(m <= MaxValidCapacity(), ++ "Hash table size overflow"); + resize(m); + + // This is after resize, to ensure that we have completed the allocation +@@ -2276,6 +2289,7 @@ class raw_hash_set { + + void reserve(size_t n) { + if (n > size() + growth_left()) { ++ ABSL_RAW_CHECK(n <= max_size(), "Hash table size overflow"); + size_t m = GrowthToLowerboundCapacity(n); + resize(NormalizeCapacity(m)); + +diff --git a/absl/container/internal/raw_hash_set_test.cc b/absl/container/internal/raw_hash_set_test.cc +index 242a97cbe3f..d5d5f3934da 100644 +--- a/absl/container/internal/raw_hash_set_test.cc ++++ b/absl/container/internal/raw_hash_set_test.cc +@@ -2510,6 +2510,14 @@ TEST(Iterator, InvalidComparisonDifferentTables) { + "Invalid iterator comparison.*non-end"); + } + ++TEST(Table, MaxSizeOverflow) { ++ size_t overflow = (std::numeric_limits::max)(); ++ EXPECT_DEATH_IF_SUPPORTED(IntTable t(overflow), "Hash table size overflow"); ++ IntTable t; ++ EXPECT_DEATH_IF_SUPPORTED(t.reserve(overflow), "Hash table size overflow"); ++ EXPECT_DEATH_IF_SUPPORTED(t.rehash(overflow), "Hash table size overflow"); ++} ++ + } // namespace + } // namespace container_internal + ABSL_NAMESPACE_END diff --git a/backport-Do-not-leak-maes-msse4.1-into-pkgconfig.patch b/backport-Do-not-leak-maes-msse4.1-into-pkgconfig.patch deleted file mode 100644 index 94e79c3792ef9e4e0562b022b14ca7509ac27638..0000000000000000000000000000000000000000 --- a/backport-Do-not-leak-maes-msse4.1-into-pkgconfig.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 09e96049995584c3489e4bd1467313e3e85af99c Mon Sep 17 00:00:00 2001 -From: Bruno Pitrus -Date: Mon, 11 Jul 2022 18:27:39 +0200 -Subject: [PATCH] Do not leak -maes -msse4.1 into pkgconfig - -Conflict: NA -Reference: https://github.com/abseil/abseil-cpp/commit/09e96049995584c3489e4bd1467313e3e85af99c ---- - CMake/AbseilHelpers.cmake | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/CMake/AbseilHelpers.cmake b/CMake/AbseilHelpers.cmake -index ebe9ddc8..9cd87c51 100644 ---- a/CMake/AbseilHelpers.cmake -+++ b/CMake/AbseilHelpers.cmake -@@ -166,6 +166,8 @@ function(absl_cc_library) - set(PC_CFLAGS "${PC_CFLAGS} ${cflag}") - elseif(${cflag} MATCHES "^(-W|/w[1234eo])") - # Don't impose our warnings on others. -+ elseif(${cflag} MATCHES "^-m") -+ # Don't impose CPU instruction requirements on others, as the code performs feature detection on runtime. - else() - set(PC_CFLAGS "${PC_CFLAGS} ${cflag}") - endif() --- -2.33.0