Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v2] selftests/mount_setattr: fix idmap_mount_tree_invalid failed to run
@ 2024-10-28  8:41 zhouyuhang
  2024-10-28 12:11 ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: zhouyuhang @ 2024-10-28  8:41 UTC (permalink / raw)
  To: brauner, sforshee, shuah
  Cc: linux-fsdevel, linux-kselftest, linux-kernel, zhouyuhang

From: zhouyuhang <zhouyuhang@kylinos.cn>

Test case idmap_mount_tree_invalid failed to run on the newer kernel
with the following output:

 #  RUN           mount_setattr_idmapped.idmap_mount_tree_invalid ...
 # mount_setattr_test.c:1428:idmap_mount_tree_invalid:Expected sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr,  sizeof(attr)) (0) ! = 0 (0)
 # idmap_mount_tree_invalid: Test terminated by assertion

This is because tmpfs is mounted at "/mnt/A", and tmpfs already
contains the flag FS_ALLOW_IDMAP after the commit 7a80e5b8c6fa ("shmem:
support idmapped mounts for tmpfs"). So calling sys_mount_setattr here
returns 0 instead of -EINVAL as expected.

Ramfs does not support idmap mounts, so we can use it here to test invalid mounts,
which allows the test case to pass with the following output:

 # Starting 1 tests from 1 test cases.
 #  RUN           mount_setattr_idmapped.idmap_mount_tree_invalid ...
 #            OK  mount_setattr_idmapped.idmap_mount_tree_invalid
 ok 1 mount_setattr_idmapped.idmap_mount_tree_invalid
 # PASSED: 1 / 1 tests passed.

Signed-off-by: zhouyuhang <zhouyuhang@kylinos.cn>
---
 .../testing/selftests/mount_setattr/mount_setattr_test.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
index c6a8c732b802..68801e1a9ec2 100644
--- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c
+++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
@@ -1414,6 +1414,13 @@ TEST_F(mount_setattr_idmapped, idmap_mount_tree_invalid)
 	ASSERT_EQ(expected_uid_gid(-EBADF, "/tmp/B/b", 0, 0, 0), 0);
 	ASSERT_EQ(expected_uid_gid(-EBADF, "/tmp/B/BB/b", 0, 0, 0), 0);
 
+	ASSERT_EQ(mount("testing", "/mnt/A", "ramfs", MS_NOATIME | MS_NODEV,
+			"size=100000,mode=700"), 0);
+
+	ASSERT_EQ(mkdir("/mnt/A/AA", 0777), 0);
+
+	ASSERT_EQ(mount("/tmp", "/mnt/A/AA", NULL, MS_BIND | MS_REC, NULL), 0);
+
 	open_tree_fd = sys_open_tree(-EBADF, "/mnt/A",
 				     AT_RECURSIVE |
 				     AT_EMPTY_PATH |
@@ -1433,6 +1440,8 @@ TEST_F(mount_setattr_idmapped, idmap_mount_tree_invalid)
 	ASSERT_EQ(expected_uid_gid(-EBADF, "/tmp/B/BB/b", 0, 0, 0), 0);
 	ASSERT_EQ(expected_uid_gid(open_tree_fd, "B/b", 0, 0, 0), 0);
 	ASSERT_EQ(expected_uid_gid(open_tree_fd, "B/BB/b", 0, 0, 0), 0);
+
+	(void)umount2("/mnt/A", MNT_DETACH);
 }
 
 TEST_F(mount_setattr, mount_attr_nosymfollow)
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests/mount_setattr: fix idmap_mount_tree_invalid failed to run
  2024-10-28  8:41 [PATCH v2] selftests/mount_setattr: fix idmap_mount_tree_invalid failed to run zhouyuhang
@ 2024-10-28 12:11 ` Christian Brauner
  2024-10-29  2:42   ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2024-10-28 12:11 UTC (permalink / raw)
  To: zhouyuhang
  Cc: sforshee, shuah, linux-fsdevel, linux-kselftest, linux-kernel,
	zhouyuhang

On Mon, Oct 28, 2024 at 04:41:32PM +0800, zhouyuhang wrote:
> From: zhouyuhang <zhouyuhang@kylinos.cn>
> 
> Test case idmap_mount_tree_invalid failed to run on the newer kernel
> with the following output:
> 
>  #  RUN           mount_setattr_idmapped.idmap_mount_tree_invalid ...
>  # mount_setattr_test.c:1428:idmap_mount_tree_invalid:Expected sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr,  sizeof(attr)) (0) ! = 0 (0)
>  # idmap_mount_tree_invalid: Test terminated by assertion
> 
> This is because tmpfs is mounted at "/mnt/A", and tmpfs already
> contains the flag FS_ALLOW_IDMAP after the commit 7a80e5b8c6fa ("shmem:
> support idmapped mounts for tmpfs"). So calling sys_mount_setattr here
> returns 0 instead of -EINVAL as expected.
> 
> Ramfs does not support idmap mounts, so we can use it here to test invalid mounts,
> which allows the test case to pass with the following output:
> 
>  # Starting 1 tests from 1 test cases.
>  #  RUN           mount_setattr_idmapped.idmap_mount_tree_invalid ...
>  #            OK  mount_setattr_idmapped.idmap_mount_tree_invalid
>  ok 1 mount_setattr_idmapped.idmap_mount_tree_invalid
>  # PASSED: 1 / 1 tests passed.
> 
> Signed-off-by: zhouyuhang <zhouyuhang@kylinos.cn>
> ---

Reviewed-by: Christian Brauner <brauner@kernel.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] selftests/mount_setattr: fix idmap_mount_tree_invalid failed to run
  2024-10-28 12:11 ` Christian Brauner
@ 2024-10-29  2:42   ` Shuah Khan
  0 siblings, 0 replies; 3+ messages in thread
From: Shuah Khan @ 2024-10-29  2:42 UTC (permalink / raw)
  To: Christian Brauner, zhouyuhang
  Cc: sforshee, shuah, linux-fsdevel, linux-kselftest, linux-kernel,
	zhouyuhang, Shuah Khan

On 10/28/24 06:11, Christian Brauner wrote:
> On Mon, Oct 28, 2024 at 04:41:32PM +0800, zhouyuhang wrote:
>> From: zhouyuhang <zhouyuhang@kylinos.cn>
>>
>> Test case idmap_mount_tree_invalid failed to run on the newer kernel
>> with the following output:
>>
>>   #  RUN           mount_setattr_idmapped.idmap_mount_tree_invalid ...
>>   # mount_setattr_test.c:1428:idmap_mount_tree_invalid:Expected sys_mount_setattr(open_tree_fd, "", AT_EMPTY_PATH, &attr,  sizeof(attr)) (0) ! = 0 (0)
>>   # idmap_mount_tree_invalid: Test terminated by assertion
>>
>> This is because tmpfs is mounted at "/mnt/A", and tmpfs already
>> contains the flag FS_ALLOW_IDMAP after the commit 7a80e5b8c6fa ("shmem:
>> support idmapped mounts for tmpfs"). So calling sys_mount_setattr here
>> returns 0 instead of -EINVAL as expected.
>>
>> Ramfs does not support idmap mounts, so we can use it here to test invalid mounts,
>> which allows the test case to pass with the following output:
>>
>>   # Starting 1 tests from 1 test cases.
>>   #  RUN           mount_setattr_idmapped.idmap_mount_tree_invalid ...
>>   #            OK  mount_setattr_idmapped.idmap_mount_tree_invalid
>>   ok 1 mount_setattr_idmapped.idmap_mount_tree_invalid
>>   # PASSED: 1 / 1 tests passed.
>>
>> Signed-off-by: zhouyuhang <zhouyuhang@kylinos.cn>
>> ---
> 
> Reviewed-by: Christian Brauner <brauner@kernel.org>

Thank you. Applied to kselftest fixes branch for next rc.

thanks,
-- Shuah

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-10-29  2:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28  8:41 [PATCH v2] selftests/mount_setattr: fix idmap_mount_tree_invalid failed to run zhouyuhang
2024-10-28 12:11 ` Christian Brauner
2024-10-29  2:42   ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox