diff mbox series

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

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

Commit Message

Sadineni, Harish Nov. 27, 2026, 1:48 p.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-16.2.inc        |   1 +
 .../gcc/gcc/0030-CVE-2026-115455.patch        | 145 ++++++++++++++++++
 2 files changed, 146 insertions(+)
 create mode 100644 meta/recipes-devtools/gcc/gcc/0030-CVE-2026-115455.patch

Comments

patchtest@automation.yoctoproject.org Nov. 27, 2026, 2:01 p.m. UTC | #1
Thank you for your submission. Patchtest identified one
or more issues with the patch. Please see the log below for
more information:

---
Testing patch /home/patchtest/share/mboxes/2-2-gcc-Fix-for-CVE-2026-115455.patch

FAIL: test CVE tag format: Missing or incorrectly formatted CVE tag in patch file. Correct or include the CVE tag in the patch with format: "CVE: CVE-YYYY-XXXX" (test_patch.TestPatch.test_cve_tag_format)

PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence)
PASS: test Signed-off-by presence (test_patch.TestPatch.test_signed_off_by_presence)
PASS: test Upstream-Status presence (test_patch.TestPatch.test_upstream_status_presence_format)
PASS: test auh changelog truncation notice (test_mbox.TestMbox.test_auh_changelog_truncation_notice)
PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test commit message user tags (test_mbox.TestMbox.test_commit_message_user_tags)
PASS: test max line length (test_metadata.TestMetadata.test_max_line_length)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test shortlog format (test_mbox.TestMbox.test_shortlog_format)
PASS: test shortlog length (test_mbox.TestMbox.test_shortlog_length)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)

SKIP: pretest pylint: No python related patches, skipping test (test_python_pylint.PyLint.pretest_pylint)
SKIP: pretest src uri left files: Patch cannot be merged (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes or older target branch, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test bugzilla entry format: No bug ID found (test_mbox.TestMbox.test_bugzilla_entry_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test pylint: No python related patches, skipping test (test_python_pylint.PyLint.test_pylint)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: Patch cannot be merged (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)

---

Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this
email with an explanation of why the patch should be accepted. If you
believe these results are due to an error in patchtest, please submit a
bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category
under 'Yocto Project Subprojects'). For more information on specific
failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank
you!
diff mbox series

Patch

diff --git a/meta/recipes-devtools/gcc/gcc-16.2.inc b/meta/recipes-devtools/gcc/gcc-16.2.inc
index 4361fbe208..f0779b14a9 100644
--- a/meta/recipes-devtools/gcc/gcc-16.2.inc
+++ b/meta/recipes-devtools/gcc/gcc-16.2.inc
@@ -78,6 +78,7 @@  SRC_URI = "${BASEURI} \
 	   file://0027-CVE-2026-125709.patch \
 	   file://0028-CVE-2026-115456.patch \
 	   file://0029-CVE-2026-114691.patch \
+	   file://0030-CVE-2026-115455.patch \
 "
 
 UNPACKDIR = "${TMPDIR}/work-shared/gcc-${PV}-${PR}/sources"
diff --git a/meta/recipes-devtools/gcc/gcc/0030-CVE-2026-115455.patch b/meta/recipes-devtools/gcc/gcc/0030-CVE-2026-115455.patch
new file mode 100644
index 0000000000..9d2e1829f5
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc/0030-CVE-2026-115455.patch
@@ -0,0 +1,145 @@ 
+From 5d419c69ce2e6b86d7da75f18736904885674219 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=5d419c69ce2e6b86d7da75f18736904885674219]
+
+Signed-off-by: Harish Sadineni <Harish.Sadineni@windriver.com>
+---
+ libstdc++-v3/include/std/bitset                    | 31 ++++++++---------
+ libstdc++-v3/testsuite/20_util/bitset/io/input.cc  |  2 ++
+ .../testsuite/20_util/bitset/io/wchar_t.cc         | 39 ++++++++++++++++++++++
+ 3 files changed, 57 insertions(+), 15 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 d581606e7dde..469c8da9ece4 100644
+--- a/libstdc++-v3/include/std/bitset
++++ b/libstdc++-v3/include/std/bitset
+@@ -1705,30 +1705,31 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
+       typedef std::basic_istream<_CharT, _Traits>  __istream_type;
+       typedef typename __istream_type::ios_base    __ios_base;
+ 
+-#pragma GCC diagnostic push
+-#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
++      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) { }
++#pragma GCC diagnostic push
++#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
++	_Buffer() : _M_ptr(_M_local)
++	{
++	  if _GLIBCXX_CONSTEXPR (!__use_local)
++	    _M_ptr = new _CharT[_Nb];
++	}
+ 
+ 	~_Buffer()
+ 	{
+-	  if _GLIBCXX_CONSTEXPR (!_S_use_alloca())
++	  if _GLIBCXX_CONSTEXPR (!__use_local)
+ 	    delete[] _M_ptr;
+ 	}
+-
+-	_CharT* const _M_ptr;
+-      };
+-      _CharT* __ptr;
+-      if _GLIBCXX_CONSTEXPR (_Buffer::_S_use_alloca())
+-	__ptr = (_CharT*)__builtin_alloca(_Nb);
+-      else
+-	__ptr = new _CharT[_Nb];
+-      const _Buffer __buf(__ptr);
+ #pragma GCC diagnostic pop
+ 
++	_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
+       const char_type __zero = __is.widen('0');
+diff --git a/libstdc++-v3/testsuite/20_util/bitset/io/input.cc b/libstdc++-v3/testsuite/20_util/bitset/io/input.cc
+index b0e301a42b10..a01e48cf2847 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