LKML Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH, Bugfix] RAMOOPS: Don't overflow over non-allocated regions
@ 2010-12-25  9:57 Ahmed S. Darwish
  2010-12-25 11:19 ` Marco Stornelli
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmed S. Darwish @ 2010-12-25  9:57 UTC (permalink / raw)
  To: Marco Stornelli, LKML
  Cc: Kyungmin Park, David Woodhouse, Greg KH, Andrew Morton

Hi,

Current code mis-calculates the ramoops header size, leading to an
overflow over the next record at best, or over a non-allocated region
at worst. Fix that calculation.

Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
--

Shouldn't this be added to -stable too?

Happy New Year!

 drivers/char/ramoops.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c
index 73dcb0e..d3d63be 100644
--- a/drivers/char/ramoops.c
+++ b/drivers/char/ramoops.c
@@ -29,7 +29,6 @@
 #include <linux/ramoops.h>
 
 #define RAMOOPS_KERNMSG_HDR "===="
-#define RAMOOPS_HEADER_SIZE   (5 + sizeof(struct timeval))
 
 #define RECORD_SIZE 4096
 
@@ -65,8 +64,8 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
 			struct ramoops_context, dump);
 	unsigned long s1_start, s2_start;
 	unsigned long l1_cpy, l2_cpy;
-	int res;
-	char *buf;
+	int res, hdr_size;
+	char *buf, *buf_orig;
 	struct timeval timestamp;
 
 	/* Only dump oopses if dump_oops is set */
@@ -74,6 +73,8 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
 		return;
 
 	buf = (char *)(cxt->virt_addr + (cxt->count * RECORD_SIZE));
+	buf_orig = buf;
+
 	memset(buf, '\0', RECORD_SIZE);
 	res = sprintf(buf, "%s", RAMOOPS_KERNMSG_HDR);
 	buf += res;
@@ -81,8 +82,9 @@ static void ramoops_do_dump(struct kmsg_dumper *dumper,
 	res = sprintf(buf, "%lu.%lu\n", (long)timestamp.tv_sec, (long)timestamp.tv_usec);
 	buf += res;
 
-	l2_cpy = min(l2, (unsigned long)(RECORD_SIZE - RAMOOPS_HEADER_SIZE));
-	l1_cpy = min(l1, (unsigned long)(RECORD_SIZE - RAMOOPS_HEADER_SIZE) - l2_cpy);
+	hdr_size = buf - buf_orig;
+	l2_cpy = min(l2, (unsigned long)(RECORD_SIZE - hdr_size));
+	l1_cpy = min(l1, (unsigned long)(RECORD_SIZE - hdr_size) - l2_cpy);
 
 	s2_start = l2 - l2_cpy;
 	s1_start = l1 - l1_cpy;

-- 
Darwish
http://darwish.07.googlepages.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, Bugfix] RAMOOPS: Don't overflow over non-allocated regions
  2010-12-25  9:57 [PATCH, Bugfix] RAMOOPS: Don't overflow over non-allocated regions Ahmed S. Darwish
@ 2010-12-25 11:19 ` Marco Stornelli
  2010-12-27 21:33   ` Ahmed S. Darwish
  0 siblings, 1 reply; 3+ messages in thread
From: Marco Stornelli @ 2010-12-25 11:19 UTC (permalink / raw)
  To: LKML
  Cc: Ahmed S. Darwish, Kyungmin Park, David Woodhouse, Greg KH, Andrew Morton

Il 25/12/2010 10:57, Ahmed S. Darwish ha scritto:
> Hi,
> 
> Current code mis-calculates the ramoops header size, leading to an
> overflow over the next record at best, or over a non-allocated region
> at worst. Fix that calculation.
> 
> Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> --

Acked-by: Marco Stornelli <marco.stornelli@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH, Bugfix] RAMOOPS: Don't overflow over non-allocated regions
  2010-12-25 11:19 ` Marco Stornelli
@ 2010-12-27 21:33   ` Ahmed S. Darwish
  0 siblings, 0 replies; 3+ messages in thread
From: Ahmed S. Darwish @ 2010-12-27 21:33 UTC (permalink / raw)
  To: Marco Stornelli
  Cc: LKML, Kyungmin Park, David Woodhouse, Greg KH, Andrew Morton,
	Linus Torvalds

On Sat, Dec 25, 2010 at 12:19:35PM +0100, Marco Stornelli wrote:
> Il 25/12/2010 10:57, Ahmed S. Darwish ha scritto:
> > 
> > Current code mis-calculates the ramoops header size, leading to an
> > overflow over the next record at best, or over a non-allocated region
> > at worst. Fix that calculation.
> > 
> > Signed-off-by: Ahmed S. Darwish <darwish.07@gmail.com>
> > --
> 
> Acked-by: Marco Stornelli <marco.stornelli@gmail.com>
>

Someone to push this to Linus before -rc8? Andrew?

--
Darwish
http://darwish.07.googlepages.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-25  9:57 [PATCH, Bugfix] RAMOOPS: Don't overflow over non-allocated regions Ahmed S. Darwish
2010-12-25 11:19 ` Marco Stornelli
2010-12-27 21:33   ` Ahmed S. Darwish

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lkml.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lkml.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lkml.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lkml.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lkml.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lkml.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lkml.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lkml.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lkml.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lkml.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lkml.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lkml.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git