Skip to content

Commit 37608ba

Browse files
committed
utsname: contribute changes to RNG
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 <[email protected]> Cc: Dominik Brodowski <[email protected]> Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent dd54fd7 commit 37608ba

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

kernel/sys.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/times.h>
2626
#include <linux/posix-timers.h>
2727
#include <linux/security.h>
28+
#include <linux/random.h>
2829
#include <linux/suspend.h>
2930
#include <linux/tty.h>
3031
#include <linux/signal.h>
@@ -1366,6 +1367,7 @@ SYSCALL_DEFINE2(sethostname, char __user *, name, int, len)
13661367
if (!copy_from_user(tmp, name, len)) {
13671368
struct new_utsname *u;
13681369

1370+
add_device_randomness(tmp, len);
13691371
down_write(&uts_sem);
13701372
u = utsname();
13711373
memcpy(u->nodename, tmp, len);
@@ -1419,6 +1421,7 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len)
14191421
if (!copy_from_user(tmp, name, len)) {
14201422
struct new_utsname *u;
14211423

1424+
add_device_randomness(tmp, len);
14221425
down_write(&uts_sem);
14231426
u = utsname();
14241427
memcpy(u->domainname, tmp, len);

kernel/utsname_sysctl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/export.h>
99
#include <linux/uts.h>
1010
#include <linux/utsname.h>
11+
#include <linux/random.h>
1112
#include <linux/sysctl.h>
1213
#include <linux/wait.h>
1314
#include <linux/rwsem.h>
@@ -57,6 +58,7 @@ static int proc_do_uts_string(struct ctl_table *table, int write,
5758
* theoretically be incorrect if there are two parallel writes
5859
* at non-zero offsets to the same sysctl.
5960
*/
61+
add_device_randomness(tmp_data, sizeof(tmp_data));
6062
down_write(&uts_sem);
6163
memcpy(get_uts(table), tmp_data, sizeof(tmp_data));
6264
up_write(&uts_sem);

0 commit comments

Comments
 (0)