Commit 87988815 authored by Vegard Nossum's avatar Vegard Nossum Committed by Linus Torvalds

utsname: completely overwrite prior information

On sethostname() and setdomainname(), previous information may be retained
if it was longer than than the new hostname/domainname.

This can be demonstrated trivially by calling sethostname() first with a
long name, then with a short name, and then calling uname() to retrieve
the full buffer that contains the hostname (and possibly parts of the old
hostname), one just has to look past the terminating zero.

I don't know if we should really care that much (hence the RFC); the only
scenarios I can possibly think of is administrator putting something
sensitive in the hostname (or domain name) by accident, and changing it
back will not undo the mistake entirely, though it's not like we can
recover gracefully from "rm -rf /" either...  The other scenario is
namespaces (CLONE_NEWUTS) where some information may be unintentionally
"inherited" from the previous namespace (a program wants to hide the
original name and does clone + sethostname, but some information is still
left).

I think the patch may be defended on grounds of the principle of least
surprise.  But I am not adamant :-)

(I guess the question now is whether userspace should be able to
write embedded NULs into the buffer or not...)

At least the observation has been made and the patch has been presented.
Signed-off-by: default avatarVegard Nossum <vegard.nossum@gmail.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: "Serge E. Hallyn" <serue@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 929f37cb
...@@ -1350,7 +1350,8 @@ asmlinkage long sys_sethostname(char __user *name, int len) ...@@ -1350,7 +1350,8 @@ asmlinkage long sys_sethostname(char __user *name, int len)
errno = -EFAULT; errno = -EFAULT;
if (!copy_from_user(tmp, name, len)) { if (!copy_from_user(tmp, name, len)) {
memcpy(utsname()->nodename, tmp, len); memcpy(utsname()->nodename, tmp, len);
utsname()->nodename[len] = 0; memset(utsname()->nodename + len, 0,
sizeof(utsname()->nodename) - len);
errno = 0; errno = 0;
} }
up_write(&uts_sem); up_write(&uts_sem);
...@@ -1396,7 +1397,8 @@ asmlinkage long sys_setdomainname(char __user *name, int len) ...@@ -1396,7 +1397,8 @@ asmlinkage long sys_setdomainname(char __user *name, int len)
errno = -EFAULT; errno = -EFAULT;
if (!copy_from_user(tmp, name, len)) { if (!copy_from_user(tmp, name, len)) {
memcpy(utsname()->domainname, tmp, len); memcpy(utsname()->domainname, tmp, len);
utsname()->domainname[len] = 0; memset(utsname()->domainname + len, 0,
sizeof(utsname()->domainname) - len);
errno = 0; errno = 0;
} }
up_write(&uts_sem); up_write(&uts_sem);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment