Skip to content

Commit c784159

Browse files
committed
selftests/filesystems: add chown() test for anonymous inodes
Test that anonymous inodes cannot be chown()ed. Link: https://lore.kernel.org/[email protected] Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 1ed9528 commit c784159

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

tools/testing/selftests/filesystems/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
dnotify_test
33
devpts_pts
44
file_stressor
5+
anon_inode_test
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22

33
CFLAGS += $(KHDR_INCLUDES)
4-
TEST_GEN_PROGS := devpts_pts file_stressor
4+
TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test
55
TEST_GEN_PROGS_EXTENDED := dnotify_test
66

77
include ../lib.mk
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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 "overlayfs/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_HARNESS_MAIN
26+

0 commit comments

Comments
 (0)