Correctly check if PIDFD_INFO_EXIT is available
PATCH v2 1/1 Correctly check if PIDFD_INFO_EXIT is available
From: Andrea Cervesato <[email protected]>
When systems are not having the PIDFD_INFO_EXIT implementation, ioctl_pidfd testing suite might fail with:
ioctl_pidfd.h:32: TBROK: ioctl(...) failed: ENOTTY (25)
Fix the ioctl_pidfd_info_exit_supported() behavior, considering ENOTTY error like a sign for not having PIDFD_INFO_EXIT implemented in the system.
---
Changes in v2:
- close pidfd when PIDFD_INFO_EXIT is supported
- Link to v1: https://lore.kernel.org/r/[email protected]
--- testcases/kernel/syscalls/ioctl/ioctl_pidfd.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
testcases/kernel/syscalls/ioctl/ioctl_pidfd.h +12 -6
@@ -11,9 +11,10 @@static inline int ioctl_pidfd_info_exit_supported (void ) { -int ret =0 ; +int ret;pid_t pid;int pidfd; +int supported =0 ;struct pidfd_info info;if (tst_kvercmp (6 ,15 ,0 ) >=0 )
@@ -29,13 +30,18 @@ static inline int ioctl_pidfd_info_exit_supported(void) pidfd =SAFE_PIDFD_OPEN (pid,0 );SAFE_WAITPID (pid,NULL ,0 ); -SAFE_IOCTL (pidfd,PIDFD_GET_INFO , &info); -SAFE_CLOSE (pidfd); + ret =ioctl (pidfd,PIDFD_GET_INFO , &info); +if (ret ==-1 ) { +if (errno !=ENOTTY ) +tst_brk (TBROK |TERRNO ,"ioctl error" ); + }else { +if (info.mask &PIDFD_INFO_EXIT ) + supported =1 ; + } -if (info.mask &PIDFD_INFO_EXIT ) - ret =1 ; +SAFE_CLOSE (pidfd); - return ret; + return supported; }#endif
---
base-commit: 91e6272febf95e19a8300695dfc2089569adf9d8
change-id: 20250729-ioctl_pidfd_supported-437d25a4c382
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines · Cyril Hrubis
Hi!
Reviewed-by Cyril Hrubis <[email protected]>
It seems we need to add also a couple of errno checks more. ioctl(PIDFD_INFO_EXIT ...) starts to fail with EINVAL from a certain version of the kernel, after introducing pidfd_ioctl function in fs/pidfs.c, while before only ENOTTY was raised.
After the introduction of "cdda1f26e74b - pidfd: add ioctl to retrieve pid info" in v6.13, the logic inside the kernel changed and we get ESRCH error due to the introduction of struct pidfd_info, but the lack of PIDFD_INFO_EXIT support: at that specific commit, only PIDFD_INFO_PID is supported.
This is due to the implementation of pidfd_ioctl(), that is not validating commands before asking for a pid task.
I guess there's either a enhancement to do in the kernel implementation, or a lack of checks from our side. Since we are talking about 3 versions of the kernel ago, we should probably verify that kernel doesn't support PIDFD_INFO_EXIT by looking at the following ioctl() errno:
- ENOTTY
- EINVAL
- ESRCH
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 10 lines · Andrea Cervesato
Quoted 3 lines · Cyril Hrubis
Hi!
Reviewed-by Cyril Hrubis <[email protected]>It seems we need to add also a couple of errno checks more.
ioctl(PIDFD_INFO_EXIT ...)starts to fail with EINVAL from a certain version of the kernel, after introducingpidfd_ioctlfunction infs/pidfs.c, while before only ENOTTY was raised.After the introduction of "
cdda1f26e74b- pidfd: add ioctl to retrieve pid info" in v6.13, the logic inside the kernel changed and we get ESRCH error due to the introduction ofstruct pidfd_info, but the lack ofPIDFD_INFO_EXITsupport: at that specific commit, onlyPIDFD_INFO_PIDis supported.This is due to the implementation of
pidfd_ioctl(), that is not validating commands before asking for a pid task.
Quoted 8 lines
I guess there's either a enhancement to do in the kernel implementation, or a lack of checks from our side. Since we are talking about 3 versions of the kernel ago, we should probably verify that kernel doesn't support
PIDFD_INFO_EXITby looking at the followingioctl()errno:- ENOTTY
- EINVAL
- ESRCH- Andrea
The pidfd_ioctl() commands check has been introduced in v6.13 with "8ce352818820 pidfs: check for valid ioctl commands", so the patch v4 that I sent needs to check for ENOIOCTLCMD as well..
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp