From: Liang Luo <[email protected]>
In the owner test, the owning user namespace of the "uns" fd is fetched
into "init_uns", but the subsequent error check tests "uns" again, which
was already validated earlier. The intended error path is therefore dead
code: if the ioctl() actually fails, "init_uns" is left at -1 and the
test proceeds to use it, surfacing the failure later as a misleading
"Don't get EPERM" (from EBADF on the invalid fd) instead of the intended
"Unable to get an owning user namespace".
Check "init_uns" instead, which is the value actually returned by the
ioctl() under test.
Fixes: 6ad92bf63e45 ("tools/testing: add a test to check nsfs ioctl-s")
Signed-off-by: Liang Luo <[email protected]>
---
tools/testing/selftests/filesystems/nsfs/owner.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/filesystems/nsfs/owner.c
b/tools/testing/selftests/filesystems/nsfs/owner.c
index 96a976c74550..8ad7b4fb7655 100644
--- a/tools/testing/selftests/filesystems/nsfs/owner.c
+++ b/tools/testing/selftests/filesystems/nsfs/owner.c
@@ -72,7 +72,7 @@ int main(int argc, char *argvp[])
return pr_err("NS_GET_USERNS returned a wrong namespace");
init_uns = ioctl(uns, NS_GET_USERNS);
- if (uns < 0)
+ if (init_uns < 0)
return pr_err("Unable to get an owning user namespace");
if (ioctl(init_uns, NS_GET_USERNS) >= 0 || errno != EPERM)
--
2.25.1