From: Andy Walker Date: Mon, 18 Sep 2006 14:11:36 +0000 (-0700) Subject: [SPARC]: Fix regression in sys_getdomainname() X-Git-Tag: v2.6.18~12^2 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9c54f91a48146778fe91423d4d467a0ee8c719b;p=linux-2.6 [SPARC]: Fix regression in sys_getdomainname() This patch corrects the buffer length checking in the sys_getdomainname() implementation for sparc/sparc64. Signed-off-by: Andy Walker Signed-off-by: David S. Miller --- diff --git a/arch/sparc/kernel/sys_sparc.c b/arch/sparc/kernel/sys_sparc.c index 94ff58c9d4..896863fb20 100644 --- a/arch/sparc/kernel/sys_sparc.c +++ b/arch/sparc/kernel/sys_sparc.c @@ -470,19 +470,21 @@ asmlinkage int sys_getdomainname(char __user *name, int len) { int nlen, err; - if (len < 0 || len > __NEW_UTS_LEN) + if (len < 0) return -EINVAL; down_read(&uts_sem); nlen = strlen(system_utsname.domainname) + 1; - if (nlen < len) - len = nlen; + err = -EINVAL; + if (nlen > len) + goto out; err = -EFAULT; - if (!copy_to_user(name, system_utsname.domainname, len)) + if (!copy_to_user(name, system_utsname.domainname, nlen)) err = 0; +out: up_read(&uts_sem); return err; } diff --git a/arch/sparc64/kernel/sys_sparc.c b/arch/sparc64/kernel/sys_sparc.c index bf5f14ee73..c608c947e6 100644 --- a/arch/sparc64/kernel/sys_sparc.c +++ b/arch/sparc64/kernel/sys_sparc.c @@ -707,19 +707,21 @@ asmlinkage long sys_getdomainname(char __user *name, int len) { int nlen, err; - if (len < 0 || len > __NEW_UTS_LEN) + if (len < 0) return -EINVAL; down_read(&uts_sem); nlen = strlen(system_utsname.domainname) + 1; - if (nlen < len) - len = nlen; + err = -EINVAL; + if (nlen > len) + goto out; err = -EFAULT; - if (!copy_to_user(name, system_utsname.domainname, len)) + if (!copy_to_user(name, system_utsname.domainname, nlen)) err = 0; +out: up_read(&uts_sem); return err; }