Page MenuHomeFreeBSD

Restrict jail(8) and jexec(8) to chdir to the user's directory only when the user is expicitly specified
ClosedPublic

Authored by jamie on Aug 5 2024, 5:41 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jan 9, 9:08 PM
Unknown Object (File)
Thu, Jan 9, 7:58 PM
Unknown Object (File)
Fri, Dec 27, 6:37 AM
Unknown Object (File)
Dec 6 2024, 9:32 AM
Unknown Object (File)
Dec 6 2024, 9:03 AM
Unknown Object (File)
Nov 9 2024, 3:55 PM
Unknown Object (File)
Oct 3 2024, 2:16 PM
Unknown Object (File)
Oct 2 2024, 3:55 PM
Subscribers

Details

Summary

The exec.clean jail parameter, or the -l option to jexec(8) execute commands in a clean environment. This includes not only environment variables as mentioned in the man pages, but also changes the current directory to the user's HOME.

The directory change, while not documented, has been there for a long time. When a user is specified (exec.jail_user or -u) it makes sense for a clean environment to execute in that user's home, as a login session does.

But when there's no user specified (but still exec.clean), it's unexpected and sometimes problematic for jailed processes to find themselves in "/root". Jail startup typically reflects system startup, which is in "/".

This patch changes jail(8) and jexec(8) to only change to the user's directory when the user is explicitly set. Since the implicit user is always root (these aren't setuid programs), that means that for example "jexec -l" will run in (jailed) "/" instead of the current directory "/root"; it would require "jexec -l -u root" to once again run in "/root".

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable