From owner-svn-soc-all@FreeBSD.ORG Thu Jun 26 20:30:46 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 28B50E58 for ; Thu, 26 Jun 2014 20:30:46 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0B4EC25C6 for ; Thu, 26 Jun 2014 20:30:46 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5QKUjZP096878 for ; Thu, 26 Jun 2014 20:30:45 GMT (envelope-from def@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.8/8.14.8/Submit) id s5QKUjn0096699 for svn-soc-all@FreeBSD.org; Thu, 26 Jun 2014 20:30:45 GMT (envelope-from def@FreeBSD.org) Date: Thu, 26 Jun 2014 20:30:45 GMT Message-Id: <201406262030.s5QKUjn0096699@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to def@FreeBSD.org using -f From: def@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r270096 - in soc2013/def/crashdump-head/sys: kern sys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Jun 2014 20:30:46 -0000 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,