mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Valdis.Kletnieks@vt.edu
To: evilsocket <evilsocket@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Stack buffer size issue
Date: Thu, 18 Sep 2008 13:36:28 -0400	[thread overview]
Message-ID: <21780.1221759388@turing-police.cc.vt.edu> (raw)
In-Reply-To: Your message of "Thu, 18 Sep 2008 14:30:12 +0200." <48D249D4.8000400@gmail.com>

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

On Thu, 18 Sep 2008 14:30:12 +0200, evilsocket said:

> char * abuffer[123];

Note that this '123' isn't anything that's known to the kernel, or passed to
it.

> This *should* give the output :
> 
> SIZE : 123

Why "should' it do so?  The kernel doesn't know or care much about what your
stack layout is, except if you overflow the provided space.

Minor nit:  'char *abuffer[123];' allocates an array of 123 pointers-to-ints,
which means it's actually 123*4 or 123*8 bytes in size, depending on the size
of a pointer (different for 32 and 64 bit programs).  So if you got 123 as
an answer, that would *still* be wrong...

> I'm using the struct task_struct in the kernel module, looping the mmap 
> to find the vm area the address resides in and then to set
> 
> mm_size = vm_end - vm_start

Right.  That's the size of the mm you're looking at. There isn't one mm
for each variable in your program.

> But doing so i obtaing only the size of the vm page the buffer resides .

That's probably because the struct mm that covers your program stack is only
one page in size.

Do a 'cat /proc/self/maps', which will show the maps in use for the /bin/cat
process, and ponder why there's a lot fewer lines than /bin/cat has variables.

[-- Attachment #2: Type: application/pgp-signature, Size: 226 bytes --]

      reply	other threads:[~2008-09-18 17:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-18 12:30 evilsocket
2008-09-18 17:36 ` Valdis.Kletnieks [this message]

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=21780.1221759388@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=evilsocket@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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®