Skip to content

Commit

Permalink
[PATCH] namespaces: utsname: switch to using uts namespaces
Browse files Browse the repository at this point in the history
Replace references to system_utsname to the per-process uts namespace
where appropriate.  This includes things like uname.

Changes: Per Eric Biederman's comments, use the per-process uts namespace
	for ELF_PLATFORM, sunrpc, and parts of net/ipv4/ipconfig.c

[[email protected]: UML fix]
[[email protected]: cleanup]
[[email protected]: build fix]
Signed-off-by: Serge E. Hallyn <[email protected]>
Cc: Kirill Korotaev <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Herbert Poetzl <[email protected]>
Cc: Andrey Savochkin <[email protected]>
Signed-off-by: Cedric Le Goater <[email protected]>
Cc: Jeff Dike <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Serge E. Hallyn authored and Linus Torvalds committed Oct 2, 2006
1 parent 0bdd7aa commit e9ff399
Show file tree
Hide file tree
Showing 35 changed files with 180 additions and 160 deletions.
26 changes: 13 additions & 13 deletions arch/alpha/kernel/osf_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,15 @@ osf_utsname(char __user *name)

down_read(&uts_sem);
error = -EFAULT;
if (copy_to_user(name + 0, system_utsname.sysname, 32))
if (copy_to_user(name + 0, utsname()->sysname, 32))
goto out;
if (copy_to_user(name + 32, system_utsname.nodename, 32))
if (copy_to_user(name + 32, utsname()->nodename, 32))
goto out;
if (copy_to_user(name + 64, system_utsname.release, 32))
if (copy_to_user(name + 64, utsname()->release, 32))
goto out;
if (copy_to_user(name + 96, system_utsname.version, 32))
if (copy_to_user(name + 96, utsname()->version, 32))
goto out;
if (copy_to_user(name + 128, system_utsname.machine, 32))
if (copy_to_user(name + 128, utsname()->machine, 32))
goto out;

error = 0;
Expand Down Expand Up @@ -449,8 +449,8 @@ osf_getdomainname(char __user *name, int namelen)

