Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 8 Oct 2016 00:01:07 +0000 (UTC)
From:      Allan Jude <allanjude@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r306834 - stable/11/sys/boot/geli
Message-ID:  <201610080001.u98017kx081226@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: allanjude
Date: Sat Oct  8 00:01:07 2016
New Revision: 306834
URL: https://svnweb.freebsd.org/changeset/base/306834

Log:
  MFC: r306677
  
  GELIBoot may attempt to read past the end of the disk
  
  PR:		213196
  Relnotes:	yes
  Sponsored by:	ScaleEngine Inc.

Modified:
  stable/11/sys/boot/geli/geliboot.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/boot/geli/geliboot.c
==============================================================================
--- stable/11/sys/boot/geli/geliboot.c	Fri Oct  7 23:52:30 2016	(r306833)
+++ stable/11/sys/boot/geli/geliboot.c	Sat Oct  8 00:01:07 2016	(r306834)
@@ -77,17 +77,25 @@ geli_taste(int read_func(void *vdev, voi
 	int error;
 	off_t alignsector;
 
-	alignsector = (lastsector * DEV_BSIZE) &
-	    ~(off_t)(DEV_GELIBOOT_BSIZE - 1);
+	alignsector = rounddown2(lastsector * DEV_BSIZE, DEV_GELIBOOT_BSIZE);
+	if (alignsector + DEV_GELIBOOT_BSIZE > ((lastsector + 1) * DEV_BSIZE)) {
+		/* Don't read past the end of the disk */
+		alignsector = (lastsector * DEV_BSIZE) + DEV_BSIZE
+		    - DEV_GELIBOOT_BSIZE;
+	}
 	error = read_func(NULL, dskp, alignsector, &buf, DEV_GELIBOOT_BSIZE);
 	if (error != 0) {
 		return (error);
 	}
-	/* Extract the last DEV_BSIZE bytes from the block. */
-	error = eli_metadata_decode(buf + (DEV_GELIBOOT_BSIZE - DEV_BSIZE),
-	    &md);
+	/* Extract the last 4k sector of the disk. */
+	error = eli_metadata_decode(buf, &md);
 	if (error != 0) {
-		return (error);
+		/* Try the last 512 byte sector instead. */
+		error = eli_metadata_decode(buf +
+		    (DEV_GELIBOOT_BSIZE - DEV_BSIZE), &md);
+		if (error != 0) {
+			return (error);
+		}
 	}
 
 	if (!(md.md_flags & G_ELI_FLAG_GELIBOOT)) {



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