0001-kexec.c-add-MFD_NOEXEC_SEAL-flag-explicitly.patch 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. From 0b176595ca1610037d1175e1786d1a8aff1fb43f Mon Sep 17 00:00:00 2001
  2. From: Chen Qi <Qi.Chen@windriver.com>
  3. Date: Tue, 6 Aug 2024 21:42:43 -0700
  4. Subject: [PATCH] kexec.c: add MFD_NOEXEC_SEAL flag explicitly
  5. Add MFD_NOEXEC_SEAL to avoid kernel warning like below:
  6. kexec[970]: memfd_create() called without MFD_EXEC or MFD_NOEXEC_SEAL set
  7. For old kernels, there will be no MFD_NOEXEC_SEAL definition, so fallback
  8. to define it to 0.
  9. Upstream-Status: Submitted [https://github.com/horms/kexec-tools/pull/7]
  10. Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
  11. ---
  12. kexec/kexec.c | 6 +++++-
  13. 1 file changed, 5 insertions(+), 1 deletion(-)
  14. diff --git a/kexec/kexec.c b/kexec/kexec.c
  15. index 6bf12d7..2f8e7cc 100644
  16. --- a/kexec/kexec.c
  17. +++ b/kexec/kexec.c
  18. @@ -61,6 +61,10 @@
  19. #define KEXEC_LOADED_PATH "/sys/kernel/kexec_loaded"
  20. #define KEXEC_CRASH_LOADED_PATH "/sys/kernel/kexec_crash_loaded"
  21. +#ifndef MFD_NOEXEC_SEAL
  22. +#define MFD_NOEXEC_SEAL 0
  23. +#endif
  24. +
  25. unsigned long long mem_min = 0;
  26. unsigned long long mem_max = ULONG_MAX;
  27. unsigned long elfcorehdrsz = 0;
  28. @@ -661,7 +665,7 @@ static int copybuf_memfd(const char *kernel_buf, size_t size)
  29. {
  30. int fd, count;
  31. - fd = memfd_create("kernel", MFD_ALLOW_SEALING);
  32. + fd = memfd_create("kernel", MFD_ALLOW_SEALING | MFD_NOEXEC_SEAL);
  33. if (fd == -1)
  34. return fd;