All of lore.kernel.org
 help / color / mirror / Atom feed
* regarding mprotect() implementation in 2.6.26 kernel
       [not found] <9debc4410807310315n4da5beafh853a71f532420e9a@mail.gmail.com>
@ 2008-07-31 10:24 ` Maxin John
  2008-07-31 15:09   ` Jeremy Fitzhardinge
  0 siblings, 1 reply; 6+ messages in thread
From: Maxin John @ 2008-07-31 10:24 UTC (permalink / raw)
  To: linux-kernel

Dear Christoph Hellwig,

( I guess you are the right person to ask this question ?)

The POSIX.2 specification of mprotect() says:

errorno should be set as ENOMEM if the addresses in the range [addr,
(addr + len)] are invalid for the address space of a process, or
specify one or more pages which are not mapped.

However, in the mprotect implementation  (asmlinkage long
sys_mprotect(unsigned long start, size_t len, unsigned long prot)) in
linux/mm/mprotect.c file, if we call mprotect() with start as NULL and
len as 0, mprotect() returns 0 and it is not setting the errono.The
following code confirms this behaviour.


*********** mprotect check code ********************

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/mman.h>

int main()
{

       int fd, ret;
       char *address;
       errno = 0;

       fd = open("./mmap_file", O_CREAT | O_RDWR, 766);
       address = (char *) mmap(0, 100, PROT_READ, MAP_SHARED, fd, 0);

       /* address argument is NULL and length argument is 0 */

       if ((ret = mprotect(NULL, 0, PROT_READ)) == -1) {
               printf("%s Error \n", strerror(errno));
               printf("mprotect functionality is correct.\n");
       } else {
               printf("mprotect functionality needs to be verified \n");
               exit(EXIT_FAILURE);
       }
       close(fd);
       return 0;
}

*********** mprotect check code ********************

Is there a reason to return 0 when the len is 0 and start is NULL ? Is
it intentional ? If not, it should be fixed.

Cheers,

Maxin B. John
Bangalore, India

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

* Re: regarding mprotect() implementation in 2.6.26 kernel
  2008-07-31 10:24 ` regarding mprotect() implementation in 2.6.26 kernel Maxin John
@ 2008-07-31 15:09   ` Jeremy Fitzhardinge
  2008-08-04 10:19     ` Maxin John
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremy Fitzhardinge @ 2008-07-31 15:09 UTC (permalink / raw)
  To: Maxin John; +Cc: linux-kernel

Maxin John wrote:
> Dear Christoph Hellwig,
>
> ( I guess you are the right person to ask this question ?)
>
> The POSIX.2 specification of mprotect() says:
>
> errorno should be set as ENOMEM if the addresses in the range [addr,
> (addr + len)] are invalid for the address space of a process, or
> specify one or more pages which are not mapped.
>
> However, in the mprotect implementation  (asmlinkage long
> sys_mprotect(unsigned long start, size_t len, unsigned long prot)) in
> linux/mm/mprotect.c file, if we call mprotect() with start as NULL and
> len as 0, mprotect() returns 0 and it is not setting the errono.The
> following code confirms this behaviour.
>   

Address 0 is a valid process address.  And you've set the length to
zero, so you technically haven't referred to any memory at all, so it
doesn't matter what the address is.

    J

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

* Re: regarding mprotect() implementation in 2.6.26 kernel
  2008-07-31 15:09   ` Jeremy Fitzhardinge
@ 2008-08-04 10:19     ` Maxin John
  2008-08-04 10:34       ` Michael Kerrisk
  0 siblings, 1 reply; 6+ messages in thread
From: Maxin John @ 2008-08-04 10:19 UTC (permalink / raw)
  To: Jeremy Fitzhardinge; +Cc: linux-kernel, ak, mtk.manpages, shields, hirofumi

Dear Jeremy,

              Thank you very much for the information and I am sorry
for my delayed reply.

        As per the patch created by Mr. hirofumi for the 2.5.26 kernel
which is described in
http://www.kernel.org/pub/linux/kernel/v2.5/ChangeLog-2.5.26 ,
and
http://linux.bkbits.net:8080/linux-2.6/?PAGE=gnupatch&REV=1.403.147.22
, the mprotect system call will set errno as ENOMEM instead of
EFAULT.

But the latest man page(man-pages-3.05) of mprotect still contains
information regarding EFAULT. The SuSv3 specification of mprotect also
doesn't say anything about EFAULT in the mprotect() details. The
following patch removes the information regarding EFAULT from the
mprotect man page.

diff -Naur man-pages-3.05/man2/mprotect.2
man-pages-3.05_modified/man2/mprotect.2
--- man-pages-3.05/man2/mprotect.2      2008-07-23 19:42:13.000000000 +0530
+++ man-pages-3.05_modified/man2/mprotect.2     2008-08-04
15:34:33.400869088 +0530
@@ -87,9 +87,6 @@
 to mark it
 .BR PROT_WRITE .
 .TP
-.B EFAULT
-The memory cannot be accessed.
-.TP
 .B EINVAL
 \fIaddr\fP is not a valid pointer,
 or not a multiple of the system page size.
