Skip to content

Commit 16195d2

Browse files
committed
coredump: validate socket name as it is written
In contrast to other parameters written into /proc/sys/kernel/core_pattern that never fail we can validate enabling the new AF_UNIX support. This is obviously racy as hell but it's always been that way. Link: https://lore.kernel.org/[email protected] Acked-by: Luca Boccassi <[email protected]> Reviewed-by: Jann Horn <[email protected]> Reviewed-by: Alexander Mikhalitsyn <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent c72d914 commit 16195d2

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

fs/coredump.c

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,13 +1236,44 @@ void validate_coredump_safety(void)
12361236
}
12371237
}
12381238

1239+
static inline bool check_coredump_socket(void)
1240+
{
1241+
if (core_pattern[0] != '@')
1242+
return true;
1243+
1244+
/*
1245+
* Coredump socket must be located in the initial mount
1246+
* namespace. Don't give the impression that anything else is
1247+
* supported right now.
1248+
*/
1249+
if (current->nsproxy->mnt_ns != init_task.nsproxy->mnt_ns)
1250+
return false;
1251+
1252+
/* Must be an absolute path. */
1253+
if (*(core_pattern + 1) != '/')
1254+
return false;
1255+
1256+
return true;
1257+
}
1258+
12391259
static int proc_dostring_coredump(const struct ctl_table *table, int write,
12401260
void *buffer, size_t *lenp, loff_t *ppos)
12411261
{
1242-
int error = proc_dostring(table, write, buffer, lenp, ppos);
1262+
int error;
1263+
ssize_t retval;
1264+
char old_core_pattern[CORENAME_MAX_SIZE];
1265+
1266+
retval = strscpy(old_core_pattern, core_pattern, CORENAME_MAX_SIZE);
1267+
1268+
error = proc_dostring(table, write, buffer, lenp, ppos);
1269+
if (error)
1270+
return error;
1271+
if (!check_coredump_socket()) {
1272+
strscpy(core_pattern, old_core_pattern, retval + 1);
1273+
return -EINVAL;
1274+
}
12431275

1244-
if (!error)
1245-
validate_coredump_safety();
1276+
validate_coredump_safety();
12461277
return error;
12471278
}
12481279

0 commit comments

Comments
 (0)