2 * Check decoding of fsmount syscall.
4 * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
7 * SPDX-License-Identifier: GPL-2.0-or-later
20 static const char *errstr;
23 k_fsmount(const unsigned int fs_fd,
24 const unsigned int flags,
25 const unsigned int attr_flags)
27 const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
28 const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
29 const kernel_ulong_t arg1 = fill | fs_fd;
30 const kernel_ulong_t arg2 = fill | flags;
31 const kernel_ulong_t arg3 = fill | attr_flags;
32 const long rc = syscall(__NR_fsmount,
33 arg1, arg2, arg3, bad, bad, bad);
34 errstr = sprintrc(rc);
41 skip_if_unavailable("/proc/self/fd/");
43 static const char path[] = "/dev/full";
44 int fd = open(path, O_WRONLY);
46 perror_msg_and_fail("open: %s", path);
53 { 1, "FSMOUNT_CLOEXEC" },
54 { 2, "0x2 /* FSMOUNT_??? */" },
55 { 0xfffffffe, "0xfffffffe /* FSMOUNT_??? */" },
56 { -1, "FSMOUNT_CLOEXEC|0xfffffffe" }
60 { 1, "MOUNT_ATTR_RDONLY" },
61 { 0x10, "MOUNT_ATTR_NOATIME" },
62 { 0xbf, "MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV"
63 "|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME"
64 "|MOUNT_ATTR_STRICTATIME|MOUNT_ATTR_NODIRATIME" },
65 { 0x40, "0x40 /* MOUNT_ATTR_??? */" },
66 { 0xffffff40, "0xffffff40 /* MOUNT_ATTR_??? */" },
67 { -1, "MOUNT_ATTR_RDONLY|MOUNT_ATTR_NOSUID|MOUNT_ATTR_NODEV"
68 "|MOUNT_ATTR_NOEXEC|MOUNT_ATTR_NOATIME"
69 "|MOUNT_ATTR_STRICTATIME|MOUNT_ATTR_NODIRATIME"
73 for (unsigned int i = 0; i < ARRAY_SIZE(flags); ++i) {
74 for (unsigned int j = 0; j < ARRAY_SIZE(attrs); ++j) {
75 k_fsmount(-1, flags[i].val, attrs[j].val);
76 printf("fsmount(-1, %s, %s) = %s\n",
77 flags[i].str, attrs[j].str, errstr);
79 k_fsmount(-100, flags[i].val, attrs[j].val);
80 printf("fsmount(-100, %s, %s) = %s\n",
81 flags[i].str, attrs[j].str, errstr);
83 k_fsmount(fd, flags[i].val, attrs[j].val);
84 printf("fsmount(%d<%s>, %s, %s) = %s\n",
85 fd, path, flags[i].str, attrs[j].str, errstr);
89 puts("+++ exited with 0 +++");
95 SKIP_MAIN_UNDEFINED("__NR_fsmount")