linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Problem with sethostname() ??
@ 2002-10-10  6:43 Suresh babu V.
  0 siblings, 0 replies; 2+ messages in thread
From: Suresh babu V. @ 2002-10-10  6:43 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1246 bytes --]

Hi,

	While attempting for some testing with sethostname() call, I got
this problem . As explained in the man page the sethostname call is
failing(ret val = -1 & errno = EFAULT(14)) for invalid address and valid
length. But the problem is after running the following test, hostname is
getting reset to NULL. I tested in both 2.4 & 2.5 kernels.

Any comments on this?? 

----------------------------------
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

main()
{
int ret, errno;
unsigned short int len;
char host[50]="tmphost"; /* hostname max size is 64 */
errno = 0;
len = sizeof(host); 

/* valid length and invalid address, expected err is EFAULT */
ret = sethostname((void *)-1, len);
printf("return val : %d, err no: %d \n",ret,errno);

} 
-------------------------------------------------

        I saw the code of sys_sethostname() function (sys.c) , in which
copy_from_user() is being called. I would like to know is it required to
validate the name argument before calling copy_from_user() to avoid such
problems.

        We could expect similar problem in setdomainname() also in which
same sort of code is used. 



PS : Please CC me your replies as I havn't subscribed to the list.
 
Thanks,
Suresh.


[-- Attachment #2: Wipro_Disclaimer.txt --]
[-- Type: text/plain, Size: 522 bytes --]

**************************Disclaimer**************************************************    
 
 Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' 
and 'confidential' and intended for use only by the individual or entity to which it is 
addressed. You are notified that any use, copying or dissemination of the information 
contained in the E-MAIL in any manner whatsoever is strictly prohibited.

****************************************************************************************

^ permalink raw reply	[flat|nested] 2+ messages in thread

* re: Problem with sethostname() ??
@ 2002-10-10 10:30 Saji Kumar VR
  0 siblings, 0 replies; 2+ messages in thread
From: Saji Kumar VR @ 2002-10-10 10:30 UTC (permalink / raw)
  To: Linux-Kernel@Vger. Kernel. Org; +Cc: Saji Kumar VR

[-- Attachment #1: Type: text/plain, Size: 2429 bytes --]


-----Original Message-----
From: saji kumar [mailto:saji.kumar@wipro.com]
Sent: Thursday, October 10, 2002 3:39 PM
To: suresh.babu@wipro.com; linux-kernel@vger.kernel.org
Cc: Kiran Vijayakumar
Subject: RE: Problem with sethostname() ??


Hi,

 If U see the code for __generic_copy_from_user() in
arch/i386/lib/usercopy.c ( from my understanding copy_from_user() boils down
to this function),

 unsigned long
__generic_copy_from_user(void *to, const void *from, unsigned long n)
{
        prefetchw(to);
        if (access_ok(VERIFY_READ, from, n))
                __copy_user_zeroing(to,from,n);
        else
                memset(to, 0, n);
        return n;
}

here, if access_ok() fails, which is the case here (when an invalid from
address is given), it memsets() the "to" address to zero,
which is the reason for the hostname being reset to NULL (please correct me
if I am wrong somewhere)

I ran this program on 2.5 kernel with the memset() removed, & it gave no
problem..

Can anyone please explain, why do we need to reset the "to" address ?

Rgds,
Saji
-----Original Message-----
From: Suresh babu V. [mailto:suresh.babu@wipro.com]
Sent: Thursday, October 10, 2002 10:48 AM
To: linux-kernel@vger.kernel.org
Cc: 'Saji Kumar VR'
Subject: Problem with sethostname() ??


Hi,
        While attempting for some testing with sethostname() call, I got
this problem . As explained in the man page the sethostname call is
failing(ret val = -1 & errno = EFAULT(14)) for invalid address and valid
length. But the problem is after running the following test, hostname is
getting reset to NULL. I tested in both 2.4 & 2.5 kernels.
Any comments on this??
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

main()
{
int ret, errno;
unsigned short int len;
char host[50]="tmphost"; /* hostname max size is 64 */
errno = 0;
len = sizeof(host);
/* valid length and invalid address, expected err is EFAULT */
ret = sethostname((void *)-1, len);
printf("return val : %d, err no: %d \n",ret,errno);
}
        I saw the code of sys_sethostname() function (sys.c) , in which
copy_from_user() is being called. I would like to know is it required to
validate the name argument before calling copy_from_user() to avoid such
problems.
        We can expect similar problem in setdomainname() also in which same
sort of code is used.
PS : Please CC me your replies as I havn't subscribed to the list.
Thanks,
Suresh.


[-- Attachment #2: Wipro_Disclaimer.txt --]
[-- Type: text/plain, Size: 522 bytes --]

**************************Disclaimer**************************************************    
 
 Information contained in this E-MAIL being proprietary to Wipro Limited is 'privileged' 
and 'confidential' and intended for use only by the individual or entity to which it is 
addressed. You are notified that any use, copying or dissemination of the information 
contained in the E-MAIL in any manner whatsoever is strictly prohibited.

****************************************************************************************

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-10-10 10:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-10  6:43 Problem with sethostname() ?? Suresh babu V.
2002-10-10 10:30 Saji Kumar VR

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).