Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/selftests/filesystems/anon_inode_test.c
50004 views
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
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
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
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
char *const empty_argv[] = {NULL};
46
char *const empty_envp[] = {NULL};
47
48
ASSERT_LT(execveat(fd_context, "", empty_argv, empty_envp, AT_EMPTY_PATH), 0);
49
ASSERT_EQ(errno, EACCES);
50
51
EXPECT_EQ(close(fd_context), 0);
52
}
53
54
TEST(anon_inode_no_open)
55
{
56
int fd_context;
57
58
fd_context = sys_fsopen("tmpfs", 0);
59
ASSERT_GE(fd_context, 0);
60
61
ASSERT_GE(dup2(fd_context, 500), 0);
62
ASSERT_EQ(close(fd_context), 0);
63
fd_context = 500;
64
65
ASSERT_LT(open("/proc/self/fd/500", 0), 0);
66
ASSERT_EQ(errno, ENXIO);
67
68
EXPECT_EQ(close(fd_context), 0);
69
}
70
71
TEST_HARNESS_MAIN
72
73
74