The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Paulo Marques <pmarques@grupopie.com>
To: Arjan van de Ven <arjan@infradead.org>
Cc: Alex Bligh - linux-kernel <linux-kernel@alex.org.uk>,
	"Vincent W. Freeh" <vin@csc.ncsu.edu>,
	linux-kernel@vger.kernel.org
Subject: Re: Understanding Linux addr space, malloc, and heap
Date: Fri, 21 Oct 2005 16:58:46 +0100	[thread overview]
Message-ID: <43591036.6000702@grupopie.com> (raw)
In-Reply-To: <1129909657.2786.25.camel@laptopd505.fenrus.org>

Arjan van de Ven wrote:
> On Fri, 2005-10-21 at 16:37 +0100, Alex Bligh - linux-kernel wrote:
> 
>>--On 21 October 2005 17:22 +0200 Arjan van de Ven <arjan@infradead.org> 
>>wrote:
>>
>>
>>>Ok I meant in the "while adhering to the standard" :)
>>
>>More precisely, as per the man page:
>>
>>>POSIX.1b says that mprotect can be used only on regions of memory
>>>obtained from mmap(2).
>>
>>But what is interesting (if anything) is this:
>>
>>>ERRORS
>>>       EINVAL addr is not a valid pointer, or not a  multiple  of
>>>       PAGESIZE.
>>
>>So if he calls mprotect with memory allocated by malloc (which should
>>fail), why doesn't he get EINVAL? He says it returns 0 (meaning it
>>succeeded). Which it shouldn't (unless he is stupendously lucky in
>>malloc's allocation, in which case it should work).
> 
> 
> it succeeds all right; it just does other things than you expect
> perhaps ;)
> 
> your alignment code had a bug, so it would align potentially to the
> wrong piece of memory

Actually, it should give a SIGSEGV for the first byte allocated, 
although I agree that it might not work for any other byte allocated in 
the case where malloc returns a pointer just at the end of a page.

I just tested the sample code and in fact I do get a SIGSEGV.

What kernel version / architecture are you testing this on?

-- 
Paulo Marques
Software Development Department - Grupo PIE, S.A.
Phone: +351 252 290600, Fax: +351 252 290601
Web: www.grupopie.com

The rule is perfect: in all matters of opinion our
adversaries are insane.
Mark Twain

  reply	other threads:[~2005-10-21 15:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-21 13:45 Understanding Linux addr space, malloc, and heap Vincent W. Freeh
2005-10-21 14:03 ` Arjan van de Ven
2005-10-21 15:11   ` Vincent W. Freeh
2005-10-21 15:20     ` Anton Altaparmakov
2005-10-21 15:21     ` Paulo Marques
2005-10-21 15:22     ` Arjan van de Ven
2005-10-21 15:37       ` Vincent W. Freeh
2005-10-21 15:48         ` Arjan van de Ven
2005-10-21 16:04           ` Vincent W. Freeh
2005-10-21 16:23             ` Arjan van de Ven
2005-10-21 15:52         ` Kyle Moffett
2005-10-21 16:10           ` Vincent W. Freeh
2005-10-21 16:19             ` Theodore Ts'o
2005-10-21 16:26             ` Paulo Marques
2005-10-21 16:14         ` Andreas Schwab
2005-10-21 16:24           ` Vincent W. Freeh
2005-10-22 19:27             ` Kyle Moffett
2005-10-21 15:37       ` Alex Bligh - linux-kernel
2005-10-21 15:47         ` Arjan van de Ven
2005-10-21 15:58           ` Paulo Marques [this message]
     [not found] <505ru-8qi-1@gated-at.bofh.it>
     [not found] ` <505Lp-B4-81@gated-at.bofh.it>
     [not found]   ` <506QZ-2cH-3@gated-at.bofh.it>
     [not found]     ` <5070Y-2qP-23@gated-at.bofh.it>
     [not found]       ` <507ac-2Cm-25@gated-at.bofh.it>
     [not found]         ` <507NL-3Em-29@gated-at.bofh.it>
     [not found]           ` <507Xd-3QT-19@gated-at.bofh.it>
     [not found]             ` <50xnU-7s2-37@gated-at.bofh.it>
2005-10-23 10:41               ` Bodo Eggert
2005-10-23 10:44                 ` Arjan van de Ven
2005-10-23 21:29                   ` Kyle Moffett
  -- strict thread matches above, loose matches on Subject: below --
2005-10-21 12:46 Vincent W. Freeh
2005-10-21 13:00 ` Arjan van de Ven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=43591036.6000702@grupopie.com \
    --to=pmarques@grupopie.com \
    --cc=arjan@infradead.org \
    --cc=linux-kernel@alex.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vin@csc.ncsu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox