Skip to content

Commit cb3278e

Browse files
Yi Fan Yuotavio
authored andcommitted
chromium: Fix font rendering with glibc-2.33
A change in the fstat syscall in glibc-2.33 causes font rendering issues when sandbox is enabled. It now handles __NR_newfstatat and __NR_fstatat64 properly in the sandbox. Taken from fedora upstream: https://src.fedoraproject.org/rpms/chromium/ c/82ff440ce80f6a03b150f768a2cba9469a8ec4f4?branch=rawhide #473 Signed-off-by: Yi Fan Yu <yifan.yu@windriver.com>
1 parent d99d6b3 commit cb3278e

File tree

2 files changed

+178
-0
lines changed

2 files changed

+178
-0
lines changed

meta-chromium/recipes-browser/chromium/chromium-gn.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SRC_URI += " \
1919
file://0009-RandBytes-Stop-including-sys-random.h-on-Linux.patch \
2020
file://0010-avoid-link-latomic-failure-on-CentOS-8-host.patch \
2121
file://0011-Fix-use-of-DCHECK-with-std-unique_ptr.patch \
22+
file://0012-Fix-font-rendering-with-glibc-2.33.patch \
2223
"
2324

2425
SRC_URI_append_libc-musl = "\
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
From 4efced4055a8836eba14199745ef2129717247b5 Mon Sep 17 00:00:00 2001
2+
From: Yi Fan Yu <yifan.yu@windriver.com>
3+
Date: Tue, 6 Apr 2021 15:30:58 -0400
4+
Subject: [PATCH] Fix font rendering with glibc-2.33
5+
6+
A change in the fstat syscall in glibc-2.33
7+
causes font rendering issues when sandbox is enabled.
8+
9+
This patch is used by both fedora33 and archlinux
10+
in their chromium builds.
11+
12+
Directly taken from:
13+
https://src.fedoraproject.org/rpms/chromium/c/
14+
82ff440ce80f6a03b150f768a2cba9469a8ec4f4?branch=rawhide
15+
16+
Upstream-Status: Submitted [https://bugs.chromium.org/p/chromium/issues/detail?id=1164975]
17+
18+
Original Author: Kevin Kofler <Kevin@tigcc.ticalc.org>
19+
20+
This fix was pointed out by MarkusVolk in
21+
https://github.com/OSSystems/meta-browser/issues/473
22+
23+
Signed-off-by: Yi Fan Yu <yifan.yu@windriver.com>
24+
---
25+
.../seccomp-bpf-helpers/baseline_policy.cc | 12 +++++++
26+
.../seccomp-bpf-helpers/sigsys_handlers.cc | 35 +++++++++++++++++++
27+
.../seccomp-bpf-helpers/sigsys_handlers.h | 5 +++
28+
sandbox/linux/services/syscall_wrappers.cc | 9 +++++
29+
sandbox/linux/services/syscall_wrappers.h | 4 +++
30+
5 files changed, 65 insertions(+)
31+
32+
diff --git a/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
33+
index e00e3125993..722eb6796b7 100644
34+
--- a/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
35+
+++ b/sandbox/linux/seccomp-bpf-helpers/baseline_policy.cc
36+
@@ -261,6 +261,18 @@ ResultExpr EvaluateSyscallImpl(int fs_denied_errno,
37+
return RestrictKillTarget(current_pid, sysno);
38+
}
39+
40+
+#if defined(__NR_newfstatat)
41+
+ if (sysno == __NR_newfstatat) {
42+
+ return RewriteFstatatSIGSYS();
43+
+ }
44+
+#endif
45+
+
46+
+#if defined(__NR_fstatat64)
47+
+ if (sysno == __NR_fstatat64) {
48+
+ return RewriteFstatatSIGSYS();
49+
+ }
50+
+#endif
51+
+
52+
if (SyscallSets::IsFileSystem(sysno) ||
53+
SyscallSets::IsCurrentDirectory(sysno)) {
54+
return Error(fs_denied_errno);
55+
diff --git a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
56+
index 76eb32493f5..09aa3f0b11c 100644
57+
--- a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
58+
+++ b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
59+
@@ -6,6 +6,8 @@
60+
61+
#include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
62+
63+
+#include <errno.h>
64+
+#include <fcntl.h>
65+
#include <stddef.h>
66+
#include <stdint.h>
67+
#include <string.h>
68+
@@ -355,6 +357,35 @@ intptr_t SIGSYSSchedHandler(const struct arch_seccomp_data& args,
69+
return -ENOSYS;
70+
}
71+
72+
+intptr_t SIGSYSFstatatHandler(const struct arch_seccomp_data& args,
73+
+ void* aux) {
74+
+ switch (args.nr) {
75+
+#if defined(__NR_newfstatat)
76+
+ case __NR_newfstatat:
77+
+#endif
78+
+#if defined(__NR_fstatat64)
79+
+ case __NR_fstatat64:
80+
+#endif
81+
+#if defined(__NR_newfstatat) || defined(__NR_fstatat64)
82+
+ if (*reinterpret_cast<const char *>(args.args[1]) == '\0'
83+
+ && args.args[3] == static_cast<uint64_t>(AT_EMPTY_PATH)) {
84+
+ return sandbox::sys_fstat64(static_cast<int>(args.args[0]),
85+
+ reinterpret_cast<struct stat64 *>(args.args[2]));
86+
+ } else {
87+
+ errno = EACCES;
88+
+ return -1;
89+
+ }
90+
+ break;
91+
+#endif
92+
+ }
93+
+
94+
+ CrashSIGSYS_Handler(args, aux);
95+
+
96+
+ // Should never be reached.
97+
+ RAW_CHECK(false);
98+
+ return -ENOSYS;
99+
+}
100+
+
101+
bpf_dsl::ResultExpr CrashSIGSYS() {
102+
return bpf_dsl::Trap(CrashSIGSYS_Handler, NULL);
103+
}
104+
@@ -387,6 +418,10 @@ bpf_dsl::ResultExpr RewriteSchedSIGSYS() {
105+
return bpf_dsl::Trap(SIGSYSSchedHandler, NULL);
106+
}
107+
108+
+bpf_dsl::ResultExpr RewriteFstatatSIGSYS() {
109+
+ return bpf_dsl::Trap(SIGSYSFstatatHandler, NULL);
110+
+}
111+
+
112+
void AllocateCrashKeys() {
113+
#if !defined(OS_NACL_NONSFI)
114+
if (seccomp_crash_key)
115+
diff --git a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h
116+
index 7a958b93b27..d0bfab74bb9 100644
117+
--- a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h
118+
+++ b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h
119+
@@ -62,6 +62,10 @@ SANDBOX_EXPORT intptr_t SIGSYSPtraceFailure(const arch_seccomp_data& args,
120+
// sched_setparam(), sched_setscheduler()
121+
SANDBOX_EXPORT intptr_t SIGSYSSchedHandler(const arch_seccomp_data& args,
122+
void* aux);
123+
+// If the fstatat syscall is actually a disguised fstat, calls the regular fstat
124+
+// syscall, otherwise, crashes in the same way as CrashSIGSYS_Handler.
125+
+SANDBOX_EXPORT intptr_t SIGSYSFstatatHandler(const struct arch_seccomp_data& args,
126+
+ void* aux);
127+
128+
// Variants of the above functions for use with bpf_dsl.
129+
SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYS();
130+
@@ -72,6 +76,7 @@ SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSKill();
131+
SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSFutex();
132+
SANDBOX_EXPORT bpf_dsl::ResultExpr CrashSIGSYSPtrace();
133+
SANDBOX_EXPORT bpf_dsl::ResultExpr RewriteSchedSIGSYS();
134+
+SANDBOX_EXPORT bpf_dsl::ResultExpr RewriteFstatatSIGSYS();
135+
136+
// Allocates a crash key so that Seccomp information can be recorded.
137+
void AllocateCrashKeys();
138+
diff --git a/sandbox/linux/services/syscall_wrappers.cc b/sandbox/linux/services/syscall_wrappers.cc
139+
index fcfd2aa129d..5396b36da9f 100644
140+
--- a/sandbox/linux/services/syscall_wrappers.cc
141+
+++ b/sandbox/linux/services/syscall_wrappers.cc
142+
@@ -261,4 +261,13 @@ int sys_sigaction(int signum,
143+
144+
#endif // defined(MEMORY_SANITIZER)
145+
146+
+SANDBOX_EXPORT int sys_fstat64(int fd, struct stat64 *buf)
147+
+{
148+
+#if defined(__NR_fstat64)
149+
+ return syscall(__NR_fstat64, fd, buf);
150+
+#else
151+
+ return syscall(__NR_fstat, fd, buf);
152+
+#endif
153+
+}
154+
+
155+
} // namespace sandbox
156+
diff --git a/sandbox/linux/services/syscall_wrappers.h b/sandbox/linux/services/syscall_wrappers.h
157+
index 1975bfbd88a..ed7ee5a1c16 100644
158+
--- a/sandbox/linux/services/syscall_wrappers.h
159+
+++ b/sandbox/linux/services/syscall_wrappers.h
160+
@@ -17,6 +17,7 @@ struct sock_fprog;
161+
struct rlimit64;
162+
struct cap_hdr;
163+
struct cap_data;
164+
+struct stat64;
165+
166+
namespace sandbox {
167+
168+
@@ -84,6 +85,9 @@ SANDBOX_EXPORT int sys_sigaction(int signum,
169+
const struct sigaction* act,
170+
struct sigaction* oldact);
171+
172+
+// Recent glibc rewrites fstat to fstatat.
173+
+SANDBOX_EXPORT int sys_fstat64(int fd, struct stat64 *buf);
174+
+
175+
} // namespace sandbox
176+
177+
#endif // SANDBOX_LINUX_SERVICES_SYSCALL_WRAPPERS_H_

0 commit comments

Comments
 (0)