From: Geoff Thorpe <geoff@geoffthorpe.net>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [uml-devel] Little heap overflow in mconsole_kern.c
Date: Wed, 17 Sep 2003 22:53:58 -0400 [thread overview]
Message-ID: <200309172253.58265.geoff@geoffthorpe.net> (raw)
In-Reply-To: <200309180022.h8I0MVNu021681@ccure.karaya.com>
On September 17, 2003 08:22 pm, Jeff Dike wrote:
> blaisorblade_spam@yahoo.it said:
> > While new points to a mconsole_entry, the code allocates
> > sizeof(mc_request), not sizeof(mconsole_entry)
>
> Gawd, someone really needs to shoot me before I destroy something...
Don't feel bad, I've come down with this bug a few times.
> BTW, It would be a good exercise for someone to go through the code and
> replace instances of
> foo = kmalloc(sizeof(type-name), ...)
> with
> foo = kmalloc(sizeof(*foo), ...)
>
> That would have prevented this bug.
FWIW: after having this problem one too many times with malloc and
friends, I started using macros of the form;
#define MYMALLOC(t,n) (t *)malloc((n) * sizeof(t))
#define MYFREE(t,p) do { \
t *_tmp_4567 = (p); \
free(_tmp_4567); \
} while(0)
These get compiled down to malloc() and free(), respectively. However
MYMALLOC has the compilation-time advantage of being typesafe according
to the return value (not void*) and size (which matches the return type).
The free() variant may seem a bit overkill, but tastes vary. Anyway, if
you adopt something like this then you can consider any direct use of
'malloc' and 'free' in the source as bugs and your audit becomes quite a
bit easier. $0.02, etc.
Cheers,
Geoff
--
Geoff Thorpe
geoff@geoffthorpe.net
http://www.geoffthorpe.net/
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
prev parent reply other threads:[~2003-09-18 2:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-16 13:59 [uml-devel] Little heap overflow in mconsole_kern.c BlaisorBlade
2003-09-18 0:22 ` Jeff Dike
2003-09-18 2:53 ` Geoff Thorpe [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=200309172253.58265.geoff@geoffthorpe.net \
--to=geoff@geoffthorpe.net \
--cc=user-mode-linux-devel@lists.sourceforge.net \
/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