RFR: 8298267: Too many conversion specifiers in CgroupV1Subsystem::pids_max_val
Severin Gehwolf
sgehwolf at openjdk.org
Wed Dec 7 13:44:43 UTC 2022
On Wed, 7 Dec 2022 12:40:13 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:
> Trivial fix.
>
> This code:
>
> ```c++
> GET_CONTAINER_INFO_CPTR(cptr, _pids, "/pids.max",
> "Maximum number of tasks is: %s", "%s %*d", pidsmax, 1024);
>
>
> Expands to this call:
>
> ```c++
> // matchline = NULL
> err = subsystem_file_line_contents(_pids, "/pids.max", NULL, "%s %*d", pidsmax);
>
>
> Which in turn hits this branch:
>
> ```c++
> if (matchline == NULL) {
> // single-line file case
> int matched = sscanf(p, scan_fmt, returnval);
> found_match = (matched == 1);
> }
>
>
> Now we're calling `sscanf()` with `scan_fmt = "%s %*d"`, this is undefined behavior as the number of conversion specifiers are larger than the number of pointers provided.
>
> This is the correct fix, because the file `pids.max` only contains a number. This is supported by:
>
> 1. Checking my own `pids.max` and
> 2. This [documentation](https://www.kernel.org/doc/Documentation/cgroup-v1/pids.txt) suggests that it only consists of a number by recommending altering the file through `echo 2 > /sys/fs/cgroup/pids/parent/pids.max`
Changes requested by sgehwolf (Reviewer).
src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp line 289:
> 287: char* CgroupV1Subsystem::pids_max_val() {
> 288: GET_CONTAINER_INFO_CPTR(cptr, _pids, "/pids.max",
> 289: "Maximum number of tasks is: %s", "%*d", pidsmax, 1024);
According to https://docs.kernel.org/admin-guide/cgroup-v2.html#pid-interface-files, file `pid.max` either contains a number or the string `max`. So I think this should be (as we need to account for something not a number):
`"Maximum number of tasks is: %s", "%1023s", pidsmax, 1024);`
The conversion from `max` to unlimited happens here:
https://github.com/openjdk/jdk/blob/master/src/hotspot/os/linux/cgroupSubsystem_linux.cpp#L559
-------------
PR: https://git.openjdk.org/jdk/pull/11557
More information about the hotspot-runtime-dev
mailing list