]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
kselftest/openat2: test for OPENAT2_REGULAR flag
authorDorjoy Chowdhury <dorjoychy111@gmail.com>
Sat, 16 May 2026 14:43:11 +0000 (16:43 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 21 May 2026 13:33:48 +0000 (15:33 +0200)
Just a happy path test.

Christian Brauner <brauner@kernel.org> says:

Update OPENAT2_REGULAR fallback define to match upper-32-bit UAPI value.
Port the test to the kselftest_harness TEST*/FIXTURE framework to match
the migrated openat2_test.c, and add a regression test ensuring
open()/openat() keep ignoring the internal __O_REGULAR carrier bit.

Signed-off-by: Dorjoy Chowdhury <dorjoychy111@gmail.com>
Link: https://patch.msgid.link/20260328172314.45807-3-dorjoychy111@gmail.com
Reviewed-by: Aleksa Sarai <aleksa@amutable.com>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
tools/testing/selftests/filesystems/openat2/openat2_test.c

index 5ea3eebb7b596dac94576693e93b29f85a5d80d6..6f5afbe2d8d3101e2e4ede33e9c09ba4a64759d0 100644 (file)
@@ -310,4 +310,53 @@ TEST_F(openat2, flag_validation)
        }
 }
 
+#ifndef OPENAT2_REGULAR
+#define OPENAT2_REGULAR ((__u64)1 << 32)
+#endif
+
+#ifndef EFTYPE
+#define EFTYPE 134
+#endif
+
+/* Kernel-internal carrier for OPENAT2_REGULAR (see __O_REGULAR in fcntl.h). */
+#ifndef __O_REGULAR
+#define __O_REGULAR (1 << 30)
+#endif
+
+/* Verify that OPENAT2_REGULAR rejects non-regular files with EFTYPE. */
+TEST_F(openat2, regular_flag)
+{
+       struct open_how how = {
+               .flags = OPENAT2_REGULAR | O_RDONLY,
+       };
+       int fd;
+
+       fd = sys_openat2(AT_FDCWD, "/dev/null", &how);
+       if (fd == -ENOENT)
+               SKIP(return, "/dev/null does not exist");
+
+       EXPECT_EQ(-EFTYPE, fd) {
+               TH_LOG("openat2 with OPENAT2_REGULAR should fail with %d (%s), got %d (%s)",
+                      -EFTYPE, strerror(EFTYPE), fd, strerror(-fd));
+       }
+       if (fd >= 0)
+               close(fd);
+}
+
+/* open()/openat() must keep ignoring the internal __O_REGULAR bit. */
+TEST(legacy_openat_ignores_o_regular)
+{
+       int fd;
+
+       fd = openat(AT_FDCWD, "/dev/null", O_RDONLY | __O_REGULAR);
+       if (fd < 0 && errno == ENOENT)
+               SKIP(return, "/dev/null does not exist");
+
+       ASSERT_GE(fd, 0) {
+               TH_LOG("legacy openat() must ignore the __O_REGULAR carrier bit, got errno %d (%s)",
+                      errno, strerror(errno));
+       }
+       close(fd);
+}
+
 TEST_HARNESS_MAIN