From: Kyle Moffett <mrmacman_g4@mac.com>
To: "Vincent W. Freeh" <vin@csc.ncsu.edu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Understanding Linux addr space, malloc, and heap
Date: Fri, 21 Oct 2005 11:52:45 -0400 [thread overview]
Message-ID: <C6F7B216-66B3-4848-9423-05AB4D826320@mac.com> (raw)
In-Reply-To: <43590B23.2090101@csc.ncsu.edu>
On Oct 21, 2005, at 11:37:07, Vincent W. Freeh wrote:
> The point of the code is to show that one can protect malloc code.
You may be able to protect malloced memory, but it's not reliable, it
doesn't follow the standard, and if it breaks you get to keep both
pieces. You tried to protect malloced memory, it wasn't reliable, it
didn't follow the standard, therefore you get to keep both pieces.
> But I can't mprotect the 66th page I malloc. And mprotect fails
> SILENTLY!
You must understand that malloc does not necessarily return a
_page_. It returns a random hunk of memory aligned to a 16 byte
boundary, which is *not* the same as aligned to a page boundary
(usually 4096 bytes). Your code is buggy:
>>> mprotect((void*)((unsigned)p & ~(pgsize-1)), 1024, PROT_NONE);
You malloced 1024 bytes (1024 != page size (usually 4096)). You then
round down to a multiple of a page size, and mprotect that page
(since you used a size < 1 page, it rounds up to a page). If malloc
returns an offset 4080 bytes into a page (aligned on a 16-byte
boundary), and you round down and protect that page, then only the
first 16 bytes of the memory you got will be protected.
You *cannot* reliably expect to mprotect() the results of malloc().
If you want to mprotect() things, you _must_ do it on mmap()ed memory.
Cheers,
Kyle Moffett
--
Somone asked me why I work on this free (http://www.fsf.org/
philosophy/) software stuff and not get a real job. Charles Shultz
had the best answer:
"Why do musicians compose symphonies and poets write poems? They do
it because life wouldn't have any meaning for them if they didn't.
That's why I draw cartoons. It's my life."
-- Charles Shultz
next prev parent reply other threads:[~2005-10-21 15:52 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-21 13:45 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 [this message]
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
[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=C6F7B216-66B3-4848-9423-05AB4D826320@mac.com \
--to=mrmacman_g4@mac.com \
--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
all inboxes | Powered by JetHome®