down_read(&uts_sem);
for (i = 0; i < len; ++i) {
__put_user(system_utsname.domainname[i], name + i);
if (system_utsname.domainname[i] == '\0')
__put_user(utsname()->domainname[i], name + i);
if (utsname()->domainname[i] == '\0')
break;
}
up_read(&uts_sem);
Expand Down Expand Up @@ -607,12 +607,12 @@ osf_sigstack(struct sigstack __user *uss, struct sigstack __user *uoss)
asmlinkage long
osf_sysinfo(int command, char __user *buf, long count)
{
static char * sysinfo_table[] = {
system_utsname.sysname,
system_utsname.nodename,
system_utsname.release,
system_utsname.version,
system_utsname.machine,
char *sysinfo_table[] = {
utsname()->sysname,
utsname()->nodename,
utsname()->release,
utsname()->version,
utsname()->machine,
"alpha", /* instruction set architecture */
"dummy", /* hardware serial number */
"dummy", /* hardware manufacturer */
Expand Down
27 changes: 16 additions & 11 deletions arch/i386/kernel/sys_i386.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ asmlinkage int sys_uname(struct old_utsname __user * name)
if (!name)
return -EFAULT;
down_read(&uts_sem);
err=copy_to_user(name, &system_utsname, sizeof (*name));
err = copy_to_user(name, utsname(), sizeof (*name));
up_read(&uts_sem);
return err?-EFAULT:0;
}
Expand All @@ -226,16 +226,21 @@ asmlinkage int sys_olduname(struct oldold_utsname __user * name)

down_read(&uts_sem);

error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
error |= __put_user(0,name->release+__OLD_UTS_LEN);
error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
error |= __put_user(0,name->version+__OLD_UTS_LEN);
error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
error |= __put_user(0,name->machine+__OLD_UTS_LEN);
error = __copy_to_user(&name->sysname, &utsname()->sysname,
__OLD_UTS_LEN);
error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
error |= __copy_to_user(&name->nodename, &utsname()->nodename,
__OLD_UTS_LEN);
error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
error |= __copy_to_user(&name->release, &utsname()->release,
__OLD_UTS_LEN);
error |= __put_user(0, name->release + __OLD_UTS_LEN);
error |= __copy_to_user(&name->version, &utsname()->version,
__OLD_UTS_LEN);
error |= __put_user(0, name->version + __OLD_UTS_LEN);
error |= __copy_to_user(&name->machine, &utsname()->machine,
__OLD_UTS_LEN);
error |= __put_user(0, name->machine + __OLD_UTS_LEN);

up_read(&uts_sem);

Expand Down
2 changes: 1 addition & 1 deletion arch/ia64/sn/kernel/sn2/sn_hwperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ static int sn_topology_show(struct seq_file *s, void *d)
"coherency_domain %d, "
"region_size %d\n",

partid, system_utsname.nodename,
partid, utsname()->nodename,
shubtype ? "shub2" : "shub1",
(u64)nasid_mask << nasid_shift, nasid_msb, nasid_shift,
system_size, sharing_size, coher, region_size);
Expand Down
2 changes: 1 addition & 1 deletion arch/m32r/kernel/sys_m32r.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ asmlinkage int sys_uname(struct old_utsname * name)
if (!name)
return -EFAULT;
down_read(&uts_sem);
err=copy_to_user(name, &system_utsname, sizeof (*name));
err = copy_to_user(name, utsname(), sizeof (*name));
up_read(&uts_sem);
return err?-EFAULT:0;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/mips/kernel/linux32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ asmlinkage long sys32_newuname(struct new_utsname __user * name)
int ret = 0;

down_read(&uts_sem);
if (copy_to_user(name,&system_utsname,sizeof *name))
if (copy_to_user(name, utsname(), sizeof *name))
ret = -EFAULT;
up_read(&uts_sem);

Expand Down
27 changes: 16 additions & 11 deletions arch/mips/kernel/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ asmlinkage int sys_execve(nabi_no_regargs struct pt_regs regs)
*/
asmlinkage int sys_uname(struct old_utsname __user * name)
{
if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
if (name && !copy_to_user(name, utsname(), sizeof (*name)))
return 0;
return -EFAULT;
}
Expand All @@ -248,16 +248,21 @@ asmlinkage int sys_olduname(struct oldold_utsname __user * name)
if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
return -EFAULT;

error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
error -= __put_user(0,name->release+__OLD_UTS_LEN);
error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
error -= __put_user(0,name->version+__OLD_UTS_LEN);
error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
error = __put_user(0,name->machine+__OLD_UTS_LEN);
error = __copy_to_user(&name->sysname, &utsname()->sysname,
__OLD_UTS_LEN);
error -= __put_user(0, name->sysname + __OLD_UTS_LEN);
error -= __copy_to_user(&name->nodename, &utsname()->nodename,
__OLD_UTS_LEN);
error -= __put_user(0, name->nodename + __OLD_UTS_LEN);
error -= __copy_to_user(&name->release, &utsname()->release,
__OLD_UTS_LEN);
error -= __put_user(0, name->release + __OLD_UTS_LEN);
error -= __copy_to_user(&name->version, &utsname()->version,
__OLD_UTS_LEN);
error -= __put_user(0, name->version + __OLD_UTS_LEN);
error -= __copy_to_user(&name->machine, &utsname()->machine,
__OLD_UTS_LEN);
error = __put_user(0, name->machine + __OLD_UTS_LEN);
error = error ? -EFAULT : 0;

return error;
Expand Down
12 changes: 6 additions & 6 deletions arch/mips/kernel/sysirix.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ asmlinkage int irix_getdomainname(char __user *name, int len)
down_read(&uts_sem);
if (len > __NEW_UTS_LEN)
len = __NEW_UTS_LEN;
err = copy_to_user(name, system_utsname.domainname, len) ? -EFAULT : 0;
err = copy_to_user(name, utsname()->domainname, len) ? -EFAULT : 0;
up_read(&uts_sem);

return err;
Expand Down Expand Up @@ -1127,11 +1127,11 @@ struct iuname {
asmlinkage int irix_uname(struct iuname __user *buf)
{
down_read(&uts_sem);
if (copy_from_user(system_utsname.sysname, buf->sysname, 65)
|| copy_from_user(system_utsname.nodename, buf->nodename, 65)
|| copy_from_user(system_utsname.release, buf->release, 65)
|| copy_from_user(system_utsname.version, buf->version, 65)
|| copy_from_user(system_utsname.machine, buf->machine, 65)) {
if (copy_from_user(utsname()->sysname, buf->sysname, 65)
|| copy_from_user(utsname()->nodename, buf->nodename, 65)
|| copy_from_user(utsname()->release, buf->release, 65)
|| copy_from_user(utsname()->version, buf->version, 65)
|| copy_from_user(utsname()->machine, buf->machine, 65)) {
return -EFAULT;
}
up_read(&uts_sem);
Expand Down
37 changes: 21 additions & 16 deletions arch/parisc/hpux/sys_hpux.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,21 @@ static int hpux_uname(struct hpux_utsname *name)

down_read(&uts_sem);

error = __copy_to_user(&name->sysname,&system_utsname.sysname,HPUX_UTSLEN-1);
error |= __put_user(0,name->sysname+HPUX_UTSLEN-1);
error |= __copy_to_user(&name->nodename,&system_utsname.nodename,HPUX_UTSLEN-1);
error |= __put_user(0,name->nodename+HPUX_UTSLEN-1);
error |= __copy_to_user(&name->release,&system_utsname.release,HPUX_UTSLEN-1);
error |= __put_user(0,name->release+HPUX_UTSLEN-1);
error |= __copy_to_user(&name->version,&system_utsname.version,HPUX_UTSLEN-1);
error |= __put_user(0,name->version+HPUX_UTSLEN-1);
error |= __copy_to_user(&name->machine,&system_utsname.machine,HPUX_UTSLEN-1);
error |= __put_user(0,name->machine+HPUX_UTSLEN-1);
error = __copy_to_user(&name->sysname, &utsname()->sysname,
HPUX_UTSLEN - 1);
error |= __put_user(0, name->sysname + HPUX_UTSLEN - 1);
error |= __copy_to_user(&name->nodename, &utsname()->nodename,
HPUX_UTSLEN - 1);
error |= __put_user(0, name->nodename + HPUX_UTSLEN - 1);
error |= __copy_to_user(&name->release, &utsname()->release,
HPUX_UTSLEN - 1);
error |= __put_user(0, name->release + HPUX_UTSLEN - 1);
error |= __copy_to_user(&name->version, &utsname()->version,
HPUX_UTSLEN - 1);
error |= __put_user(0, name->version + HPUX_UTSLEN - 1);
error |= __copy_to_user(&name->machine, &utsname()->machine,
HPUX_UTSLEN - 1);
error |= __put_user(0, name->machine + HPUX_UTSLEN - 1);

up_read(&uts_sem);

Expand Down Expand Up @@ -373,8 +378,8 @@ int hpux_utssys(char *ubuf, int n, int type)
/* TODO: print a warning about using this? */
down_write(&uts_sem);
error = -EFAULT;
if (!copy_from_user(system_utsname.sysname, ubuf, len)) {
system_utsname.sysname[len] = 0;
if (!copy_from_user(utsname()->sysname, ubuf, len)) {
utsname()->sysname[len] = 0;
error = 0;
}
up_write(&uts_sem);
Expand All @@ -400,8 +405,8 @@ int hpux_utssys(char *ubuf, int n, int type)
/* TODO: print a warning about this? */
down_write(&uts_sem);
error = -EFAULT;
if (!copy_from_user(system_utsname.release, ubuf, len)) {
system_utsname.release[len] = 0;
if (!copy_from_user(utsname()->release, ubuf, len)) {
utsname()->release[len] = 0;
error = 0;
}
up_write(&uts_sem);
Expand All @@ -422,13 +427,13 @@ int hpux_getdomainname(char *name, int len)

down_read(&uts_sem);

nlen = strlen(system_utsname.domainname) + 1;
nlen = strlen(utsname()->domainname) + 1;

if (nlen < len)
len = nlen;
if(len > __NEW_UTS_LEN)
goto done;
if(copy_to_user(name, system_utsname.domainname, len))
if(copy_to_user(name, utsname()->domainname, len))
goto done;
err = 0;
done:
Expand Down
14 changes: 7 additions & 7 deletions arch/powerpc/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ long ppc_newuname(struct new_utsname __user * name)
int err = 0;

down_read(&uts_sem);
if (copy_to_user(name, &system_utsname, sizeof(*name)))
if (copy_to_user(name, utsname(), sizeof(*name)))
err = -EFAULT;
up_read(&uts_sem);
if (!err)
Expand All @@ -273,7 +273,7 @@ int sys_uname(struct old_utsname __user *name)
int err = 0;

down_read(&uts_sem);
if (copy_to_user(name, &system_utsname, sizeof(*name)))
if (copy_to_user(name, utsname(), sizeof(*name)))
err = -EFAULT;
up_read(&uts_sem);
if (!err)
Expand All @@ -289,19 +289,19 @@ int sys_olduname(struct oldold_utsname __user *name)
return -EFAULT;

down_read(&uts_sem);
error = __copy_to_user(&name->sysname, &system_utsname.sysname,
error = __copy_to_user(&name->sysname, &utsname()->sysname,
__OLD_UTS_LEN);
error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
error |= __copy_to_user(&name->nodename, &system_utsname.nodename,
error |= __copy_to_user(&name->nodename, &utsname()->nodename,
__OLD_UTS_LEN);
error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
error |= __copy_to_user(&name->release, &system_utsname.release,
error |= __copy_to_user(&name->release, &utsname()->release,
__OLD_UTS_LEN);
error |= __put_user(0, name->release + __OLD_UTS_LEN);
error |= __copy_to_user(&name->version, &system_utsname.version,
error |= __copy_to_user(&name->version, &utsname()->version,
__OLD_UTS_LEN);
error |= __put_user(0, name->version + __OLD_UTS_LEN);
error |= __copy_to_user(&name->machine, &system_utsname.machine,
error |= __copy_to_user(&name->machine, &utsname()->machine,
__OLD_UTS_LEN);
error |= override_machine(name->machine);
up_read(&uts_sem);
Expand Down
2 changes: 1 addition & 1 deletion arch/sh/kernel/sys_sh.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ asmlinkage int sys_uname(struct old_utsname * name)
if (!name)
return -EFAULT;
down_read(&uts_sem);
err=copy_to_user(name, &system_utsname, sizeof (*name));
err = copy_to_user(name, utsname(), sizeof (*name));
up_read(&uts_sem);
return err?-EFAULT:0;
}
Expand Down
2 changes: 1 addition & 1 deletion arch/sh64/kernel/sys_sh64.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ asmlinkage int sys_uname(struct old_utsname * name)
if (!name)
return -EFAULT;
down_read(&uts_sem);
err=copy_to_user(name, &system_utsname, sizeof (*name));
err = copy_to_user(name, utsname(), sizeof (*name));
up_read(&uts_sem);
return err?-EFAULT:0;
}
4 changes: 2 additions & 2 deletions arch/sparc/kernel/sys_sparc.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,13 @@ asmlinkage int sys_getdomainname(char __user *name, int len)

down_read(&uts_sem);

nlen = strlen(system_utsname.domainname) + 1;
nlen = strlen(utsname()->domainname) + 1;
err = -EINVAL;
if (nlen > len)
goto out;

err = -EFAULT;
if (!copy_to_user(name, system_utsname.domainname, nlen))
if (!copy_to_user(name, utsname()->domainname, nlen))
err = 0;

out:
Expand Down
15 changes: 10 additions & 5 deletions arch/sparc/kernel/sys_sunos.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,18 @@ asmlinkage int sunos_uname(struct sunos_utsname __user *name)
{
int ret;
down_read(&uts_sem);
ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0], sizeof(name->sname) - 1);
ret = copy_to_user(&name->sname[0], &utsname()->sysname[0],
sizeof(name->sname) - 1);
if (!ret) {
ret |= __copy_to_user(&name->nname[0], &system_utsname.nodename[0], sizeof(name->nname) - 1);
ret |= __copy_to_user(&name->nname[0], &utsname()->nodename[0],
sizeof(name->nname) - 1);
ret |= __put_user('\0', &name->nname[8]);
ret |= __copy_to_user(&name->rel[0], &system_utsname.release[0], sizeof(name->rel) - 1);
ret |= __copy_to_user(&name->ver[0], &system_utsname.version[0], sizeof(name->ver) - 1);
ret |= __copy_to_user(&name->mach[0], &system_utsname.machine[0], sizeof(name->mach) - 1);
ret |= __copy_to_user(&name->rel[0], &utsname()->release[0],
sizeof(name->rel) - 1);
ret |= __copy_to_user(&name->ver[0], &utsname()->version[0],
sizeof(name->ver) - 1);
ret |= __copy_to_user(&name->mach[0], &utsname()->machine[0],
sizeof(name->mach) - 1);
}
up_read(&uts_sem);
return ret ? -EFAULT : 0;
Expand Down
4 changes: 2 additions & 2 deletions arch/sparc64/kernel/sys_sparc.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,13 +712,13 @@ asmlinkage long sys_getdomainname(char __user *name, int len)

down_read(&uts_sem);

nlen = strlen(system_utsname.domainname) + 1;
nlen = strlen(utsname()->domainname) + 1;
err = -EINVAL;
if (nlen > len)
goto out;

err = -EFAULT;
if (!copy_to_user(name, system_utsname.domainname, nlen))
if (!copy_to_user(name, utsname()->domainname, nlen))
err = 0;

out:
Expand Down
10 changes: 5 additions & 5 deletions arch/sparc64/kernel/sys_sunos32.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,16 @@ asmlinkage int sunos_uname(struct sunos_utsname __user *name)
int ret;

down_read(&uts_sem);
ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0],
ret = copy_to_user(&name->sname[0], &utsname()->sysname[0],
sizeof(name->sname) - 1);
ret |= copy_to_user(&name->nname[0], &system_utsname.nodename[0],
ret |= copy_to_user(&name->nname[0], &utsname()->nodename[0],
sizeof(name->nname) - 1);
ret |= put_user('\0', &name->nname[8]);
ret |= copy_to_user(&name->rel[0], &system_utsname.release[0],
ret |= copy_to_user(&name->rel[0], &utsname()->release[0],
sizeof(name->rel) - 1);
ret |= copy_to_user(&name->ver[0], &system_utsname.version[0],
ret |= copy_to_user(&name->ver[0], &utsname()->version[0],
sizeof(name->ver) - 1);
ret |= copy_to_user(&name->mach[0], &system_utsname.machine[0],
ret |= copy_to_user(&name->mach[0], &utsname()->machine[0],
sizeof(name->mach) - 1);
up_read(&uts_sem);
return (ret ? -EFAULT : 0);
Expand Down
Loading

0 comments on commit e9ff399

Please sign in to comment.