Received: from eggs.gnu.org ([2001:4830:134:3::10]:34068) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yczcx-0003qd-P4 for qemu-devel@nongnu.org; Tue, 31 Mar 2015 13:07:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yczcu-0007w8-In for qemu-devel@nongnu.org; Tue, 31 Mar 2015 13:06:59 -0400 Received: from prv-mh.provo.novell.com ([137.65.248.74]:44943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yczcu-0007vx-Bx for qemu-devel@nongnu.org; Tue, 31 Mar 2015 13:06:56 -0400 Message-Id: <551A7FCB020000480010C8A4@prv-mh.provo.novell.com> Date: Tue, 31 Mar 2015 11:06:51 -0600 From: "Bruce Rogers" References: <1427756790-7922-1-git-send-email-brogers@suse.com> <20150331040250.GA23911@morn.localdomain> <551A5FB6020000480010C836@prv-mh.provo.novell.com> <20150331163729.GB4523@HEDWIG.INI.CMU.EDU> <20150331164615.GA29388@morn.localdomain> In-Reply-To: <20150331164615.GA29388@morn.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Subject: Re: [Qemu-devel] [SeaBIOS] [PATCH] smbios: ensure comparison SMBIOS string can't be paragraph aligned List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Gabriel L. Somlo" , Kevin O'Connor Cc: seabios@seabios.org, qemu-devel@nongnu.org, kraxel@redhat.com >>> On 3/31/2015 at 10:46 AM, Kevin O'Connor = wrote:=20 > On Tue, Mar 31, 2015 at 12:37:30PM -0400, Gabriel L. Somlo wrote: >> On Tue, Mar 31, 2015 at 08:49:58AM -0600, Bruce Rogers wrote: >> > >>> On 3/30/2015 at 10:02 PM, Kevin O'Connor = wrote:=20 >> > > On Mon, Mar 30, 2015 at 05:06:30PM -0600, Bruce Rogers wrote: >> > >> The SMBIOS anchor string _SM_ is stored within SeaBIOS to validate >> > >> an SMBIOS entry point structure. There is the possibility = (observed) >> > >> that this comparison string ends up paragraph aligned and = mistakenly >> > >> found during a search for the real SMBIOS entry point. Ensure it = will >> > >> never end up on a paragraph boundary by storing it at odd = alignment. >> > >=20 >> > > Thanks. >> > >=20 >> > > What OS was this on? It's really an OS bug as the OS needs to = check >> > > both the signature and the checksum. >> > >=20 >> > > My preferred approach to addressing this would be to turn >> > > p->anchor_string into a u32 and do an integer compare instead of a >> > > string compare. Although technically this can lead to the same >> > > potential issue, in practice it should not happen because SeaBIOS' >> > > init code is relocated out of the f-segment during startup (while >> > > static strings are generally not). >> > >=20 >> > > -Kevin >> >=20 >> > This was actually flagged by the QEMU make check test in >> > tests/bios-tables-test.c, where the code has asserts based on the >> > first find of the _SM_ string found on a paragraph boundary in the >> > f segment. It assumes that the string found is sufficient to identify >> > the smbios entry point structure. >> >=20 >> > I read in=20 > http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0= .pdf >> > where there are number of steps needed to verify the entry-point, = beyond >> > finding the anchor string. So I assume that the make check test = needs to >> > be fixed. >> >=20 >> > But I wonder if bios creators are also supposed to ensure that there = is no >> > such string findable on a paragraph boundary so as to avoid any = potential >> > confusion? I don't have expereince writing bios's so I am only = guessing >> > at that. >>=20 >> I guess on physical hardware that would be mitigated by the BIOS's >> .rodata (or whatever the equivalent thing is called in BIOS-speak) >> NOT falling within 0xf0000..0xfffff :) >>=20 >> If there's no way to guarantee that with SeaBIOS, I suppose the >> qemu test could be rewritten to account for the possibility of >> "false positive" signatures... >=20 > I would do both - change SeaBIOS to (in practice) not put "_SM_" in > the f-segment and change the QEMU test to not stop on the first "_SM_" > it finds. SeaBIOS patch below (untested). >=20 > -Kevin >=20 >=20 > diff --git a/src/fw/biostables.c b/src/fw/biostables.c > index 50a891b..450aca2 100644 > --- a/src/fw/biostables.c > +++ b/src/fw/biostables.c > @@ -271,7 +271,7 @@ copy_smbios(void *pos) > if (SMBiosAddr) > return; > struct smbios_entry_point *p =3D pos; > - if (memcmp(p->anchor_string, "_SM_", 4)) > + if (p->signature !=3D SMBIOS_SIGNATURE) > return; > if (checksum(pos, 0x10) !=3D 0) > return; > diff --git a/src/fw/smbios.c b/src/fw/smbios.c > index dba0541..f3b5ad9 100644 > --- a/src/fw/smbios.c > +++ b/src/fw/smbios.c > @@ -37,7 +37,7 @@ smbios_entry_point_setup(u16 max_structure_size, > =20 > struct smbios_entry_point ep; > memset(&ep, 0, sizeof(ep)); > - memcpy(ep.anchor_string, "_SM_", 4); > + ep.signature =3D SMBIOS_SIGNATURE; > ep.length =3D 0x1f; > ep.smbios_major_version =3D 2; > ep.smbios_minor_version =3D 4; > diff --git a/src/std/smbios.h b/src/std/smbios.h > index 0513716..4ccf2ea 100644 > --- a/src/std/smbios.h > +++ b/src/std/smbios.h > @@ -3,11 +3,13 @@ > =20 > #include "types.h" // u32 > =20 > +#define SMBIOS_SIGNATURE 0x5f4d535f // "_SM_" > + > /* SMBIOS entry point -- must be written to a 16-bit aligned address > between 0xf0000 and 0xfffff. > */ > struct smbios_entry_point { > - char anchor_string[4]; > + u32 signature; > u8 checksum; > u8 length; > u8 smbios_major_version; Agreed. Thanks. Bruce