linux-sandbox-syscall-broker-use-struct-kernel_stat.patch 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384
  1. From 4b438323d68840453b5ef826c3997568e2e0e8c7 Mon Sep 17 00:00:00 2001
  2. From: Matthew Denton <mpdenton@chromium.org>
  3. Date: Mon, 19 Jul 2021 14:03:13 +0000
  4. Subject: [PATCH] Reland "Reland "Linux sandbox syscall broker: use struct
  5. kernel_stat""
  6. This reverts commit ff277a52ece0b216617d770f201ed66955fe70b9.
  7. Reason for revert: reland
  8. The fix included in the reland is that fstatat64() needs to be
  9. allowed in the broker process's seccomp policy.
  10. This CL also includes some extra tests that the kernel_stat structures
  11. match the layout the kernel expects.
  12. Bug: 1164975, 1199431
  13. Test: trogdor Chromebook successfully boots and allows login.
  14. Original change's description:
  15. > Revert "Reland "Linux sandbox syscall broker: use struct kernel_stat""
  16. >
  17. > This reverts commit cffbc4432af79f720ae3c75dff380b853701bd64.
  18. >
  19. > Reason for revert: https://bugs.chromium.org/p/chromium/issues/detail?id=1199431
  20. >
  21. > Original change's description:
  22. > > Reland "Linux sandbox syscall broker: use struct kernel_stat"
  23. > >
  24. > > This reverts commit 23030dc650cdfa22631f25bef937905f27f06a2c.
  25. > >
  26. > > Original change's description:
  27. > > > Revert "Linux sandbox syscall broker: use struct kernel_stat"
  28. > > >
  29. > > > This reverts commit 784b0fcd8a3ca6bcd3acb9cfd624ec9cbbac2789.
  30. > > >
  31. > > > Reason for revert: Causing failure in
  32. > > > Step "sandbox_linux_unittests" failing on builder "Linux ChromiumOS MSan Tests"
  33. > > > See crbug.com/1198480
  34. > > >
  35. > > > Original change's description:
  36. > > > > Linux sandbox syscall broker: use struct kernel_stat
  37. > > > >
  38. > > > > The struct stat used in libc is different (in size and field ordering)
  39. > > > > from the structure assumed by the Linux kernel. So, when emulating
  40. > > > > system calls, we need to use the struct definition the kernel expects.
  41. > > > >
  42. > > > > This CL adds linux_stat.h that includes definitions of the different
  43. > > > > kernel structs.
  44. > > > >
  45. > > > > Change-Id: I53cad35c2251dff0f6b7ea77528cfa58ef3cab4a
  46. > > > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2780876
  47. > > > > Commit-Queue: Matthew Denton <mpdenton@chromium.org>
  48. > > > > Reviewed-by: Robert Sesek <rsesek@chromium.org>
  49. > > > > Cr-Commit-Position: refs/heads/master@{#871767}
  50. > > >
  51. > > > Change-Id: Icbec38f2103c8424dec79ab1870b97c3e83f9361
  52. > > > No-Presubmit: true
  53. > > > No-Tree-Checks: true
  54. > > > No-Try: true
  55. > > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2821812
  56. > > > Auto-Submit: Victor Vianna <victorvianna@google.com>
  57. > > > Owners-Override: Victor Vianna <victorvianna@google.com>
  58. > > > Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
  59. > > > Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
  60. > > > Cr-Commit-Position: refs/heads/master@{#871882}
  61. > >
  62. > > Change-Id: I1f39bb5242961474def594ff7dbea52009f2cee4
  63. > > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2824115
  64. > > Auto-Submit: Matthew Denton <mpdenton@chromium.org>
  65. > > Commit-Queue: Matthew Denton <mpdenton@chromium.org>
  66. > > Reviewed-by: Robert Sesek <rsesek@chromium.org>
  67. > > Cr-Commit-Position: refs/heads/master@{#872812}
  68. >
  69. > Fixed: 1199431
  70. > Change-Id: Iebfc0c48201bf22ff9c54d8d5c8a43d26a880098
  71. > No-Presubmit: true
  72. > No-Tree-Checks: true
  73. > No-Try: true
  74. > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2830459
  75. > Auto-Submit: Kyle Horimoto <khorimoto@chromium.org>
  76. > Commit-Queue: Matthew Denton <mpdenton@chromium.org>
  77. > Commit-Queue: Kinuko Yasuda <kinuko@chromium.org>
  78. > Reviewed-by: Matthew Denton <mpdenton@chromium.org>
  79. > Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
  80. > Owners-Override: Kinuko Yasuda <kinuko@chromium.org>
  81. > Cr-Commit-Position: refs/heads/master@{#873173}
  82. Change-Id: Ibe6a485070f33489aaa157b51b908c2d23d174d7
  83. Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2848936
  84. Reviewed-by: Robert Sesek <rsesek@chromium.org>
  85. Commit-Queue: Matthew Denton <mpdenton@chromium.org>
  86. Cr-Commit-Position: refs/heads/master@{#902981}
  87. ---
  88. sandbox/linux/BUILD.gn | 1 +
  89. .../seccomp_broker_process_unittest.cc | 40 +++-
  90. sandbox/linux/seccomp-bpf-helpers/DEPS | 1 -
  91. ...scall_parameters_restrictions_unittests.cc | 4 -
  92. sandbox/linux/services/syscall_wrappers.cc | 50 ++++-
  93. sandbox/linux/services/syscall_wrappers.h | 15 ++
  94. .../services/syscall_wrappers_unittest.cc | 129 +++++++++++-
  95. sandbox/linux/syscall_broker/DEPS | 3 +-
  96. sandbox/linux/syscall_broker/broker_client.cc | 4 +-
  97. sandbox/linux/syscall_broker/broker_client.h | 4 +-
  98. sandbox/linux/syscall_broker/broker_host.cc | 23 ++-
  99. .../syscall_broker/broker_process_unittest.cc | 74 +++----
  100. .../remote_syscall_arg_handler_unittest.cc | 36 ++--
  101. .../syscall_broker/syscall_dispatcher.cc | 67 ++++---
  102. .../linux/syscall_broker/syscall_dispatcher.h | 27 ++-
  103. sandbox/linux/system_headers/linux_stat.h | 188 ++++++++++++++++++
  104. sandbox/linux/system_headers/linux_time.h | 26 +++
  105. sandbox/linux/tests/test_utils.cc | 15 ++
  106. sandbox/linux/tests/test_utils.h | 2 +
  107. .../policy/linux/bpf_broker_policy_linux.cc | 4 +-
  108. 20 files changed, 595 insertions(+), 118 deletions(-)
  109. create mode 100644 sandbox/linux/system_headers/linux_stat.h
  110. diff --git a/sandbox/linux/BUILD.gn b/sandbox/linux/BUILD.gn
  111. index 2f778dd0bc..ccbbc91716 100644
  112. --- a/sandbox/linux/BUILD.gn
  113. +++ b/sandbox/linux/BUILD.gn
  114. @@ -443,6 +443,7 @@ source_set("sandbox_services_headers") {
  115. "system_headers/linux_ptrace.h",
  116. "system_headers/linux_seccomp.h",
  117. "system_headers/linux_signal.h",
  118. + "system_headers/linux_stat.h",
  119. "system_headers/linux_syscalls.h",
  120. "system_headers/linux_time.h",
  121. "system_headers/linux_ucontext.h",
  122. diff --git a/sandbox/linux/integration_tests/seccomp_broker_process_unittest.cc b/sandbox/linux/integration_tests/seccomp_broker_process_unittest.cc
  123. index 9da9c68911..8a941983b1 100644
  124. --- a/sandbox/linux/integration_tests/seccomp_broker_process_unittest.cc
  125. +++ b/sandbox/linux/integration_tests/seccomp_broker_process_unittest.cc
  126. @@ -34,6 +34,7 @@
  127. #include "sandbox/linux/syscall_broker/broker_file_permission.h"
  128. #include "sandbox/linux/syscall_broker/broker_process.h"
  129. #include "sandbox/linux/system_headers/linux_seccomp.h"
  130. +#include "sandbox/linux/system_headers/linux_stat.h"
  131. #include "sandbox/linux/system_headers/linux_syscalls.h"
  132. #include "sandbox/linux/tests/scoped_temporary_file.h"
  133. #include "sandbox/linux/tests/test_utils.h"
  134. @@ -202,6 +203,26 @@ namespace {
  135. // not accept this as a valid error number. E.g. bionic accepts up to 255, glibc
  136. // and musl up to 4096.
  137. const int kFakeErrnoSentinel = 254;
  138. +
  139. +void ConvertKernelStatToLibcStat(default_stat_struct& in_stat,
  140. + struct stat& out_stat) {
  141. + out_stat.st_dev = in_stat.st_dev;
  142. + out_stat.st_ino = in_stat.st_ino;
  143. + out_stat.st_mode = in_stat.st_mode;
  144. + out_stat.st_nlink = in_stat.st_nlink;
  145. + out_stat.st_uid = in_stat.st_uid;
  146. + out_stat.st_gid = in_stat.st_gid;
  147. + out_stat.st_rdev = in_stat.st_rdev;
  148. + out_stat.st_size = in_stat.st_size;
  149. + out_stat.st_blksize = in_stat.st_blksize;
  150. + out_stat.st_blocks = in_stat.st_blocks;
  151. + out_stat.st_atim.tv_sec = in_stat.st_atime_;
  152. + out_stat.st_atim.tv_nsec = in_stat.st_atime_nsec_;
  153. + out_stat.st_mtim.tv_sec = in_stat.st_mtime_;
  154. + out_stat.st_mtim.tv_nsec = in_stat.st_mtime_nsec_;
  155. + out_stat.st_ctim.tv_sec = in_stat.st_ctime_;
  156. + out_stat.st_ctim.tv_nsec = in_stat.st_ctime_nsec_;
  157. +}
  158. } // namespace
  159. // There are a variety of ways to make syscalls in a sandboxed process. One is
  160. @@ -217,6 +238,10 @@ class Syscaller {
  161. virtual int Open(const char* filepath, int flags) = 0;
  162. virtual int Access(const char* filepath, int mode) = 0;
  163. + // NOTE: we use struct stat instead of default_stat_struct, to make the libc
  164. + // syscaller simpler. Copying from default_stat_struct (the structure returned
  165. + // from a stat sycall) to struct stat (the structure exposed by a libc to its
  166. + // users) is simpler than going in the opposite direction.
  167. virtual int Stat(const char* filepath,
  168. bool follow_links,
  169. struct stat* statbuf) = 0;
  170. @@ -243,8 +268,12 @@ class IPCSyscaller : public Syscaller {
  171. int Stat(const char* filepath,
  172. bool follow_links,
  173. struct stat* statbuf) override {
  174. - return broker_->GetBrokerClientSignalBased()->Stat(filepath, follow_links,
  175. - statbuf);
  176. + default_stat_struct buf;
  177. + int ret = broker_->GetBrokerClientSignalBased()->DefaultStatForTesting(
  178. + filepath, follow_links, &buf);
  179. + if (ret >= 0)
  180. + ConvertKernelStatToLibcStat(buf, *statbuf);
  181. + return ret;
  182. }
  183. int Rename(const char* oldpath, const char* newpath) override {
  184. @@ -300,10 +329,13 @@ class DirectSyscaller : public Syscaller {
  185. int Stat(const char* filepath,
  186. bool follow_links,
  187. struct stat* statbuf) override {
  188. - int ret = follow_links ? syscall(__NR_stat, filepath, statbuf)
  189. - : syscall(__NR_lstat, filepath, statbuf);
  190. + struct kernel_stat buf;
  191. + int ret = syscall(__NR_newfstatat, AT_FDCWD, filepath, &buf,
  192. + follow_links ? 0 : AT_SYMLINK_NOFOLLOW);
  193. if (ret < 0)
  194. return -errno;
  195. +
  196. + ConvertKernelStatToLibcStat(buf, *statbuf);
  197. return ret;
  198. }
  199. diff --git a/sandbox/linux/seccomp-bpf-helpers/DEPS b/sandbox/linux/seccomp-bpf-helpers/DEPS
  200. index 4419fd1da3..95d1bb6cbb 100644
  201. --- a/sandbox/linux/seccomp-bpf-helpers/DEPS
  202. +++ b/sandbox/linux/seccomp-bpf-helpers/DEPS
  203. @@ -3,5 +3,4 @@ include_rules = [
  204. "+sandbox/linux/seccomp-bpf",
  205. "+sandbox/linux/services",
  206. "+sandbox/linux/system_headers",
  207. - "+third_party/lss/linux_syscall_support.h",
  208. ]
  209. diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc b/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc
  210. index 903e702eab..76c393032c 100644
  211. --- a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc
  212. +++ b/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc
  213. @@ -37,10 +37,6 @@
  214. #include "sandbox/linux/system_headers/linux_time.h"
  215. #include "sandbox/linux/tests/unit_tests.h"
  216. -#if !defined(OS_ANDROID)
  217. -#include "third_party/lss/linux_syscall_support.h" // for MAKE_PROCESS_CPUCLOCK
  218. -#endif
  219. -
  220. namespace sandbox {
  221. namespace {
  222. diff --git a/sandbox/linux/services/syscall_wrappers.cc b/sandbox/linux/services/syscall_wrappers.cc
  223. index fcfd2aa129..3bec18a14e 100644
  224. --- a/sandbox/linux/services/syscall_wrappers.cc
  225. +++ b/sandbox/linux/services/syscall_wrappers.cc
  226. @@ -4,6 +4,7 @@
  227. #include "sandbox/linux/services/syscall_wrappers.h"
  228. +#include <fcntl.h>
  229. #include <pthread.h>
  230. #include <sched.h>
  231. #include <setjmp.h>
  232. @@ -14,11 +15,13 @@
  233. #include <unistd.h>
  234. #include <cstring>
  235. +#include "base/check.h"
  236. #include "base/compiler_specific.h"
  237. #include "base/logging.h"
  238. #include "build/build_config.h"
  239. #include "sandbox/linux/system_headers/capability.h"
  240. #include "sandbox/linux/system_headers/linux_signal.h"
  241. +#include "sandbox/linux/system_headers/linux_stat.h"
  242. #include "sandbox/linux/system_headers/linux_syscalls.h"
  243. namespace sandbox {
  244. @@ -217,7 +220,7 @@ asm(
  245. #undef STR
  246. #undef XSTR
  247. -#endif
  248. +#endif // defined(ARCH_CPU_X86_FAMILY)
  249. int sys_sigaction(int signum,
  250. const struct sigaction* act,
  251. @@ -241,7 +244,7 @@ int sys_sigaction(int signum,
  252. #error "Unsupported architecture."
  253. #endif
  254. }
  255. -#endif
  256. +#endif // defined(ARCH_CPU_X86_FAMILY)
  257. }
  258. LinuxSigAction linux_oldact = {};
  259. @@ -259,6 +262,47 @@ int sys_sigaction(int signum,
  260. return result;
  261. }
  262. -#endif // defined(MEMORY_SANITIZER)
  263. +#endif // !defined(OS_NACL_NONSFI)
  264. +
  265. +int sys_stat(const char* path, struct kernel_stat* stat_buf) {
  266. + int res;
  267. +#if !defined(__NR_stat)
  268. + res = syscall(__NR_newfstatat, AT_FDCWD, path, stat_buf, 0);
  269. +#else
  270. + res = syscall(__NR_stat, path, stat_buf);
  271. +#endif
  272. + if (res == 0)
  273. + MSAN_UNPOISON(stat_buf, sizeof(*stat_buf));
  274. + return res;
  275. +}
  276. +
  277. +int sys_lstat(const char* path, struct kernel_stat* stat_buf) {
  278. + int res;
  279. +#if !defined(__NR_lstat)
  280. + res = syscall(__NR_newfstatat, AT_FDCWD, path, stat_buf, AT_SYMLINK_NOFOLLOW);
  281. +#else
  282. + res = syscall(__NR_lstat, path, stat_buf);
  283. +#endif
  284. + if (res == 0)
  285. + MSAN_UNPOISON(stat_buf, sizeof(*stat_buf));
  286. + return res;
  287. +}
  288. +
  289. +int sys_fstatat64(int dirfd,
  290. + const char* pathname,
  291. + struct kernel_stat64* stat_buf,
  292. + int flags) {
  293. +#if defined(__NR_fstatat64)
  294. + int res = syscall(__NR_fstatat64, dirfd, pathname, stat_buf, flags);
  295. + if (res == 0)
  296. + MSAN_UNPOISON(stat_buf, sizeof(*stat_buf));
  297. + return res;
  298. +#else // defined(__NR_fstatat64)
  299. + // We should not reach here on 64-bit systems, as the *stat*64() are only
  300. + // necessary on 32-bit.
  301. + RAW_CHECK(false);
  302. + return -ENOSYS;
  303. +#endif
  304. +}
  305. } // namespace sandbox
  306. diff --git a/sandbox/linux/services/syscall_wrappers.h b/sandbox/linux/services/syscall_wrappers.h
  307. index 1975bfbd88..b55340e4a2 100644
  308. --- a/sandbox/linux/services/syscall_wrappers.h
  309. +++ b/sandbox/linux/services/syscall_wrappers.h
  310. @@ -17,6 +17,8 @@ struct sock_fprog;
  311. struct rlimit64;
  312. struct cap_hdr;
  313. struct cap_data;
  314. +struct kernel_stat;
  315. +struct kernel_stat64;
  316. namespace sandbox {
  317. @@ -84,6 +86,19 @@ SANDBOX_EXPORT int sys_sigaction(int signum,
  318. const struct sigaction* act,
  319. struct sigaction* oldact);
  320. +// Some architectures do not have stat() and lstat() syscalls. In that case,
  321. +// these wrappers will use newfstatat(), which is available on all other
  322. +// architectures, with the same capabilities as stat() and lstat().
  323. +SANDBOX_EXPORT int sys_stat(const char* path, struct kernel_stat* stat_buf);
  324. +SANDBOX_EXPORT int sys_lstat(const char* path, struct kernel_stat* stat_buf);
  325. +
  326. +// Takes care of unpoisoning |stat_buf| for MSAN. Check-fails if fstatat64() is
  327. +// not a supported syscall on the current platform.
  328. +SANDBOX_EXPORT int sys_fstatat64(int dirfd,
  329. + const char* pathname,
  330. + struct kernel_stat64* stat_buf,
  331. + int flags);
  332. +
  333. } // namespace sandbox
  334. #endif // SANDBOX_LINUX_SERVICES_SYSCALL_WRAPPERS_H_
  335. diff --git a/sandbox/linux/services/syscall_wrappers_unittest.cc b/sandbox/linux/services/syscall_wrappers_unittest.cc
  336. index 32820f60a8..64b9cea80f 100644
  337. --- a/sandbox/linux/services/syscall_wrappers_unittest.cc
  338. +++ b/sandbox/linux/services/syscall_wrappers_unittest.cc
  339. @@ -5,15 +5,19 @@
  340. #include "sandbox/linux/services/syscall_wrappers.h"
  341. #include <stdint.h>
  342. +#include <string.h>
  343. #include <sys/syscall.h>
  344. #include <sys/types.h>
  345. #include <sys/wait.h>
  346. #include <unistd.h>
  347. -#include <cstring>
  348. +#include "base/logging.h"
  349. +#include "base/memory/page_size.h"
  350. #include "base/posix/eintr_wrapper.h"
  351. #include "build/build_config.h"
  352. #include "sandbox/linux/system_headers/linux_signal.h"
  353. +#include "sandbox/linux/system_headers/linux_stat.h"
  354. +#include "sandbox/linux/tests/scoped_temporary_file.h"
  355. #include "sandbox/linux/tests/test_utils.h"
  356. #include "sandbox/linux/tests/unit_tests.h"
  357. #include "testing/gtest/include/gtest/gtest.h"
  358. @@ -93,6 +97,129 @@ TEST(SyscallWrappers, LinuxSigSet) {
  359. linux_sigset);
  360. }
  361. +TEST(SyscallWrappers, Stat) {
  362. + // Create a file to stat, with 12 bytes of data.
  363. + ScopedTemporaryFile tmp_file;
  364. + EXPECT_EQ(12, write(tmp_file.fd(), "blahblahblah", 12));
  365. +
  366. + // To test we have the correct stat structures for each kernel/platform, we
  367. + // will right-align them on a page, with a guard page after.
  368. + char* two_pages = static_cast<char*>(TestUtils::MapPagesOrDie(2));
  369. + TestUtils::MprotectLastPageOrDie(two_pages, 2);
  370. + char* page1_end = two_pages + base::GetPageSize();
  371. +
  372. + // First, check that calling stat with |stat_buf| pointing to the last byte on
  373. + // a page causes EFAULT.
  374. + int res = sys_stat(tmp_file.full_file_name(),
  375. + reinterpret_cast<struct kernel_stat*>(page1_end - 1));
  376. + ASSERT_EQ(res, -1);
  377. + ASSERT_EQ(errno, EFAULT);
  378. +
  379. + // Now, check that we have the correctly sized stat structure.
  380. + struct kernel_stat* sb = reinterpret_cast<struct kernel_stat*>(
  381. + page1_end - sizeof(struct kernel_stat));
  382. + // Memset to c's so we can check the kernel zero'd the padding...
  383. + memset(sb, 'c', sizeof(struct kernel_stat));
  384. + res = sys_stat(tmp_file.full_file_name(), sb);
  385. + ASSERT_EQ(res, 0);
  386. +
  387. + // Following fields may never be consistent but should be non-zero.
  388. + // Don't trust the platform to define fields with any particular sign.
  389. + EXPECT_NE(0u, static_cast<unsigned int>(sb->st_dev));
  390. + EXPECT_NE(0u, static_cast<unsigned int>(sb->st_ino));
  391. + EXPECT_NE(0u, static_cast<unsigned int>(sb->st_mode));
  392. + EXPECT_NE(0u, static_cast<unsigned int>(sb->st_blksize));
  393. + EXPECT_NE(0u, static_cast<unsigned int>(sb->st_blocks));
  394. +
  395. +// We are the ones that made the file.
  396. +// Note: normally gid and uid overflow on backwards-compatible 32-bit systems
  397. +// and we end up with dummy uids and gids in place here.
  398. +#if defined(ARCH_CPU_64_BITS)
  399. + EXPECT_EQ(geteuid(), sb->st_uid);
  400. + EXPECT_EQ(getegid(), sb->st_gid);
  401. +#endif
  402. +
  403. + // Wrote 12 bytes above which should fit in one block.
  404. + EXPECT_EQ(12u, sb->st_size);
  405. +
  406. + // Can't go backwards in time, 1500000000 was some time ago.
  407. + EXPECT_LT(1500000000u, static_cast<unsigned int>(sb->st_atime_));
  408. + EXPECT_LT(1500000000u, static_cast<unsigned int>(sb->st_mtime_));
  409. + EXPECT_LT(1500000000u, static_cast<unsigned int>(sb->st_ctime_));
  410. +
  411. + // Checking the padding for good measure.
  412. +#if defined(__x86_64__)
  413. + EXPECT_EQ(0u, sb->__pad0);
  414. + EXPECT_EQ(0u, sb->__unused4[0]);
  415. + EXPECT_EQ(0u, sb->__unused4[1]);
  416. + EXPECT_EQ(0u, sb->__unused4[2]);
  417. +#elif defined(__aarch64__)
  418. + EXPECT_EQ(0u, sb->__pad1);
  419. + EXPECT_EQ(0, sb->__pad2);
  420. + EXPECT_EQ(0u, sb->__unused4);
  421. + EXPECT_EQ(0u, sb->__unused5);
  422. +#endif
  423. +}
  424. +
  425. +TEST(SyscallWrappers, LStat) {
  426. + // Create a file to stat, with 12 bytes of data.
  427. + ScopedTemporaryFile tmp_file;
  428. + EXPECT_EQ(12, write(tmp_file.fd(), "blahblahblah", 12));
  429. +
  430. + // Also create a symlink.
  431. + std::string symlink_name;
  432. + {
  433. + ScopedTemporaryFile tmp_file2;
  434. + symlink_name = tmp_file2.full_file_name();
  435. + }
  436. + int rc = symlink(tmp_file.full_file_name(), symlink_name.c_str());
  437. + if (rc != 0) {
  438. + PLOG(ERROR) << "Couldn't symlink " << symlink_name << " to target "
  439. + << tmp_file.full_file_name();
  440. + GTEST_FAIL();
  441. + }
  442. +
  443. + struct kernel_stat lstat_info;
  444. + rc = sys_lstat(symlink_name.c_str(), &lstat_info);
  445. + if (rc < 0 && errno == EOVERFLOW) {
  446. + GTEST_SKIP();
  447. + }
  448. + if (rc != 0) {
  449. + PLOG(ERROR) << "Couldn't sys_lstat " << symlink_name;
  450. + GTEST_FAIL();
  451. + }
  452. +
  453. + struct kernel_stat stat_info;
  454. + rc = sys_stat(symlink_name.c_str(), &stat_info);
  455. + if (rc < 0 && errno == EOVERFLOW) {
  456. + GTEST_SKIP();
  457. + }
  458. + if (rc != 0) {
  459. + PLOG(ERROR) << "Couldn't sys_stat " << symlink_name;
  460. + GTEST_FAIL();
  461. + }
  462. +
  463. + struct kernel_stat tmp_file_stat_info;
  464. + rc = sys_stat(tmp_file.full_file_name(), &tmp_file_stat_info);
  465. + if (rc < 0 && errno == EOVERFLOW) {
  466. + GTEST_SKIP();
  467. + }
  468. + if (rc != 0) {
  469. + PLOG(ERROR) << "Couldn't sys_stat " << tmp_file.full_file_name();
  470. + GTEST_FAIL();
  471. + }
  472. +
  473. + // lstat should produce information about a symlink.
  474. + ASSERT_TRUE(S_ISLNK(lstat_info.st_mode));
  475. +
  476. + // stat-ing symlink_name and tmp_file should produce the same inode.
  477. + ASSERT_EQ(stat_info.st_ino, tmp_file_stat_info.st_ino);
  478. +
  479. + // lstat-ing symlink_name should give a different inode than stat-ing
  480. + // symlink_name.
  481. + ASSERT_NE(stat_info.st_ino, lstat_info.st_ino);
  482. +}
  483. +
  484. } // namespace
  485. } // namespace sandbox
  486. diff --git a/sandbox/linux/syscall_broker/DEPS b/sandbox/linux/syscall_broker/DEPS
  487. index c477f7d363..149c463b06 100644
  488. --- a/sandbox/linux/syscall_broker/DEPS
  489. +++ b/sandbox/linux/syscall_broker/DEPS
  490. @@ -1,4 +1,5 @@
  491. include_rules = [
  492. - "+sandbox/linux/system_headers",
  493. "+sandbox/linux/bpf_dsl",
  494. + "+sandbox/linux/services",
  495. + "+sandbox/linux/system_headers",
  496. ]
  497. diff --git a/sandbox/linux/syscall_broker/broker_client.cc b/sandbox/linux/syscall_broker/broker_client.cc
  498. index 6b1b5be433..e24f659fcf 100644
  499. --- a/sandbox/linux/syscall_broker/broker_client.cc
  500. +++ b/sandbox/linux/syscall_broker/broker_client.cc
  501. @@ -166,7 +166,7 @@ int BrokerClient::Rmdir(const char* path) const {
  502. int BrokerClient::Stat(const char* pathname,
  503. bool follow_links,
  504. - struct stat* sb) const {
  505. + struct kernel_stat* sb) const {
  506. if (!pathname || !sb)
  507. return -EFAULT;
  508. @@ -181,7 +181,7 @@ int BrokerClient::Stat(const char* pathname,
  509. int BrokerClient::Stat64(const char* pathname,
  510. bool follow_links,
  511. - struct stat64* sb) const {
  512. + struct kernel_stat64* sb) const {
  513. if (!pathname || !sb)
  514. return -EFAULT;
  515. diff --git a/sandbox/linux/syscall_broker/broker_client.h b/sandbox/linux/syscall_broker/broker_client.h
  516. index 05e14c83f2..26ca78101c 100644
  517. --- a/sandbox/linux/syscall_broker/broker_client.h
  518. +++ b/sandbox/linux/syscall_broker/broker_client.h
  519. @@ -61,10 +61,10 @@ class SANDBOX_EXPORT BrokerClient : public SyscallDispatcher {
  520. int Rmdir(const char* path) const override;
  521. int Stat(const char* pathname,
  522. bool follow_links,
  523. - struct stat* sb) const override;
  524. + struct kernel_stat* sb) const override;
  525. int Stat64(const char* pathname,
  526. bool follow_links,
  527. - struct stat64* sb) const override;
  528. + struct kernel_stat64* sb) const override;
  529. int Unlink(const char* unlink) const override;
  530. private:
  531. diff --git a/sandbox/linux/syscall_broker/broker_host.cc b/sandbox/linux/syscall_broker/broker_host.cc
  532. index 1cd03a18df..1cdc01a888 100644
  533. --- a/sandbox/linux/syscall_broker/broker_host.cc
  534. +++ b/sandbox/linux/syscall_broker/broker_host.cc
  535. @@ -20,9 +20,11 @@
  536. #include "base/files/scoped_file.h"
  537. #include "base/logging.h"
  538. #include "base/posix/eintr_wrapper.h"
  539. +#include "sandbox/linux/services/syscall_wrappers.h"
  540. #include "sandbox/linux/syscall_broker/broker_command.h"
  541. #include "sandbox/linux/syscall_broker/broker_permission_list.h"
  542. #include "sandbox/linux/syscall_broker/broker_simple_message.h"
  543. +#include "sandbox/linux/system_headers/linux_stat.h"
  544. #include "sandbox/linux/system_headers/linux_syscalls.h"
  545. namespace sandbox {
  546. @@ -193,10 +195,12 @@ void StatFileForIPC(const BrokerCommandSet& allowed_command_set,
  547. RAW_CHECK(reply->AddIntToMessage(-permission_list.denied_errno()));
  548. return;
  549. }
  550. +
  551. if (command_type == COMMAND_STAT) {
  552. - struct stat sb;
  553. - int sts =
  554. - follow_links ? stat(file_to_access, &sb) : lstat(file_to_access, &sb);
  555. + struct kernel_stat sb;
  556. +
  557. + int sts = follow_links ? sandbox::sys_stat(file_to_access, &sb)
  558. + : sandbox::sys_lstat(file_to_access, &sb);
  559. if (sts < 0) {
  560. RAW_CHECK(reply->AddIntToMessage(-errno));
  561. return;
  562. @@ -205,10 +209,12 @@ void StatFileForIPC(const BrokerCommandSet& allowed_command_set,
  563. RAW_CHECK(
  564. reply->AddDataToMessage(reinterpret_cast<char*>(&sb), sizeof(sb)));
  565. } else {
  566. +#if defined(__NR_fstatat64)
  567. DCHECK(command_type == COMMAND_STAT64);
  568. - struct stat64 sb;
  569. - int sts = follow_links ? stat64(file_to_access, &sb)
  570. - : lstat64(file_to_access, &sb);
  571. + struct kernel_stat64 sb;
  572. +
  573. + int sts = sandbox::sys_fstatat64(AT_FDCWD, file_to_access, &sb,
  574. + follow_links ? 0 : AT_SYMLINK_NOFOLLOW);
  575. if (sts < 0) {
  576. RAW_CHECK(reply->AddIntToMessage(-errno));
  577. return;
  578. @@ -216,6 +222,11 @@ void StatFileForIPC(const BrokerCommandSet& allowed_command_set,
  579. RAW_CHECK(reply->AddIntToMessage(0));
  580. RAW_CHECK(
  581. reply->AddDataToMessage(reinterpret_cast<char*>(&sb), sizeof(sb)));
  582. +#else // defined(__NR_fstatat64)
  583. + // We should not reach here on 64-bit systems, as the *stat*64() are only
  584. + // necessary on 32-bit.
  585. + RAW_CHECK(false);
  586. +#endif
  587. }
  588. }
  589. diff --git a/sandbox/linux/syscall_broker/broker_process_unittest.cc b/sandbox/linux/syscall_broker/broker_process_unittest.cc
  590. index 55ba6bccb2..c65f25a78a 100644
  591. --- a/sandbox/linux/syscall_broker/broker_process_unittest.cc
  592. +++ b/sandbox/linux/syscall_broker/broker_process_unittest.cc
  593. @@ -811,7 +811,7 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  594. const char* bad_leading_path5 = "/mbogo/fictitioux";
  595. const char* bad_leading_path6 = "/mbogo/fictitiousa";
  596. - struct stat sb;
  597. + default_stat_struct sb;
  598. {
  599. // Actual file with permissions to see file but command not allowed.
  600. @@ -824,7 +824,7 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  601. memset(&sb, 0, sizeof(sb));
  602. EXPECT_EQ(-kFakeErrnoSentinel,
  603. - open_broker.GetBrokerClientSignalBased()->Stat(
  604. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  605. tempfile_name, follow_links, &sb));
  606. }
  607. @@ -840,7 +840,7 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  608. memset(&sb, 0, sizeof(sb));
  609. EXPECT_EQ(-kFakeErrnoSentinel,
  610. - open_broker.GetBrokerClientSignalBased()->Stat(
  611. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  612. nonesuch_name, follow_links, &sb));
  613. }
  614. {
  615. @@ -852,7 +852,7 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  616. memset(&sb, 0, sizeof(sb));
  617. EXPECT_EQ(-kFakeErrnoSentinel,
  618. - open_broker.GetBrokerClientSignalBased()->Stat(
  619. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  620. tempfile_name, follow_links, &sb));
  621. }
  622. {
  623. @@ -864,38 +864,39 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  624. ASSERT_TRUE(open_broker.Init(base::BindOnce(&NoOpCallback)));
  625. memset(&sb, 0, sizeof(sb));
  626. - EXPECT_EQ(-ENOENT, open_broker.GetBrokerClientSignalBased()->Stat(
  627. - nonesuch_name, follow_links, &sb));
  628. + EXPECT_EQ(-ENOENT,
  629. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  630. + nonesuch_name, follow_links, &sb));
  631. // Gets denied all the way back to root since no create permission.
  632. EXPECT_EQ(-kFakeErrnoSentinel,
  633. - open_broker.GetBrokerClientSignalBased()->Stat(
  634. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  635. leading_path1, follow_links, &sb));
  636. EXPECT_EQ(-kFakeErrnoSentinel,
  637. - open_broker.GetBrokerClientSignalBased()->Stat(
  638. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  639. leading_path2, follow_links, &sb));
  640. EXPECT_EQ(-kFakeErrnoSentinel,
  641. - open_broker.GetBrokerClientSignalBased()->Stat(
  642. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  643. leading_path3, follow_links, &sb));
  644. // Not fooled by substrings.
  645. EXPECT_EQ(-kFakeErrnoSentinel,
  646. - open_broker.GetBrokerClientSignalBased()->Stat(
  647. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  648. bad_leading_path1, follow_links, &sb));
  649. EXPECT_EQ(-kFakeErrnoSentinel,
  650. - open_broker.GetBrokerClientSignalBased()->Stat(
  651. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  652. bad_leading_path2, follow_links, &sb));
  653. EXPECT_EQ(-kFakeErrnoSentinel,
  654. - open_broker.GetBrokerClientSignalBased()->Stat(
  655. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  656. bad_leading_path3, follow_links, &sb));
  657. EXPECT_EQ(-kFakeErrnoSentinel,
  658. - open_broker.GetBrokerClientSignalBased()->Stat(
  659. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  660. bad_leading_path4, follow_links, &sb));
  661. EXPECT_EQ(-kFakeErrnoSentinel,
  662. - open_broker.GetBrokerClientSignalBased()->Stat(
  663. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  664. bad_leading_path5, follow_links, &sb));
  665. EXPECT_EQ(-kFakeErrnoSentinel,
  666. - open_broker.GetBrokerClientSignalBased()->Stat(
  667. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  668. bad_leading_path6, follow_links, &sb));
  669. }
  670. {
  671. @@ -907,37 +908,41 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  672. ASSERT_TRUE(open_broker.Init(base::BindOnce(&NoOpCallback)));
  673. memset(&sb, 0, sizeof(sb));
  674. - EXPECT_EQ(-ENOENT, open_broker.GetBrokerClientSignalBased()->Stat(
  675. - nonesuch_name, follow_links, &sb));
  676. + EXPECT_EQ(-ENOENT,
  677. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  678. + nonesuch_name, follow_links, &sb));
  679. // Gets ENOENT all the way back to root since it has create permission.
  680. - EXPECT_EQ(-ENOENT, open_broker.GetBrokerClientSignalBased()->Stat(
  681. - leading_path1, follow_links, &sb));
  682. - EXPECT_EQ(-ENOENT, open_broker.GetBrokerClientSignalBased()->Stat(
  683. - leading_path2, follow_links, &sb));
  684. + EXPECT_EQ(-ENOENT,
  685. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  686. + leading_path1, follow_links, &sb));
  687. + EXPECT_EQ(-ENOENT,
  688. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  689. + leading_path2, follow_links, &sb));
  690. // But can always get the root.
  691. - EXPECT_EQ(0, open_broker.GetBrokerClientSignalBased()->Stat(
  692. - leading_path3, follow_links, &sb));
  693. + EXPECT_EQ(0,
  694. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  695. + leading_path3, follow_links, &sb));
  696. // Not fooled by substrings.
  697. EXPECT_EQ(-kFakeErrnoSentinel,
  698. - open_broker.GetBrokerClientSignalBased()->Stat(
  699. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  700. bad_leading_path1, follow_links, &sb));
  701. EXPECT_EQ(-kFakeErrnoSentinel,
  702. - open_broker.GetBrokerClientSignalBased()->Stat(
  703. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  704. bad_leading_path2, follow_links, &sb));
  705. EXPECT_EQ(-kFakeErrnoSentinel,
  706. - open_broker.GetBrokerClientSignalBased()->Stat(
  707. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  708. bad_leading_path3, follow_links, &sb));
  709. EXPECT_EQ(-kFakeErrnoSentinel,
  710. - open_broker.GetBrokerClientSignalBased()->Stat(
  711. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  712. bad_leading_path4, follow_links, &sb));
  713. EXPECT_EQ(-kFakeErrnoSentinel,
  714. - open_broker.GetBrokerClientSignalBased()->Stat(
  715. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  716. bad_leading_path5, follow_links, &sb));
  717. EXPECT_EQ(-kFakeErrnoSentinel,
  718. - open_broker.GetBrokerClientSignalBased()->Stat(
  719. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  720. bad_leading_path6, follow_links, &sb));
  721. }
  722. {
  723. @@ -949,8 +954,9 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  724. ASSERT_TRUE(open_broker.Init(base::BindOnce(&NoOpCallback)));
  725. memset(&sb, 0, sizeof(sb));
  726. - EXPECT_EQ(0, open_broker.GetBrokerClientSignalBased()->Stat(
  727. - tempfile_name, follow_links, &sb));
  728. + EXPECT_EQ(0,
  729. + open_broker.GetBrokerClientSignalBased()->DefaultStatForTesting(
  730. + tempfile_name, follow_links, &sb));
  731. // Following fields may never be consistent but should be non-zero.
  732. // Don't trust the platform to define fields with any particular sign.
  733. @@ -968,9 +974,9 @@ void TestStatHelper(bool fast_check_in_client, bool follow_links) {
  734. EXPECT_EQ(12, sb.st_size);
  735. // Can't go backwards in time, 1500000000 was some time ago.
  736. - EXPECT_LT(1500000000u, static_cast<unsigned int>(sb.st_atime));
  737. - EXPECT_LT(1500000000u, static_cast<unsigned int>(sb.st_mtime));
  738. - EXPECT_LT(1500000000u, static_cast<unsigned int>(sb.st_ctime));
  739. + EXPECT_LT(1500000000u, static_cast<unsigned int>(sb.st_atime_));
  740. + EXPECT_LT(1500000000u, static_cast<unsigned int>(sb.st_mtime_));
  741. + EXPECT_LT(1500000000u, static_cast<unsigned int>(sb.st_ctime_));
  742. }
  743. }
  744. diff --git a/sandbox/linux/syscall_broker/remote_syscall_arg_handler_unittest.cc b/sandbox/linux/syscall_broker/remote_syscall_arg_handler_unittest.cc
  745. index fffa9bb708..f517a9867c 100644
  746. --- a/sandbox/linux/syscall_broker/remote_syscall_arg_handler_unittest.cc
  747. +++ b/sandbox/linux/syscall_broker/remote_syscall_arg_handler_unittest.cc
  748. @@ -16,6 +16,7 @@
  749. #include "base/memory/page_size.h"
  750. #include "base/posix/unix_domain_socket.h"
  751. #include "base/test/bind.h"
  752. +#include "sandbox/linux/tests/test_utils.h"
  753. #include "sandbox/linux/tests/unit_tests.h"
  754. #include "testing/gtest/include/gtest/gtest.h"
  755. @@ -52,19 +53,6 @@ void VerifyCorrectString(std::string str, size_t size) {
  756. }
  757. }
  758. -void* MapPagesOrDie(size_t num_pages) {
  759. - void* addr = mmap(nullptr, num_pages * base::GetPageSize(),
  760. - PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  761. - PCHECK(addr);
  762. - return addr;
  763. -}
  764. -
  765. -void MprotectLastPageOrDie(char* addr, size_t num_pages) {
  766. - size_t last_page_offset = (num_pages - 1) * base::GetPageSize();
  767. - PCHECK(mprotect(addr + last_page_offset, base::GetPageSize(), PROT_NONE) >=
  768. - 0);
  769. -}
  770. -
  771. pid_t ForkWaitingChild(base::OnceCallback<void(int)>
  772. after_parent_signals_callback = base::DoNothing(),
  773. base::ScopedFD* parent_sync_fd = nullptr) {
  774. @@ -105,13 +93,13 @@ void ReadTest(const ReadTestConfig& test_config) {
  775. size_t total_pages = (test_config.start_at + test_config.total_size +
  776. base::GetPageSize() - 1) /
  777. base::GetPageSize();
  778. - char* mmap_addr = static_cast<char*>(MapPagesOrDie(total_pages));
  779. + char* mmap_addr = static_cast<char*>(TestUtils::MapPagesOrDie(total_pages));
  780. char* addr = mmap_addr + test_config.start_at;
  781. FillBufferWithPath(addr, test_config.total_size,
  782. test_config.include_null_byte);
  783. if (test_config.last_page_inaccessible)
  784. - MprotectLastPageOrDie(mmap_addr, total_pages);
  785. + TestUtils::MprotectLastPageOrDie(mmap_addr, total_pages);
  786. pid_t pid = ForkWaitingChild();
  787. munmap(mmap_addr, base::GetPageSize() * total_pages);
  788. @@ -212,7 +200,7 @@ SANDBOX_TEST(BrokerRemoteSyscallArgHandler, ReadChunkPlus1EndingOnePastPage) {
  789. }
  790. SANDBOX_TEST(BrokerRemoteSyscallArgHandler, ReadChildExited) {
  791. - void* addr = MapPagesOrDie(1);
  792. + void* addr = TestUtils::MapPagesOrDie(1);
  793. FillBufferWithPath(static_cast<char*>(addr), strlen(kPathPart) + 1, true);
  794. base::ScopedFD parent_sync, child_sync;
  795. @@ -240,10 +228,10 @@ SANDBOX_TEST(BrokerRemoteSyscallArgHandler, ReadChildExited) {
  796. }
  797. SANDBOX_TEST(BrokerRemoteSyscallArgHandler, BasicWrite) {
  798. - void* read_from = MapPagesOrDie(1);
  799. + void* read_from = TestUtils::MapPagesOrDie(1);
  800. const size_t write_size = base::GetPageSize();
  801. FillBufferWithPath(static_cast<char*>(read_from), write_size, false);
  802. - char* write_to = static_cast<char*>(MapPagesOrDie(1));
  803. + char* write_to = static_cast<char*>(TestUtils::MapPagesOrDie(1));
  804. base::ScopedFD parent_signal_fd;
  805. const std::vector<int> empty_fd_vec;
  806. @@ -278,8 +266,8 @@ SANDBOX_TEST(BrokerRemoteSyscallArgHandler, BasicWrite) {
  807. }
  808. SANDBOX_TEST(BrokerRemoteSyscallArgHandler, WriteToInvalidAddress) {
  809. - char* write_to = static_cast<char*>(MapPagesOrDie(1));
  810. - MprotectLastPageOrDie(write_to, 1);
  811. + char* write_to = static_cast<char*>(TestUtils::MapPagesOrDie(1));
  812. + TestUtils::MprotectLastPageOrDie(write_to, 1);
  813. base::ScopedFD parent_signal_fd;
  814. const std::vector<int> empty_fd_vec;
  815. @@ -295,11 +283,11 @@ SANDBOX_TEST(BrokerRemoteSyscallArgHandler, WriteToInvalidAddress) {
  816. }
  817. SANDBOX_TEST(BrokerRemoteSyscallArgHandler, WritePartiallyToInvalidAddress) {
  818. - char* read_from = static_cast<char*>(MapPagesOrDie(2));
  819. + char* read_from = static_cast<char*>(TestUtils::MapPagesOrDie(2));
  820. const size_t write_size = base::GetPageSize();
  821. FillBufferWithPath(static_cast<char*>(read_from), write_size, false);
  822. - char* write_to = static_cast<char*>(MapPagesOrDie(2));
  823. - MprotectLastPageOrDie(write_to, 2);
  824. + char* write_to = static_cast<char*>(TestUtils::MapPagesOrDie(2));
  825. + TestUtils::MprotectLastPageOrDie(write_to, 2);
  826. write_to += base::GetPageSize() / 2;
  827. base::ScopedFD parent_signal_fd;
  828. const std::vector<int> empty_fd_vec;
  829. @@ -314,7 +302,7 @@ SANDBOX_TEST(BrokerRemoteSyscallArgHandler, WritePartiallyToInvalidAddress) {
  830. }
  831. SANDBOX_TEST(BrokerRemoteSyscallArgHandler, WriteChildExited) {
  832. - char* addr = static_cast<char*>(MapPagesOrDie(1));
  833. + char* addr = static_cast<char*>(TestUtils::MapPagesOrDie(1));
  834. FillBufferWithPath(static_cast<char*>(addr), strlen(kPathPart) + 1, true);
  835. base::ScopedFD parent_sync, child_sync;
  836. diff --git a/sandbox/linux/syscall_broker/syscall_dispatcher.cc b/sandbox/linux/syscall_broker/syscall_dispatcher.cc
  837. index b9ee93c14a..8a42397ef8 100644
  838. --- a/sandbox/linux/syscall_broker/syscall_dispatcher.cc
  839. +++ b/sandbox/linux/syscall_broker/syscall_dispatcher.cc
  840. @@ -19,8 +19,18 @@ namespace syscall_broker {
  841. #define BROKER_UNPOISON_STRING(x)
  842. #endif
  843. +int SyscallDispatcher::DefaultStatForTesting(const char* pathname,
  844. + bool follow_links,
  845. + default_stat_struct* sb) {
  846. +#if defined(__NR_fstatat64)
  847. + return Stat64(pathname, follow_links, sb);
  848. +#elif defined(__NR_newfstatat)
  849. + return Stat(pathname, follow_links, sb);
  850. +#endif
  851. +}
  852. +
  853. int SyscallDispatcher::PerformStatat(const arch_seccomp_data& args,
  854. - bool arch64) {
  855. + bool stat64) {
  856. if (static_cast<int>(args.args[0]) != AT_FDCWD)
  857. return -EPERM;
  858. // Only allow the AT_SYMLINK_NOFOLLOW flag which is used by some libc
  859. @@ -30,13 +40,29 @@ int SyscallDispatcher::PerformStatat(const arch_seccomp_data& args,
  860. const bool follow_links =
  861. !(static_cast<int>(args.args[3]) & AT_SYMLINK_NOFOLLOW);
  862. - if (arch64) {
  863. + if (stat64) {
  864. return Stat64(reinterpret_cast<const char*>(args.args[1]), follow_links,
  865. - reinterpret_cast<struct stat64*>(args.args[2]));
  866. + reinterpret_cast<struct kernel_stat64*>(args.args[2]));
  867. }
  868. return Stat(reinterpret_cast<const char*>(args.args[1]), follow_links,
  869. - reinterpret_cast<struct stat*>(args.args[2]));
  870. + reinterpret_cast<struct kernel_stat*>(args.args[2]));
  871. +}
  872. +
  873. +int SyscallDispatcher::PerformUnlinkat(const arch_seccomp_data& args) {
  874. + if (static_cast<int>(args.args[0]) != AT_FDCWD)
  875. + return -EPERM;
  876. +
  877. + int flags = static_cast<int>(args.args[2]);
  878. +
  879. + if (flags == AT_REMOVEDIR) {
  880. + return Rmdir(reinterpret_cast<const char*>(args.args[1]));
  881. + }
  882. +
  883. + if (flags != 0)
  884. + return -EPERM;
  885. +
  886. + return Unlink(reinterpret_cast<const char*>(args.args[1]));
  887. }
  888. int SyscallDispatcher::DispatchSyscall(const arch_seccomp_data& args) {
  889. @@ -127,59 +153,42 @@ int SyscallDispatcher::DispatchSyscall(const arch_seccomp_data& args) {
  890. #if defined(__NR_stat)
  891. case __NR_stat:
  892. return Stat(reinterpret_cast<const char*>(args.args[0]), true,
  893. - reinterpret_cast<struct stat*>(args.args[1]));
  894. + reinterpret_cast<struct kernel_stat*>(args.args[1]));
  895. #endif
  896. #if defined(__NR_stat64)
  897. case __NR_stat64:
  898. return Stat64(reinterpret_cast<const char*>(args.args[0]), true,
  899. - reinterpret_cast<struct stat64*>(args.args[1]));
  900. + reinterpret_cast<struct kernel_stat64*>(args.args[1]));
  901. #endif
  902. #if defined(__NR_lstat)
  903. case __NR_lstat:
  904. // See https://crbug.com/847096
  905. BROKER_UNPOISON_STRING(reinterpret_cast<const char*>(args.args[0]));
  906. return Stat(reinterpret_cast<const char*>(args.args[0]), false,
  907. - reinterpret_cast<struct stat*>(args.args[1]));
  908. + reinterpret_cast<struct kernel_stat*>(args.args[1]));
  909. #endif
  910. #if defined(__NR_lstat64)
  911. case __NR_lstat64:
  912. // See https://crbug.com/847096
  913. BROKER_UNPOISON_STRING(reinterpret_cast<const char*>(args.args[0]));
  914. return Stat64(reinterpret_cast<const char*>(args.args[0]), false,
  915. - reinterpret_cast<struct stat64*>(args.args[1]));
  916. -#endif
  917. -#if defined(__NR_fstatat)
  918. - case __NR_fstatat:
  919. - return PerformStatat(args, /*arch64=*/false);
  920. + reinterpret_cast<struct kernel_stat64*>(args.args[1]));
  921. #endif
  922. #if defined(__NR_fstatat64)
  923. case __NR_fstatat64:
  924. - return PerformStatat(args, /*arch64=*/true);
  925. + return PerformStatat(args, /*stat64=*/true);
  926. #endif
  927. #if defined(__NR_newfstatat)
  928. case __NR_newfstatat:
  929. - return PerformStatat(args, /*arch64=*/false);
  930. + return PerformStatat(args, /*stat64=*/false);
  931. #endif
  932. #if defined(__NR_unlink)
  933. case __NR_unlink:
  934. return Unlink(reinterpret_cast<const char*>(args.args[0]));
  935. #endif
  936. #if defined(__NR_unlinkat)
  937. - case __NR_unlinkat: {
  938. - if (static_cast<int>(args.args[0]) != AT_FDCWD)
  939. - return -EPERM;
  940. -
  941. - int flags = static_cast<int>(args.args[2]);
  942. -
  943. - if (flags == AT_REMOVEDIR) {
  944. - return Rmdir(reinterpret_cast<const char*>(args.args[1]));
  945. - }
  946. -
  947. - if (flags != 0)
  948. - return -EPERM;
  949. -
  950. - return Unlink(reinterpret_cast<const char*>(args.args[1]));
  951. - }
  952. + case __NR_unlinkat:
  953. + return PerformUnlinkat(args);
  954. #endif // defined(__NR_unlinkat)
  955. default:
  956. RAW_CHECK(false);
  957. diff --git a/sandbox/linux/syscall_broker/syscall_dispatcher.h b/sandbox/linux/syscall_broker/syscall_dispatcher.h
  958. index d8b8874ad9..1d6653caf3 100644
  959. --- a/sandbox/linux/syscall_broker/syscall_dispatcher.h
  960. +++ b/sandbox/linux/syscall_broker/syscall_dispatcher.h
  961. @@ -9,13 +9,15 @@
  962. #include <cstddef>
  963. #include "sandbox/linux/system_headers/linux_seccomp.h"
  964. +#include "sandbox/linux/system_headers/linux_stat.h"
  965. +#include "sandbox/sandbox_export.h"
  966. namespace sandbox {
  967. namespace syscall_broker {
  968. // An abstract class that defines all the system calls we perform for the
  969. // sandboxed process.
  970. -class SyscallDispatcher {
  971. +class SANDBOX_EXPORT SyscallDispatcher {
  972. public:
  973. // Emulates access()/faccessat().
  974. // X_OK will always return an error in practice since the broker process
  975. @@ -40,19 +42,34 @@ class SyscallDispatcher {
  976. virtual int Rmdir(const char* path) const = 0;
  977. // Emulates stat()/stat64()/lstat()/lstat64()/fstatat()/newfstatat().
  978. + // Stat64 is only available on 32-bit systems.
  979. virtual int Stat(const char* pathname,
  980. bool follow_links,
  981. - struct stat* sb) const = 0;
  982. + struct kernel_stat* sb) const = 0;
  983. virtual int Stat64(const char* pathname,
  984. bool follow_links,
  985. - struct stat64* sb) const = 0;
  986. + struct kernel_stat64* sb) const = 0;
  987. // Emulates unlink()/unlinkat().
  988. virtual int Unlink(const char* unlink) const = 0;
  989. + // Different architectures use a different syscall from the stat family by
  990. + // default in glibc. E.g. 32-bit systems use *stat*64() and fill out struct
  991. + // kernel_stat64, whereas 64-bit systems use *stat*() and fill out struct
  992. + // kernel_stat. Some tests want to call the SyscallDispatcher directly, and
  993. + // should be using the default stat in order to test against glibc.
  994. + int DefaultStatForTesting(const char* pathname,
  995. + bool follow_links,
  996. + default_stat_struct* sb);
  997. +
  998. // Validates the args passed to a *statat*() syscall and performs the syscall
  999. - // using Stat() or Stat64().
  1000. - int PerformStatat(const arch_seccomp_data& args, bool arch64);
  1001. + // using Stat(), or on 32-bit systems it uses Stat64() for the *statat64()
  1002. + // syscalls.
  1003. + int PerformStatat(const arch_seccomp_data& args, bool stat64);
  1004. +
  1005. + // Validates the args passed to an unlinkat() syscall and performs the syscall
  1006. + // using either Unlink() or Rmdir().
  1007. + int PerformUnlinkat(const arch_seccomp_data& args);
  1008. // Reads the syscall number and arguments, imposes some policy (e.g. the *at()
  1009. // system calls must only allow AT_FDCWD as the first argument), and
  1010. diff --git a/sandbox/linux/system_headers/linux_stat.h b/sandbox/linux/system_headers/linux_stat.h
  1011. new file mode 100644
  1012. index 0000000000..35788eb22a
  1013. --- /dev/null
  1014. +++ b/sandbox/linux/system_headers/linux_stat.h
  1015. @@ -0,0 +1,188 @@
  1016. +// Copyright 2021 The Chromium Authors. All rights reserved.
  1017. +// Use of this source code is governed by a BSD-style license that can be
  1018. +// found in the LICENSE file.
  1019. +
  1020. +#ifndef SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_STAT_H_
  1021. +#define SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_STAT_H_
  1022. +
  1023. +#include <stdint.h>
  1024. +
  1025. +#include "build/build_config.h"
  1026. +#include "sandbox/linux/system_headers/linux_syscalls.h"
  1027. +
  1028. +#if defined(ARCH_CPU_MIPS_FAMILY)
  1029. +#if defined(ARCH_CPU_64_BITS)
  1030. +struct kernel_stat {
  1031. +#else
  1032. +struct kernel_stat64 {
  1033. +#endif
  1034. + unsigned st_dev;
  1035. + unsigned __pad0[3];
  1036. + unsigned long long st_ino;
  1037. + unsigned st_mode;
  1038. + unsigned st_nlink;
  1039. + unsigned st_uid;
  1040. + unsigned st_gid;
  1041. + unsigned st_rdev;
  1042. + unsigned __pad1[3];
  1043. + long long st_size;
  1044. + unsigned st_atime_;
  1045. + unsigned st_atime_nsec_;
  1046. + unsigned st_mtime_;
  1047. + unsigned st_mtime_nsec_;
  1048. + unsigned st_ctime_;
  1049. + unsigned st_ctime_nsec_;
  1050. + unsigned st_blksize;
  1051. + unsigned __pad2;
  1052. + unsigned long long st_blocks;
  1053. +};
  1054. +#else
  1055. +struct kernel_stat64 {
  1056. + unsigned long long st_dev;
  1057. + unsigned char __pad0[4];
  1058. + unsigned __st_ino;
  1059. + unsigned st_mode;
  1060. + unsigned st_nlink;
  1061. + unsigned st_uid;
  1062. + unsigned st_gid;
  1063. + unsigned long long st_rdev;
  1064. + unsigned char __pad3[4];
  1065. + long long st_size;
  1066. + unsigned st_blksize;
  1067. + unsigned long long st_blocks;
  1068. + unsigned st_atime_;
  1069. + unsigned st_atime_nsec_;
  1070. + unsigned st_mtime_;
  1071. + unsigned st_mtime_nsec_;
  1072. + unsigned st_ctime_;
  1073. + unsigned st_ctime_nsec_;
  1074. + unsigned long long st_ino;
  1075. +};
  1076. +#endif
  1077. +
  1078. +#if defined(__i386__) || defined(__ARM_ARCH_3__) || defined(__ARM_EABI__)
  1079. +struct kernel_stat {
  1080. + /* The kernel headers suggest that st_dev and st_rdev should be 32bit
  1081. + * quantities encoding 12bit major and 20bit minor numbers in an interleaved
  1082. + * format. In reality, we do not see useful data in the top bits. So,
  1083. + * we'll leave the padding in here, until we find a better solution.
  1084. + */
  1085. + unsigned short st_dev;
  1086. + short pad1;
  1087. + unsigned st_ino;
  1088. + unsigned short st_mode;
  1089. + unsigned short st_nlink;
  1090. + unsigned short st_uid;
  1091. + unsigned short st_gid;
  1092. + unsigned short st_rdev;
  1093. + short pad2;
  1094. + unsigned st_size;
  1095. + unsigned st_blksize;
  1096. + unsigned st_blocks;
  1097. + unsigned st_atime_;
  1098. + unsigned st_atime_nsec_;
  1099. + unsigned st_mtime_;
  1100. + unsigned st_mtime_nsec_;
  1101. + unsigned st_ctime_;
  1102. + unsigned st_ctime_nsec_;
  1103. + unsigned __unused4;
  1104. + unsigned __unused5;
  1105. +};
  1106. +#elif defined(__x86_64__)
  1107. +struct kernel_stat {
  1108. + uint64_t st_dev;
  1109. + uint64_t st_ino;
  1110. + uint64_t st_nlink;
  1111. + unsigned st_mode;
  1112. + unsigned st_uid;
  1113. + unsigned st_gid;
  1114. + unsigned __pad0;
  1115. + uint64_t st_rdev;
  1116. + int64_t st_size;
  1117. + int64_t st_blksize;
  1118. + int64_t st_blocks;
  1119. + uint64_t st_atime_;
  1120. + uint64_t st_atime_nsec_;
  1121. + uint64_t st_mtime_;
  1122. + uint64_t st_mtime_nsec_;
  1123. + uint64_t st_ctime_;
  1124. + uint64_t st_ctime_nsec_;
  1125. + int64_t __unused4[3];
  1126. +};
  1127. +#elif (defined(ARCH_CPU_MIPS_FAMILY) && defined(ARCH_CPU_32_BITS))
  1128. +struct kernel_stat {
  1129. + unsigned st_dev;
  1130. + int st_pad1[3];
  1131. + unsigned st_ino;
  1132. + unsigned st_mode;
  1133. + unsigned st_nlink;
  1134. + unsigned st_uid;
  1135. + unsigned st_gid;
  1136. + unsigned st_rdev;
  1137. + int st_pad2[2];
  1138. + long st_size;
  1139. + int st_pad3;
  1140. + long st_atime_;
  1141. + long st_atime_nsec_;
  1142. + long st_mtime_;
  1143. + long st_mtime_nsec_;
  1144. + long st_ctime_;
  1145. + long st_ctime_nsec_;
  1146. + int st_blksize;
  1147. + int st_blocks;
  1148. + int st_pad4[14];
  1149. +};
  1150. +#elif defined(__aarch64__)
  1151. +struct kernel_stat {
  1152. + unsigned long st_dev;
  1153. + unsigned long st_ino;
  1154. + unsigned int st_mode;
  1155. + unsigned int st_nlink;
  1156. + unsigned int st_uid;
  1157. + unsigned int st_gid;
  1158. + unsigned long st_rdev;
  1159. + unsigned long __pad1;
  1160. + long st_size;
  1161. + int st_blksize;
  1162. + int __pad2;
  1163. + long st_blocks;
  1164. + long st_atime_;
  1165. + unsigned long st_atime_nsec_;
  1166. + long st_mtime_;
  1167. + unsigned long st_mtime_nsec_;
  1168. + long st_ctime_;
  1169. + unsigned long st_ctime_nsec_;
  1170. + unsigned int __unused4;
  1171. + unsigned int __unused5;
  1172. +};
  1173. +#endif
  1174. +
  1175. +// On 32-bit systems, we default to the 64-bit stat struct like libc
  1176. +// implementations do. Otherwise we default to the normal stat struct which is
  1177. +// already 64-bit.
  1178. +// These defines make it easy to call the right syscall to fill out a 64-bit
  1179. +// stat struct, which is the default in libc implementations but requires
  1180. +// different syscall names on 32 and 64-bit platforms.
  1181. +#if defined(__NR_fstatat64)
  1182. +
  1183. +namespace sandbox {
  1184. +using default_stat_struct = struct kernel_stat64;
  1185. +} // namespace sandbox
  1186. +
  1187. +#define __NR_fstatat_default __NR_fstatat64
  1188. +#define __NR_fstat_default __NR_fstat64
  1189. +
  1190. +#elif defined(__NR_newfstatat)
  1191. +
  1192. +namespace sandbox {
  1193. +using default_stat_struct = struct kernel_stat;
  1194. +} // namespace sandbox
  1195. +
  1196. +#define __NR_fstatat_default __NR_newfstatat
  1197. +#define __NR_fstat_default __NR_fstat
  1198. +
  1199. +#else
  1200. +#error "one of fstatat64 and newfstatat must be defined"
  1201. +#endif
  1202. +
  1203. +#endif // SANDBOX_LINUX_SYSTEM_HEADERS_LINUX_STAT_H_
  1204. diff --git a/sandbox/linux/system_headers/linux_time.h b/sandbox/linux/system_headers/linux_time.h
  1205. index 780f24dddd..f18c806611 100644
  1206. --- a/sandbox/linux/system_headers/linux_time.h
  1207. +++ b/sandbox/linux/system_headers/linux_time.h
  1208. @@ -11,6 +11,32 @@
  1209. #define CPUCLOCK_CLOCK_MASK 3
  1210. #endif
  1211. +#if !defined(CPUCLOCK_PROF)
  1212. +#define CPUCLOCK_PROF 0
  1213. +#endif
  1214. +
  1215. +#if !defined(CPUCLOCK_VIRT)
  1216. +#define CPUCLOCK_VIRT 1
  1217. +#endif
  1218. +
  1219. +#if !defined(CPUCLOCK_SCHED)
  1220. +#define CPUCLOCK_SCHED 2
  1221. +#endif
  1222. +
  1223. +#if !defined(CPUCLOCK_PERTHREAD_MASK)
  1224. +#define CPUCLOCK_PERTHREAD_MASK 4
  1225. +#endif
  1226. +
  1227. +#if !defined(MAKE_PROCESS_CPUCLOCK)
  1228. +#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
  1229. + ((int)(~(unsigned)(pid) << 3) | (int)(clock))
  1230. +#endif
  1231. +
  1232. +#if !defined(MAKE_THREAD_CPUCLOCK)
  1233. +#define MAKE_THREAD_CPUCLOCK(tid, clock) \
  1234. + ((int)(~(unsigned)(tid) << 3) | (int)((clock) | CPUCLOCK_PERTHREAD_MASK))
  1235. +#endif
  1236. +
  1237. #if !defined(CLOCKFD)
  1238. #define CLOCKFD 3
  1239. #endif
  1240. diff --git a/sandbox/linux/tests/test_utils.cc b/sandbox/linux/tests/test_utils.cc
  1241. index 847c20b20c..cf6041a4b4 100644
  1242. --- a/sandbox/linux/tests/test_utils.cc
  1243. +++ b/sandbox/linux/tests/test_utils.cc
  1244. @@ -5,12 +5,14 @@
  1245. #include "sandbox/linux/tests/test_utils.h"
  1246. #include <errno.h>
  1247. +#include <sys/mman.h>
  1248. #include <sys/stat.h>
  1249. #include <sys/types.h>
  1250. #include <sys/wait.h>
  1251. #include <unistd.h>
  1252. #include "base/check_op.h"
  1253. +#include "base/memory/page_size.h"
  1254. #include "base/posix/eintr_wrapper.h"
  1255. namespace sandbox {
  1256. @@ -39,4 +41,17 @@ void TestUtils::HandlePostForkReturn(pid_t pid) {
  1257. }
  1258. }
  1259. +void* TestUtils::MapPagesOrDie(size_t num_pages) {
  1260. + void* addr = mmap(nullptr, num_pages * base::GetPageSize(),
  1261. + PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
  1262. + PCHECK(addr);
  1263. + return addr;
  1264. +}
  1265. +
  1266. +void TestUtils::MprotectLastPageOrDie(char* addr, size_t num_pages) {
  1267. + size_t last_page_offset = (num_pages - 1) * base::GetPageSize();
  1268. + PCHECK(mprotect(addr + last_page_offset, base::GetPageSize(), PROT_NONE) >=
  1269. + 0);
  1270. +}
  1271. +
  1272. } // namespace sandbox
  1273. diff --git a/sandbox/linux/tests/test_utils.h b/sandbox/linux/tests/test_utils.h
  1274. index 7cf9749fe4..43b028b1e3 100644
  1275. --- a/sandbox/linux/tests/test_utils.h
  1276. +++ b/sandbox/linux/tests/test_utils.h
  1277. @@ -19,6 +19,8 @@ class TestUtils {
  1278. // makes sure that if fork() succeeded the child exits
  1279. // and the parent waits for it.
  1280. static void HandlePostForkReturn(pid_t pid);
  1281. + static void* MapPagesOrDie(size_t num_pages);
  1282. + static void MprotectLastPageOrDie(char* addr, size_t num_pages);
  1283. private:
  1284. DISALLOW_IMPLICIT_CONSTRUCTORS(TestUtils);
  1285. diff --git a/sandbox/policy/linux/bpf_broker_policy_linux.cc b/sandbox/policy/linux/bpf_broker_policy_linux.cc
  1286. index 2963bb9ca8..6dc8c0581b 100644
  1287. --- a/sandbox/policy/linux/bpf_broker_policy_linux.cc
  1288. +++ b/sandbox/policy/linux/bpf_broker_policy_linux.cc
  1289. @@ -93,8 +93,8 @@ ResultExpr BrokerProcessPolicy::EvaluateSyscall(int sysno) const {
  1290. return Allow();
  1291. break;
  1292. #endif
  1293. -#if defined(__NR_fstatat)
  1294. - case __NR_fstatat:
  1295. +#if defined(__NR_fstatat64)
  1296. + case __NR_fstatat64:
  1297. if (allowed_command_set_.test(syscall_broker::COMMAND_STAT))
  1298. return Allow();
  1299. break;