Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Mar 2021 22:23:11 GMT
From:      Alex Richardson <arichardson@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: c4a6d3b183af - stable/13 - capsicum-test: Update for O_BENEATH removal
Message-ID:  <202103172223.12HMNBng046070@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by arichardson:

URL: https://cgit.FreeBSD.org/src/commit/?id=c4a6d3b183af4f34ddd7637eeb8e2ad2008f914c

commit c4a6d3b183af4f34ddd7637eeb8e2ad2008f914c
Author:     Alex Richardson <arichardson@FreeBSD.org>
AuthorDate: 2021-03-12 17:12:10 +0000
Commit:     Alex Richardson <arichardson@FreeBSD.org>
CommitDate: 2021-03-17 22:22:50 +0000

    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
    
    (cherry picked from commit 8cf5812af4b7f4933983822ff8e1e9185818fbef)
---
 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202103172223.12HMNBng046070>