RFR: 8298267: Too many conversion specifiers in CgroupV1Subsystem::pids_max_val

Johan Sjölen jsjolen at openjdk.org
Wed Dec 7 12:48:43 UTC 2022


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`

-------------

Commit messages:
 - Fix bug

Changes: https://git.openjdk.org/jdk/pull/11557/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11557&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8298267
  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/11557.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11557/head:pull/11557

PR: https://git.openjdk.org/jdk/pull/11557


More information about the hotspot-runtime-dev mailing list