Re: TASK_SIZE related query.

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

 



On Wed, Mar 31, 2004 at 12:04:05 +0530, Amith wrote:
> hi all,
> 
> this code is from namei.c -> do_getname which is called from getname()
> --> which is from sys_open()..
> 
> static inline int do_getname(const char *filename, char *page)
> {
>  int retval;
>  unsigned long len = PATH_MAX;
> 
>  if ((unsigned long) filename >= TASK_SIZE) {
>   if (!segment_eq(get_fs(), KERNEL_DS))
>    return -EFAULT;
> 
> Here , TASK_SIZE has been #defined as :
> 
> #define TASK_SIZE            (PAGE_OFFSET)
> 
> and PAGE_OFFSET as :
> 
> #define PAGE_OFFSET      ((unsigned long)__PAGE_OFFSET)
> 
> /*
>  * A __PAGE_OFFSET of 0xC0000000 means that the kernel has
>  * a virtual address space of one gigabyte, which limits the
>  * amount of physical memory you can use to about 950MB.
>  *
>   */
> 
> #define __PAGE_OFFSET  (0xC0000000)
> 
> Now, refering to the code above :
> if ((unsigned long) filename >= TASK_SIZE)
> 
> why is this if() for ?
> and why is it checking  filename >= TASK_SIZE  ?
> 
> i beleive filename is still in userspace right ?  is it checking for the
> same ?
> and also please explain what this TASK_SIZE stands for - i'am confused.

For speed reasons, kernel is mapped in each processes memory above the
TASK_SIZE, protected from access (requires privilege level 0 to access).

Now since the syscall is running with CPL 0, it can access that memory.
So it checks that the address is in the valid range.

But sometimes it's reasonable to do syscalls from kernel. That's what
the segment_eq is for.

Note: I think, that the check should actualy be:
if((unsigned long)filename + len >= TASK_SIZE)

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

Attachment: signature.asc
Description: Digital 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