From: Thomas Jarosch <thomas.jarosch@intra2net.com>
To: Pekka Enberg <penberg@cs.helsinki.fi>
Cc: David Rientjes <rientjes@google.com>,
Christoph Lameter <cl@gentwo.org>,
linux-kernel@vger.kernel.org
Subject: [slabinfo PATCH v2] Fix off-by-one buffer corruption after readlink() call
Date: Mon, 17 Oct 2011 16:48:10 +0200 [thread overview]
Message-ID: <201110171648.11074.thomas.jarosch@intra2net.com> (raw)
In-Reply-To: <CAOJsxLGS519114eonOWbDTwO+CL_e=buiW7XdbtxfCUpYz=Y6A@mail.gmail.com>
readlink() never zero terminates the provided buffer.
Therefore we already do
buffer[count] = 0;
This leads to an off-by-one buffer corruption as readlink()
might return the full size of the buffer.
The common technique is to reduce the buffer size by one.
Another fix would be to check
"
if (count < 0 || count == sizeof(buffer))
fatal();
"
Reducing the buffer size by one is easier IMHO.
Signed-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Christoph Lameter <cl@gentwo.org>
---
tools/slub/slabinfo.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/slub/slabinfo.c b/tools/slub/slabinfo.c
index 868cc93..cc1a378 100644
--- a/tools/slub/slabinfo.c
+++ b/tools/slub/slabinfo.c
@@ -1145,7 +1145,7 @@ static void read_slab_dir(void)
switch (de->d_type) {
case DT_LNK:
alias->name = strdup(de->d_name);
- count = readlink(de->d_name, buffer, sizeof(buffer));
+ count = readlink(de->d_name, buffer, sizeof(buffer)-1);
if (count < 0)
fatal("Cannot read symlink %s\n", de->d_name);
--
1.7.6.4
prev parent reply other threads:[~2011-10-17 14:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-14 16:56 [slabinfo PATCH] Fix off-by-one after readlink() call Thomas Jarosch
2011-10-14 17:16 ` Christoph Lameter
2011-10-14 17:26 ` Thomas Jarosch
2011-10-14 17:57 ` Christoph Lameter
2011-10-14 19:53 ` David Rientjes
2011-10-17 7:16 ` Pekka Enberg
2011-10-17 14:48 ` Thomas Jarosch [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=201110171648.11074.thomas.jarosch@intra2net.com \
--to=thomas.jarosch@intra2net.com \
--cc=cl@gentwo.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
--cc=rientjes@google.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.