Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add error message output to respond to the impact of Ubuntu 24.04 #1042

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions benchexec/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"CONTAINER_GID",
"CONTAINER_HOME",
"CONTAINER_HOSTNAME",
"check_apparmor_userns_restriction",
]


Expand Down Expand Up @@ -115,6 +116,28 @@
)
"""Whether we use generated native code for clone or an unsafe Python fallback"""

_ERROR_MSG_USER_NS_RESTRICTION = (
"Unprivileged user namespaces forbidden on this system, please "
"enable them with 'sysctl -w kernel.apparmor_restrict_unprivileged_userns=0'. "
"Ubuntu disables them by default since 24.04, refer to "
"https://ubuntu.com/blog/ubuntu-23-10-restricted-unprivileged-user-namespaces "
"for more information."
)


def check_apparmor_userns_restriction(error: OSError):
"""Check whether the passed OSError was likely caused by Ubuntu's AppArmor-based
restriction of user namespaces."""
return (
error.errno
in [
errno.EPERM,
errno.EACCES,
]
and util.try_read_file("/proc/sys/kernel/apparmor_restrict_unprivileged_userns")
== "1"
)


@contextlib.contextmanager
def allocate_stack(size=DEFAULT_STACK_SIZE):
Expand Down
2 changes: 2 additions & 0 deletions benchexec/containerexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ def child():
traceback.extract_tb(e.__traceback__, limit=-1)[0].line,
e,
)
if container.check_apparmor_userns_restriction(e):
logging.critical(container._ERROR_MSG_USER_NS_RESTRICTION)
PhilippWendler marked this conversation as resolved.
Show resolved Hide resolved
return CHILD_OSERROR

try:
Expand Down
2 changes: 2 additions & 0 deletions benchexec/containerized_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def _init_container_and_load_tool(tool_module, *args, **kwargs):
try:
_init_container(*args, **kwargs)
except OSError as e:
if container.check_apparmor_userns_restriction(e):
raise BenchExecException(container._ERROR_MSG_USER_NS_RESTRICTION)
raise BenchExecException(f"Failed to configure container: {e}")
return _load_tool(tool_module)

Expand Down
4 changes: 4 additions & 0 deletions doc/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ that are not usable on all distributions by default:
On CentOS it can be necessary to enable this feature with
`sudo sysctl -w user.max_user_namespaces=10000` or a respective entry
in `/etc/sysctl.conf` (the exact value is not important).
On Ubuntu 24.04 (or newer versions) it can be necessary to enable this feature with
`sysctl -w kernel.apparmor_restrict_unprivileged_userns=0` or a respective entry
in `/etc/sysctl.conf`.


- **Unprivileged Overlay Filesystem**: This is only available since Linux 5.11
(kernel option `CONFIG_OVERLAY_FS`),
Expand Down
2 changes: 1 addition & 1 deletion doc/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ in a container with `containerexec` than using `benchexec` or `runexec`.

#### `Cannot execute ...: Unprivileged user namespaces forbidden on this system...`
Unprivileged user namespaces are forbidden on your system
(this is the default on some distributions like Debian, Arch Linux, and CentOS).
(this is the default on some distributions like Debian, Arch Linux, CentOS, and Ubuntu since 24.04).
Please check the [system requirements](INSTALL.md#kernel-requirements)
how to enable them.

Expand Down