From: malc <av1474@comtv.ru>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: Kevin Wolf <kwolf@redhat.com>, Paul Brook <paul@codesourcery.com>,
qemu-devel@nongnu.org,
Jean-Christophe Dubois <jcd@tribudubois.net>
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 15:24:33 +0400 (MSD) [thread overview]
Message-ID: <Pine.LNX.4.64.0905291506340.3744@linmac.oyster.ru> (raw)
In-Reply-To: <4A1FBEB2.2030009@codemonkey.ws>
On Fri, 29 May 2009, Anthony Liguori wrote:
> malc wrote:
> > On Fri, 29 May 2009, Anthony Liguori wrote:
> >
> >
> > Dereference of NULL is UB[1] and dereferencing result of malloc(1) will
> > just plain work.
> >
>
> So let's ignoring returning NULL as a possibility..
>
> >> Putting the abort() in there is going to introduce a ton of subtle bugs,
> >> I vote for changing qemu_malloc() to have a sane behavior.
> >>
> >
> > And those will be caught, given one a chance to analyze things, unlike
> > head in the sand approach of hoping things would just work.
> >
> > After doing some research, after the aforementioned lengthy discussion,
> > the only free OS that straight-forwardly described what it does was
> > OpenBSD:
> >
> > http://www.openbsd.org/cgi-bin/man.cgi?query=malloc&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
> >
> > P.S. So far the abort that went into qemu_malloc caught one usage of zero
> > allocation (once again coming from qcow2).'
> >
>
> But the zero allocation isn't a bug if we return malloc(1). This is a
> common convention and while it may not be portable to every platform's
> underlying malloc, we can make this convention portable with qemu_malloc().
Yes we can. I argue that this is not a good convention.
>
> At the end of the day, the result is a harder to misuse qemu_malloc()
> and that's a very good thing. I don't want a user to "discover" a
> non-portable use of malloc() while trying to do something important.
Options:
a. return NULL
b. return malloc(1)
c. abort
d. do what OpenBSD does
Pros/cons:
a. Pros: Simple to implement
Matches one of original malloc behaviours
Cons: Observable
Dereference == UB
Breaks the assumption that qemu_malloc should never return NULL
b. Pros: Simple to implement
Matches one of original malloc behaviours
Cons: Useless allocation
No guard against accidental dereferences
Might result in a return of a NULL
c. Pros: Simple to implement
Helps in finding call-sites
Cons: Doesn't match match the standard prescribed behaviours
Will abort the application even if the call-site is prepared
to cope with the fact that it requested zero bytes
d. Pros: Matches one of original malloc behaviours
Provides safety net against accidental dereferences
Cons: Not trivial to implement (and also complicates the whole family
qemu_realloc/qemu_free)
Doesn't help in identifying call-sites
In a nutshell what i argue is that, if someone doesn't need any memory
it shouldn't be asking for it, and it's not that unlikely that the
author never considered the possibility of his code requesting zero
bytes of memory, so in my view helping to locate all offenders and
auditing them is good enough reason for option c, that's why it's
there in repository.
--
mailto:av1474@comtv.ru
next prev parent reply other threads:[~2009-05-29 11:24 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-29 5:58 [Qemu-devel] [PATCH] use qemu_malloc and friends consistently Jean-Christophe Dubois
2009-05-29 8:42 ` Kevin Wolf
2009-05-29 9:05 ` Anthony Liguori
2009-05-29 9:51 ` malc
2009-05-29 10:05 ` Kevin Wolf
2009-05-29 10:23 ` malc
2009-05-29 10:34 ` Kevin Wolf
2009-05-29 10:40 ` malc
2009-05-29 10:49 ` Kevin Wolf
2009-05-29 10:56 ` Anthony Liguori
2009-05-29 11:06 ` malc
2009-05-29 11:14 ` Kevin Wolf
2009-05-29 10:53 ` Anthony Liguori
2009-05-29 11:24 ` malc [this message]
2009-05-29 12:36 ` Gerd Hoffmann
2009-05-29 13:07 ` Paul Brook
2009-05-29 13:46 ` Gerd Hoffmann
2009-05-29 13:59 ` Glauber Costa
2009-05-29 14:34 ` Anthony Liguori
2009-05-29 15:06 ` malc
2009-05-29 17:17 ` Julian Seward
2009-05-29 18:41 ` Gerd Hoffmann
2009-05-29 21:12 ` David Turner
2009-05-29 21:13 ` David Turner
2009-06-02 7:26 ` Gerd Hoffmann
2009-06-02 7:47 ` Anthony Liguori
2009-06-02 8:58 ` Daniel P. Berrange
2009-06-02 18:03 ` David Turner
2009-06-02 8:48 ` Avi Kivity
2009-06-02 18:02 ` David Turner
2009-06-02 18:13 ` Paul Brook
2009-06-02 19:49 ` David Turner
2009-06-02 20:04 ` Paul Brook
2009-06-02 20:42 ` David Turner
2009-06-02 20:45 ` Gerd Hoffmann
2009-06-02 20:48 ` Gerd Hoffmann
2009-06-02 20:58 ` Paul Brook
2009-06-02 21:19 ` David Turner
2009-06-02 19:03 ` Avi Kivity
2009-05-29 12:51 ` Markus Armbruster
2009-05-29 10:57 ` Gerd Hoffmann
2009-05-29 11:28 ` malc
2009-05-29 9:28 ` jcd
2009-05-29 9:38 ` Kevin Wolf
2009-06-01 11:59 ` Jamie Lokier
[not found] <18212122.68761243590277678.JavaMail.root@srv-05.w4a.fr>
2009-05-29 10:00 ` jcd
2009-05-29 10:10 ` Kevin Wolf
[not found] <2171027.69001243598252547.JavaMail.root@srv-05.w4a.fr>
2009-05-29 12:00 ` jcd
2009-05-29 12:05 ` Kevin Wolf
2009-05-29 12:13 ` jcd
2009-05-29 12:32 ` Markus Armbruster
2009-05-29 12:38 ` jcd
[not found] <28932640.69341243603994530.JavaMail.root@srv-05.w4a.fr>
2009-05-29 13:35 ` jcd
[not found] <28912134.69441243608238156.JavaMail.root@srv-05.w4a.fr>
2009-05-29 14:46 ` jcd
[not found] <33383337.69831243610071896.JavaMail.root@srv-05.w4a.fr>
2009-05-29 15:15 ` jcd
[not found] <1758936.71791243858884274.JavaMail.root@srv-05.w4a.fr>
2009-06-01 12:24 ` jcd
2009-06-01 23:46 ` Jamie Lokier
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=Pine.LNX.4.64.0905291506340.3744@linmac.oyster.ru \
--to=av1474@comtv.ru \
--cc=anthony@codemonkey.ws \
--cc=jcd@tribudubois.net \
--cc=kwolf@redhat.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).