aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani2020-12-17 11:20:55 +0100
committerPhilipp Stephani2020-12-29 14:37:51 +0100
commit202a61d09cddf420ce2f18f86aea741f086022fd (patch)
tree567adc566589c3cda9cb3b4e615e575c34f3ec1c /test
parent2334f9bfa3f54a606d1748ab86ee9fd481369d7a (diff)
downloademacs-scratch/seccomp.tar.gz
emacs-scratch/seccomp.zip
Add a helper binary to create a basic Secure Computing filter.scratch/seccomp
The binary uses the 'seccomp' helper library. The library isn't needed to load the generated Secure Computing filter. * configure.ac: Check for 'seccomp' header and library. * lib-src/seccomp-filter.c: New helper binary to generate a generic Secure Computing filter for GNU/Linux. * lib-src/Makefile.in (DONT_INSTALL): Add 'seccomp-filter' helper binary if possible. (all): Add Secure Computing filter file if possible. (seccomp-filter$(EXEEXT)): Compile helper binary. (seccomp-filter.bpf seccomp-filter.pfc): Generate filter files. * test/src/emacs-tests.el (emacs-tests/seccomp/allows-stdout) (emacs-tests/seccomp/forbids-subprocess): New unit tests. * test/Makefile.in (src/emacs-tests.log): Add dependency on the helper binary.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.in2
l---------test/src/emacs-resources/seccomp-filter.bpf1
-rw-r--r--test/src/emacs-tests.el45
3 files changed, 48 insertions, 0 deletions
diff --git a/test/Makefile.in b/test/Makefile.in
index b6cf6493e32..670bdd6c3da 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -272,6 +272,8 @@ $(test_module): $(test_module:${SO}=.c) ../src/emacs-module.h
272 $(srcdir)/../lib/timespec.c $(srcdir)/../lib/gettime.c 272 $(srcdir)/../lib/timespec.c $(srcdir)/../lib/gettime.c
273endif 273endif
274 274
275src/emacs-tests.log: ../lib-src/seccomp-filter.c
276
275## Check that there is no 'automated' subdirectory, which would 277## Check that there is no 'automated' subdirectory, which would
276## indicate an incomplete merge from an older version of Emacs where 278## indicate an incomplete merge from an older version of Emacs where
277## the tests were arranged differently. 279## the tests were arranged differently.
diff --git a/test/src/emacs-resources/seccomp-filter.bpf b/test/src/emacs-resources/seccomp-filter.bpf
new file mode 120000
index 00000000000..b3d603d0aeb
--- /dev/null
+++ b/test/src/emacs-resources/seccomp-filter.bpf
@@ -0,0 +1 @@
../../../lib-src/seccomp-filter.bpf \ No newline at end of file
diff --git a/test/src/emacs-tests.el b/test/src/emacs-tests.el
index 7618a9c6752..e9333fe9d32 100644
--- a/test/src/emacs-tests.el
+++ b/test/src/emacs-tests.el
@@ -25,7 +25,9 @@
25 25
26(require 'cl-lib) 26(require 'cl-lib)
27(require 'ert) 27(require 'ert)
28(require 'ert-x)
28(require 'rx) 29(require 'rx)
30(require 'subr-x)
29 31
30(ert-deftest emacs-tests/seccomp/absent-file () 32(ert-deftest emacs-tests/seccomp/absent-file ()
31 (skip-unless (string-match-p (rx bow "SECCOMP" eow) 33 (skip-unless (string-match-p (rx bow "SECCOMP" eow)
@@ -128,4 +130,47 @@ to `make-temp-file', which see."
128 (concat "--seccomp=" filter)) 130 (concat "--seccomp=" filter))
129 0))))) 131 0)))))
130 132
133(ert-deftest emacs-tests/seccomp/allows-stdout ()
134 (let ((emacs
135 (expand-file-name invocation-name invocation-directory))
136 (filter (ert-resource-file "seccomp-filter.bpf"))
137 (process-environment nil))
138 (skip-unless (file-executable-p emacs))
139 (skip-unless (file-readable-p filter))
140 ;; The --seccomp option is processed early, without filename
141 ;; handlers. Therefore remote or quoted filenames wouldn't work.
142 (should-not (file-remote-p filter))
143 (cl-callf file-name-unquote filter)
144 (with-temp-buffer
145 (let ((status (call-process
146 emacs nil t nil
147 "--quick" "--batch"
148 (concat "--seccomp=" filter)
149 (format "--eval=%S" '(message "Hi")))))
150 (ert-info ((format "Process output: %s" (buffer-string)))
151 (should (eql status 0)))
152 (should (equal (string-trim (buffer-string)) "Hi"))))))
153
154(ert-deftest emacs-tests/seccomp/forbids-subprocess ()
155 (let ((emacs
156 (expand-file-name invocation-name invocation-directory))
157 (filter (ert-resource-file "seccomp-filter.bpf"))
158 (process-environment nil))
159 (skip-unless (file-executable-p emacs))
160 (skip-unless (file-readable-p filter))
161 ;; The --seccomp option is processed early, without filename
162 ;; handlers. Therefore remote or quoted filenames wouldn't work.
163 (should-not (file-remote-p filter))
164 (cl-callf file-name-unquote filter)
165 (with-temp-buffer
166 (let ((status
167 (call-process
168 emacs nil t nil
169 "--quick" "--batch"
170 (concat "--seccomp=" filter)
171 (format "--eval=%S" `(call-process ,emacs nil nil nil
172 "--version")))))
173 (ert-info ((format "Process output: %s" (buffer-string)))
174 (should-not (eql status 0)))))))
175
131;;; emacs-tests.el ends here 176;;; emacs-tests.el ends here