Skip to content
Snippets Groups Projects
  1. Jan 08, 2019
  2. Dec 12, 2018
    • Tycho Andersen's avatar
      samples: add an example of seccomp user trap · fec7b669
      Tycho Andersen authored
      
      The idea here is just to give a demonstration of how one could safely use
      the SECCOMP_RET_USER_NOTIF feature to do mount policies. This particular
      policy is (as noted in the comment) not very interesting, but it serves to
      illustrate how one might apply a policy dodging the various TOCTOU issues.
      
      Signed-off-by: default avatarTycho Andersen <tycho@tycho.ws>
      CC: Kees Cook <keescook@chromium.org>
      CC: Andy Lutomirski <luto@amacapital.net>
      CC: Oleg Nesterov <oleg@redhat.com>
      CC: Eric W. Biederman <ebiederm@xmission.com>
      CC: "Serge E. Hallyn" <serge@hallyn.com>
      CC: Christian Brauner <christian@brauner.io>
      CC: Tyler Hicks <tyhicks@canonical.com>
      CC: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      fec7b669
  3. Jul 17, 2018
  4. Feb 22, 2018
    • Michal Hocko's avatar
      samples/seccomp: do not compile when cross compiled · 6275ecbc
      Michal Hocko authored
      
      samples/seccomp relies on the host setting which is not suitable for
      crosscompilation and it actually fails when crosscompiling s390 and
      powerpc all{yes,mod}config on x86_64 with
      
      samples/seccomp/bpf-helper.h:135:2: error: #error __BITS_PER_LONG value unusable.
       #error __BITS_PER_LONG value unusable.
        ^
      In file included from samples/seccomp/bpf-fancy.c:13:0:
      samples/seccomp/bpf-fancy.c: In function ‘main’:
      samples/seccomp/bpf-fancy.c:38:11: error: ‘__NR_exit’ undeclared (first use in this function)
         SYSCALL(__NR_exit, ALLOW),
      
      and many others. I am doing these for compile testing and it's been
      quite useful to catch issues. Crosscompiling sample code on the other
      hand doesn't seem all that important so it seems like the easiest way to
      simply disable samples/seccomp when crosscompiling.
      
      Fixing this properly is not that easy as Kees explains:
      : IIRC, one of the problems is with build ordering problems: the kernel
      : headers used by the samples aren't available when cross compiling.
      
      Signed-off-by: default avatarMichal Hocko <mhocko@suse.com>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      6275ecbc
  5. Nov 18, 2017
  6. Nov 02, 2017
    • Greg Kroah-Hartman's avatar
      License cleanup: add SPDX GPL-2.0 license identifier to files with no license · b2441318
      Greg Kroah-Hartman authored
      
      Many source files in the tree are missing licensing information, which
      makes it harder for compliance tools to determine the correct license.
      
      By default all files without license information are under the default
      license of the kernel, which is GPL version 2.
      
      Update the files which contain no license information with the 'GPL-2.0'
      SPDX license identifier.  The SPDX identifier is a legally binding
      shorthand, which can be used instead of the full boiler plate text.
      
      This patch is based on work done by Thomas Gleixner and Kate Stewart and
      Philippe Ombredanne.
      
      How this work was done:
      
      Patches were generated and checked against linux-4.14-rc6 for a subset of
      the use cases:
       - file had no licensing information it it.
       - file was a */uapi/* one with no licensing information in it,
       - file was a */uapi/* one with existing licensing information,
      
      Further patches will be generated in subsequent months to fix up cases
      where non-standard license headers were used, and references to license
      had to be inferred by heuristics based on keywords.
      
      The analysis to determine which SPDX License Identifier to be applied to
      a file was done in a spreadsheet of side by side results from of the
      output of two independent scanners (ScanCode & Windriver) producing SPDX
      tag:value files created by Philippe Ombredanne.  Philippe prepared the
      base worksheet, and did an initial spot review of a few 1000 files.
      
      The 4.13 kernel was the starting point of the analysis with 60,537 files
      assessed.  Kate Stewart did a file by file comparison of the scanner
      results in the spreadsheet to determine which SPDX license identifier(s)
      to be applied to the file. She confirmed any determination that was not
      immediately clear with lawyers working with the Linux Foundation.
      
      Criteria used to select files for SPDX license identifier tagging was:
       - Files considered eligible had to be source code files.
       - Make and config files were included as candidates if they contained >5
         lines of source
       - File already had some variant of a license header in it (even if <5
         lines).
      
      All documentation files were explicitly excluded.
      
      The following heuristics were used to determine which SPDX license
      identifiers to apply.
      
       - when both scanners couldn't find any license traces, file was
         considered to have no license information in it, and the top level
         COPYING file license applied.
      
         For non */uapi/* files that summary was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0                                              11139
      
         and resulted in the first patch in this series.
      
         If that file was a */uapi/* path one, it was "GPL-2.0 WITH
         Linux-syscall-note" otherwise it was "GPL-2.0".  Results of that was:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|-------
         GPL-2.0 WITH Linux-syscall-note                        930
      
         and resulted in the second patch in this series.
      
       - if a file had some form of licensing information in it, and was one
         of the */uapi/* ones, it was denoted with the Linux-syscall-note if
         any GPL family license was found in the file or had no licensing in
         it (per prior point).  Results summary:
      
         SPDX license identifier                            # files
         ---------------------------------------------------|------
         GPL-2.0 WITH Linux-syscall-note                       270
         GPL-2.0+ WITH Linux-syscall-note                      169
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause)    21
         ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)    17
         LGPL-2.1+ WITH Linux-syscall-note                      15
         GPL-1.0+ WITH Linux-syscall-note                       14
         ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause)    5
         LGPL-2.0+ WITH Linux-syscall-note                       4
         LGPL-2.1 WITH Linux-syscall-note                        3
         ((GPL-2.0 WITH Linux-syscall-note) OR MIT)              3
         ((GPL-2.0 WITH Linux-syscall-note) AND MIT)             1
      
         and that resulted in the third patch in this series.
      
       - when the two scanners agreed on the detected license(s), that became
         the concluded license(s).
      
       - when there was disagreement between the two scanners (one detected a
         license but the other didn't, or they both detected different
         licenses) a manual inspection of the file occurred.
      
       - In most cases a manual inspection of the information in the file
         resulted in a clear resolution of the license that should apply (and
         which scanner probably needed to revisit its heuristics).
      
       - When it was not immediately clear, the license identifier was
         confirmed with lawyers working with the Linux Foundation.
      
       - If there was any question as to the appropriate license identifier,
         the file was flagged for further research and to be revisited later
         in time.
      
      In total, over 70 hours of logged manual review was done on the
      spreadsheet to determine the SPDX license identifiers to apply to the
      source files by Kate, Philippe, Thomas and, in some cases, confirmation
      by lawyers working with the Linux Foundation.
      
      Kate also obtained a third independent scan of the 4.13 code base from
      FOSSology, and compared selected files where the other two scanners
      disagreed against that SPDX file, to see if there was new insights.  The
      Windriver scanner is based on an older version of FOSSology in part, so
      they are related.
      
      Thomas did random spot checks in about 500 files from the spreadsheets
      for the uapi headers and agreed with SPDX license identifier in the
      files he inspected. For the non-uapi files Thomas did random spot checks
      in about 15000 files.
      
      In initial set of patches against 4.14-rc6, 3 files were found to have
      copy/paste license identifier errors, and have been fixed to reflect the
      correct identifier.
      
      Additionally Philippe spent 10 hours this week doing a detailed manual
      inspection and review of the 12,461 patched files from the initial patch
      version early this week with:
       - a full scancode scan run, collecting the matched texts, detected
         license ids and scores
       - reviewing anything where there was a license detected (about 500+
         files) to ensure that the applied SPDX license was correct
       - reviewing anything where there was no detection but the patch license
         was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
         SPDX license was correct
      
      This produced a worksheet with 20 files needing minor correction.  This
      worksheet was then exported into 3 different .csv files for the
      different types of files to be modified.
      
      These .csv files were then reviewed by Greg.  Thomas wrote a script to
      parse the csv files and add the proper SPDX tag to the file, in the
      format that the file expected.  This script was further refined by Greg
      based on the output to detect more types of files automatically and to
      distinguish between header and source .c files (which need different
      comment types.)  Finally Greg ran the script using the .csv files to
      generate the patches.
      
      Reviewed-by: default avatarKate Stewart <kstewart@linuxfoundation.org>
      Reviewed-by: default avatarPhilippe Ombredanne <pombredanne@nexb.com>
      Reviewed-by: default avatarThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b2441318
  7. Aug 17, 2017
  8. Aug 14, 2017
  9. Jan 09, 2017
  10. Nov 01, 2016
  11. Jul 07, 2016
    • Olof Johansson's avatar
      samples/seccomp: Add standalone config option · f6041c1d
      Olof Johansson authored
      
      Add a separate Kconfig option for SAMPLES_SECCOMP.
      
      Main reason for this is that, just like other samples, it's forced to
      be a module.
      
      Without this, since the sample is a target only controlled by
      CONFIG_SECCOMP_FILTER, the samples will be built before include files are
      put in place properly. For example, from an arm64 allmodconfig built with
      "make -sk -j 32" (without specific target), the following happens:
      
        samples/seccomp/bpf-fancy.c:13:27: fatal error: linux/seccomp.h: No such file or directory
        samples/seccomp/bpf-helper.h:20:50: fatal error: linux/seccomp.h: No such file or directory
        samples/seccomp/dropper.c:20:27: fatal error: linux/seccomp.h: No such file or directory
        samples/seccomp/bpf-direct.c:21:27: fatal error: linux/seccomp.h: No such file or directory
      
      So, just stick to the same format as other samples.
      
      Signed-off-by: default avatarOlof Johansson <olof@lixom.net>
      Signed-off-by: default avatarKees Cook <keescook@chromium.org>
      f6041c1d
  12. Feb 17, 2015
  13. Apr 03, 2014
    • Markos Chandras's avatar
      samples/seccomp/Makefile: do not build tests if cross-compiling for MIPS · e9107f88
      Markos Chandras authored
      
      The Makefile is designed to use the host toolchain so it may be unsafe
      to build the tests if the kernel has been configured and built for
      another architecture.  This fixes a build problem when the kernel has
      been configured and built for the MIPS architecture but the host is not
      MIPS (cross-compiled).  The MIPS syscalls are only defined if one of the
      following is true:
      
       1) _MIPS_SIM == _MIPS_SIM_ABI64
       2) _MIPS_SIM == _MIPS_SIM_ABI32
       3) _MIPS_SIM == _MIPS_SIM_NABI32
      
      Of course, none of these make sense on a non-MIPS toolchain and the
      following build problem occurs when building on a non-MIPS host.
      
        linux/usr/include/linux/kexec.h:50: userspace cannot reference function or variable defined in the kernel
        samples/seccomp/bpf-direct.c: In function `emulator':
        samples/seccomp/bpf-direct.c:76:17: error: `__NR_write' undeclared (first use in this function)
      
      Signed-off-by: default avatarMarkos Chandras <markos.chandras@imgtec.com>
      Reported-by: default avatarPaul Gortmaker <paul.gortmaker@windriver.com>
      Cc: Ralf Baechle <ralf@linux-mips.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      e9107f88
  14. Feb 05, 2013
    • Arnd Bergmann's avatar
      samples/seccomp: be less stupid about cross compiling · 275aaa68
      Arnd Bergmann authored
      
      The seccomp filters are currently built for the build host, not for the
      machine that they are going to run on, but they are also built for with
      the -m32 flag if the kernel is built for a 32 bit machine, both of which
      seems rather odd.
      
      It broke allyesconfig on my machine, which is x86-64, but building for
      32 bit ARM, with this error message:
      
        In file included from /usr/include/stdio.h:28:0,
                         from samples/seccomp/bpf-fancy.c:15:
        /usr/include/features.h:324:26: fatal error: bits/predefs.h: No such file or directory
      
      because there are no 32 bit libc headers installed on this machine.  We
      should really be building all the samples for the target machine rather
      than the build host, but since the infrastructure for that appears to be
      missing right now, let's be a little bit smarter and not pass the '-m32'
      flag to the HOSTCC when cross- compiling.
      
      Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
      Cc: James Morris <james.l.morris@oracle.com>
      Acked-by: default avatarWill Drewry <wad@chromium.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
      275aaa68
  15. Sep 12, 2012
  16. Aug 03, 2012
  17. Jun 28, 2012
  18. Apr 19, 2012
  19. Apr 14, 2012
    • Will Drewry's avatar
      Documentation: prctl/seccomp_filter · 8ac270d1
      Will Drewry authored
      
      Documents how system call filtering using Berkeley Packet
      Filter programs works and how it may be used.
      Includes an example for x86 and a semi-generic
      example using a macro-based code generator.
      
      Acked-by: default avatarEric Paris <eparis@redhat.com>
      Signed-off-by: default avatarWill Drewry <wad@chromium.org>
      Acked-by: default avatarKees Cook <keescook@chromium.org>
      
      v18: - added acked by
           - update no new privs numbers
      v17: - remove @compat note and add Pitfalls section for arch checking
             (keescook@chromium.org)
      v16: -
      v15: -
      v14: - rebase/nochanges
      v13: - rebase on to 88ebdda6
      v12: - comment on the ptrace_event use
           - update arch support comment
           - note the behavior of SECCOMP_RET_DATA when there are multiple filters
             (keescook@chromium.org)
           - lots of samples/ clean up incl 64-bit bpf-direct support
             (markus@chromium.org)
           - rebase to linux-next
      v11: - overhaul return value language, updates (keescook@chromium.org)
           - comment on do_exit(SIGSYS)
      v10: - update for SIGSYS
           - update for new seccomp_data layout
           - update for ptrace option use
      v9: - updated bpf-direct.c for SIGILL
      v8: - add PR_SET_NO_NEW_PRIVS to the samples.
      v7: - updated for all the new stuff in v7: TRAP, TRACE
          - only talk about PR_SET_SECCOMP now
          - fixed bad JLE32 check (coreyb@linux.vnet.ibm.com)
          - adds dropper.c: a simple system call disabler
      v6: - tweak the language to note the requirement of
            PR_SET_NO_NEW_PRIVS being called prior to use. (luto@mit.edu)
      v5: - update sample to use system call arguments
          - adds a "fancy" example using a macro-based generator
          - cleaned up bpf in the sample
          - update docs to mention arguments
          - fix prctl value (eparis@redhat.com)
          - language cleanup (rdunlap@xenotime.net)
      v4: - update for no_new_privs use
          - minor tweaks
      v3: - call out BPF <-> Berkeley Packet Filter (rdunlap@xenotime.net)
          - document use of tentative always-unprivileged
          - guard sample compilation for i386 and x86_64
      v2: - move code to samples (corbet@lwn.net)
      Signed-off-by: default avatarJames Morris <james.l.morris@oracle.com>
      8ac270d1
Loading