redundant checks in getdomainname
RFC 1/1 redundant checks in getdomainname
Whilst looking at uses of __NEW_UTS_LEN in the kernel I spotted that sparc and sparc64 architectures have their own implementation of the getdomainname system call. Looking at these it appears there is a redundant check against __NEW_UTS_LEN in each.
We first bound the users buffer length by the current length of the domainname uts member. This element by definition cannot be longer than __NEW_UTS_LEN, so the following check can never trigger.
asmlinkage int sys_getdomainname(char __user *name, int len) {
[...]
nlen = strlen(system_utsname.domainname) + 1;
if (nlen < len)
len = nlen;
if (len > __NEW_UTS_LEN)
goto done;[...]
}
Attached is a patch to remove this check from both sparc and sparc64 architectures. As I do not have the said hardware I have been unable to test it.
Also can anyone tell me why these architectures have this call, the generic code implies that uname can be used to fetch this information and does not therefore supply an implmentation.
-apw
== 8< =The sparc/sparc64 architectures seem to have implmentations of the sys_getdomainname system call. The both seem to contain a redundant check for len > __NEW_UTS_LEN which firstly should be reasonable as it is allowable to pass an oversized buffer to this call and secondly can never trigger as it will have been rounded down to the current length of this field which must be less than this limit.
--- sparc/kernel/sys_sparc.c | 2 -- sparc64/kernel/sys_sparc.c | 2 -- 2 files changed, 4 deletions(-)
arch/sparc/kernel/sys_sparc.c +0 -2
@@ -471,8 +471,6 @@ asmlinkage int sys_getdomainname(char __if (nlen < len) len = nlen; -if (len > __NEW_UTS_LEN) - goto done;if (copy_to_user (name, system_utsname.domainname, len)) goto done; err =0 ;
arch/sparc64/kernel/sys_sparc.c +0 -2
@@ -463,8 +463,6 @@ asmlinkage int sys_getdomainname(char __if (nlen < len) len = nlen; -if (len > __NEW_UTS_LEN) - goto done;if (copy_to_user (name, system_utsname.domainname, len)) goto done; err =0 ;
Quoted 3 lines · Andy Whitcroft
We first bound the users buffer length by the current length of the domainname uts member. This element by definition cannot be longer than
__NEW_UTS_LEN, so the following check can never trigger.
Actually, if you look at this, the code handles one specific case:
len >= __NEW_UTS_LEN + 1
&& strlen(system_utsname.domainname) = __NEW_UTS_LEN
In this case, an error is returned, which seems wrong since the user has given us enough space to return the whole thing properly terminated.
So the check is not meaningless. I don't have access to the SunOS man pages, but I'd guess this behaviour has something to do with what it expects.
Quoted 3 lines
Also can anyone tell me why these architectures have this call, the generic code implies that uname can be used to fetch this information and does not therefore supply an implmentation.
SunOS compatibility.
Signature · 1 line
Keith M Wesolowski