0006-seedrng-fix-for-glibc-2.24-not-providing-random-head.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From cb57abb46f06f4ede8d9ccbdaac67377fdf416cf Mon Sep 17 00:00:00 2001
  2. From: Thomas Devoogdt <thomas@devoogdt.com>
  3. Date: Mon, 10 Apr 2023 19:58:15 +0200
  4. Subject: [PATCH] seedrng: fix for glibc <= 2.24 not providing random header
  5. - dropped the wrong define (not sure why it was there)
  6. - <sys/random.h> not available if glibc <= 2.24
  7. - GRND_NONBLOCK not defined if <sys/random.h> not included
  8. - ret < 0 && errno == ENOSYS has to be true to get creditable set
  9. Signed-off-by: Thomas Devoogdt <thomas@devoogdt.com>
  10. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
  11. Upstream: https://git.busybox.net/busybox/commit/?id=cb57abb46f06f4ede8d9ccbdaac67377fdf416cf
  12. ---
  13. miscutils/seedrng.c | 14 ++++++++++----
  14. 1 file changed, 10 insertions(+), 4 deletions(-)
  15. diff --git a/miscutils/seedrng.c b/miscutils/seedrng.c
  16. index 7cc855141..3bf6e2ea7 100644
  17. --- a/miscutils/seedrng.c
  18. +++ b/miscutils/seedrng.c
  19. @@ -42,25 +42,31 @@
  20. #include "libbb.h"
  21. #include <linux/random.h>
  22. -#include <sys/random.h>
  23. #include <sys/file.h>
  24. /* Fix up glibc <= 2.24 not having getrandom() */
  25. #if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ <= 24
  26. #include <sys/syscall.h>
  27. -# define getrandom(...) bb_getrandom(__VA_ARGS__)
  28. static ssize_t getrandom(void *buffer, size_t length, unsigned flags)
  29. {
  30. # if defined(__NR_getrandom)
  31. return syscall(__NR_getrandom, buffer, length, flags);
  32. # else
  33. - return ENOSYS;
  34. + errno = ENOSYS;
  35. + return -1;
  36. # endif
  37. }
  38. +#else
  39. +#include <sys/random.h>
  40. +#endif
  41. +
  42. +/* Apparently some headers don't ship with this yet. */
  43. +#ifndef GRND_NONBLOCK
  44. +#define GRND_NONBLOCK 0x0001
  45. #endif
  46. #ifndef GRND_INSECURE
  47. -#define GRND_INSECURE 0x0004 /* Apparently some headers don't ship with this yet. */
  48. +#define GRND_INSECURE 0x0004
  49. #endif
  50. #define DEFAULT_SEED_DIR "/var/lib/seedrng"
  51. --
  52. 2.39.1