~

  Please advise me if this information is irrelevant or wrong.

Thanks and Regards,

Maxin B. John
Bangalore, India.


On Thu, Jul 31, 2008 at 8:39 PM, Jeremy Fitzhardinge <jeremy@goop.org> wrote:
> Maxin John wrote:
>> Dear Christoph Hellwig,
>>
>> ( I guess you are the right person to ask this question ?)
>>
>> The POSIX.2 specification of mprotect() says:
>>
>> errorno should be set as ENOMEM if the addresses in the range [addr,
>> (addr + len)] are invalid for the address space of a process, or
>> specify one or more pages which are not mapped.
>>
>> However, in the mprotect implementation  (asmlinkage long
>> sys_mprotect(unsigned long start, size_t len, unsigned long prot)) in
>> linux/mm/mprotect.c file, if we call mprotect() with start as NULL and
>> len as 0, mprotect() returns 0 and it is not setting the errono.The
>> following code confirms this behaviour.
>>
>
> Address 0 is a valid process address.  And you've set the length to
> zero, so you technically haven't referred to any memory at all, so it
> doesn't matter what the address is.
>
>    J
>

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

* Re: regarding mprotect() implementation in 2.6.26 kernel
  2008-08-04 10:19     ` Maxin John
@ 2008-08-04 10:34       ` Michael Kerrisk
  2008-08-04 10:41         ` Michael Kerrisk
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Kerrisk @ 2008-08-04 10:34 UTC (permalink / raw)
  To: Maxin John
  Cc: Jeremy Fitzhardinge, linux-kernel, ak, mtk.manpages, shields,
	hirofumi

Hallo Maxin,

On Mon, Aug 4, 2008 at 12:19 PM, Maxin John <maxin.john@gmail.com> wrote:
> Dear Jeremy,
>
>              Thank you very much for the information and I am sorry
> for my delayed reply.
>
>        As per the patch created by Mr. hirofumi for the 2.5.26 kernel
> which is described in
> http://www.kernel.org/pub/linux/kernel/v2.5/ChangeLog-2.5.26 ,
> and
> http://linux.bkbits.net:8080/linux-2.6/?PAGE=gnupatch&REV=1.403.147.22
> , the mprotect system call will set errno as ENOMEM instead of
> EFAULT.
>
> But the latest man page(man-pages-3.05) of mprotect still contains
> information regarding EFAULT.

Yes, that text looks to be in error.

> The SuSv3 specification of mprotect also
> doesn't say anything about EFAULT in the mprotect() details. The
> following patch removes the information regarding EFAULT from the
> mprotect man page.

Before I apply this...  Did you check what was the situation in 2.4 kernels?

Cheers,

Michael


> diff -Naur man-pages-3.05/man2/mprotect.2
> man-pages-3.05_modified/man2/mprotect.2
> --- man-pages-3.05/man2/mprotect.2      2008-07-23 19:42:13.000000000 +0530
> +++ man-pages-3.05_modified/man2/mprotect.2     2008-08-04
> 15:34:33.400869088 +0530
> @@ -87,9 +87,6 @@
>  to mark it
>  .BR PROT_WRITE .
>  .TP
> -.B EFAULT
> -The memory cannot be accessed.
> -.TP
>  .B EINVAL
>  \fIaddr\fP is not a valid pointer,
>  or not a multiple of the system page size.
> ~
>
>  Please advise me if this information is irrelevant or wrong.
>
> Thanks and Regards,
>
> Maxin B. John
> Bangalore, India.
>
>
> On Thu, Jul 31, 2008 at 8:39 PM, Jeremy Fitzhardinge <jeremy@goop.org> wrote:
>> Maxin John wrote:
>>> Dear Christoph Hellwig,
>>>
>>> ( I guess you are the right person to ask this question ?)
>>>
>>> The POSIX.2 specification of mprotect() says:
>>>
>>> errorno should be set as ENOMEM if the addresses in the range [addr,
>>> (addr + len)] are invalid for the address space of a process, or
>>> specify one or more pages which are not mapped.
>>>
>>> However, in the mprotect implementation  (asmlinkage long
>>> sys_mprotect(unsigned long start, size_t len, unsigned long prot)) in
>>> linux/mm/mprotect.c file, if we call mprotect() with start as NULL and
>>> len as 0, mprotect() returns 0 and it is not setting the errono.The
>>> following code confirms this behaviour.
>>>
>>
>> Address 0 is a valid process address.  And you've set the length to
>> zero, so you technically haven't referred to any memory at all, so it
>> doesn't matter what the address is.
>>
>>    J
>>
>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html

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

* Re: regarding mprotect() implementation in 2.6.26 kernel
  2008-08-04 10:34       ` Michael Kerrisk
@ 2008-08-04 10:41         ` Michael Kerrisk
  2008-08-04 11:18           ` Maxin John
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Kerrisk @ 2008-08-04 10:41 UTC (permalink / raw)
  To: Maxin John
  Cc: Jeremy Fitzhardinge, linux-kernel, ak, mtk.manpages, shields,
	hirofumi

