]> git.baikalelectronics.ru Git - kernel.git/commit
selftests: add openat2(2) selftests
authorAleksa Sarai <cyphar@cyphar.com>
Sat, 18 Jan 2020 12:08:00 +0000 (23:08 +1100)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 18 Jan 2020 14:19:18 +0000 (09:19 -0500)
commite46b21ed3beb0318cce6c82914565b19ab19dc40
tree418470992a734633f506e8a04e32db89b72c7dd7
parent9e0343670d65e928746009ea32a2649e70c3bc57
selftests: add openat2(2) selftests

Test all of the various openat2(2) flags. A small stress-test of a
symlink-rename attack is included to show that the protections against
".."-based attacks are sufficient.

The main things these self-tests are enforcing are:

  * The struct+usize ABI for openat2(2) and copy_struct_from_user() to
    ensure that upgrades will be handled gracefully (in addition,
    ensuring that misaligned structures are also handled correctly).

  * The -EINVAL checks for openat2(2) are all correctly handled to avoid
    userspace passing unknown or conflicting flag sets (most
    importantly, ensuring that invalid flag combinations are checked).

  * All of the RESOLVE_* semantics (including errno values) are
    correctly handled with various combinations of paths and flags.

  * RESOLVE_IN_ROOT correctly protects against the symlink rename(2)
    attack that has been responsible for several CVEs (and likely will
    be responsible for several more).

Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
tools/testing/selftests/Makefile
tools/testing/selftests/openat2/.gitignore [new file with mode: 0644]
tools/testing/selftests/openat2/Makefile [new file with mode: 0644]
tools/testing/selftests/openat2/helpers.c [new file with mode: 0644]
tools/testing/selftests/openat2/helpers.h [new file with mode: 0644]
tools/testing/selftests/openat2/openat2_test.c [new file with mode: 0644]
tools/testing/selftests/openat2/rename_attack_test.c [new file with mode: 0644]
tools/testing/selftests/openat2/resolve_test.c [new file with mode: 0644]