@dsh-ray/assistant-verifier 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +286 -2
  3. package/cordis.patch.yml +10 -0
  4. package/lib/config.d.ts +47 -0
  5. package/lib/config.d.ts.map +1 -0
  6. package/lib/config.js +82 -0
  7. package/lib/config.js.map +1 -0
  8. package/lib/creation-review-native.d.ts +30 -0
  9. package/lib/creation-review-native.d.ts.map +1 -0
  10. package/lib/creation-review-native.js +137 -0
  11. package/lib/creation-review-native.js.map +1 -0
  12. package/lib/creation-review-store.d.ts +108 -0
  13. package/lib/creation-review-store.d.ts.map +1 -0
  14. package/lib/creation-review-store.js +715 -0
  15. package/lib/creation-review-store.js.map +1 -0
  16. package/lib/creation-review.d.ts +317 -0
  17. package/lib/creation-review.d.ts.map +1 -0
  18. package/lib/creation-review.js +842 -0
  19. package/lib/creation-review.js.map +1 -0
  20. package/lib/drivers.d.ts +153 -0
  21. package/lib/drivers.d.ts.map +1 -0
  22. package/lib/drivers.js +825 -0
  23. package/lib/drivers.js.map +1 -0
  24. package/lib/host.d.ts +93 -0
  25. package/lib/host.d.ts.map +1 -0
  26. package/lib/host.js +2 -0
  27. package/lib/host.js.map +1 -0
  28. package/lib/index.d.ts +26 -0
  29. package/lib/index.d.ts.map +1 -0
  30. package/lib/index.js +18 -0
  31. package/lib/index.js.map +1 -0
  32. package/lib/linux-behavior-assets.d.ts +17 -0
  33. package/lib/linux-behavior-assets.d.ts.map +1 -0
  34. package/lib/linux-behavior-assets.js +73 -0
  35. package/lib/linux-behavior-assets.js.map +1 -0
  36. package/lib/linux-behavior-runner.d.ts +10 -0
  37. package/lib/linux-behavior-runner.d.ts.map +1 -0
  38. package/lib/linux-behavior-runner.js +69 -0
  39. package/lib/linux-behavior-runner.js.map +1 -0
  40. package/lib/linux-behavior-runtime.d.ts +67 -0
  41. package/lib/linux-behavior-runtime.d.ts.map +1 -0
  42. package/lib/linux-behavior-runtime.js +500 -0
  43. package/lib/linux-behavior-runtime.js.map +1 -0
  44. package/lib/memory-review-native.d.ts +50 -0
  45. package/lib/memory-review-native.d.ts.map +1 -0
  46. package/lib/memory-review-native.js +166 -0
  47. package/lib/memory-review-native.js.map +1 -0
  48. package/lib/memory-review.d.ts +50 -0
  49. package/lib/memory-review.d.ts.map +1 -0
  50. package/lib/memory-review.js +363 -0
  51. package/lib/memory-review.js.map +1 -0
  52. package/lib/native-behavior-artifact.d.ts +9 -0
  53. package/lib/native-behavior-artifact.d.ts.map +1 -0
  54. package/lib/native-behavior-artifact.js +144 -0
  55. package/lib/native-behavior-artifact.js.map +1 -0
  56. package/lib/native-behavior-worker.d.ts +3 -0
  57. package/lib/native-behavior-worker.d.ts.map +1 -0
  58. package/lib/native-behavior-worker.js +453 -0
  59. package/lib/native-behavior-worker.js.map +1 -0
  60. package/lib/plugin-behavior-config.d.ts +34 -0
  61. package/lib/plugin-behavior-config.d.ts.map +1 -0
  62. package/lib/plugin-behavior-config.js +170 -0
  63. package/lib/plugin-behavior-config.js.map +1 -0
  64. package/lib/plugin-behavior-runner.d.ts +57 -0
  65. package/lib/plugin-behavior-runner.d.ts.map +1 -0
  66. package/lib/plugin-behavior-runner.js +910 -0
  67. package/lib/plugin-behavior-runner.js.map +1 -0
  68. package/lib/review-authority-lineage.d.ts +109 -0
  69. package/lib/review-authority-lineage.d.ts.map +1 -0
  70. package/lib/review-authority-lineage.js +135 -0
  71. package/lib/review-authority-lineage.js.map +1 -0
  72. package/lib/review-maintenance.d.ts +20 -0
  73. package/lib/review-maintenance.d.ts.map +1 -0
  74. package/lib/review-maintenance.js +24 -0
  75. package/lib/review-maintenance.js.map +1 -0
  76. package/lib/revision-regression-review.d.ts +41 -0
  77. package/lib/revision-regression-review.d.ts.map +1 -0
  78. package/lib/revision-regression-review.js +379 -0
  79. package/lib/revision-regression-review.js.map +1 -0
  80. package/lib/revision-review.d.ts +242 -0
  81. package/lib/revision-review.d.ts.map +1 -0
  82. package/lib/revision-review.js +600 -0
  83. package/lib/revision-review.js.map +1 -0
  84. package/lib/service.d.ts +138 -0
  85. package/lib/service.d.ts.map +1 -0
  86. package/lib/service.js +878 -0
  87. package/lib/service.js.map +1 -0
  88. package/lib/source-review-git.d.ts +32 -0
  89. package/lib/source-review-git.d.ts.map +1 -0
  90. package/lib/source-review-git.js +241 -0
  91. package/lib/source-review-git.js.map +1 -0
  92. package/lib/source-review-native.d.ts +27 -0
  93. package/lib/source-review-native.d.ts.map +1 -0
  94. package/lib/source-review-native.js +149 -0
  95. package/lib/source-review-native.js.map +1 -0
  96. package/lib/source-review-store.d.ts +44 -0
  97. package/lib/source-review-store.d.ts.map +1 -0
  98. package/lib/source-review-store.js +212 -0
  99. package/lib/source-review-store.js.map +1 -0
  100. package/lib/source-review.d.ts +86 -0
  101. package/lib/source-review.d.ts.map +1 -0
  102. package/lib/source-review.js +255 -0
  103. package/lib/source-review.js.map +1 -0
  104. package/lib/store.d.ts +84 -0
  105. package/lib/store.d.ts.map +1 -0
  106. package/lib/store.js +386 -0
  107. package/lib/store.js.map +1 -0
  108. package/lib/version.d.ts +2 -0
  109. package/lib/version.d.ts.map +1 -0
  110. package/lib/version.js +2 -0
  111. package/lib/version.js.map +1 -0
  112. package/package.json +144 -3
  113. package/runtime/plugin-observer-launcher.c +246 -0
