]> git.itanic.dy.fi Git - linux-stable/commitdiff
utsname: contribute changes to RNG
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 27 Sep 2022 09:35:16 +0000 (11:35 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 29 Sep 2022 19:37:27 +0000 (21:37 +0200)
On some small machines with little entropy, a quasi-unique hostname is
sometimes a relevant factor. I've seen, for example, 8 character
alpha-numeric serial numbers. In addition, the time at which the hostname
is set is usually a decent measurement of how long early boot took. So,
call add_device_randomness() on new hostnames, which feeds its arguments
to the RNG in addition to a fresh cycle counter.

Low cost hooks like this never hurt and can only ever help, and since
this costs basically nothing for an operation that is never a fast path,
this is an overall easy win.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
kernel/sys.c
kernel/utsname_sysctl.c

index b911fa6d81ab7a19bc3d40dfb796e361adbbcc8d..35339bd5fc9f86df9af836c2264c33d02ea75763 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/times.h>
 #include <linux/posix-timers.h>
 #include <linux/security.h>
+#include <linux/random.h>
 #include <linux/suspend.h>
 #include <linux/tty.h>
 #include <linux/signal.h>
@@ -1366,6 +1367,7 @@ SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
        if (!copy_from_user(tmp, name, len)) {
                struct new_utsname *u;
 
+               add_device_randomness(tmp, len);
                down_write(&uts_sem);
                u = utsname();
                memcpy(u->nodename, tmp, len);
@@ -1419,6 +1421,7 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
        if (!copy_from_user(tmp, name, len)) {
                struct new_utsname *u;
 
+               add_device_randomness(tmp, len);
                down_write(&uts_sem);
                u = utsname();
                memcpy(u->domainname, tmp, len);
index 4ca61d49885b68187eb6fcb6ad209209b955b400..de16bcf14b0388434db1e9ee6c74680e20efa0f1 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/export.h>
 #include <linux/uts.h>
 #include <linux/utsname.h>
+#include <linux/random.h>
 #include <linux/sysctl.h>
 #include <linux/wait.h>
 #include <linux/rwsem.h>
@@ -57,6 +58,7 @@ static int proc_do_uts_string(struct ctl_table *table, int write,
                 * theoretically be incorrect if there are two parallel writes
                 * at non-zero offsets to the same sysctl.
                 */
+               add_device_randomness(tmp_data, sizeof(tmp_data));
                down_write(&uts_sem);
                memcpy(get_uts(table), tmp_data, sizeof(tmp_data));
                up_write(&uts_sem);