From: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: kosaki.motohiro@jp.fujitsu.com, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH] mm: Remove ZERO_SIZE_PTR.
Date: Fri, 26 Feb 2010 15:59:03 +0900 (JST) [thread overview]
Message-ID: <20100226155618.8D9E.A69D9226@jp.fujitsu.com> (raw)
In-Reply-To: <201002260635.o1Q6ZYET040848@www262.sakura.ne.jp>
> [RFC][PATCH] mm: Remove ZERO_SIZE_PTR.
>
> kmalloc() and friends are sometimes used in a way
>
> struct foo *ptr = kmalloc(size + sizeof(struct foo), GFP_KERNEL);
> if (!ptr)
> return -ENOMEM;
> ptr->size = size;
> ...
> return 0;
>
> Everybody should check for ptr != NULL, and most callers are actually checking
> for ptr != NULL. But nobody is checking for ptr != ZERO_SIZE_PTR.
>
> If caller passed 0 as size argument by error (e.g. integer overflow bug),
> the caller will start writing against address starting from ZERO_SIZE_PTR
> because the caller assumes that "size + sizeof(struct foo)" bytes of memory is
> successfully allocated. (kstrdup() is an example, although it will be
> impossible to pass s where strlen(s) == (size_t) -1 .)
>
> Yes, this is the fault of caller. But ZERO_SIZE_PTR is too small value to
> distinguish "NULL pointer dereference" and "ZERO_SIZE_PTR dereference" because
> address printed by oops message can easily exceed ZERO_SIZE_PTR when
> "struct foo" is large.
>
> Therefore, at the cost of being unable to distinguish "NULL pointer
> dereference" and "ZERO_SIZE_PTR dereference" in some cases, removing
> ZERO_SIZE_PTR could reduce the risk of "ZERO_SIZE_PTR dereference" in many
> cases.
NAK. yes, it could. but it is no worth. nobody want slower kernel.
next prev parent reply other threads:[~2010-02-26 6:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-26 6:35 Tetsuo Handa
2010-02-26 6:59 ` KOSAKI Motohiro [this message]
2010-02-26 8:38 ` Tetsuo Handa
2010-02-26 8:44 ` KOSAKI Motohiro
2010-02-26 18:23 ` David Wagner
2010-02-26 7:26 ` David Wagner
2010-02-26 16:39 ` Christoph Lameter
2010-02-27 0:59 ` Tetsuo Handa
2010-03-03 21:54 ` Pavel Machek
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=20100226155618.8D9E.A69D9226@jp.fujitsu.com \
--to=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
/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®