package/package.json CHANGED
@@ -1,6 +1,147 @@
1
1
  {
2
2
  "name": "@dsh-ray/assistant-verifier",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Independent, bounded task acceptance verification with durable contracts and receipts.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./lib/index.js",
8
+ "types": "./lib/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "default": "./lib/index.js"
13
+ },
14
+ "./plugin-behavior-runner": {
15
+ "types": "./lib/plugin-behavior-runner.d.ts",
16
+ "default": "./lib/plugin-behavior-runner.js"
17
+ },
18
+ "./plugin-behavior-config": {
19
+ "types": "./lib/plugin-behavior-config.d.ts",
20
+ "default": "./lib/plugin-behavior-config.js"
21
+ },
22
+ "./cordis.patch.yml": "./cordis.patch.yml",
23
+ "./package.json": "./package.json",
24
+ "./linux-behavior-runtime": {
25
+ "types": "./lib/linux-behavior-runtime.d.ts",
26
+ "default": "./lib/linux-behavior-runtime.js"
27
+ },
28
+ "./review-maintenance": {
29
+ "types": "./lib/review-maintenance.d.ts",
30
+ "default": "./lib/review-maintenance.js"
31
+ }
32
+ },
33
+ "files": [
34
+ "lib",
35
+ "runtime",
36
+ "cordis.patch.yml",
37
+ "README.md",
38
+ "LICENSE"
39
+ ],
40
+ "engines": {
41
+ "node": ">=24.9.0"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/22-ai-00/dsh-ray.git",
49
+ "directory": "plugins/assistant-verifier"
50
+ },
51
+ "keywords": [
52
+ "deepseek",
53
+ "deepseek-harness",
54
+ "dsh-plugin"
55
+ ],
56
+ "dsh": {
57
+ "bundle": {
58
+ "patch": "./cordis.patch.yml"
59
+ },
60
+ "protection": {
61
+ "floor": "immutable"
62
+ }
63
+ },
64
+ "peerDependencies": {
65
+ "@deepseek-ai/cordis": "^4.1.0",
66
+ "@deepseek-ai/dsh-agent": ">=0.2.2-rc.5 <0.3.0",
67
+ "@deepseek-ai/dsh-llm": ">=0.2.2-rc.5 <0.3.0",
68
+ "@deepseek-ai/dsh-session": ">=0.2.2-rc.5 <0.3.0",
69
+ "@deepseek-ai/dsh-system-prompt": ">=0.2.2-rc.5 <0.3.0",
70
+ "@deepseek-ai/dsh-tools": ">=0.2.2-rc.5 <0.3.0",
71
+ "@dsh-ray/assistant-actions": ">=0.1.0 <0.3.0",
72
+ "@dsh-ray/assistant-automations": ">=0.1.24 <0.3.0",
73
+ "@dsh-ray/assistant-delivery": ">=0.1.24 <0.3.0",
74
+ "@dsh-ray/assistant-evaluation": ">=0.1.24 <0.3.0",
75
+ "@dsh-ray/assistant-policy": ">=0.1.0 <0.3.0",
76
+ "@dsh-ray/plugin-control-plane": ">=0.1.0 <0.3.0"
77
+ },
78
+ "peerDependenciesMeta": {
79
+ "@deepseek-ai/cordis": {
80
+ "optional": true
81
+ },
82
+ "@dsh-ray/assistant-automations": {
83
+ "optional": true
84
+ },
85
+ "@dsh-ray/assistant-delivery": {
86
+ "optional": true
87
+ },
88
+ "@dsh-ray/assistant-evaluation": {
89
+ "optional": true
90
+ },
91
+ "@dsh-ray/assistant-actions": {
92
+ "optional": true
93
+ },
94
+ "@deepseek-ai/dsh-agent": {
95
+ "optional": true
96
+ },
97
+ "@deepseek-ai/dsh-llm": {
98
+ "optional": true
99
+ },
100
+ "@deepseek-ai/dsh-session": {
101
+ "optional": true
102
+ },
103
+ "@deepseek-ai/dsh-tools": {
104
+ "optional": true
105
+ },
106
+ "@deepseek-ai/dsh-system-prompt": {
107
+ "optional": true
108
+ },
109
+ "@dsh-ray/assistant-policy": {
110
+ "optional": true
111
+ },
112
+ "@dsh-ray/plugin-control-plane": {
113
+ "optional": true
114
+ }
115
+ },
116
+ "devDependencies": {
117
+ "@deepseek-ai/cordis": "4.1.0",
118
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.5",
119
+ "@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.5",
120
+ "@deepseek-ai/dsh-agent-loop": "0.2.2-rc.5",
121
+ "@deepseek-ai/dsh-agent-loop-testkit": "0.2.2-rc.5",
122
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.5",
123
+ "@deepseek-ai/dsh-session": "0.2.2-rc.5",
124
+ "@deepseek-ai/dsh-session-projection": "0.2.2-rc.5",
125
+ "@deepseek-ai/dsh-system-prompt": "0.2.2-rc.5",
126
+ "@deepseek-ai/dsh-tool-executor-native": "0.2.2-rc.5",
127
+ "@deepseek-ai/dsh-tools": "0.2.2-rc.5",
128
+ "@types/node": "22.20.0",
129
+ "typescript": "6.0.3",
130
+ "vitest": "4.1.8",
131
+ "@dsh-ray/assistant-delivery": "0.2.0",
132
+ "@dsh-ray/assistant-automations": "0.2.0",
133
+ "@dsh-ray/assistant-policy": "0.2.0",
134
+ "@dsh-ray/assistant-evaluation": "0.2.0"
135
+ },
136
+ "dependencies": {
137
+ "@deepseek-ai/schemastery": "3.19.0",
138
+ "@dsh-ray/assistant-growth-contract": "0.2.0",
139
+ "@dsh-ray/assistant-isolation": "0.2.0",
140
+ "@dsh-ray/task-acceptance-contract": "0.2.0"
141
+ },
142
+ "scripts": {
143
+ "build": "tsc -p tsconfig.build.json",
144
+ "test": "vitest run",
145
+ "typecheck": "tsc -p tsconfig.json --noEmit"
146
+ }
6
147
  }
