chromium-glibc-2.33.patch 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Patch made by Kevin Kofler <Kevin@tigcc.ticalc.org>
  2. # https://bugzilla.redhat.com/show_bug.cgi?id=1904652
  3. diff -up chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc.fstatfix chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
  4. --- chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc.fstatfix 2021-01-25 10:11:45.427436398 -0500
  5. +++ chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc 2021-01-25 10:12:51.337699003 -0500
  6. @@ -257,6 +257,18 @@ ResultExpr EvaluateSyscallImpl(int fs_de
  7. return RestrictKillTarget(current_pid, sysno);
  8. }
  9. +#if defined(__NR_newfstatat)
  10. + if (sysno == __NR_newfstatat) {
  11. + return RewriteFstatatSIGSYS();
  12. + }
  13. +#endif
  14. +
  15. +#if defined(__NR_fstatat64)
  16. + if (sysno == __NR_fstatat64) {
  17. + return RewriteFstatatSIGSYS();
  18. + }
  19. +#endif
  20. +
  21. if (SyscallSets::IsFileSystem(sysno) ||
  22. SyscallSets::IsCurrentDirectory(sysno)) {
  23. return Error(fs_denied_errno);
  24. diff -up chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc.fstatfix chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
  25. --- chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc.fstatfix 2021-01-25 10:13:10.179774081 -0500
  26. +++ chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc 2021-01-25 10:16:18.790525746 -0500
  27. @@ -6,6 +6,8 @@
  28. #include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
  29. +#include <errno.h>
  30. +#include <fcntl.h>
  31. #include <stddef.h>
  32. #include <stdint.h>
  33. #include <string.h>
  34. @@ -355,6 +357,35 @@ intptr_t SIGSYSSchedHandler(const struct
  35. return -ENOSYS;
  36. }
  37. +intptr_t SIGSYSFstatatHandler(const struct arch_seccomp_data& args,
  38. + void* aux) {
  39. + switch (args.nr) {
  40. +#if defined(__NR_newfstatat)
  41. + case __NR_newfstatat:
  42. +#endif
  43. +#if defined(__NR_fstatat64)
  44. + case __NR_fstatat64:
  45. +#endif
  46. +#if defined(__NR_newfstatat) || defined(__NR_fstatat64)
  47. + if (*reinterpret_cast<const char *>(args.args[1]) == '\0'
  48. + && args.args[3] == static_cast<uint64_t>(AT_EMPTY_PATH)) {
  49. + return sandbox::sys_fstat64(static_cast<int>(args.args[0]),
  50. + reinterpret_cast<struct stat64 *>(args.args[2]));
  51. + } else {
  52. + errno = EACCES;
  53. + return -1;
  54. + }
  55. + break;
  56. +#endif
  57. + }
  58. +
  59. + CrashSIGSYS_Handler(args, aux);
  60. +
  61. + // Should never be reached.
  62. + RAW_CHECK(false);
  63. + return -ENOSYS;
  64. +}
  65. +
  66. bpf_dsl::ResultExpr CrashSIGSYS() {
  67. return bpf_dsl::Trap(CrashSIGSYS_Handler, NULL);
  68. }
  69. @@ -387,6 +418,10 @@ bpf_dsl::ResultExpr RewriteSchedSIGSYS()
  70. return bpf_dsl::Trap(SIGSYSSchedHandler, NULL);
  71. }
  72. +bpf_dsl::ResultExpr RewriteFstatatSIGSYS() {
  73. + return bpf_dsl::Trap(SIGSYSFstatatHandler, NULL);
  74. +}
  75. +
  76. void AllocateCrashKeys() {
  77. #if !defined(OS_NACL_NONSFI)
  78. if (seccomp_crash_key)
  79. diff -up chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h.fstatfix chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h
  80. --- chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h.fstatfix 2021-01-25 10:16:36.982598236 -0500
  81. +++ chromium-88.0.4324.96/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h 2021-01-25 10:18:45.705111027 -0500
  82. @@ -62,6 +62,10 @@ SANDBOX_EXPORT intptr_t SIGSYSPtraceFail
  83. // sched_setparam(), sched_setscheduler()
  84. SANDBOX_EXPORT intptr_t SIGSYSSchedHandler(const arch_seccomp_data& args,
  85. void* aux);
  86. +// If the fstatat syscall is actually a disguised fstat, calls the regular fstat
  87. +// syscall, otherwise, crashes in the same way as CrashSIGSYS_Handler.
  88. +SANDBOX_EXPORT intptr_t SIGSYSFstatatHandler(const struct arch_seccomp_data& args,
  89. + void* aux);
  90. // Variants of the above functions for use with bpf_dsl.
  91. SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYS();
  92. @@ -72,6 +76,7 @@ SANDBOX_EXPORT bpf_dsl::ResultExpr Crash
  93. SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSFutex();
  94. SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSPtrace();
  95. SANDBOX_EXPORT bpf_dsl::ResultExpr RewriteSchedSIGSYS();
  96. +SANDBOX_EXPORT bpf_dsl::ResultExpr RewriteFstatatSIGSYS();
  97. // Allocates a crash key so that Seccomp information can be recorded.
  98. void AllocateCrashKeys();
  99. diff -up chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.cc.fstatfix chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.cc
  100. --- chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.cc.fstatfix 2021-01-25 10:18:53.307141311 -0500
  101. +++ chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.cc 2021-01-25 10:19:46.982355293 -0500
  102. @@ -261,4 +261,13 @@ int sys_sigaction(int signum,
  103. #endif // defined(MEMORY_SANITIZER)
  104. +SANDBOX_EXPORT int sys_fstat64(int fd, struct stat64 *buf)
  105. +{
  106. +#if defined(__NR_fstat64)
  107. + return syscall(__NR_fstat64, fd, buf);
  108. +#else
  109. + return syscall(__NR_fstat, fd, buf);
  110. +#endif
  111. +}
  112. +
  113. } // namespace sandbox
  114. diff -up chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.h.fstatfix chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.h
  115. --- chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.h.fstatfix 2021-01-25 10:19:53.115379741 -0500
  116. +++ chromium-88.0.4324.96/sandbox/linux/services/syscall_wrappers.h 2021-01-25 10:20:45.485588421 -0500
  117. @@ -17,6 +17,7 @@ struct sock_fprog;
  118. struct rlimit64;
  119. struct cap_hdr;
  120. struct cap_data;
  121. +struct stat64;
  122. namespace sandbox {
  123. @@ -84,6 +85,9 @@ SANDBOX_EXPORT int sys_sigaction(int sig
  124. const struct sigaction* act,
  125. struct sigaction* oldact);
  126. +// Recent glibc rewrites fstat to fstatat.
  127. +SANDBOX_EXPORT int sys_fstat64(int fd, struct stat64 *buf);
  128. +
  129. } // namespace sandbox
  130. #endif // SANDBOX_LINUX_SERVICES_SYSCALL_WRAPPERS_H_