chroot is called without a chdir after it, so the working directory stays outside the jail

tx0/c:chroot-without-chdirrecommendedwarningsecurity, cwe-243

What it finds

chroot(dir); changes the root directory but not the working directory, which may still be outside the new root and gives access to everything beneath it. chdir("/") right after closes that.

From the rule's source, chroot_without_chdir.rs.

Example from the rule's tests
#include <unistd.h> int jail(const char *dir){  return chroot(dir);tx0 reports: chroot is not followed by chdir} int closed(const char *dir){  if (chroot(dir) != 0)    return -1;  return chdir("/");}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:chroot-without-chdir" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/c:chroot-without-chdir] reason="..."

tx0 explain tx0/c:chroot-without-chdir shows the same in the terminal. Found a false positive? Report it.