@@ -0,0 +1,246 @@
1
+ /* Fixed Linux x86-64/aarch64 observer boundary. Built into the verifier image only. */
2
+ #define _GNU_SOURCE
3
+ #include <errno.h>
4
+ #include <fcntl.h>
5
+ #include <linux/audit.h>
6
+ #include <linux/filter.h>
7
+ #include <linux/seccomp.h>
8
+ #include <sched.h>
9
+ #include <stddef.h>
10
+ #include <stdint.h>
11
+ #include <stdio.h>
12
+ #include <stdlib.h>
13
+ #include <sys/prctl.h>
14
+ #include <sys/socket.h>
15
+ #include <sys/syscall.h>
16
+ #include <sys/ioctl.h>
17
+ #include <unistd.h>
18
+
19
+ #if defined(__x86_64__)
20
+ #define DSH_AUDIT_ARCH AUDIT_ARCH_X86_64
21
+ #elif defined(__aarch64__)
22
+ #define DSH_AUDIT_ARCH AUDIT_ARCH_AARCH64
23
+ #else
24
+ #error "unsupported verifier architecture"
25
+ #endif
26
+ #ifndef DSH_NODE_PATH
27
+ #define DSH_NODE_PATH "/usr/local/bin/node"
28
+ #endif
29
+
30
+ #ifdef DSH_PARENT_PRELOAD
31
+ __attribute__((constructor)) static void protect_observer(void) {
32
+ if (prctl(PR_SET_DUMPABLE, 0, 0, 0, 0) != 0) _exit(125);
33
+ }
34
+ #elif defined(DSH_CHILD_PRELOAD)
35
+ /* The first filter permits exactly the Node exec. This constructor runs in
36
+ * the dynamic loader before any Node or candidate JavaScript and closes that
37
+ * one-time execveat allowance for the lifetime of the process. */
38
+ __attribute__((constructor)) static void close_exec_window(void) {
39
+ struct sock_filter filter[] = {
40
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, arch)),
41
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, DSH_AUDIT_ARCH, 1, 0),
42
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
43
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
44
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_execve, 0, 1),
45
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
46
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_execveat, 0, 1),
47
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
48
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
49
+ };
50
+ struct sock_fprog program = { .len = sizeof(filter) / sizeof(filter[0]), .filter = filter };
51
+ if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) _exit(125);
52
+ if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &program) != 0) _exit(125);
53
+ }
54
+ #elif defined(DSH_PARENT_PRELOAD_TEST)
55
+ int main(void) { return prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) == 0 ? 0 : 1; }
56
+ #elif defined(DSH_CHILD_PRELOAD_TEST)
57
+ int main(void) {
58
+ int fd = open("/bin/false", O_PATH | O_CLOEXEC);
59
+ if (fd < 0) return 2;
60
+ char *args[] = { "false", NULL }, *environment[] = { NULL };
61
+ errno = 0;
62
+ if (syscall(SYS_execveat, fd, "", args, environment, AT_EMPTY_PATH) != -1 || errno != EPERM) return 3;
63
+ errno = 0;
64
+ if (syscall(SYS_execve, "/bin/false", args, environment) != -1 || errno != EPERM) return 4;
65
+ return 0;
66
+ }
67
+ #else
68
+ #define BLOCK(number) BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, number, 0, 1), \
69
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM)
70
+ #define BLOCK_ENOSYS(number) BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, number, 0, 1), \
71
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | ENOSYS)
72
+
73
+ static int restrict_syscalls(int node_fd) {
74
+ const uint32_t writing = O_WRONLY | O_RDWR | O_CREAT | O_TRUNC | O_APPEND | (O_TMPFILE & ~O_DIRECTORY);
75
+ struct sock_filter filter[] = {
76
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, arch)),
77
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, DSH_AUDIT_ARCH, 1, 0),
78
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
79
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
80
+ BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0x40000000U),
81
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
82
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL_PROCESS),
83
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
84
+ /* The pinned Node ABI needs no syscall added after Linux 6.1. Unknown
85
+ * future numbers must not silently gain new filesystem write authority. */
86
+ BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 451, 0, 1),
87
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
88
+ BLOCK(__NR_ptrace), BLOCK(__NR_process_vm_readv), BLOCK(__NR_process_vm_writev),
89
+ BLOCK(__NR_kcmp), BLOCK(__NR_kill), BLOCK(__NR_tkill), BLOCK(__NR_tgkill),
90
+ BLOCK(__NR_rt_sigqueueinfo), BLOCK(__NR_rt_tgsigqueueinfo),
91
+ BLOCK(__NR_pidfd_open), BLOCK(__NR_pidfd_getfd), BLOCK(__NR_pidfd_send_signal),
92
+ BLOCK(__NR_prlimit64),
93
+ BLOCK(__NR_socket), BLOCK(__NR_socketpair), BLOCK(__NR_connect),
94
+ BLOCK(__NR_bind), BLOCK(__NR_listen), BLOCK(__NR_accept), BLOCK(__NR_accept4),
95
+ BLOCK(__NR_sendto), BLOCK(__NR_sendmsg), BLOCK(__NR_sendmmsg),
96
+ BLOCK(__NR_recvfrom), BLOCK(__NR_recvmsg), BLOCK(__NR_recvmmsg),
97
+ BLOCK(__NR_io_uring_setup), BLOCK(__NR_io_uring_enter), BLOCK(__NR_io_uring_register),
98
+ BLOCK(__NR_bpf), BLOCK(__NR_perf_event_open), BLOCK(__NR_userfaultfd),
99
+ BLOCK(__NR_sched_setaffinity), BLOCK(__NR_sched_setscheduler),
100
+ BLOCK(__NR_sched_setparam), BLOCK(__NR_sched_setattr), BLOCK(__NR_setpriority),
101
+ BLOCK(__NR_ioprio_set), BLOCK(__NR_process_madvise),
102
+ BLOCK_ENOSYS(__NR_clone3),
103
+ #ifdef __NR_fork
104
+ BLOCK(__NR_fork),
105
+ #endif
106
+ #ifdef __NR_vfork
107
+ BLOCK(__NR_vfork),
108
+ #endif
109
+ BLOCK(__NR_execve),
110
+ BLOCK(__NR_openat2),
111
+ #ifdef __NR_creat
112
+ BLOCK(__NR_creat),
113
+ #endif
114
+ BLOCK(__NR_truncate), BLOCK(__NR_ftruncate), BLOCK(__NR_fallocate),
115
+ BLOCK(__NR_fchmod), BLOCK(__NR_fchmodat), BLOCK(__NR_fchown), BLOCK(__NR_fchownat),
116
+ #ifdef __NR_chmod
117
+ BLOCK(__NR_chmod),
118
+ #endif
119
+ #ifdef __NR_chown
120
+ BLOCK(__NR_chown),
121
+ #endif
122
+ #ifdef __NR_lchown
123
+ BLOCK(__NR_lchown),
124
+ #endif
125
+ BLOCK(__NR_linkat), BLOCK(__NR_symlinkat), BLOCK(__NR_unlinkat), BLOCK(__NR_renameat),
126
+ #ifdef __NR_link
127
+ BLOCK(__NR_link),
128
+ #endif
129
+ #ifdef __NR_symlink
130
+ BLOCK(__NR_symlink),
131
+ #endif
132
+ #ifdef __NR_unlink
133
+ BLOCK(__NR_unlink),
134
+ #endif
135
+ #ifdef __NR_rename
136
+ BLOCK(__NR_rename),
137
+ #endif
138
+ BLOCK(__NR_renameat2), BLOCK(__NR_mkdirat), BLOCK(__NR_mknodat), BLOCK(__NR_utimensat),
139
+ #ifdef __NR_mkdir
140
+ BLOCK(__NR_mkdir),
141
+ #endif
142
+ #ifdef __NR_rmdir
143
+ BLOCK(__NR_rmdir),
144
+ #endif
145
+ #ifdef __NR_mknod
146
+ BLOCK(__NR_mknod),
147
+ #endif
148
+ #ifdef __NR_utime
149
+ BLOCK(__NR_utime),
150
+ #endif
151
+ #ifdef __NR_utimes
152
+ BLOCK(__NR_utimes),
153
+ #endif
154
+ #ifdef __NR_futimesat
155
+ BLOCK(__NR_futimesat),
156
+ #endif
157
+ BLOCK(__NR_mount), BLOCK(__NR_umount2),
158
+ BLOCK(__NR_pivot_root), BLOCK(__NR_setns), BLOCK(__NR_unshare),
159
+ BLOCK(__NR_open_tree), BLOCK(__NR_move_mount), BLOCK(__NR_fsopen),
160
+ BLOCK(__NR_fsconfig), BLOCK(__NR_fsmount), BLOCK(__NR_fspick),
161
+ BLOCK(__NR_setxattr), BLOCK(__NR_lsetxattr), BLOCK(__NR_fsetxattr),
162
+ BLOCK(__NR_removexattr), BLOCK(__NR_lremovexattr), BLOCK(__NR_fremovexattr),
163
+ /* libuv must set inherited pipe descriptors nonblocking. No other ioctl
164
+ * command, including terminal signalling controls, is available. */
165
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_ioctl, 0, 3),
166
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
167
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, FIONBIO, 1, 0),
168
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
169
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
170
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_fcntl, 0, 11),
171
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
172
+ BLOCK(F_SETOWN), BLOCK(F_SETSIG), BLOCK(F_SETOWN_EX),
173
+ BLOCK(F_SETLEASE), BLOCK(F_NOTIFY),
174
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
175
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_clone, 0, 4),
176
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
177
+ BPF_STMT(BPF_ALU | BPF_AND | BPF_K, CLONE_THREAD),
178
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, CLONE_THREAD, 1, 0),
179
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
180
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
181
+ #ifdef __NR_open
182
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_open, 0, 4),
183
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[1])),
184
+ BPF_STMT(BPF_ALU | BPF_AND | BPF_K, writing),
185
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
186
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
187
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
188
+ #endif
189
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_openat, 0, 4),
190
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[2])),
191
+ BPF_STMT(BPF_ALU | BPF_AND | BPF_K, writing),
192
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, 1, 0),
193
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
194
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
195
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_execveat, 0, 7),
196
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[0])),
197
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, (uint32_t) node_fd, 0, 4),
198
+ BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, args[4])),
199
+ BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AT_EMPTY_PATH, 1, 0),
200
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
201
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
202
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
203
+ BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
204
+ };
205
+ struct sock_fprog program = { .len = sizeof(filter) / sizeof(filter[0]), .filter = filter };
206
+ if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) return -1;
207
+ return prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &program);
208
+ }
209
+
210
+ #ifdef DSH_LAUNCHER_TEST
211
+ int main(void) {
212
+ int node_fd = open(DSH_NODE_PATH, O_PATH | O_CLOEXEC);
213
+ if (node_fd < 0 || restrict_syscalls(node_fd) != 0) return 2;
214
+ errno = 0;
215
+ if (syscall(SYS_socket, AF_INET, SOCK_STREAM, 0) != -1 || errno != EPERM) return 3;
216
+ errno = 0;
217
+ if (openat(AT_FDCWD, "/tmp/dsh-verifier-probe", O_CREAT | O_WRONLY, 0600) != -1 || errno != EPERM) return 4;
218
+ errno = 0;
219
+ if (syscall(SYS_execve, "/bin/false", NULL, NULL) != -1 || errno != EPERM) return 5;
220
+ int fd = open("/etc/passwd", O_RDONLY | O_CLOEXEC);
221
+ if (fd < 0) return 6;
222
+ close(fd);
223
+ return 0;
224
+ }
225
+ #else
226
+ int main(int argc, char **argv) {
227
+ (void)argv;
228
+ if (argc != 1) return 125;
229
+ int node_fd = open(DSH_NODE_PATH, O_PATH | O_CLOEXEC);
230
+ if (node_fd < 0) return 125;
231
+ char *args[] = { "node", "--permission", "--disable-sigusr1",
232
+ "--allow-fs-read=/opt/dsh-plugin-verifier/candidate.mjs",
233
+ "--allow-fs-read=/opt/dsh-plugin-verifier/node_modules",
234
+ "--allow-fs-read=/opt/dsh-plugin-verifier/plugins/assistant-verifier/node_modules",
235
+ "--allow-fs-read=/workspace/plugin/package/lib",
236
+ "--allow-fs-read=/workspace/plugin/package/package.json",
237
+ "--allow-fs-read=/workspace/plugin/package/node_modules",
238
+ "/opt/dsh-plugin-verifier/candidate.mjs", NULL };
239
+ char *env[] = { "PATH=/usr/bin:/bin", "LANG=C", "LC_ALL=C", "NODE_ENV=production",
240
+ "LD_PRELOAD=/opt/dsh-plugin-verifier/child-protect.so", NULL };
241
+ if (restrict_syscalls(node_fd) != 0) return 125;
242
+ syscall(SYS_execveat, node_fd, "", args, env, AT_EMPTY_PATH);
243
+ return 125;
244
+ }
245
+ #endif
246
+ #endif