10 Aug, 2020

1 commit

  • To build host programs, you need to add the program names to 'hostprogs'
    to use the necessary build rule, but it is not enough to build them
    because there is no dependency.

    There are two types of host programs: built as the prerequisite of
    another (e.g. gen_crc32table in lib/Makefile), or always built when
    Kbuild visits the Makefile (e.g. genksyms in scripts/genksyms/Makefile).

    The latter is typical in Makefiles under scripts/, which contains host
    programs globally used during the kernel build. To build them, you need
    to add them to both 'hostprogs' and 'always-y'.

    This commit adds hostprogs-always-y as a shorthand.

    The same applies to user programs. net/bpfilter/Makefile builds
    bpfilter_umh on demand, hence always-y is unneeded. In contrast,
    programs under samples/ are added to both 'userprogs' and 'always-y'
    so they are always built when Kbuild visits the Makefiles.

    userprogs-always-y works as a shorthand.

    Signed-off-by: Masahiro Yamada
    Acked-by: Miguel Ojeda

    Masahiro Yamada
     

17 May, 2020

1 commit

  • These userspace programs include UAPI headers exported to usr/include/.
    'make headers' always works for the target architecture (i.e. the same
    architecture as the kernel), so the sample programs should be built for
    the target as well. Kbuild now supports 'userprogs' for that.

    I also guarded the CONFIG option by 'depends on CC_CAN_LINK' because
    $(CC) may not provide libc.

    The 'ifndef CROSS_COMPILE' is no longer needed.

    BTW, the -m31 for s390 is left-over code. Commit 5a79859ae0f3 ("s390:
    remove 31 bit support") killed it.

    Signed-off-by: Masahiro Yamada
    Acked-by: Sam Ravnborg

    Masahiro Yamada
     

25 Mar, 2020

1 commit


04 Feb, 2020

1 commit

  • In old days, the "host-progs" syntax was used for specifying host
    programs. It was renamed to the current "hostprogs-y" in 2004.

    It is typically useful in scripts/Makefile because it allows Kbuild to
    selectively compile host programs based on the kernel configuration.

    This commit renames like follows:

    always -> always-y
    hostprogs-y -> hostprogs

    So, scripts/Makefile will look like this:

    always-$(CONFIG_BUILD_BIN2C) += ...
    always-$(CONFIG_KALLSYMS) += ...
    ...
    hostprogs := $(always-y) $(always-m)

    I think this makes more sense because a host program is always a host
    program, irrespective of the kernel configuration. We want to specify
    which ones to compile by CONFIG options, so always-y will be handier.

    The "always", "hostprogs-y", "hostprogs-m" will be kept for backward
    compatibility for a while.

    Signed-off-by: Masahiro Yamada

    Masahiro Yamada
     

03 Jan, 2020

1 commit

  • The sizes by which seccomp_notif and seccomp_notif_resp are allocated are
    based on the SECCOMP_GET_NOTIF_SIZES ioctl. This allows for graceful
    extension of these datastructures. If userspace zeroes out the
    datastructure based on its version, and it is lagging behind the kernel's
    version, it will end up sending trailing garbage. On the other hand,
    if it is ahead of the kernel version, it will write extra zero space,
    and potentially cause corruption.

    Signed-off-by: Sargun Dhillon
    Suggested-by: Tycho Andersen
    Link: https://lore.kernel.org/r/20191230203503.4925-1-sargun@sargun.me
    Fixes: fec7b6690541 ("samples: add an example of seccomp user trap")
    Cc: stable@vger.kernel.org
    Signed-off-by: Kees Cook

    Sargun Dhillon
     

18 May, 2019

1 commit


03 May, 2019

1 commit


08 Jan, 2019

1 commit

  • Both the .o and the actual executable need to be built with -m32 in order
    to link correctly.

    Reported-by: Ingo Molnar
    Signed-off-by: Tycho Andersen
    Reviewed-by: Kees Cook
    Cc: Borislav Petkov
    Cc: James Morris
    Cc: Linus Torvalds
    Cc: Peter Zijlstra
    Cc: Thomas Gleixner
    Fixes: fec7b6690541 ("samples: add an example of seccomp user trap")
    Link: http://lkml.kernel.org/r/20190107231631.1849-1-tycho@tycho.ws
    Signed-off-by: Ingo Molnar

    Tycho Andersen
     

12 Dec, 2018

1 commit

  • 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: Tycho Andersen
    CC: Kees Cook
    CC: Andy Lutomirski
    CC: Oleg Nesterov
    CC: Eric W. Biederman
    CC: "Serge E. Hallyn"
    CC: Christian Brauner
    CC: Tyler Hicks
    CC: Akihiro Suda
    Signed-off-by: Kees Cook

    Tycho Andersen
     

18 Jul, 2018

1 commit

  • In preparation for enabling command line LDLIBS, re-name HOST_LOADLIBES
    to KBUILD_HOSTLDLIBS as the internal use only flags. Also rename
    existing usage to HOSTLDLIBS for consistency. This should not have any
    visible effects.

    Signed-off-by: Laura Abbott
    Signed-off-by: Masahiro Yamada

    Laura Abbott
     

23 Feb, 2018

1 commit

  • 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: Michal Hocko
    Signed-off-by: Kees Cook

    Michal Hocko
     

18 Nov, 2017

1 commit


02 Nov, 2017

1 commit

  • 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
    Reviewed-by: Philippe Ombredanne
    Reviewed-by: Thomas Gleixner
    Signed-off-by: Greg Kroah-Hartman

    Greg Kroah-Hartman
     

09 Jan, 2017

1 commit

  • There were some bugs in the JNE64 and JLT64 comparision macros. This fixes
    them, improves comments, and cleans up the file while we are at it.

    Reported-by: Stephen Röttger
    Signed-off-by: Mathias Svensson
    Signed-off-by: Kees Cook
    Cc: stable@vger.kernel.org
    Signed-off-by: James Morris

    Mathias Svensson
     

01 Nov, 2016

3 commits


08 Jul, 2016

1 commit

  • 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: Olof Johansson
    Signed-off-by: Kees Cook

    Olof Johansson
     

18 Feb, 2015

1 commit

  • Fixes a potential corruption with uninitialized stack memory in the
    seccomp BPF sample program.

    [akpm@linux-foundation.org: coding-style fixlet]
    Signed-off-by: Kees Cook
    Reported-by: Robert Swiecki
    Tested-by: Robert Swiecki
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Kees Cook
     

04 Apr, 2014

1 commit

  • 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: Markos Chandras
    Reported-by: Paul Gortmaker
    Cc: Ralf Baechle
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Markos Chandras
     

05 Feb, 2013

1 commit

  • 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: Arnd Bergmann
    Acked-by: Kees Cook
    Cc: Heiko Carstens
    Cc: James Morris
    Acked-by: Will Drewry
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Arnd Bergmann
     

12 Sep, 2012

1 commit

  • On s390 the flag to force 31 builds is -m31 instead of -m32 unlike
    on all (?) other architectures.

    Fixes this compile error:

    HOSTCC samples/seccomp/bpf-direct.o
    cc1: error: unrecognized command line option "-m32"
    make[2]: *** [samples/seccomp/bpf-direct.o] Error 1

    Signed-off-by: Heiko Carstens
    Acked-by: Kees Cook
    Signed-off-by: James Morris

    Heiko Carstens
     

03 Aug, 2012

1 commit

  • The LO_ARG define needs to consider endianness also for 32 bit builds.

    The "bpf_fancy" test case didn't work on s390 in 32 bit and compat mode
    because the LO_ARG define resulted in a BPF program which read the upper
    halve of the 64 bit system call arguments instead of the lower halves.

    Signed-off-by: Heiko Carstens
    Acked-by: Kees Cook
    Signed-off-by: James Morris

    Heiko Carstens
     

28 Jun, 2012

1 commit


19 Apr, 2012

1 commit

  • This change fixes the compilation error triggered here for
    i386 allmodconfig in linux-next:
    http://kisskb.ellerman.id.au/kisskb/buildresult/6123842/

    Logic attempting to predict the host architecture has been
    removed from the Makefile. Instead, the bpf-direct sample
    should now compile on any architecture, but if the architecture
    is not supported, it will compile a minimal main() function.

    This change also ensures the samples are not compiled when
    there is no seccomp filter support.

    (Note, I wasn't able to reproduce the error locally, but
    the existing approach was clearly flawed. This tweak
    should resolve your issue and avoid other future weirdness.)

    Reported-by: Paul Gortmaker
    Suggested-by: Kees Cook
    Signed-off-by: Will Drewry
    Signed-off-by: James Morris

    Will Drewry
     

14 Apr, 2012

1 commit

  • 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: Eric Paris
    Signed-off-by: Will Drewry
    Acked-by: Kees Cook

    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 88ebdda6159ffc15699f204c33feb3e431bf9bdc
    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: James Morris

    Will Drewry