Skip to content

Commit faae106

Browse files
author
Allan Sandfeld Jensen
committed
[Backport] sandbox: linux: allow clock_nanosleep & gettime64
This is a rewrite and expansion of https://crrev.com/c/2717027. Starting with newer versions of glibc (>=2.32), the timing syscalls are assumed to be 64bit to fix the Y2038 bug and are called unconditionally. Older 32bit systems where the 64bit syscalls return ENOSYS will fallback to the 32bit variants. Newer glibc versions also refactored the nanosleep() function to use clock_nanosleep syscalls, so allow it as well. BUG=chromium:1183928 TEST=Local builds & booting on kevin. Change-Id: I0c00ad527fbd8b0eab4d91b381bcc135624d1e9d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2744134 Commit-Queue: Adrian Ratiu <adrian.ratiu@collabora.corp-partner.google.com> Reviewed-by: Matthew Denton <mpdenton@chromium.org> Cr-Commit-Position: refs/heads/master@{#862126} Reviewed-by: Michal Klocek <michal.klocek@qt.io>
1 parent 652f834 commit faae106

File tree

7 files changed

+47
-1
lines changed

7 files changed

+47
-1
lines changed

chromium/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Addanki Gandhi Kishor <kishor.ag@samsung.com>
3333
Adenilson Cavalcanti <a.cavalcanti@samsung.com>
3434
Aditya Bhargava <heuristicist@gmail.com>
3535
Adrian Belgun <adrian.belgun@intel.com>
36+
Adrian Ratiu <adrian.ratiu@collabora.corp-partner.google.com>
3637
Ahmet Emir Ercin <ahmetemiremir@gmail.com>
3738
Ajay Berwal <a.berwal@samsung.com>
3839
Ajay Berwal <ajay.berwal@samsung.com>

chromium/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ ResultExpr EvaluateSyscallImpl(int fs_denied_errno,
160160
return Allow();
161161
#endif
162162

163-
if (sysno == __NR_clock_gettime || sysno == __NR_clock_nanosleep) {
163+
if (SyscallSets::IsClockApi(sysno)) {
164164
return RestrictClockID();
165165
}
166166

chromium/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ class RestrictClockIdPolicy : public bpf_dsl::Policy {
5555
ResultExpr EvaluateSyscall(int sysno) const override {
5656
switch (sysno) {
5757
case __NR_clock_gettime:
58+
#if defined(__NR_clock_gettime64)
59+
case __NR_clock_gettime64:
60+
#endif
5861
case __NR_clock_getres:
5962
case __NR_clock_nanosleep:
63+
#if defined(__NR_clock_nanosleep_time64)
64+
case __NR_clock_nanosleep_time64:
65+
#endif
6066
return RestrictClockID();
6167
default:
6268
return Allow();

chromium/sandbox/linux/seccomp-bpf-helpers/syscall_sets.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ bool SyscallSets::IsAllowedGettime(int sysno) {
3838
case __NR_clock_getres: // Allowed only on Android with parameters
3939
// filtered by RestrictClokID().
4040
case __NR_clock_gettime: // Parameters filtered by RestrictClockID().
41+
#if defined(__NR_clock_gettime64)
42+
case __NR_clock_gettime64: // Parameters filtered by RestrictClockID().
43+
#endif
4144
case __NR_clock_nanosleep: // Parameters filtered by RestrictClockID().
45+
#if defined(__NR_clock_nanosleep_time64)
46+
case __NR_clock_nanosleep_time64: // Parameters filtered by RestrictClockID().
47+
#endif
4248
case __NR_clock_settime: // Privileged.
4349
#if defined(__i386__) || \
4450
(defined(ARCH_CPU_MIPS_FAMILY) && defined(ARCH_CPU_32_BITS))
@@ -975,6 +981,22 @@ bool SyscallSets::IsAdvancedTimer(int sysno) {
975981
}
976982
}
977983

984+
bool SyscallSets::IsClockApi(int sysno) {
985+
switch (sysno) {
986+
case __NR_clock_gettime:
987+
#if defined(__NR_clock_gettime64)
988+
case __NR_clock_gettime64:
989+
#endif
990+
case __NR_clock_nanosleep:
991+
#if defined(__NR_clock_nanosleep_time64)
992+
case __NR_clock_nanosleep_time64:
993+
#endif
994+
return true;
995+
default:
996+
return false;
997+
}
998+
}
999+
9781000
bool SyscallSets::IsExtendedAttributes(int sysno) {
9791001
switch (sysno) {
9801002
case __NR_fgetxattr:

chromium/sandbox/linux/seccomp-bpf-helpers/syscall_sets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class SANDBOX_EXPORT SyscallSets {
9999
static bool IsFaNotify(int sysno);
100100
static bool IsTimer(int sysno);
101101
static bool IsAdvancedTimer(int sysno);
102+
static bool IsClockApi(int sysno);
102103
static bool IsExtendedAttributes(int sysno);
103104
static bool IsMisc(int sysno);
104105
#if defined(__arm__)

chromium/sandbox/linux/system_headers/arm_linux_syscalls.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,14 @@
14531453
#define __NR_landlock_restrict_self (__NR_SYSCALL_BASE + 446)
14541454
#endif
14551455

1456+
#if !defined(__NR_clock_gettime64)
1457+
#define __NR_clock_gettime64 (__NR_SYSCALL_BASE+403)
1458+
#endif
1459+
1460+
#if !defined(__NR_clock_nanosleep_time64)
1461+
#define __NR_clock_nanosleep_time64 (__NR_SYSCALL_BASE+407)
1462+
#endif
1463+
14561464
// ARM private syscalls.
14571465
#if !defined(__ARM_NR_BASE)
14581466
#define __ARM_NR_BASE (__NR_SYSCALL_BASE + 0xF0000)

chromium/sandbox/linux/system_headers/mips_linux_syscalls.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,4 +1445,12 @@
14451445
#define __NR_landlock_restrict_self (__NR_Linux + 446)
14461446
#endif
14471447

1448+
#if !defined(__NR_clock_gettime64)
1449+
#define __NR_clock_gettime64 (__NR_Linux + 403)
1450+
#endif
1451+
1452+
#if !defined(__NR_clock_nanosleep_time64)
1453+
#define __NR_clock_nanosleep_time64 (__NR_Linux + 407)
1454+
#endif
1455+
14481456
#endif // SANDBOX_LINUX_SYSTEM_HEADERS_MIPS_LINUX_SYSCALLS_H_

0 commit comments

Comments
 (0)