svn commit: r306834 - stable/11/sys/boot/geli
Allan Jude
allanjude at FreeBSD.org
Sat Oct 8 00:01:08 UTC 2016
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)) {
More information about the svn-src-all
mailing list