public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfsdump: prevent segfault in cb_add_inogrp
@ 2015-08-26 14:33 rjohnston
  2015-08-26 16:42 ` Eric Sandeen
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: rjohnston @ 2015-08-26 14:33 UTC (permalink / raw)
  To: xfs

[-- Attachment #1: prevent-segfault-in-cb_add_inogrp.patch --]
[-- Type: text/plain, Size: 1744 bytes --]

The call to memset will segfault because the offset for the first
parameter is done twice. We are using pointer math to do the
calculation.
The first time is when calculating oldsize, the size of i2gseg_t
is accounted for.
	oldsize = (numsegs - SEGPERHNK) * sizeof(i2gseg_t);
Then in the call to memset, oldsize is again multiplied by the size
of i2gmap_t.
	memset(inomap.i2gmap + oldsize, ...)
	
i2gmap holds the used inodes in each chunk. When there are 2^31 chunk
entries, it could describe 2^31 (1 inode/chunk)- 2^40 (64 inodes/chunk).

With 100s of millions of inodes there are enough entries to wrap the
32 bit variable oldsize.

Switching to use array index notation instead of calculating the
pointer address twice ;) would resolve this issue. The unneeded
local variable oldsize can be removed as well.

---
 dump/inomap.c |    8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Index: b/dump/inomap.c
===================================================================
--- a/dump/inomap.c
+++ b/dump/inomap.c
@@ -1125,8 +1125,7 @@ cb_add_inogrp( void *arg1, intgen_t fsfd
 		lastsegp->segoff = 0;
 
 		if (lastsegp->hnkoff == inomap.hnkmaplen) {
-			intgen_t numsegs;
-			intgen_t oldsize;
+			int64_t numsegs;
 
 			inomap.hnkmaplen++;
 			inomap.hnkmap = (hnk_t *)
@@ -1140,10 +1139,7 @@ cb_add_inogrp( void *arg1, intgen_t fsfd
 				return -1;
 
 			/* zero the new portion of the i2gmap */
-			oldsize = (numsegs - SEGPERHNK) * sizeof(i2gseg_t);
-
-			memset(inomap.i2gmap + oldsize,
-			       0,
+			memset(&inomap.i2gmap[numsegs - SEGPERHNK], 0,
 			       SEGPERHNK * sizeof(i2gseg_t));
 		}
 

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

end of thread, other threads:[~2015-09-21 13:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-26 14:33 [PATCH] xfsdump: prevent segfault in cb_add_inogrp rjohnston
2015-08-26 16:42 ` Eric Sandeen
2015-08-26 17:10   ` Rich Johnston
2015-08-26 21:26     ` Dave Chinner
2015-08-26 17:36 ` [PATCH V2] " rjohnston
2015-08-26 21:37   ` Dave Chinner
2015-08-26 21:57     ` Rich Johnston
2015-08-26 22:19       ` Eric Sandeen
2015-08-26 22:27         ` Eric Sandeen
2015-08-26 22:21       ` Dave Chinner
2015-08-26 22:29 ` [PATCH V3] " rjohnston
2015-08-26 22:56   ` Dave Chinner
2015-08-26 22:58     ` Rich Johnston
2015-09-21 13:42       ` Rich Johnston
2015-08-26 23:00   ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox