diff --git a/testcases/kernel/syscalls/chmod/.gitignore b/testcases/kernel/syscalls/chmod/.gitignore index 4e856df4372..170141f80b6 100644 --- a/testcases/kernel/syscalls/chmod/.gitignore +++ b/testcases/kernel/syscalls/chmod/.gitignore @@ -5,3 +5,4 @@ /chmod05 /chmod06 /chmod07 +/chmod08 diff --git a/testcases/kernel/syscalls/chmod/chmod08.c b/testcases/kernel/syscalls/chmod/chmod08.c new file mode 100644 index 00000000000..e3590b71f6a --- /dev/null +++ b/testcases/kernel/syscalls/chmod/chmod08.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2020 Invisible Things Lab + * Michał Kowalczyk + */ + +/* + * DESCRIPTION + * Changes file access permissions using `chmod` with bits outside of 07777 in + * `mode` set and verifies if they were ignored. + * + * WARNING + * The fact that these bits are ignored is not documented (at the time of + * writing). Failure of this test doesn't necessarily mean that a regression + * in Linux was introduced, its intention is to catch accidental interface + * changes and warn kernel developers if that happens. + */ + +#include +#include +#include +#include + +#include "tst_test.h" + +#define OPEN_MODE 0644 +#define CHMOD_MODE (0777 | ~07777) +#define TESTFILE "testfile" + +static void test_chmod(void) +{ + struct stat stat_buf; + + TEST(chmod(TESTFILE, CHMOD_MODE)); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "chmod(%s, %#o) failed", TESTFILE, CHMOD_MODE); + return; + } + + SAFE_STAT(TESTFILE, &stat_buf); + + mode_t expected = S_IFREG | (CHMOD_MODE & 07777); + if (stat_buf.st_mode != expected) { + tst_res(TFAIL, "%s: Incorrect mode 0%04o, expected 0%04o", + TESTFILE, stat_buf.st_mode, expected); + return; + } + tst_res(TPASS, "Unknown mode bits were ignored as expected"); +} + +static void setup(void) +{ + int fd; + + fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, OPEN_MODE); + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .setup = setup, + .test_all = test_chmod, +}; diff --git a/testcases/kernel/syscalls/chown/chown02.c b/testcases/kernel/syscalls/chown/chown02.c index a459f092b2c..4afbfcb6554 100644 --- a/testcases/kernel/syscalls/chown/chown02.c +++ b/testcases/kernel/syscalls/chown/chown02.c @@ -81,10 +81,10 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) -#define NEW_PERMS1 (S_IFREG|S_IRWXU|S_IRWXG|S_ISUID|S_ISGID) -#define NEW_PERMS2 (S_IFREG|S_IRWXU|S_ISGID) -#define EXP_PERMS (S_IFREG|S_IRWXU|S_IRWXG) +#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) +#define NEW_PERMS1 (S_IRWXU|S_IRWXG|S_ISUID|S_ISGID) +#define NEW_PERMS2 (S_IRWXU|S_ISGID) +#define EXP_PERMS (S_IRWXU|S_IRWXG) #define TESTFILE1 "testfile1" #define TESTFILE2 "testfile2" diff --git a/testcases/kernel/syscalls/chown/chown03.c b/testcases/kernel/syscalls/chown/chown03.c index 2c7bcfe7d8c..5a4eef4c514 100644 --- a/testcases/kernel/syscalls/chown/chown03.c +++ b/testcases/kernel/syscalls/chown/chown03.c @@ -84,8 +84,8 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) -#define NEW_PERMS (S_IFREG|S_IRWXU|S_IRWXG|S_ISUID|S_ISGID) +#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) +#define NEW_PERMS (S_IRWXU|S_IRWXG|S_ISUID|S_ISGID) #define TESTFILE "testfile" TCID_DEFINE(chown03); diff --git a/testcases/kernel/syscalls/chown/chown05.c b/testcases/kernel/syscalls/chown/chown05.c index 840558c08a3..02faefb31d2 100644 --- a/testcases/kernel/syscalls/chown/chown05.c +++ b/testcases/kernel/syscalls/chown/chown05.c @@ -79,7 +79,7 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) +#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) #define TESTFILE "testfile" TCID_DEFINE(chown05); diff --git a/testcases/kernel/syscalls/fchown/fchown02.c b/testcases/kernel/syscalls/fchown/fchown02.c index 0fef74dee6c..2395eb8dc0b 100644 --- a/testcases/kernel/syscalls/fchown/fchown02.c +++ b/testcases/kernel/syscalls/fchown/fchown02.c @@ -39,10 +39,10 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH -#define NEW_PERMS1 S_IFREG | S_IRWXU | S_IRWXG | S_ISUID | S_ISGID -#define NEW_PERMS2 S_IFREG | S_IRWXU | S_ISGID -#define EXP_PERMS S_IFREG | S_IRWXU | S_IRWXG +#define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH +#define NEW_PERMS1 S_IRWXU | S_IRWXG | S_ISUID | S_ISGID +#define NEW_PERMS2 S_IRWXU | S_ISGID +#define EXP_PERMS S_IRWXU | S_IRWXG #define TESTFILE1 "testfile1" #define TESTFILE2 "testfile2" diff --git a/testcases/kernel/syscalls/fchown/fchown03.c b/testcases/kernel/syscalls/fchown/fchown03.c index f7fe994fdf8..43076458fcc 100644 --- a/testcases/kernel/syscalls/fchown/fchown03.c +++ b/testcases/kernel/syscalls/fchown/fchown03.c @@ -42,8 +42,8 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE (mode_t)(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) -#define NEW_PERMS (mode_t)(S_IFREG | S_IRWXU | S_IRWXG | S_ISUID | S_ISGID) +#define FILE_MODE (mode_t)(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) +#define NEW_PERMS (mode_t)(S_IRWXU | S_IRWXG | S_ISUID | S_ISGID) #define FCHOWN_PERMS (mode_t)(NEW_PERMS & ~(S_ISUID | S_ISGID)) #define TESTFILE "testfile" diff --git a/testcases/kernel/syscalls/fchown/fchown05.c b/testcases/kernel/syscalls/fchown/fchown05.c index 1897a2e831f..e9234aba782 100644 --- a/testcases/kernel/syscalls/fchown/fchown05.c +++ b/testcases/kernel/syscalls/fchown/fchown05.c @@ -35,7 +35,7 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH +#define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH #define TESTFILE "testfile" TCID_DEFINE(fchown05); diff --git a/testcases/kernel/syscalls/lchown/lchown01.c b/testcases/kernel/syscalls/lchown/lchown01.c index 89c85e98774..c083392b95d 100644 --- a/testcases/kernel/syscalls/lchown/lchown01.c +++ b/testcases/kernel/syscalls/lchown/lchown01.c @@ -43,7 +43,7 @@ #include "safe_macros.h" #include "compat_16.h" -#define FILE_MODE (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) +#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) #define TESTFILE "testfile" #define SFILE "slink_file" diff --git a/testcases/kernel/syscalls/open/.gitignore b/testcases/kernel/syscalls/open/.gitignore index 4309e3a72f4..186eb820970 100644 --- a/testcases/kernel/syscalls/open/.gitignore +++ b/testcases/kernel/syscalls/open/.gitignore @@ -13,3 +13,4 @@ /open12_child /open13 /open14 +/open15 diff --git a/testcases/kernel/syscalls/open/open15.c b/testcases/kernel/syscalls/open/open15.c new file mode 100644 index 00000000000..2e7cb44d662 --- /dev/null +++ b/testcases/kernel/syscalls/open/open15.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2020 Invisible Things Lab + * Michał Kowalczyk + */ + +/* + * DESCRIPTION + * Creates a file using `open` with bits outside of 07777 in `mode` set and + * verifies if they were ignored. + * + * WARNING + * The fact that these bits are ignored is not documented (at the time of + * writing). Failure of this test doesn't necessarily mean that a regression + * in Linux was introduced, its intention is to catch accidental interface + * changes and warn kernel developers if that happens. + */ + +#include +#include +#include + +#include "tst_test.h" + +#define TEST_FILE "testfile" + +static struct tcase { + char *filename; + int flags; + mode_t mode; +} tcases[] = { + {TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777}, + {TEST_FILE, 0, ~07777}, +}; + +static void verify_open(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + TEST(open(tc->filename, tc->flags, tc->mode)); + int fd = TST_RET; + if (fd == -1) { + tst_res(TFAIL | TTERRNO, "Cannot open the file"); + return; + } + tst_res(TPASS, "Unknown mode bits were ignored as expected"); + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .test = verify_open, +}; diff --git a/testcases/kernel/syscalls/openat/.gitignore b/testcases/kernel/syscalls/openat/.gitignore index 2928dae2265..2d15872ab9f 100644 --- a/testcases/kernel/syscalls/openat/.gitignore +++ b/testcases/kernel/syscalls/openat/.gitignore @@ -2,3 +2,4 @@ /openat02 /openat02_child /openat03 +/openat04 diff --git a/testcases/kernel/syscalls/openat/openat04.c b/testcases/kernel/syscalls/openat/openat04.c new file mode 100644 index 00000000000..4bb23c454d8 --- /dev/null +++ b/testcases/kernel/syscalls/openat/openat04.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2020 Invisible Things Lab + * Michał Kowalczyk + */ + +/* + * DESCRIPTION + * Creates a file using `openat` with bits outside of 07777 in `mode` set and + * verifies if they were ignored. + * + * WARNING + * The fact that these bits are ignored is not documented (at the time of + * writing). Failure of this test doesn't necessarily mean that a regression + * in Linux was introduced, its intention is to catch accidental interface + * changes and warn kernel developers if that happens. + */ + +#include +#include +#include + +#include "tst_test.h" + +#define TEST_FILE "testfile" + +static struct tcase { + char *filename; + int flags; + mode_t mode; +} tcases[] = { + {TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777}, + {TEST_FILE, 0, ~07777}, +}; + +static void verify_open(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + + TEST(openat(AT_FDCWD, tc->filename, tc->flags, tc->mode)); + int fd = TST_RET; + if (fd == -1) { + tst_res(TFAIL | TTERRNO, "Cannot open the file"); + return; + } + tst_res(TPASS, "Unknown mode bits were ignored as expected"); + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .test = verify_open, +}; diff --git a/testcases/kernel/syscalls/openat2/.gitignore b/testcases/kernel/syscalls/openat2/.gitignore index 5a0843a8522..490efd4e968 100644 --- a/testcases/kernel/syscalls/openat2/.gitignore +++ b/testcases/kernel/syscalls/openat2/.gitignore @@ -1,3 +1,4 @@ -openat201 -openat202 -openat203 +/openat201 +/openat202 +/openat203 +/openat204 diff --git a/testcases/kernel/syscalls/openat2/openat204.c b/testcases/kernel/syscalls/openat2/openat204.c new file mode 100644 index 00000000000..b5cffa6bd35 --- /dev/null +++ b/testcases/kernel/syscalls/openat2/openat204.c @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2020 Invisible Things Lab + * Michał Kowalczyk + */ + +/* + * DESCRIPTION + * Creates a file using `openat2` with bits outside of 07777 in `mode` set and + * verifies if they were ignored. + * + * WARNING + * The fact that these bits are ignored is not documented (at the time of + * writing). Failure of this test doesn't necessarily mean that a regression + * in Linux was introduced, its intention is to catch accidental interface + * changes and warn kernel developers if that happens. + */ + +#include +#include +#include + +#include "tst_test.h" +#include "lapi/openat2.h" + +#define TEST_FILE "testfile" + +static struct tcase { + char *filename; + uint64_t flags; + uint64_t mode; + uint64_t resolve; +} tcases[] = { + {TEST_FILE, O_RDWR | O_CREAT, 0644 | ~07777, 0}, + {TEST_FILE, 0, ~07777, 0}, +}; + +static void verify_open(unsigned int n) +{ + struct tcase *tc = &tcases[n]; + struct open_how how = { + .flags = tc->flags, + .mode = tc->mode, + .resolve = tc->resolve, + }; + + TEST(openat2(AT_FDCWD, tc->filename, &how, sizeof(how))); + int fd = TST_RET; + if (fd == -1) { + tst_res(TFAIL | TTERRNO, "Cannot open the file"); + return; + } + tst_res(TPASS, "Unknown mode bits were ignored as expected"); + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .tcnt = ARRAY_SIZE(tcases), + .needs_tmpdir = 1, + .test = verify_open, +};