mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@osdl.org>
To: Alexey Dobriyan <adobriyan@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: grep /proc/slabinfo + rm -rf => lockup
Date: Wed, 28 Jun 2006 14:24:52 -0700	[thread overview]
Message-ID: <20060628142452.5842b126.akpm@osdl.org> (raw)
In-Reply-To: <20060628210523.GA7555@martell.zuzino.mipt.ru>

Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> VT1: while true; do grep xfs /proc/slabinfo; done
> VT2: rm -rf linux-vanilla

Yup, we have a buffer overrun in /proc/slabinfo.

From: Andrew Morton <akpm@osdl.org>

The recent vsnprintf() fix introduced an off-by-one, and it's now possible to
overrun the target buffer by one byte.  Fix it so that local variable `end'
_really_ points at the last writeable byte.

[jeremy@goop.org: make the `size==0' case work properly]
Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 lib/vsprintf.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff -puN lib/vsprintf.c~vsnprintf-fix lib/vsprintf.c
--- a/lib/vsprintf.c~vsnprintf-fix
+++ a/lib/vsprintf.c
@@ -259,7 +259,9 @@ int vsnprintf(char *buf, size_t size, co
 	int len;
 	unsigned long long num;
 	int i, base;
-	char *str, *end, c;
+	char *str;		/* Where we're writing to */
+	char *end;		/* The terminal '\0' (if any) */
+	char c;
 	const char *s;
 
 	int flags;		/* flags to number() */
@@ -283,7 +285,10 @@ int vsnprintf(char *buf, size_t size, co
 	}
 
 	str = buf;
-	end = buf + size;
+	if (size > 0)
+		end = buf + size - 1;
+	else
+		end = buf;
 
 	/* Make sure end is always >= buf */
 	if (end < buf) {
_


      reply	other threads:[~2006-06-28 21:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-28 21:05 Alexey Dobriyan
2006-06-28 21:24 ` Andrew Morton [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=20060628142452.5842b126.akpm@osdl.org \
    --to=akpm@osdl.org \
    --cc=adobriyan@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®