Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(959)

Unified Diff: sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc

Issue 260793003: [MIPS] Add seccomp bpf support (Closed) Base URL: https://git.chromium.org/git/chromium/src.git@master
Patch Set: Fix problem with truncation of syscall value in CrashSIGSYS_Handler Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
diff --git a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
index c4a6f92c01d423521aee83ffcaf2e4cc35f4e82a..7e4aac29f5e3c190229a93dee294f0dd592917ec 100644
--- a/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.cc
@@ -44,11 +44,29 @@ void WriteToStdErr(const char* error_message, size_t size) {
}
}
+uint32_t TruncSysnoToValue(uint32_t sysno) {
+#if defined(__mips__)
+ // On MIPS syscall numbers are in different range than on x86 and ARM
+ if (sysno < __NR_Linux || sysno > __NR_Linux + __NR_Linux_syscalls)
+ // 4000 (truncated to zero) is valid syscall number on mips O32 ABI.
+ // Invalid syscall will be printed with a value that is out of range
+ // on apropriate ABI.
+ sysno = sysno - __NR_Linux + 1000;
jln (very slow on Chromium) 2014/05/16 19:30:17 I don't understand what this does. Please documen
nedeljko 2014/05/19 17:37:23 On MIPS O32 ABI value of __NR_Linux is 4000. The
nedeljko 2014/05/22 17:38:55 Done.
+ else
+ sysno = sysno - __NR_Linux;
+#else
+ if (sysno >= 1024)
+ sysno = 0;
+#endif
+ return sysno;
+}
+
// Print a seccomp-bpf failure to handle |sysno| to stderr in an
// async-signal safe way.
void PrintSyscallError(uint32_t sysno) {
- if (sysno >= 1024)
- sysno = 0;
+
+ sysno = TruncSysnoToValue(sysno);
+
// TODO(markus): replace with async-signal safe snprintf when available.
const size_t kNumDigits = 4;
char sysno_base10[kNumDigits];
@@ -59,8 +77,14 @@ void PrintSyscallError(uint32_t sysno) {
rem /= 10;
sysno_base10[i] = '0' + mod;
}
+#if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32)
+ static const char kSeccompErrorPrefix[] =
+ __FILE__":**CRASHING**:" SECCOMP_MESSAGE_COMMON_CONTENT
+ " in syscall 4000 + ";
+#else
static const char kSeccompErrorPrefix[] =
__FILE__":**CRASHING**:" SECCOMP_MESSAGE_COMMON_CONTENT " in syscall ";
+#endif
static const char kSeccompErrorPostfix[] = "\n";
WriteToStdErr(kSeccompErrorPrefix, sizeof(kSeccompErrorPrefix) - 1);
WriteToStdErr(sysno_base10, sizeof(sysno_base10));
@@ -73,8 +97,7 @@ namespace sandbox {
intptr_t CrashSIGSYS_Handler(const struct arch_seccomp_data& args, void* aux) {
uint32_t syscall = args.nr;
- if (syscall >= 1024)
- syscall = 0;
+
PrintSyscallError(syscall);
// Encode 8-bits of the 1st two arguments too, so we can discern which socket

Powered by Google App Engine
This is Rietveld 408576698