Linux MIPS Architecture development
 help / color / mirror / Atom feed
* mprotect(PROT_NONE) doesn't prevent reading/writing on 2.6.14 Au1550
@ 2005-12-12 21:34 Clem Taylor
  2005-12-13  4:52 ` Pete Popov
  0 siblings, 1 reply; 2+ messages in thread
From: Clem Taylor @ 2005-12-12 21:34 UTC (permalink / raw)
  To: linux-mips

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

Hi,

It seems that mprotect(PROT_NONE) isn't actually doing anything on my
2.6.14 au1550 system.

Attached is a simple test that allocates 64K (64K aligned),
reads/writes the buffer, mprotect(PROT_NONE) the buffer and then
attempts to read and write to the buffer a second time. I expected
that writing to a PROT_NONE page would result in a segfault, but on
the Au1550 the program runs without faulting. Running the same code on
x86 (2.6.13) segfaults as expected.

Is there some reason why mprotect() wouldn't work on the Au1550, or is
this a bug?

                                         Thanks,
                                         Clem Taylor

[-- Attachment #2: mprotectTest.c --]
[-- Type: text/x-csrc, Size: 1124 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/mman.h>
#include <string.h>
#include <errno.h>

int main ( int argc, char *argv [ ] )
{
    int size = 65536, i, ret;
    unsigned char *buffer;

    /* allocate 64K, 64K aligned */
    buffer = memalign ( size, size );
    if ( buffer == NULL )
    {
        fprintf ( stderr, "memalign() failed.\n" );
        return 1;
    }

    fprintf ( stderr, "buffer=%p size=%d\n", buffer, size );

    /* write and read buffer */
    memset ( buffer, 0xAA, size );
    for ( i = 0; i < 2; i++ )
        fprintf ( stderr, "buffer [ %d ] = 0x%02X\n", i, buffer [ i ] );

    /* disable reading and writing */
    ret = mprotect ( buffer, size, PROT_NONE );
    if ( ret != 0 )
    {
        fprintf ( stderr, "mprotect(%p,%d,PROT_NONE) failed: %s\n",
            buffer, size, strerror ( errno ) );
        return 1;
    }

    /* write buffer, should segfault */
    memset ( buffer, 0x55, size );

    /* read buffer, should segfault */
    for ( i = 0; i < 2; i++ )
        fprintf ( stderr, "buffer [ %d ] = 0x%02X\n", i, buffer [ i ] );

    return 0;
}


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

* Re: mprotect(PROT_NONE) doesn't prevent reading/writing on 2.6.14 Au1550
  2005-12-12 21:34 mprotect(PROT_NONE) doesn't prevent reading/writing on 2.6.14 Au1550 Clem Taylor
@ 2005-12-13  4:52 ` Pete Popov
  0 siblings, 0 replies; 2+ messages in thread
From: Pete Popov @ 2005-12-13  4:52 UTC (permalink / raw)
  To: Clem Taylor; +Cc: 'linux-mips@linux-mips.org'

On Mon, 2005-12-12 at 16:34 -0500, Clem Taylor wrote:
> Hi,
> 
> It seems that mprotect(PROT_NONE) isn't actually doing anything on my
> 2.6.14 au1550 system.
> 
> Attached is a simple test that allocates 64K (64K aligned),
> reads/writes the buffer, mprotect(PROT_NONE) the buffer and then
> attempts to read and write to the buffer a second time. I expected
> that writing to a PROT_NONE page would result in a segfault, but on
> the Au1550 the program runs without faulting. Running the same code on
> x86 (2.6.13) segfaults as expected.
> 
> Is there some reason why mprotect() wouldn't work on the Au1550, or is
> this a bug?

Do you have another MIPS system you can test this on?

Pete

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

end of thread, other threads:[~2005-12-13  4:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-12-12 21:34 mprotect(PROT_NONE) doesn't prevent reading/writing on 2.6.14 Au1550 Clem Taylor
2005-12-13  4:52 ` Pete Popov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox