Re: Problem with sethostname() ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Attachment: pgp00173.pgp
Description: PGP signature


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux