From 51e58aced4dabdac64510b20216e1eec0dff4fab Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Tue, 7 Mar 2023 14:40:25 -0800 Subject: [PATCH] libprocessgroup: Add argument checks in KillProcessGroup() Apparently there is Java code that calls KillProcessGroup() with an invalid initialPid argument. Hence this CL that makes KillProcessGroup() fail early if one of its arguments is invalid. Change-Id: I42f98eed139d9d0950428d04180e4613ba74b4e6 Signed-off-by: Bart Van Assche --- libprocessgroup/processgroup.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libprocessgroup/processgroup.cpp b/libprocessgroup/processgroup.cpp index 38f19ff58..f7af08bbe 100644 --- a/libprocessgroup/processgroup.cpp +++ b/libprocessgroup/processgroup.cpp @@ -446,6 +446,14 @@ static int DoKillProcessGroupOnce(const char* cgroup, uid_t uid, int initialPid, static int KillProcessGroup(uid_t uid, int initialPid, int signal, int retries, int* max_processes) { + if (uid < 0) { + LOG(ERROR) << __func__ << ": invalid UID " << uid; + return -1; + } + if (initialPid <= 0) { + LOG(ERROR) << __func__ << ": invalid PID " << initialPid; + return -1; + } std::string hierarchy_root_path; if (CgroupsAvailable()) { CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &hierarchy_root_path);