From: Waldemar Brodkorb <wbx@openadk.org>
To: buildroot@buildroot.org
Subject: [Buildroot] [PATCH] package/uclibc: Fix SSP support for RISCV32
Date: Sat, 15 Aug 2026 21:17:21 +0200 [thread overview]
Message-ID: <aoC7Qd8pbR8RIl0H@waldemar-brodkorb.de> (raw)
Add patch pending upstream to fix SSP for RISCV32.
Fixes:
https://autobuild.buildroot.org/results/1b6/1b6f2161b11390b6545bddbc39b444401c718ebb/
Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
---
.../0001-Fix-SSP-support-for-riscv32.patch | 174 ++++++++++++++++++
1 file changed, 174 insertions(+)
create mode 100644 package/uclibc/0001-Fix-SSP-support-for-riscv32.patch
diff --git a/package/uclibc/0001-Fix-SSP-support-for-riscv32.patch b/package/uclibc/0001-Fix-SSP-support-for-riscv32.patch
new file mode 100644
index 0000000000..b2e38726f5
--- /dev/null
+++ b/package/uclibc/0001-Fix-SSP-support-for-riscv32.patch
@@ -0,0 +1,174 @@
+From c6efc293a52fdde7d4876243faaaa768fe052719 Mon Sep 17 00:00:00 2001
+From: Waldemar Brodkorb <wbx@openadk.org>
+Date: Sat, 15 Aug 2026 18:20:33 +0200
+Subject: [PATCH] Fix SSP support for riscv32
+
+On modern 32-bit architectures like RISC-V (riscv32), legacy 32-bit
+time syscalls like __NR_gettimeofday are intentionally omitted because
+RV32 implements a strict time64-only ABI to avoid the Year 2038 bug.
+
+Therefore, use AT_RANDOM from the auxiliary vector first, as glibc does,
+to obtain random data for the stack canary. If AT_RANDOM is unavailable,
+fall back to reading random data from /dev/urandom.
+
+Tested with aarch64, riscv32 and riscv32 noMMU targets.
+
+Upstream: https://mailman.openadk.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/thread/WIKMWPXJYAPTVVZ2MMZINUJNPIJXBMOE/
+Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
+---
+ extra/Configs/Config.in | 10 -------
+ ldso/include/dl-syscall.h | 12 --------
+ ldso/ldso/ldso.c | 4 ++-
+ libc/misc/internals/__uClibc_main.c | 4 ++-
+ libc/sysdeps/linux/common/dl-osinfo.h | 40 +++++++++++++++++----------
+ 5 files changed, 32 insertions(+), 38 deletions(-)
+
+diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in
+index c3aabf1b4..15a072593 100644
+--- a/extra/Configs/Config.in
++++ b/extra/Configs/Config.in
+@@ -2211,16 +2211,6 @@ config UCLIBC_HAS_SSP
+
+ Most people will answer N.
+
+-config SSP_QUICK_CANARY
+- bool "Use simple guard values without accessing /dev/urandom"
+- depends on UCLIBC_HAS_SSP
+- help
+- Use gettimeofday(2) to define the __guard without accessing
+- /dev/urandom.
+- WARNING: This makes smashing stack protector vulnerable to timing
+- attacks.
+- Most people will answer N.
+-
+ choice
+ prompt "Propolice protection blocking signal"
+ depends on UCLIBC_HAS_SSP
+diff --git a/ldso/include/dl-syscall.h b/ldso/include/dl-syscall.h
+index c143b8d45..e08b2cd41 100644
+--- a/ldso/include/dl-syscall.h
++++ b/ldso/include/dl-syscall.h
+@@ -260,18 +260,6 @@ _dl_pread(int fd, void *buf, size_t count, off_t offset)
+ }
+ #endif
+
+-#ifdef __UCLIBC_HAS_SSP__
+-# include <sys/time.h>
+-# define __NR__dl_gettimeofday __NR_gettimeofday
+-static __always_inline _syscall2(int, _dl_gettimeofday, struct timeval *, tv,
+-# ifdef __USE_BSD
+- struct timezone *
+-# else
+- void *
+-# endif
+- , tz)
+-#endif
+-
+ /* Some architectures always use 12 as page shift for mmap2() eventhough the
+ * real PAGE_SHIFT != 12. Other architectures use the same value as
+ * PAGE_SHIFT...
+diff --git a/ldso/ldso/ldso.c b/ldso/ldso/ldso.c
+index 55f7d7e45..96ee3d496 100755
+--- a/ldso/ldso/ldso.c
++++ b/ldso/ldso/ldso.c
+@@ -1225,7 +1225,9 @@ of this helper program; chances are you did not intend to run this program.\n\
+ #ifdef __UCLIBC_HAS_SSP__
+ _dl_debug_early("Setting up SSP guards\n");
+ /* Set up the stack checker's canary. */
+- stack_chk_guard = _dl_setup_stack_chk_guard ();
++ stack_chk_guard = _dl_setup_stack_chk_guard (
++ _dl_auxvt[AT_RANDOM].a_type == AT_RANDOM ?
++ (void *)_dl_auxvt[AT_RANDOM].a_un.a_val : NULL);
+ # ifdef THREAD_SET_STACK_GUARD
+ THREAD_SET_STACK_GUARD (stack_chk_guard);
+ # else
+diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
+index 549606505..bbf471b17 100644
+--- a/libc/misc/internals/__uClibc_main.c
++++ b/libc/misc/internals/__uClibc_main.c
+@@ -296,7 +296,9 @@ void __uClibc_init(void)
+ #ifndef SHARED
+ # ifdef __UCLIBC_HAS_SSP__
+ /* Set up the stack checker's canary. */
+- stack_chk_guard = _dl_setup_stack_chk_guard();
++ stack_chk_guard = _dl_setup_stack_chk_guard(
++ _dl_auxvt[AT_RANDOM].a_type == AT_RANDOM ?
++ (void *)_dl_auxvt[AT_RANDOM].a_un.a_val : NULL);
+ # ifdef THREAD_SET_STACK_GUARD
+ THREAD_SET_STACK_GUARD (stack_chk_guard);
+ # else
+diff --git a/libc/sysdeps/linux/common/dl-osinfo.h b/libc/sysdeps/linux/common/dl-osinfo.h
+index 3110cb05d..0a42ea094 100644
+--- a/libc/sysdeps/linux/common/dl-osinfo.h
++++ b/libc/sysdeps/linux/common/dl-osinfo.h
+@@ -21,22 +21,42 @@
+ # ifdef IS_IN_libc
+ # include <fcntl.h>
+ # include <unistd.h>
+-# include <sys/time.h>
++# include <string.h>
+ # define OPEN open
+ # define READ read
+ # define CLOSE close
+-# define GETTIMEOFDAY gettimeofday
++# define MEMCPY memcpy
+ # else
++# include <dl-string.h>
+ # define OPEN _dl_open
+ # define READ _dl_read
+ # define CLOSE _dl_close
+-# define GETTIMEOFDAY _dl_gettimeofday
++# define MEMCPY _dl_memcpy
+ # endif
+
+-static __always_inline uintptr_t _dl_setup_stack_chk_guard(void)
++static __always_inline uintptr_t
++_dl_setup_stack_chk_guard(void *dl_random)
+ {
+ uintptr_t ret;
+-# ifndef __SSP_QUICK_CANARY__
++
++ /*
++ * Linux supplies random data through AT_RANDOM.
++ * Use it directly when available.
++ */
++ if (dl_random != NULL) {
++ MEMCPY(&ret, dl_random, sizeof(ret));
++
++#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
++ ret &= ~(uintptr_t)0xff;
++#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
++ ret &= ~((uintptr_t)0xff << (8 * (sizeof(ret) - 1)));
++#else
++# error "Unknown byte order"
++#endif
++
++ return ret;
++ }
++
+ {
+ int fd = OPEN("/dev/urandom", O_RDONLY, 0);
+ if (fd >= 0) {
+@@ -46,18 +66,10 @@ static __always_inline uintptr_t _dl_setup_stack_chk_guard(void)
+ return ret;
+ }
+ }
+-# endif /* !__SSP_QUICK_CANARY__ */
+
+- /* Start with the "terminator canary". */
++ /* Fallback just the "terminator canary". */
+ ret = 0xFF0A0D00UL;
+
+- /* Everything failed? Or we are using a weakened model of the
+- * terminator canary */
+- {
+- struct timeval tv;
+- if (GETTIMEOFDAY(&tv, NULL) != (-1))
+- ret ^= tv.tv_usec ^ tv.tv_sec;
+- }
+ return ret;
+ }
+ # endif /* libc || rtld */
+--
+2.47.3
+
--
2.47.3
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next reply other threads:[~2026-08-15 19:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-15 19:17 Waldemar Brodkorb [this message]
2026-08-15 20:27 ` [Buildroot] [PATCH] package/uclibc: Fix SSP support for RISCV32 Romain Naour via buildroot
2026-08-16 10:45 ` Julien Olivain via buildroot
2026-08-22 12:39 ` Titouan Christophe via buildroot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aoC7Qd8pbR8RIl0H@waldemar-brodkorb.de \
--to=wbx@openadk.org \
--cc=buildroot@buildroot.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox