| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" | 5 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" |
| 6 #include "sandbox/linux/seccomp-bpf/port.h" | 6 #include "sandbox/linux/seccomp-bpf/port.h" |
| 7 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | 7 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" |
| 8 | 8 |
| 9 namespace playground2 { | 9 namespace playground2 { |
| 10 | 10 |
| 11 uint32_t SyscallIterator::Next() { | 11 uint32_t SyscallIterator::Next() { |
| 12 if (done_) { | 12 if (done_) { |
| 13 return num_; | 13 return num_; |
| 14 } | 14 } |
| 15 | 15 |
| 16 uint32_t val; | 16 uint32_t val; |
| 17 do { | 17 do { |
| 18 // |num_| has been initialized to 0, which we assume is also MIN_SYSCALL. | 18 // |num_| has been initialized to 0, which we assume is also MIN_SYSCALL. |
| 19 // This true for supported architectures (Intel and ARM EABI). | 19 // This true for supported architectures (Intel and ARM EABI). |
| 20 COMPILE_ASSERT(MIN_SYSCALL == 0u, | 20 COMPILE_ASSERT(MIN_SYSCALL == 0u, min_syscall_should_always_be_zero); |
| 21 min_syscall_should_always_be_zero); | |
| 22 val = num_; | 21 val = num_; |
| 23 | 22 |
| 24 // First we iterate up to MAX_PUBLIC_SYSCALL, which is equal to MAX_SYSCALL | 23 // First we iterate up to MAX_PUBLIC_SYSCALL, which is equal to MAX_SYSCALL |
| 25 // on Intel architectures, but leaves room for private syscalls on ARM. | 24 // on Intel architectures, but leaves room for private syscalls on ARM. |
| 26 if (num_ <= MAX_PUBLIC_SYSCALL) { | 25 if (num_ <= MAX_PUBLIC_SYSCALL) { |
| 27 if (invalid_only_ && num_ < MAX_PUBLIC_SYSCALL) { | 26 if (invalid_only_ && num_ < MAX_PUBLIC_SYSCALL) { |
| 28 num_ = MAX_PUBLIC_SYSCALL; | 27 num_ = MAX_PUBLIC_SYSCALL; |
| 29 } else { | 28 } else { |
| 30 ++num_; | 29 ++num_; |
| 31 } | 30 } |
| 32 #if defined(__arm__) | 31 #if defined(__arm__) |
| 33 // ARM EABI includes "ARM private" system calls starting at | 32 // ARM EABI includes "ARM private" system calls starting at |
| 34 // MIN_PRIVATE_SYSCALL, and a "ghost syscall private to the kernel" at | 33 // MIN_PRIVATE_SYSCALL, and a "ghost syscall private to the kernel" at |
| 35 // MIN_GHOST_SYSCALL. | 34 // MIN_GHOST_SYSCALL. |
| 36 } else if (num_ < MIN_PRIVATE_SYSCALL - 1) { | 35 } else if (num_ < MIN_PRIVATE_SYSCALL - 1) { |
| 37 num_ = MIN_PRIVATE_SYSCALL - 1; | 36 num_ = MIN_PRIVATE_SYSCALL - 1; |
| 38 } else if (num_ <= MAX_PRIVATE_SYSCALL) { | 37 } else if (num_ <= MAX_PRIVATE_SYSCALL) { |
| 39 if (invalid_only_ && num_ < MAX_PRIVATE_SYSCALL) { | 38 if (invalid_only_ && num_ < MAX_PRIVATE_SYSCALL) { |
| 40 num_ = MAX_PRIVATE_SYSCALL; | 39 num_ = MAX_PRIVATE_SYSCALL; |
| 41 } else { | 40 } else { |
| 42 ++num_; | 41 ++num_; |
| 43 } | 42 } |
| 44 } else if (num_ < MIN_GHOST_SYSCALL - 1) { | 43 } else if (num_ < MIN_GHOST_SYSCALL - 1) { |
| 45 num_ = MIN_GHOST_SYSCALL - 1; | 44 num_ = MIN_GHOST_SYSCALL - 1; |
| 46 } else if (num_ <= MAX_SYSCALL) { | 45 } else if (num_ <= MAX_SYSCALL) { |
| 47 if (invalid_only_ && num_ < MAX_SYSCALL) { | 46 if (invalid_only_ && num_ < MAX_SYSCALL) { |
| 48 num_ = MAX_SYSCALL; | 47 num_ = MAX_SYSCALL; |
| 49 } else { | 48 } else { |
| 50 ++num_; | 49 ++num_; |
| 51 } | 50 } |
| 52 #endif | 51 #endif |
| 53 // BPF programs only ever operate on unsigned quantities. So, that's how | 52 // BPF programs only ever operate on unsigned quantities. So, that's how |
| 54 // we iterate; we return values from 0..0xFFFFFFFFu. But there are places, | 53 // we iterate; we return values from 0..0xFFFFFFFFu. But there are places, |
| 55 // where the kernel might interpret system call numbers as signed | 54 // where the kernel might interpret system call numbers as signed |
| 56 // quantities, so the boundaries between signed and unsigned values are | 55 // quantities, so the boundaries between signed and unsigned values are |
| 57 // potential problem cases. We want to explicitly return these values from | 56 // potential problem cases. We want to explicitly return these values from |
| 58 // our iterator. | 57 // our iterator. |
| 59 } else if (num_ < 0x7FFFFFFFu) { | 58 } else if (num_ < 0x7FFFFFFFu) { |
| 60 num_ = 0x7FFFFFFFu; | 59 num_ = 0x7FFFFFFFu; |
| 61 } else if (num_ < 0x80000000u) { | 60 } else if (num_ < 0x80000000u) { |
| 62 num_ = 0x80000000u; | 61 num_ = 0x80000000u; |
| 63 } else if (num_ < 0xFFFFFFFFu) { | 62 } else if (num_ < 0xFFFFFFFFu) { |
| 64 num_ = 0xFFFFFFFFu; | 63 num_ = 0xFFFFFFFFu; |
| 65 } | 64 } |
| 66 } while (invalid_only_ && IsValid(val)); | 65 } while (invalid_only_ && IsValid(val)); |
| 67 | 66 |
| 68 done_ |= val == 0xFFFFFFFFu; | 67 done_ |= val == 0xFFFFFFFFu; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 79 } | 78 } |
| 80 return false; | 79 return false; |
| 81 } | 80 } |
| 82 | 81 |
| 83 #if defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__)) | 82 #if defined(__arm__) && (defined(__thumb__) || defined(__ARM_EABI__)) |
| 84 bool SyscallIterator::IsArmPrivate(uint32_t num) { | 83 bool SyscallIterator::IsArmPrivate(uint32_t num) { |
| 85 return (num >= MIN_PRIVATE_SYSCALL && num <= MAX_PRIVATE_SYSCALL) || | 84 return (num >= MIN_PRIVATE_SYSCALL && num <= MAX_PRIVATE_SYSCALL) || |
| 86 (num >= MIN_GHOST_SYSCALL && num <= MAX_SYSCALL); | 85 (num >= MIN_GHOST_SYSCALL && num <= MAX_SYSCALL); |
| 87 } | 86 } |
| 88 #else | 87 #else |
| 89 bool SyscallIterator::IsArmPrivate(uint32_t) { | 88 bool SyscallIterator::IsArmPrivate(uint32_t) { return false; } |
| 90 return false; | |
| 91 } | |
| 92 #endif | 89 #endif |
| 93 | 90 |
| 94 } // namespace | 91 } // namespace |
| 95 | |
| OLD | NEW |