This adds tests to lock specific flags in place, and verifies that the expected rules hold. Signed-off-by: Sargun Dhillon <sargun@xxxxxxxxx> --- tools/include/uapi/linux/mount.h | 1 + .../mount_setattr/mount_setattr_test.c | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tools/include/uapi/linux/mount.h b/tools/include/uapi/linux/mount.h index 4d93967f8aea..66f302019373 100644 --- a/tools/include/uapi/linux/mount.h +++ b/tools/include/uapi/linux/mount.h @@ -135,5 +135,6 @@ struct mount_attr { /* List of all mount_attr versions. */ #define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */ +#define MOUNT_ATTR_SIZE_VER1 40 #endif /* _UAPI_LINUX_MOUNT_H */ diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c b/tools/testing/selftests/mount_setattr/mount_setattr_test.c index 2aaa4aae41f5..3411fe17400b 100644 --- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c +++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c @@ -1551,4 +1551,46 @@ TEST_F(mount_setattr, mount_attr_lock) ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), 0); } +TEST_F(mount_setattr, mount_attr_do_lock) +{ + struct mount_attr attr = {}; + + attr.attr_lock = MOUNT_ATTR_NODIRATIME; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), -1); + ASSERT_EQ(errno, EINVAL); + + attr.attr_lock = MOUNT_ATTR__ATIME; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), -1); + ASSERT_EQ(errno, EINVAL); + + /* Do not allow locking unset locks */ + attr.attr_lock = MOUNT_ATTR_NOEXEC; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), -1); + ASSERT_EQ(errno, EINVAL); + + /* Set and lock at the same time */ + attr.attr_set = MOUNT_ATTR_NOEXEC; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), 0); + ASSERT_EQ(errno, EINVAL); + + memset(&attr, 0, sizeof(attr)); + /* Make sure we can't clear noexec now (that locking worked) */ + attr.attr_clr = MOUNT_ATTR_NOEXEC; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), -1); + ASSERT_EQ(errno, EPERM); + + memset(&attr, 0, sizeof(attr)); + attr.attr_set = MOUNT_ATTR_NODEV; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), 0); + + memset(&attr, 0, sizeof(attr)); + attr.attr_lock = MOUNT_ATTR_NODEV; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), 0); + + /* Make sure we can't clear MOUNT_ATTR_NODEV */ + memset(&attr, 0, sizeof(attr)); + attr.attr_clr = MOUNT_ATTR_NODEV; + ASSERT_EQ(sys_mount_setattr(-1, "/tmp/C", 0, &attr, sizeof(attr)), -1); + ASSERT_EQ(errno, EPERM); +} TEST_HARNESS_MAIN -- 2.39.3