Ya, I got the reason for hostname getting reset to NULL. But this is not happening in some old version of kernel (2.4.2), in which memset() is not called in the "else" part. I am trying to figure out which patch/problem caused these changes. Thanks, Suresh. -----Original Message----- From: Angelo Dell'Aera [mailto:buffer@users.sourceforge.net] Sent: Friday, October 11, 2002 9:20 PM To: suresh.babu@wipro.com Cc: Kernelnewbies Subject: Re: Problem with sethostname() ? On Fri, 11 Oct 2002 13:53:01 +0530 "Suresh babu V." <suresh.babu@wipro.com> wrote: >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. [..] > 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. Please look at copy_from_user() code. #define copy_from_user(to,from,n) \ (__builtin_constant_p(n) ? \ __constant_copy_from_user((to),(from),(n)) : \ __generic_copy_from_user((to),(from),(n))) static inline unsigned long __constant_copy_from_user(void *to, const void *from, unsigned long n) { if (access_ok(VERIFY_READ, from, n)) __constant_copy_user_zeroing(to,from,n); else memset(to, 0, n); return n; } 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; } So, when in your code example, copy_from_user() fails (returning n) errno was previously set to -EFAULT in sys_sethostname() as you saw but memset was invoked so setting hostname to NULL. Regards, Angelo Dell'Aera 'buffer' <buffer@users.sourceforge.net> PGP information in e-mail header
**************************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. ****************************************************************************************