Skip to content

Commit fa1bdca

Browse files
nir9kees
authored andcommitted
exec: remove legacy custom binfmt modules autoloading
Problem: The search binary handler logic contains legacy code to handle automatically loading kernel modules of unsupported binary formats. This logic is a leftover from a.out-to-ELF transition. After removal of a.out support, this code has no use anymore. Solution: Clean up this code from the search binary handler, also remove the line initialising retval to -ENOENT and instead just return -ENOEXEC if the flow has reached the end of the func. Note: Anyone who might find future uses for this legacy code would be better off using binfmt_misc to trigger whatever module loading they might need - would be more flexible that way. Suggested-by: Alexander Viro <viro@zeniv.linux.org.uk> Signed-off-by: Nir Lichtman <nir@lichtman.org> Link: https://lore.kernel.org/r/20241116231323.GA225987@lichtman.org Signed-off-by: Kees Cook <kees@kernel.org>
1 parent 4188fc3 commit fa1bdca

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

fs/exec.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,13 +1723,11 @@ int remove_arg_zero(struct linux_binprm *bprm)
17231723
}
17241724
EXPORT_SYMBOL(remove_arg_zero);
17251725

1726-
#define printable(c) (((c)=='\t') || ((c)=='\n') || (0x20<=(c) && (c)<=0x7e))
17271726
/*
17281727
* cycle the list of binary formats handler, until one recognizes the image
17291728
*/
17301729
static int search_binary_handler(struct linux_binprm *bprm)
17311730
{
1732-
bool need_retry = IS_ENABLED(CONFIG_MODULES);
17331731
struct linux_binfmt *fmt;
17341732
int retval;
17351733

@@ -1741,8 +1739,6 @@ static int search_binary_handler(struct linux_binprm *bprm)
17411739
if (retval)
17421740
return retval;
17431741

1744-
retval = -ENOENT;
1745-
retry:
17461742
read_lock(&binfmt_lock);
17471743
list_for_each_entry(fmt, &formats, lh) {
17481744
if (!try_module_get(fmt->module))
@@ -1760,17 +1756,7 @@ static int search_binary_handler(struct linux_binprm *bprm)
17601756
}
17611757
read_unlock(&binfmt_lock);
17621758

1763-
if (need_retry) {
1764-
if (printable(bprm->buf[0]) && printable(bprm->buf[1]) &&
1765-
printable(bprm->buf[2]) && printable(bprm->buf[3]))
1766-
return retval;
1767-
if (request_module("binfmt-%04x", *(ushort *)(bprm->buf + 2)) < 0)
1768-
return retval;
1769-
need_retry = false;
1770-
goto retry;
1771-
}
1772-
1773-
return retval;
1759+
return -ENOEXEC;
17741760
}
17751761

17761762
/* binfmt handlers will call back into begin_new_exec() on success. */

0 commit comments

Comments
 (0)