diff --git a/.github/workflows/build-extra.yml b/.github/workflows/build-extra.yml index c1c240922..a7b7c8a3e 100644 --- a/.github/workflows/build-extra.yml +++ b/.github/workflows/build-extra.yml @@ -5,9 +5,9 @@ on: branches: [ master ] paths-ignore: - '.github/ISSUE_TEMPLATE/*' - - 'etc/**' - - 'contrib/gtksourceview-5/**' + - 'contrib/syntax/**' - 'contrib/vim/**' + - 'etc/**' - 'src/man/*.txt' - .git-blame-ignore-revs - .github/dependabot.yml @@ -27,9 +27,9 @@ on: branches: [ master ] paths-ignore: - '.github/ISSUE_TEMPLATE/*' - - 'etc/**' - - 'contrib/gtksourceview-5/**' + - 'contrib/syntax/**' - 'contrib/vim/**' + - 'etc/**' - 'src/man/*.txt' - .git-blame-ignore-revs - .github/dependabot.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index b86d432f9..9cf216492 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -10,9 +10,9 @@ on: branches: [ master ] paths-ignore: - '.github/ISSUE_TEMPLATE/*' - - 'etc/**' - - 'contrib/gtksourceview-5/**' + - 'contrib/syntax/**' - 'contrib/vim/**' + - 'etc/**' - 'src/man/*.txt' - .git-blame-ignore-revs - .github/dependabot.yml @@ -32,9 +32,9 @@ on: branches: [ master ] paths-ignore: - '.github/ISSUE_TEMPLATE/*' - - 'etc/**' - - 'contrib/gtksourceview-5/**' + - 'contrib/syntax/**' - 'contrib/vim/**' + - 'etc/**' - 'src/man/*.txt' - .git-blame-ignore-revs - .github/dependabot.yml @@ -88,7 +88,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@a34ca99b4610d924e04c68db79e503e1f79f9f02 + uses: github/codeql-action/init@3ebbd71c74ef574dbc558c82f70e52732c8b44fe with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -99,7 +99,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@a34ca99b4610d924e04c68db79e503e1f79f9f02 + uses: github/codeql-action/autobuild@3ebbd71c74ef574dbc558c82f70e52732c8b44fe # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -113,4 +113,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@a34ca99b4610d924e04c68db79e503e1f79f9f02 + uses: github/codeql-action/analyze@3ebbd71c74ef574dbc558c82f70e52732c8b44fe diff --git a/.gitignore b/.gitignore index 7333b1c8d..db3b16893 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ config.log config.mk config.sh config.status +contrib/syntax/files/example +contrib/syntax/files/firejail-profile.lang +contrib/syntax/files/firejail.vim firejail-*.tar.xz firejail-login.5 firejail-profile.5 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9a5f19b54..97730e533 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,8 +38,7 @@ If you add a new command, here's the checklist: - [ ] Update manpages: firejail(1) and firejail-profile(5) - [ ] Update shell completions - - [ ] Update vim syntax files - - [ ] Update gtksourceview language specs + - [ ] Update syntax files (run `make syntax` or just `make`) - [ ] Update --help # Editing the wiki diff --git a/Makefile b/Makefile index 119bf6b4b..443c3183f 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,10 @@ MAN_TARGET = man MAN_SRC = src/man endif +ifneq ($(HAVE_CONTRIB_INSTALL),no) +CONTRIB_TARGET = contrib +endif + COMPLETIONDIRS = src/zsh_completion src/bash_completion APPS = src/firecfg/firecfg src/firejail/firejail src/firemon/firemon src/profstats/profstats src/jailcheck/jailcheck @@ -17,16 +21,32 @@ SBOX_APPS_NON_DUMPABLE += src/fnettrace-icmp/fnettrace-icmp MYDIRS = src/lib $(MAN_SRC) $(COMPLETIONDIRS) MYLIBS = src/libpostexecseccomp/libpostexecseccomp.so src/libtrace/libtrace.so src/libtracelog/libtracelog.so COMPLETIONS = src/zsh_completion/_firejail src/bash_completion/firejail.bash_completion -MANPAGES = firejail.1 firemon.1 firecfg.1 firejail-profile.5 firejail-login.5 firejail-users.5 jailcheck.1 SECCOMP_FILTERS = seccomp seccomp.debug seccomp.32 seccomp.block_secondary seccomp.mdwx seccomp.mdwx.32 +MANPAGES = firejail.1 firemon.1 firecfg.1 firejail-profile.5 firejail-login.5 firejail-users.5 jailcheck.1 + +SYSCALL_HEADERS := $(sort $(wildcard src/include/syscall*.h)) + +# Lists of keywords used in profiles; used for generating syntax files. +SYNTAX_LISTS = \ + contrib/syntax/lists/profile_commands_arg0.list \ + contrib/syntax/lists/profile_commands_arg1.list \ + contrib/syntax/lists/profile_conditionals.list \ + contrib/syntax/lists/profile_macros.list \ + contrib/syntax/lists/syscall_groups.list \ + contrib/syntax/lists/syscalls.list \ + contrib/syntax/lists/system_errnos.list + +SYNTAX_FILES_IN := $(sort $(wildcard contrib/syntax/files/*.in)) +SYNTAX_FILES := $(SYNTAX_FILES_IN:.in=) + ALL_ITEMS = $(APPS) $(SBOX_APPS) $(SBOX_APPS_NON_DUMPABLE) $(MYLIBS) .PHONY: all -all: all_items mydirs $(MAN_TARGET) filters +all: all_items mydirs filters $(MAN_TARGET) $(CONTRIB_TARGET) config.mk config.sh: - printf 'run ./configure to generate %s\n' "$@" >&2 - false + @printf 'error: run ./configure to generate %s\n' "$@" >&2 + @false .PHONY: all_items $(ALL_ITEMS) all_items: $(ALL_ITEMS) @@ -38,11 +58,6 @@ mydirs: $(MYDIRS) $(MYDIRS): $(MAKE) -C $@ -$(MANPAGES): src/man config.mk - ./mkman.sh $(VERSION) src/man/$(basename $@).man $@ - -man: $(MANPAGES) - filters: $(SECCOMP_FILTERS) $(SBOX_APPS_NON_DUMPABLE) seccomp: src/fseccomp/fseccomp src/fsec-optimize/fsec-optimize src/fseccomp/fseccomp default seccomp @@ -65,14 +80,83 @@ seccomp.mdwx: src/fseccomp/fseccomp seccomp.mdwx.32: src/fseccomp/fseccomp src/fseccomp/fseccomp memory-deny-write-execute.32 seccomp.mdwx.32 +$(MANPAGES): src/man config.mk + ./mkman.sh $(VERSION) src/man/$(basename $@).man $@ + +man: $(MANPAGES) + +# Makes all targets in contrib/ +.PHONY: contrib +contrib: syntax + +.PHONY: syntax +syntax: $(SYNTAX_FILES) + +# TODO: include/rlimit are false positives +contrib/syntax/lists/profile_commands_arg0.list: src/firejail/profile.c + @sed -En 's/.*strn?cmp\(ptr, "([^ "]*[^ ])".*/\1/p' $< | \ + grep -Ev '^(include|rlimit)$$' | sed 's/\./\\./' | LC_ALL=C sort -u >$@ + +# TODO: private-lib is special-cased in the code and doesn't match the regex +contrib/syntax/lists/profile_commands_arg1.list: src/firejail/profile.c + @{ sed -En 's/.*strn?cmp\(ptr, "([^"]+) ".*/\1/p' $<; echo private-lib; } | \ + LC_ALL=C sort -u >$@ + +contrib/syntax/lists/profile_conditionals.list: src/firejail/profile.c + @awk -- 'BEGIN {process=0;} /^Cond conditionals\[\] = \{$$/ {process=1;} \ + /\t*\{"[^"]+".*/ \ + { if (process) {print gensub(/^\t*\{"([^"]+)".*$$/, "\\1", 1);} } \ + /^\t\{ NULL, NULL \}$$/ {process=0;}' \ + $< | LC_ALL=C sort -u >$@ + +contrib/syntax/lists/profile_macros.list: src/firejail/macros.c + @sed -En 's/.*\$$\{([^}]+)\}.*/\1/p' $< | LC_ALL=C sort -u >$@ + +contrib/syntax/lists/syscall_groups.list: src/lib/syscall.c + @sed -En 's/.*"@([^",]+).*/\1/p' $< | LC_ALL=C sort -u >$@ + +contrib/syntax/lists/syscalls.list: $(SYSCALL_HEADERS) + @sed -n 's/{\s\+"\([^"]\+\)",.*},/\1/p' $(SYSCALL_HEADERS) | \ + LC_ALL=C sort -u >$@ + +contrib/syntax/lists/system_errnos.list: src/lib/errno.c + @sed -En 's/.*"(E[^"]+).*/\1/p' $< | LC_ALL=C sort -u >$@ + +pipe_fromlf = { tr '\n' '|' | sed 's/|$$//'; } +space_fromlf = { tr '\n' ' ' | sed 's/ $$//'; } +edit_syntax_file = sed \ + -e "s/@make_input@/$$(basename $@). Generated from $$(basename $<) by make./" \ + -e "s/@FJ_PROFILE_COMMANDS_ARG0@/$$($(pipe_fromlf) $@ + +# gtksourceview language-specs +contrib/syntax/files/%.lang: contrib/syntax/files/%.lang.in $(SYNTAX_LISTS) + @printf 'Generating %s from %s\n' $@ $< + @$(edit_syntax_file) $< >$@ + +# vim syntax files +contrib/syntax/files/%.vim: contrib/syntax/files/%.vim.in $(SYNTAX_LISTS) + @printf 'Generating %s from %s\n' $@ $< + @$(edit_syntax_file) $< >$@ + .PHONY: clean clean: for dir in $$(dirname $(ALL_ITEMS)) $(MYDIRS); do \ $(MAKE) -C $$dir clean; \ done $(MAKE) -C test clean - rm -f $(MANPAGES) $(MANPAGES:%=%.gz) firejail*.rpm rm -f $(SECCOMP_FILTERS) + rm -f $(MANPAGES) $(MANPAGES:%=%.gz) firejail*.rpm + rm -f $(SYNTAX_FILES) rm -f test/utils/index.html* rm -f test/utils/wget-log rm -f test/utils/firejail-test-file* @@ -124,10 +208,10 @@ ifeq ($(HAVE_CONTRIB_INSTALL),yes) install -m 0755 -d $(DESTDIR)$(datarootdir)/vim/vimfiles/ftdetect install -m 0755 -d $(DESTDIR)$(datarootdir)/vim/vimfiles/syntax install -m 0644 contrib/vim/ftdetect/firejail.vim $(DESTDIR)$(datarootdir)/vim/vimfiles/ftdetect - install -m 0644 contrib/vim/syntax/firejail.vim $(DESTDIR)$(datarootdir)/vim/vimfiles/syntax - # gtksourceview-5 language-specs + install -m 0644 contrib/syntax/files/firejail.vim $(DESTDIR)$(datarootdir)/vim/vimfiles/syntax + # gtksourceview language-specs install -m 0755 -d $(DESTDIR)$(datarootdir)/gtksourceview-5/language-specs - install -m 0644 contrib/gtksourceview-5/language-specs/firejail-profile.lang $(DESTDIR)$(datarootdir)/gtksourceview-5/language-specs + install -m 0644 contrib/syntax/files/firejail-profile.lang $(DESTDIR)$(datarootdir)/gtksourceview-5/language-specs endif # documents install -m 0755 -d $(DESTDIR)$(docdir) diff --git a/README b/README index 74318fa16..762668a88 100644 --- a/README +++ b/README @@ -125,6 +125,8 @@ Alexander Stein (https://github.com/ajstein) alkim0 (https://github.com/alkim0) - warn when encountering EIO during remount - Add profile for chafa +amano-kenji (https://github.com/amano-kenji) + - fix private-etc in qutebrowser profile Amin Vakil (https://github.com/aminvakil) - whois profile fix - added profile for strawberry @@ -679,6 +681,8 @@ Laurent Declercq (https://github.com/nuxwin) - fixed test for shell interpreter in chroots LaurentGH (https://github.com/LaurentGH) - allow private-bin parameters to be absolute paths +layderv (https://github.com/layderv) + - prevent sandbox name from containing only digits lecso7 (https://github.com/lecso7) - added goldendict profile - allow evince to read .cbz file format diff --git a/README.md b/README.md index f261da2a3..7d1c88c65 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ We also keep a list of profile fixes for previous released versions in [etc-fixe ### private-etc rework ````` - --private-etc, --private-etc=file,directory + --private-etc, --private-etc=file,directory,@group The files installed by --private-etc are copies of the original system files from /etc directory. By default, the command brings in a skeleton of files and directories used by most con‐ @@ -192,24 +192,23 @@ We also keep a list of profile fixes for previous released versions in [etc-fixe $ firejail --private-etc dig debian.org - For X11/GTK/QT/Gnome/KDE programs add GUI group as a parameter. - Example: + For X11/GTK/QT/Gnome/KDE programs add @x11 group as a parame‐ + ter. Example: - $ firejail --private-etc=GUI,python* gimp + $ firejail --private-etc=@x11,gcrypt,python* gimp - /etc/python* directories are not part of the generic GUI group. - These directories are reuqired by Gimp plugin system. File glob‐ - bing is supported. + gcrypt and /etc/python* directories are not part of the generic + @x11 group. File globbing is supported. - For games, add GAMES group: + For games, add @games group: - $ firejail --private-etc=GUI,GAMES warzone2100 + $ firejail --private-etc=@games,@x11 warzone2100 - Sound and networking files are included automatically, unless - --nosound or --net=none are specified. Files for encrypted - TLS/SSL protocol are in TLS-CA group. + Sound and networking files are included automatically, unless + --nosound or --net=none are specified. Files for encrypted + TLS/SSL protocol are in @tls-ca group. - $ firejail --private-etc=TLS-CA,wgetrc wget https://debian.org + $ firejail --private-etc=@tls-ca,wgetrc wget https://debian.org Note: The easiest way to extract the list of /etc files accessed by your program is using strace utility: diff --git a/RELNOTES b/RELNOTES index 478bf297d..6230fe81b 100644 --- a/RELNOTES +++ b/RELNOTES @@ -1,6 +1,7 @@ firejail (0.9.73) baseline; urgency=low * work in progress * modif: Stop forwarding own double-dash to the shell (#5599 #5600) + * modif: prevent sandbox name from containing only digits (#5578) * docs: remove apparmor options in --help when building without apparmor support (#5589) * fix: qutebrowser not opening tabs (#5601) diff --git a/contrib/syntax/files/example.in b/contrib/syntax/files/example.in new file mode 100644 index 000000000..74bcdc079 --- /dev/null +++ b/contrib/syntax/files/example.in @@ -0,0 +1,16 @@ +# @make_input@ +# Example file to check the values of input variables. + +FJ_PROFILE_COMMANDS_ARG0 = @FJ_PROFILE_COMMANDS_ARG0@ + +FJ_PROFILE_COMMANDS_ARG1 = @FJ_PROFILE_COMMANDS_ARG1@ + +FJ_PROFILE_CONDITIONALS = @FJ_PROFILE_CONDITIONALS@ + +FJ_PROFILE_MACROS = @FJ_PROFILE_MACROS@ + +FJ_SYSCALLS = @FJ_SYSCALLS@ + +FJ_SYSCALL_GROUPS = @FJ_SYSCALL_GROUPS@ + +FJ_SYSTEM_ERRNOS = @FJ_SYSTEM_ERRNOS@ diff --git a/contrib/gtksourceview-5/language-specs/firejail-profile.lang b/contrib/syntax/files/firejail-profile.lang.in similarity index 59% rename from contrib/gtksourceview-5/language-specs/firejail-profile.lang rename to contrib/syntax/files/firejail-profile.lang.in index 61c37f98f..acd5c86ce 100644 --- a/contrib/gtksourceview-5/language-specs/firejail-profile.lang +++ b/contrib/syntax/files/firejail-profile.lang.in @@ -1,4 +1,5 @@ +