From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 5321821E0B9FF for ; Mon, 5 Feb 2018 06:55:23 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Feb 2018 07:01:04 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,465,1511856000"; d="scan'208";a="28908063" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga001.jf.intel.com with ESMTP; 05 Feb 2018 07:01:04 -0800 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 5 Feb 2018 07:00:52 -0800 Received: from fmsmsx103.amr.corp.intel.com ([169.254.2.47]) by fmsmsx101.amr.corp.intel.com ([169.254.1.39]) with mapi id 14.03.0319.002; Mon, 5 Feb 2018 07:00:51 -0800 From: "Carsey, Jaben" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH] ShellPkg/map: Fix out-of-bound read when "map fsn" Thread-Index: AQHTnkUqD+L9H17nRkqJLq1SLqo1IKOV56zQ Date: Mon, 5 Feb 2018 15:00:51 +0000 Message-ID: References: <20180205054953.212680-1-ruiyu.ni@intel.com> In-Reply-To: <20180205054953.212680-1-ruiyu.ni@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNTBlY2Q4MjYtODM3Ni00MmU4LWI3ZWItNzBjNTczYTBmODkwIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6Ik1CQjhKaTlORG9iY0xTeE5hMzBLak4wRzZOelpHNGRcL3pFeE5JWGVid1wvaz0ifQ== x-ctpclassification: CTP_NT x-originating-ip: [10.1.200.106] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/map: Fix out-of-bound read when "map fsn" X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Feb 2018 14:55:23 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Jaben Carsey > -----Original Message----- > From: Ni, Ruiyu > Sent: Sunday, February 04, 2018 9:50 PM > To: edk2-devel@lists.01.org > Cc: Carsey, Jaben ; Wang, Jian J > > Subject: [PATCH] ShellPkg/map: Fix out-of-bound read when "map fsn" > Importance: High >=20 > The below code reads additional one CHAR16 when copying > content from Specific to NewSpecific. > NewSpecific =3D AllocateCopyPool( > StrSize(Specific) + sizeof(CHAR16), Specific > ); >=20 > The patch fixes this issue. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Cc: Jaben Carsey > Cc: Jian J Wang > --- > ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c | 18 ++++++++++++-- > ---- > 1 file changed, 12 insertions(+), 6 deletions(-) >=20 > diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c > b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c > index 3f5925f507..9166ca2205 100644 > --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c > +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Map.c > @@ -1,7 +1,7 @@ > /** @file > Main file for map shell level 2 command. >=20 > - Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.
> + Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.
> (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
> (C) Copyright 2016 Hewlett Packard Enterprise Development LP
>=20 > @@ -220,19 +220,25 @@ MappingListHasType( > IN CONST BOOLEAN Consist > ) > { > - CHAR16 *NewSpecific; > - RETURN_STATUS Status; > + CHAR16 *NewSpecific; > + RETURN_STATUS Status; > + UINTN Length; >=20 > // > // specific has priority > // > if (Specific !=3D NULL) { > - NewSpecific =3D AllocateCopyPool(StrSize(Specific) + sizeof(CHAR16), > Specific); > + Length =3D StrLen (Specific); > + // > + // Allocate enough buffer for Specific and potential ":" > + // > + NewSpecific =3D AllocatePool ((Length + 2) * sizeof(CHAR16)); > if (NewSpecific =3D=3D NULL){ > return FALSE; > } > - if (NewSpecific[StrLen(NewSpecific)-1] !=3D L':') { > - Status =3D StrnCatS(NewSpecific, (StrSize(Specific) + > sizeof(CHAR16))/sizeof(CHAR16), L":", StrLen(L":")); > + StrCpyS (NewSpecific, Length + 2, Specific); > + if (Specific[Length - 1] !=3D L':') { > + Status =3D StrnCatS(NewSpecific, Length + 2, L":", StrLen(L":")); > if (EFI_ERROR (Status)) { > FreePool(NewSpecific); > return FALSE; > -- > 2.16.1.windows.1