diff mbox series

[wrynose,2/2] gcc: Fix for CVE-2026-115455

Message ID 20261204095524.1907176-2-Harish.Sadineni@windriver.com
State New
Headers show
Series [wrynose,1/2] gcc: Fix for CVE-2026-114691 | expand

Commit Message

Sadineni, Harish Dec. 4, 2026, 9:55 a.m. UTC
From: Harish Sadineni <Harish.Sadineni@windriver.com>

libstdc++: Fix stack corruption in std::bitset stream extraction [PR124370]

The __builtin_alloca argument didn't account for the size or alignment
of wide characters.
Replace __builtin_alloca with an array _CharT[small ? N : 1] which is
used for small, or a heap allocation otherwise.

Refrences:
https://nvd.nist.gov/vuln/detail/cve-2026-115455
https://gcc.gnu.org/cgit/gcc/patch/?id=5d419c69ce2e6b86d7da75f18736904885674219

Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
---
 meta/recipes-devtools/gcc/gcc-15.3.inc        |   1 +
 .../gcc/gcc/0031-CVE-2026-115455.patch        | 140 ++++++++++++++++++
 2 files changed, 141 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/0031-CVE-2026-115455.patch
diff mbox series

Patch

diff --git a/meta/recipes-devtools/gcc/gcc-15.3.inc b/meta/recipes-devtools/gcc/gcc-15.3.inc
index b87b4ce9f4..8898a4a207 100644
--- a/meta/recipes-devtools/gcc/gcc-15.3.inc
+++ b/meta/recipes-devtools/gcc/gcc-15.3.inc
@@ -77,6 +77,7 @@  SRC_URI = "${BASEURI} \
            file://0001-mapper-localhost-might-not-be-known.patch \
 	   file://0029-CVE-2026-102010.patch \
 	   file://0030-CVE-2026-114691.patch \
+	   file://0031-CVE-2026-115455.patch \
 "
 
 UNPACKDIR = "${TMPDIR}/work-shared/gcc-${PV}-${PR}/sources"
