diff options
| author | Christian Brauner <brauner@kernel.org> | 2026-08-03 14:15:00 +0200 |
|---|---|---|
| committer | Christian Brauner <brauner@kernel.org> | 2026-08-03 23:36:18 +0200 |
| commit | b604897764047229c6a931e1980cac1b2197d9d2 (patch) | |
| tree | 11c7bb5b86359a6b38fe025725b2b1dd2d9e66ce /include/linux/binfmt_misc.h | |
| parent | e98067e72ff81b054bda8135e1c348d13f54e553 (diff) | |
binfmt_misc: correctly account pre-opened interpreters
An 'F' entry, and every interpreter a 'B' entry binds, holds a file open
from registration until the entry goes away, pinning the file, its inode,
the mount it came from and that mount's superblock. Nothing bounds how
many of those a user namespace can hold. An entry binds at most
BINFMT_MISC_INTERP_MAX interpreters, but nothing caps the entries.
Charge each binding to the user namespace and uid that makes it against a
new UCOUNT_BINFMT_MISC_INTERPRETERS. Going over budget causes -ENOSPC.
A per-instance cap would suck. Instances are keyed on the user
namespace. So any constant is multiplied by the number of namespaces the
caller creates. Creating those is virtually free. A ucount charges the
namespace and every one of its ancestors. And a namespace can raise only
its own limit. So nesting buys nothing.
The knob is /proc/sys/user/max_binfmt_misc_interpreters. Leave it at the
max_threads/2 default fork_init() gives a new type. No existing
configuration comes close to that.
binfmt_misc is tristate, which makes it the first ucount user that can be
built as a module. Export inc_ucount() and dec_ucount(); without them
CONFIG_BINFMT_MISC=m fails to link. Export them to binfmt_misc alone:
charging a ucount type is not something a module has any business doing
in general, and the list is trivial to extend if a second user shows up.
init_user_ns and init_binfmt_misc are already exported for the same
module.
Link: https://patch.msgid.link/20260803-work-binfmt_misc-interplimit-v1-1-4a2435500bd9@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
Diffstat (limited to 'include/linux/binfmt_misc.h')
| -rw-r--r-- | include/linux/binfmt_misc.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/binfmt_misc.h b/include/linux/binfmt_misc.h index 072e4b3dd78d..8045b10dd3e5 100644 --- a/include/linux/binfmt_misc.h +++ b/include/linux/binfmt_misc.h @@ -7,6 +7,7 @@ struct bpf_prog; struct file; struct linux_binprm; +struct ucounts; struct user_namespace; #define BINFMT_MISC_OPS_NAME_MAX 16 @@ -21,6 +22,7 @@ struct user_namespace; * struct binfmt_misc_interp - an interpreter an entry was registered with * @list: link in the entry's list, in registration order * @file: the file, opened at registration and never resolved again + * @ucounts: the UCOUNT_BINFMT_MISC_INTERPRETERS charge the binding took * @path: the path it was registered under, used as the name the interpreter * runs under; stored after @name in the same allocation * @name: the name the load program selects it by; empty for the fixed @@ -33,6 +35,7 @@ struct user_namespace; struct binfmt_misc_interp { struct list_head list; struct file *file; + struct ucounts *ucounts; const char *path; char name[]; }; |
