From: Christian Goeschel Ndjomouo Date: Tue, 25 Nov 2025 04:54:39 +0000 (-0500) Subject: kill: use ul_get_valid_pidfd_or_err() to validate user provided pidfd inodes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15225d77b822d05da2561ee874d5927f9d4eeb0b;p=thirdparty%2Futil-linux.git kill: use ul_get_valid_pidfd_or_err() to validate user provided pidfd inodes Signed-off-by: Christian Goeschel Ndjomouo --- diff --git a/misc-utils/kill.c b/misc-utils/kill.c index 245c3b6b7..ff0dcae52 100644 --- a/misc-utils/kill.c +++ b/misc-utils/kill.c @@ -534,8 +534,7 @@ static int kill_with_timeout(const struct kill_control *ctl) info.si_value.sival_int = ctl->use_sigval != 0 ? ctl->use_sigval : ctl->numsig; - if ((pfd = pidfd_open(ctl->pid, 0)) < 0) - err(EXIT_FAILURE, _("pidfd_open() failed: %d"), ctl->pid); + pfd = ul_get_valid_pidfd_or_err(ctl->pid, ctl->pidfd_ino); p.fd = pfd; p.events = POLLIN; @@ -564,22 +563,6 @@ static int kill_with_timeout(const struct kill_control *ctl) } #endif -#ifdef USE_KILL_WITH_PIDFDINO -static int validate_pfd_ino(int pfd, ino_t pfd_ino) -{ - int rc; - struct stat f; - - rc = fstat(pfd, &f); - if (rc != 0) - return -EINVAL; - - if (f.st_ino != pfd_ino) - return -EINVAL; - return 0; -} -#endif - static int kill_verbose(const struct kill_control *ctl) { int rc = 0; @@ -603,15 +586,7 @@ static int kill_verbose(const struct kill_control *ctl) #ifdef USE_KILL_WITH_PIDFDINO if ((ctl->pidfd_ino > 0)) { int pfd; - pfd = pidfd_open(ctl->pid, 0); - if (pfd < 0) - err(EXIT_FAILURE, _("pidfd_open() failed: %d"), ctl->pid); - - rc = validate_pfd_ino(pfd, ctl->pidfd_ino); - if (rc < 0) - errx(EXIT_FAILURE, _("pidfd inode %"PRIu64" not found for pid %d: %s"), - ctl->pidfd_ino, ctl->pid, strerror(-rc)); - + pfd = ul_get_valid_pidfd_or_err(ctl->pid, ctl->pidfd_ino); rc = pidfd_send_signal(pfd, ctl->numsig, 0, 0); if (rc < 0) err(EXIT_FAILURE, _("pidfd_send_signal() failed"));