On Mon, Aug 4, 2008 at 12:34 PM, Michael Kerrisk
<mtk.manpages@googlemail.com> wrote:
> Hallo Maxin,
>
> On Mon, Aug 4, 2008 at 12:19 PM, Maxin John <maxin.john@gmail.com> wrote:
>> Dear Jeremy,
>>
>>              Thank you very much for the information and I am sorry
>> for my delayed reply.
>>
>>        As per the patch created by Mr. hirofumi for the 2.5.26 kernel
>> which is described in
>> http://www.kernel.org/pub/linux/kernel/v2.5/ChangeLog-2.5.26 ,
>> and
>> http://linux.bkbits.net:8080/linux-2.6/?PAGE=gnupatch&REV=1.403.147.22
>> , the mprotect system call will set errno as ENOMEM instead of
>> EFAULT.
>>
>> But the latest man page(man-pages-3.05) of mprotect still contains
>> information regarding EFAULT.
>
> Yes, that text looks to be in error.
>
>> The SuSv3 specification of mprotect also
>> doesn't say anything about EFAULT in the mprotect() details. The
>> following patch removes the information regarding EFAULT from the
>> mprotect man page.
>
> Before I apply this...  Did you check what was the situation in 2.4 kernels?

So, after a quick search, it looks as though in kernels before 2.4.19,
the EFAULT error resulted instead of ENOMEM for this case.  Does that
sound right to you?

Cheers,

Michael

>> diff -Naur man-pages-3.05/man2/mprotect.2
>> man-pages-3.05_modified/man2/mprotect.2
>> --- man-pages-3.05/man2/mprotect.2      2008-07-23 19:42:13.000000000 +0530
>> +++ man-pages-3.05_modified/man2/mprotect.2     2008-08-04
>> 15:34:33.400869088 +0530
>> @@ -87,9 +87,6 @@
>>  to mark it
>>  .BR PROT_WRITE .
>>  .TP
>> -.B EFAULT
>> -The memory cannot be accessed.
>> -.TP
>>  .B EINVAL
>>  \fIaddr\fP is not a valid pointer,
>>  or not a multiple of the system page size.
>> ~
>>
>>  Please advise me if this information is irrelevant or wrong.
>>
>> Thanks and Regards,
>>
>> Maxin B. John
>> Bangalore, India.
>>
>>
>> On Thu, Jul 31, 2008 at 8:39 PM, Jeremy Fitzhardinge <jeremy@goop.org> wrote:
>>> Maxin John wrote:
>>>> Dear Christoph Hellwig,
>>>>
>>>> ( I guess you are the right person to ask this question ?)
>>>>
>>>> The POSIX.2 specification of mprotect() says:
>>>>
>>>> errorno should be set as ENOMEM if the addresses in the range [addr,
>>>> (addr + len)] are invalid for the address space of a process, or
>>>> specify one or more pages which are not mapped.
>>>>
>>>> However, in the mprotect implementation  (asmlinkage long
>>>> sys_mprotect(unsigned long start, size_t len, unsigned long prot)) in
>>>> linux/mm/mprotect.c file, if we call mprotect() with start as NULL and
>>>> len as 0, mprotect() returns 0 and it is not setting the errono.The
>>>> following code confirms this behaviour.
>>>>
>>>
>>> Address 0 is a valid process address.  And you've set the length to
>>> zero, so you technically haven't referred to any memory at all, so it
>>> doesn't matter what the address is.
>>>
>>>    J
>>>
>>
>
>
>
> --
> Michael Kerrisk
> Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
> man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
> Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html
>



-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
man-pages online: http://www.kernel.org/doc/man-pages/online_pages.html
Found a bug? http://www.kernel.org/doc/man-pages/reporting_bugs.html

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

* Re: regarding mprotect() implementation in 2.6.26 kernel
  2008-08-04 10:41         ` Michael Kerrisk
@ 2008-08-04 11:18           ` Maxin John
  0 siblings, 0 replies; 6+ messages in thread
From: Maxin John @ 2008-08-04 11:18 UTC (permalink / raw)
  To: Michael Kerrisk
  Cc: Jeremy Fitzhardinge, linux-kernel, ak, mtk.manpages, shields,
	hirofumi

Dear Michael,


> So, after a quick search, it looks as though in kernels before 2.4.19,
> the EFAULT error resulted instead of ENOMEM for this case.  Does that
> sound right to you?

 Yes, I do agree with you. After Linux Kernel version 2.4.19 , the
ENOMEM error resulted instead of EFAULT in the mprotect().

Regards,

Maxin B. John
Bangalore, India

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

end of thread, other threads:[~2008-08-04 11:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <9debc4410807310315n4da5beafh853a71f532420e9a@mail.gmail.com>
2008-07-31 10:24 ` regarding mprotect() implementation in 2.6.26 kernel Maxin John
2008-07-31 15:09   ` Jeremy Fitzhardinge
2008-08-04 10:19     ` Maxin John
2008-08-04 10:34       ` Michael Kerrisk
2008-08-04 10:41         ` Michael Kerrisk
2008-08-04 11:18           ` Maxin John

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.