From 8cf5812af4b7f4933983822ff8e1e9185818fbef Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Fri, 12 Mar 2021 17:12:10 +0000 Subject: [PATCH] capsicum-test: Update for O_BENEATH removal Update the tests to check O_RESOLVE_BENEATH instead. If this looks reasonable, I'll try to upstream this change. This keeps a compat fallback for O_BENEATH since the Linux port still has/had O_BENEATH with "no .., no absolute paths" semantics. Test Plan: `/usr/tests/sys/capsicum/capsicum-test -u 977` passes and runs the O_RESOLVE_BENEATH tests. Reviewed By: markj Differential Revision: https://reviews.freebsd.org/D29016 --- contrib/capsicum-test/openat.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/contrib/capsicum-test/openat.cc b/contrib/capsicum-test/openat.cc index 5447558cde89..e3f0c2a731f8 100644 --- a/contrib/capsicum-test/openat.cc +++ b/contrib/capsicum-test/openat.cc @@ -341,22 +341,26 @@ FORK_TEST_F(OpenatTest, InCapabilityMode) { EXPECT_OPENAT_FAIL_TRAVERSAL(sub_fd_, "/etc/passwd", O_RDONLY); } -#ifdef O_BENEATH +#if !defined(O_RESOLVE_BENEATH) && defined(O_BENEATH) +#define O_RESOLVE_BENEATH O_BENEATH +#endif + +#ifdef O_RESOLVE_BENEATH TEST_F(OpenatTest, WithFlag) { - CheckPolicing(O_BENEATH); + CheckPolicing(O_RESOLVE_BENEATH); // Check with AT_FDCWD. - EXPECT_OPEN_OK(openat(AT_FDCWD, "topfile", O_RDONLY|O_BENEATH)); - EXPECT_OPEN_OK(openat(AT_FDCWD, "subdir/bottomfile", O_RDONLY|O_BENEATH)); + EXPECT_OPEN_OK(openat(AT_FDCWD, "topfile", O_RDONLY|O_RESOLVE_BENEATH)); + EXPECT_OPEN_OK(openat(AT_FDCWD, "subdir/bottomfile", O_RDONLY|O_RESOLVE_BENEATH)); - // Can't open paths starting with "/" with O_BENEATH specified. - EXPECT_OPENAT_FAIL_TRAVERSAL(AT_FDCWD, "/etc/passwd", O_RDONLY|O_BENEATH); - EXPECT_OPENAT_FAIL_TRAVERSAL(dir_fd_, "/etc/passwd", O_RDONLY|O_BENEATH); - EXPECT_OPENAT_FAIL_TRAVERSAL(sub_fd_, "/etc/passwd", O_RDONLY|O_BENEATH); + // Can't open paths starting with "/" with O_RESOLVE_BENEATH specified. + EXPECT_OPENAT_FAIL_TRAVERSAL(AT_FDCWD, "/etc/passwd", O_RDONLY|O_RESOLVE_BENEATH); + EXPECT_OPENAT_FAIL_TRAVERSAL(dir_fd_, "/etc/passwd", O_RDONLY|O_RESOLVE_BENEATH); + EXPECT_OPENAT_FAIL_TRAVERSAL(sub_fd_, "/etc/passwd", O_RDONLY|O_RESOLVE_BENEATH); } FORK_TEST_F(OpenatTest, WithFlagInCapabilityMode) { EXPECT_OK(cap_enter()); // Enter capability mode - CheckPolicing(O_BENEATH); + CheckPolicing(O_RESOLVE_BENEATH); } #endif