1 // SPDX-License-Identifier: GPL-2.0
2 #define _GNU_SOURCE
3 #define __SANE_USERSPACE_TYPES__
4
5 #include <fcntl.h>
6 #include <stdio.h>
7 #include <sys/stat.h>
8
9 #include "../kselftest_harness.h"
10 #include "wrappers.h"
11
TEST(anon_inode_no_chown)12 TEST(anon_inode_no_chown)
13 {
14 int fd_context;
15
16 fd_context = sys_fsopen("tmpfs", 0);
17 ASSERT_GE(fd_context, 0);
18
19 ASSERT_LT(fchown(fd_context, 1234, 5678), 0);
20 ASSERT_EQ(errno, EOPNOTSUPP);
21
22 EXPECT_EQ(close(fd_context), 0);
23 }
24
TEST(anon_inode_no_chmod)25 TEST(anon_inode_no_chmod)
26 {
27 int fd_context;
28
29 fd_context = sys_fsopen("tmpfs", 0);
30 ASSERT_GE(fd_context, 0);
31
32 ASSERT_LT(fchmod(fd_context, 0777), 0);
33 ASSERT_EQ(errno, EOPNOTSUPP);
34
35 EXPECT_EQ(close(fd_context), 0);
36 }
37
TEST(anon_inode_no_exec)38 TEST(anon_inode_no_exec)
39 {
40 int fd_context;
41
42 fd_context = sys_fsopen("tmpfs", 0);
43 ASSERT_GE(fd_context, 0);
44
45 ASSERT_LT(execveat(fd_context, "", NULL, NULL, AT_EMPTY_PATH), 0);
46 ASSERT_EQ(errno, EACCES);
47
48 EXPECT_EQ(close(fd_context), 0);
49 }
50
TEST(anon_inode_no_open)51 TEST(anon_inode_no_open)
52 {
53 int fd_context;
54
55 fd_context = sys_fsopen("tmpfs", 0);
56 ASSERT_GE(fd_context, 0);
57
58 ASSERT_GE(dup2(fd_context, 500), 0);
59 ASSERT_EQ(close(fd_context), 0);
60 fd_context = 500;
61
62 ASSERT_LT(open("/proc/self/fd/500", 0), 0);
63 ASSERT_EQ(errno, ENXIO);
64
65 EXPECT_EQ(close(fd_context), 0);
66 }
67
68 TEST_HARNESS_MAIN
69
70