[openssh-commits] [openssh] 03/87: disallow non-MAP_ANON mmap(2) in seccomp sandbox
git+noreply at mindrot.org
git+noreply at mindrot.org
Fri Oct 30 20:20:40 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit 46ea12755813564424ff7a3096ed6e029fbaa9b7
Author: Damien Miller <djm at mindrot.org>
AuthorDate: Fri Oct 30 13:05:03 2026 +1100
disallow non-MAP_ANON mmap(2) in seccomp sandbox
harden sandbox by disallowing non-anonymous mappings
Anthropic ANT-2026-DVPHBUJ2
---
sandbox-seccomp-filter.c | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
diff --git a/sandbox-seccomp-filter.c b/sandbox-seccomp-filter.c
index 9454f18ee..2d83fc3e6 100644
--- a/sandbox-seccomp-filter.c
+++ b/sandbox-seccomp-filter.c
@@ -154,6 +154,25 @@
/* reload syscall number; all rules expect it in accumulator */ \
BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
offsetof(struct seccomp_data, nr))
+/* Deny unless syscall argument contains all values in mask */
+#define SC_DENY_UNLESS_ARG_BITS(_nr, _arg_nr, _arg_mask, _errno) \
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, (_nr), 0, 8), \
+ /* load, mask and test syscall argument, low word */ \
+ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
+ offsetof(struct seccomp_data, args[(_arg_nr)]) + ARG_LO_OFFSET), \
+ BPF_STMT(BPF_ALU+BPF_AND+BPF_K, ((_arg_mask) & 0xFFFFFFFF)), \
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ((_arg_mask) & 0xFFFFFFFF), 0, 3), \
+ /* load, mask and test syscall argument, high word */ \
+ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
+ offsetof(struct seccomp_data, args[(_arg_nr)]) + ARG_HI_OFFSET), \
+ BPF_STMT(BPF_ALU+BPF_AND+BPF_K, \
+ (((uint32_t)((uint64_t)(_arg_mask) >> 32)) & 0xFFFFFFFF)), \
+ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, \
+ (((uint32_t)((uint64_t)(_arg_mask) >> 32)) & 0xFFFFFFFF), 1, 0), \
+ BPF_STMT(BPF_RET+BPF_K, SECCOMP_RET_ERRNO|(_errno)), \
+ /* reload syscall number; all rules expect it in accumulator */ \
+ BPF_STMT(BPF_LD+BPF_W+BPF_ABS, \
+ offsetof(struct seccomp_data, nr))
#define SC_DENY_UNLESS_MASK(_nr, _arg_nr, _arg_val, _errno) \
/* Special handling for futex(2) that combines a bitmap and operation number */
#if defined(__NR_futex) || defined(__NR_futex_time64)
@@ -196,9 +215,14 @@
# else
# define SC_MMAP_FLAGS MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED
# endif /* MAP_FIXED_NOREPLACE */
-/* Use this for both __NR_mmap and __NR_mmap2 variants */
+/*
+ * Use this for both __NR_mmap and __NR_mmap2 variants.
+ * Only anonymous mappings are needed; requiring MAP_ANONYMOUS prevents
+ * mapping of any file descriptor the process holds (e.g. the client socket).
+ */
# define SC_MMAP(_nr) \
SC_DENY_UNLESS_ARG_MASK(_nr, 3, SC_MMAP_FLAGS, EINVAL), \
+ SC_DENY_UNLESS_ARG_BITS(_nr, 3, MAP_ANONYMOUS, EINVAL), \
SC_ALLOW_ARG_MASK(_nr, 2, PROT_READ|PROT_WRITE|PROT_NONE)
#endif /* __NR_mmap || __NR_mmap2 */
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list