Skip to content

Commit a6323bd

Browse files
petrpavludkruces
authored andcommitted
module: Prevent silent truncation of module name in delete_module(2)
Passing a module name longer than MODULE_NAME_LEN to the delete_module syscall results in its silent truncation. This really isn't much of a problem in practice, but it could theoretically lead to the removal of an incorrect module. It is more sensible to return ENAMETOOLONG or ENOENT in such a case. Update the syscall to return ENOENT, as documented in the delete_module(2) man page to mean "No module by that name exists." This is appropriate because a module with a name longer than MODULE_NAME_LEN cannot be loaded in the first place. Signed-off-by: Petr Pavlu <[email protected]> Reviewed-by: Daniel Gomez <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Gomez <[email protected]>
1 parent 768da2e commit a6323bd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

kernel/module/main.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,14 +779,16 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
779779
struct module *mod;
780780
char name[MODULE_NAME_LEN];
781781
char buf[MODULE_FLAGS_BUF_SIZE];
782-
int ret, forced = 0;
782+
int ret, len, forced = 0;
783783

784784
if (!capable(CAP_SYS_MODULE) || modules_disabled)
785785
return -EPERM;
786786

787-
if (strncpy_from_user(name, name_user, MODULE_NAME_LEN-1) < 0)
788-
return -EFAULT;
789-
name[MODULE_NAME_LEN-1] = '\0';
787+
len = strncpy_from_user(name, name_user, MODULE_NAME_LEN);
788+
if (len == 0 || len == MODULE_NAME_LEN)
789+
return -ENOENT;
790+
if (len < 0)
791+
return len;
790792

791793
audit_log_kern_module(name);
792794

0 commit comments

Comments
 (0)