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.115; helo=mga14.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 D924921A07093 for ; Tue, 19 Feb 2019 01:34:16 -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 fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2019 01:34:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,387,1544515200"; d="scan'208";a="139772053" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga001.jf.intel.com with ESMTP; 19 Feb 2019 01:34:16 -0800 Received: from fmsmsx117.amr.corp.intel.com (10.18.116.17) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 19 Feb 2019 01:34:16 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx117.amr.corp.intel.com (10.18.116.17) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 19 Feb 2019 01:34:15 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.194]) with mapi id 14.03.0415.000; Tue, 19 Feb 2019 17:34:13 +0800 From: "Ni, Ray" To: "Wang, Jian J" , "edk2-devel@lists.01.org" CC: "Gao, Liming" , "Kinney, Michael D" Thread-Topic: [PATCH v2 1/2] MdePkg/UefiDevicePathLib: Add sanity check for FilePath device path Thread-Index: AQHUyDSMVmYyvRuOjU+2aswcmC7ooqXm2rQw Date: Tue, 19 Feb 2019 09:34:12 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C025327@SHSMSX104.ccr.corp.intel.com> References: <20190219092139.844-1-jian.j.wang@intel.com> <20190219092139.844-2-jian.j.wang@intel.com> In-Reply-To: <20190219092139.844-2-jian.j.wang@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2 1/2] MdePkg/UefiDevicePathLib: Add sanity check for FilePath device path X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Feb 2019 09:34:17 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Wang, Jian J > Sent: Tuesday, February 19, 2019 5:22 PM > To: edk2-devel@lists.01.org > Cc: Gao, Liming ; Ni, Ray ; Kinne= y, > Michael D > Subject: [PATCH v2 1/2] MdePkg/UefiDevicePathLib: Add sanity check for > FilePath device path >=20 > > v2: fix wrong detection of FilePath device path >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1497 >=20 > Current implementation of IsDevicePathValid() is not enough for type of > MEDIA_FILEPATH_DP, which has NULL-terminated string in the device path. > This patch add a simple NULL character check at Length position. >=20 > Cc: Liming Gao > Cc: Ray Ni > Cc: Michael D Kinney > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jian J Wang > --- > MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c | 9 +++++++++ > 1 file changed, 9 insertions(+) >=20 > diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c > b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c > index 5d7635fe3e..dd1bddc1c2 100644 > --- a/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c > +++ b/MdePkg/Library/UefiDevicePathLib/DevicePathUtilities.c > @@ -95,6 +95,15 @@ IsDevicePathValid ( > return FALSE; > } > } > + > + // > + // FilePath must be a NULL-terminated string. > + // > + if (DevicePathType (DevicePath) =3D=3D MEDIA_DEVICE_PATH && > + DevicePathSubType (DevicePath) =3D=3D MEDIA_FILEPATH_DP && > + *(CHAR16 *)((UINT8 *)DevicePath + NodeLength - 2) !=3D 0) { Can we assume the device path node buffer contains exact the null terminate= d string? What if the buffer contains some padding bytes after null terminated string= ? To handle this case, can we convert the DevicePath to FILEPATH_DEVICE_PATH = and use logic similar as below? FILEPATH_DEVICE_PATH *FilePath; FilePath =3D (FILEPATH_DEVICE_PATH *) DevicePath; MaxSize =3D (NodeLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)) / sizeof (CHAR= 16); If (StrnLenS (FilePath->PathName, MaxSize) =3D=3D MaxSize) { Return FALSE; } > + return FALSE; > + } > } >=20 > // > -- > 2.17.1.windows.2