Commit 57989ed4 authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

[PATCH] fix failed sethostname corrupting the data

(Stephan Maciej)
parent da602a16
......@@ -1159,6 +1159,7 @@ asmlinkage long sys_newuname(struct new_utsname __user * name)
asmlinkage long sys_sethostname(char __user *name, int len)
{
int errno;
char tmp[__NEW_UTS_LEN];
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
......@@ -1166,7 +1167,8 @@ asmlinkage long sys_sethostname(char __user *name, int len)
return -EINVAL;
down_write(&uts_sem);
errno = -EFAULT;
if (!copy_from_user(system_utsname.nodename, name, len)) {
if (!copy_from_user(tmp, name, len)) {
memcpy(system_utsname.nodename, tmp, len);
system_utsname.nodename[len] = 0;
errno = 0;
}
......@@ -1198,6 +1200,7 @@ asmlinkage long sys_gethostname(char __user *name, int len)
asmlinkage long sys_setdomainname(char __user *name, int len)
{
int errno;
char tmp[__NEW_UTS_LEN];
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
......@@ -1206,9 +1209,10 @@ asmlinkage long sys_setdomainname(char __user *name, int len)
down_write(&uts_sem);
errno = -EFAULT;
if (!copy_from_user(system_utsname.domainname, name, len)) {
errno = 0;
if (!copy_from_user(tmp, name, len)) {
memcpy(system_utsname.domainname, tmp, len);
system_utsname.domainname[len] = 0;
errno = 0;
}
up_write(&uts_sem);
return errno;
......
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