Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 Jun 2014 20:30:45 GMT
From:      def@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r270096 - in soc2013/def/crashdump-head/sys: kern sys
Message-ID:  <201406262030.s5QKUjn0096699@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: def
Date: Thu Jun 26 20:30:44 2014
New Revision: 270096
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=270096

Log:
  Remember offset where data from the buffer should be written and make sure
  they are come one after another.
  Fix wrong pointer arithmetic.
  

Modified:
  soc2013/def/crashdump-head/sys/kern/kern_shutdown.c
  soc2013/def/crashdump-head/sys/sys/kerneldump.h

Modified: soc2013/def/crashdump-head/sys/kern/kern_shutdown.c
==============================================================================
--- soc2013/def/crashdump-head/sys/kern/kern_shutdown.c	Thu Jun 26 19:48:59 2014	(r270095)
+++ soc2013/def/crashdump-head/sys/kern/kern_shutdown.c	Thu Jun 26 20:30:44 2014	(r270096)
@@ -877,21 +877,29 @@
 	struct kerneldumpkey *kdk;
 	struct kerneldumpbuffer *kdb;
 	int error;
+	size_t len;
 
 	kdk = di->kdk;
 	kdb = di->kdb;
 
+	/* Data have to be written one after another. */
+	if (kdb->offset != 0 && kdb->offset != offset &&
+	    kdb->offset + kdb->used != offset) {
+		return (-1);
+	}
+
 	/* Write kernel dump headers. */
-	if (kdb->kdhoffset == 0 || offset == di->mediaoffset + di->mediasize -
-	    sizeof(struct kerneldumpheader)) {
-		kdb->kdhoffset = offset + length;
+	if (kdb->offset == 0 || kdb->offset == di->mediaoffset +
+	    di->mediasize - sizeof(struct kerneldumpheader)) {
+		kdb->offset = offset + length;
 		return (di->dumper(di->priv, virtual, physical, offset,
 		    length));
 	}
 
 	while (kdb->used + length >= KERNELDUMP_BUFFER_SIZE) {
-		memcpy(kdb->buf + kdb->used, virtual, KERNELDUMP_BUFFER_SIZE -
-		    kdb->used);
+		len = KERNELDUMP_BUFFER_SIZE - kdb->used;
+		memcpy(kdb->buf + kdb->used, virtual, len);
+		kdb->used += len;
 
 		error = rijndael_blockEncrypt(&kdk->ci, &kdk->ki, kdb->buf,
 		    KERNELDUMP_BUFFER_SIZE * 8, kdb->buf);
@@ -902,15 +910,15 @@
 		if (error <= 0)
 			return (-1);
 
-		error = di->dumper(di->priv, kdb->buf, physical, offset,
+		error = di->dumper(di->priv, kdb->buf, physical, kdb->offset,
 		    KERNELDUMP_BUFFER_SIZE);
 		if (error)
 			return (error);
 
 		kdb->used = 0;
-		virtual = (void *)((char *)virtual + KERNELDUMP_BUFFER_SIZE);
-		length -= KERNELDUMP_BUFFER_SIZE;
-		offset += KERNELDUMP_BUFFER_SIZE;
+		kdb->offset += KERNELDUMP_BUFFER_SIZE;
+		virtual = (void *)((char *)virtual + len);
+		length -= len;
 	}
 	if (length > 0) {
 		memcpy(kdb->buf + kdb->used, virtual, length);

Modified: soc2013/def/crashdump-head/sys/sys/kerneldump.h
==============================================================================
--- soc2013/def/crashdump-head/sys/sys/kerneldump.h	Thu Jun 26 19:48:59 2014	(r270095)
+++ soc2013/def/crashdump-head/sys/sys/kerneldump.h	Thu Jun 26 20:30:44 2014	(r270096)
@@ -116,7 +116,7 @@
 struct kerneldumpbuffer {
 	uint8_t	buf[KERNELDUMP_BUFFER_SIZE];	/* Raw data buffer. */
 	size_t	used;				/* Number of bytes used in buf. */
-	off_t	kdhoffset;			/* Offset value of the first kdh. */
+	off_t	offset; 			/* Offset where to write data from buf. */
 };
 
 void kerneldump_crypto_init(struct dumperinfo *di, struct kerneldumpkey *kdk,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406262030.s5QKUjn0096699>