diff --git a/meta/recipes-devtools/gcc/gcc/0031-CVE-2026-115455.patch b/meta/recipes-devtools/gcc/gcc/0031-CVE-2026-115455.patch
new file mode 100644
index 0000000000..91ad4bd216
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/0031-CVE-2026-115455.patch
@@ -0,0 +1,140 @@ 
+From 2ffbcde8634f69ae6086e2677bd90ecbad687f9f Mon Sep 17 00:00:00 2001
+From: Jonathan Wakely <jwakely@redhat.com>
+Date: Thu, 1 Oct 2026 22:50:13 +0100
+Subject: libstdc++: Fix stack corruption in std::bitset stream extraction
+ [PR124370]
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The __builtin_alloca argument didn't account for the size or alignment
+of wide characters.
+Replace __builtin_alloca with an array _CharT[small ? N : 1] which is
+used for small, or a heap allocation otherwise.
+
+libstdc++-v3/ChangeLog:
+
+	PR libstdc++/124370
+	* include/std/bitset (operator>>): Use array inside _Buffer
+	instead of __builtin_alloca.
+	* testsuite/20_util/bitset/io/input.cc: Suppress pedwarn about
+	C++14 binary literal.
+	* testsuite/20_util/bitset/io/wchar_t.cc: New test.
+
+CVE: CVE-2026-115455
+Upstream-Status: Backport [https://gcc.gnu.org/cgit/gcc/patch/?id=2ffbcde8634f69ae6086e2677bd90ecbad687f9f]
+
+Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
+(cherry picked from commit 5d419c69ce2e6b86d7da75f18736904885674219)
+---
+ libstdc++-v3/include/std/bitset                    | 25 +++++++-------
+ libstdc++-v3/testsuite/20_util/bitset/io/input.cc  |  2 ++
+ .../testsuite/20_util/bitset/io/wchar_t.cc         | 39 ++++++++++++++++++++++
+ 3 files changed, 54 insertions(+), 12 deletions(-)
+ create mode 100644 libstdc++-v3/testsuite/20_util/bitset/io/wchar_t.cc
+
+diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
+index c07117ae8d82..f9ec96fbb5dd 100644
+--- a/libstdc++-v3/include/std/bitset
++++ b/libstdc++-v3/include/std/bitset
+@@ -1605,26 +1605,27 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
+       typedef std::basic_istream<_CharT, _Traits>  __istream_type;
+       typedef typename __istream_type::ios_base    __ios_base;
+ 
++      static const bool __use_local = _Nb * sizeof(_CharT) <= 256;
++
+       struct _Buffer
+       {
+-	static _GLIBCXX_CONSTEXPR bool _S_use_alloca() { return _Nb <= 256; }
+-
+-	explicit _Buffer(_CharT* __p) : _M_ptr(__p) { }
++	_Buffer() : _M_ptr(_M_local)
++	{
++	  if _GLIBCXX17_CONSTEXPR (!__use_local)
++	    _M_ptr = new _CharT[_Nb];
++	}
+ 
+ 	~_Buffer()
+ 	{
+-	  if _GLIBCXX17_CONSTEXPR (!_S_use_alloca())
++	  if _GLIBCXX17_CONSTEXPR (!__use_local)
+ 	    delete[] _M_ptr;
+ 	}
+ 
+-	_CharT* const _M_ptr;
+-      };
+-      _CharT* __ptr;
+-      if _GLIBCXX17_CONSTEXPR (_Buffer::_S_use_alloca())
+-	__ptr = (_CharT*)__builtin_alloca(_Nb);
+-      else
+-	__ptr = new _CharT[_Nb];
+-      const _Buffer __buf(__ptr);
++	_CharT* _M_ptr;
++	_CharT _M_local[__use_local && _Nb != 0 ? _Nb : 1];
++      } __buf;
++
++      _CharT* __ptr = __buf._M_ptr;
+ 
+       // _GLIBCXX_RESOLVE_LIB_DEFECTS
+       // 303. Bitset input operator underspecified
+diff --git a/libstdc++-v3/testsuite/20_util/bitset/io/input.cc b/libstdc++-v3/testsuite/20_util/bitset/io/input.cc
+index ab7cc36fc833..6bd658f7e911 100644
+--- a/libstdc++-v3/testsuite/20_util/bitset/io/input.cc
++++ b/libstdc++-v3/testsuite/20_util/bitset/io/input.cc
+@@ -42,6 +42,8 @@ void test01()
+   VERIFY( ss.rdstate() == ios_base::goodbit ); // LWG 3199
+ }
+ 
++#pragma GCC diagnostic ignored "-Wc++14-extensions" // 0b literals
++
+ void
+ test02()
+ {
+diff --git a/libstdc++-v3/testsuite/20_util/bitset/io/wchar_t.cc b/libstdc++-v3/testsuite/20_util/bitset/io/wchar_t.cc
+new file mode 100644
+index 000000000000..6c7c496daa17
+--- /dev/null
++++ b/libstdc++-v3/testsuite/20_util/bitset/io/wchar_t.cc
+@@ -0,0 +1,39 @@
++// { dg-do run }
++
++// C++98 23.3.5.3 bitset operators
++
++#include <bitset>
++#include <sstream>
++#include <testsuite_hooks.h>
++
++#pragma GCC diagnostic ignored "-Wc++14-extensions" // 0b literals
++
++// Bug 124370 - Out-of-bounds write for wistream >> bitset
++void
++test_pr124370()
++{
++  std::wistringstream input(L"10011011001101");
++  std::bitset<10> b;
++  input >> b;
++  VERIFY( b == std::bitset<10>(0b1001101100) );
++}
++
++// Round-trip through a wide stream.
++template<int N>
++void
++test_round_trip()
++{
++  std::bitset<N> a(0b100110110011010101101010), b;
++  std::wstringstream ss;
++  ss << a;
++  ss >> b;
++  VERIFY( b == a );
++}
++
++int main()
++{
++  test_pr124370();
++  test_round_trip<0>();
++  test_round_trip<24>();
++  test_round_trip<1024>();
++}
+-- 
+cgit 
+