From owner-svn-src-all@freebsd.org Tue Oct 4 16:33:04 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6BE85AF48B6; Tue, 4 Oct 2016 16:33:04 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 237C4E52; Tue, 4 Oct 2016 16:33:04 +0000 (UTC) (envelope-from allanjude@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u94GX3fW051605; Tue, 4 Oct 2016 16:33:03 GMT (envelope-from allanjude@FreeBSD.org) Received: (from allanjude@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u94GX3HL051604; Tue, 4 Oct 2016 16:33:03 GMT (envelope-from allanjude@FreeBSD.org) Message-Id: <201610041633.u94GX3HL051604@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: allanjude set sender to allanjude@FreeBSD.org using -f From: Allan Jude Date: Tue, 4 Oct 2016 16:33:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r306677 - head/sys/boot/geli X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2016 16:33:04 -0000 Author: allanjude Date: Tue Oct 4 16:33:03 2016 New Revision: 306677 URL: https://svnweb.freebsd.org/changeset/base/306677 Log: GELIBoot may attempt to read past the end of the disk Usually there is some slack after the last partition due to 4k alignment In the 10.3 EC2 images, there was not. EC2 seems to hang if you try to read past the end of the disk in the loader, resulting in an unbootable instance after upgrading to 11.0 PR: 213196 Reported by: Peter Ankerstal Tested by: cperciva Reviewed by: tsoome MFC after: 3 days Sponsored by: ScaleEngine Inc. Differential Revision: https://reviews.freebsd.org/D8144 Modified: head/sys/boot/geli/geliboot.c Modified: head/sys/boot/geli/geliboot.c ============================================================================== --- head/sys/boot/geli/geliboot.c Tue Oct 4 16:29:26 2016 (r306676) +++ head/sys/boot/geli/geliboot.c Tue Oct 4 16:33:03 2016 (r306677) @@ -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)) {