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.151; helo=mga17.intel.com; envelope-from=jian.j.wang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 11A55208F6118 for ; Tue, 19 Feb 2019 02:12:15 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2019 02:12:14 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,388,1544515200"; d="scan'208";a="117313524" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga006.jf.intel.com with ESMTP; 19 Feb 2019 02:12:13 -0800 Received: from shsmsx106.ccr.corp.intel.com (10.239.4.159) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 19 Feb 2019 02:12:12 -0800 Received: from shsmsx107.ccr.corp.intel.com ([169.254.9.162]) by SHSMSX106.ccr.corp.intel.com ([169.254.10.174]) with mapi id 14.03.0415.000; Tue, 19 Feb 2019 18:12:10 +0800 From: "Wang, Jian J" To: "Ni, Ray" , "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: AQHUyDZG+2S5FouG4kOwUn4olZGxv6Xm4kLg Date: Tue, 19 Feb 2019 10:12:10 +0000 Message-ID: References: <20190219092139.844-1-jian.j.wang@intel.com> <20190219092139.844-2-jian.j.wang@intel.com> <734D49CCEBEEF84792F5B80ED585239D5C025327@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5C025327@SHSMSX104.ccr.corp.intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMDk5OGZkMjQtNWI0Zi00N2JjLWJlZjctMzVhYzk1OThjNjY5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiTjI5aTFQbmpZTExONFNPcmJFZzRQTllUUWc2UmtDTG1SNkVvSXBCRXpGbzUwVlZwOGNhdUJSOFQxa0pcL3krdTYifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action 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 10:12:16 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Ray, > -----Original Message----- > From: Ni, Ray > Sent: Tuesday, February 19, 2019 5:34 PM > To: Wang, Jian J ; edk2-devel@lists.01.org > Cc: Gao, Liming ; Kinney, Michael D > > Subject: RE: [PATCH v2 1/2] MdePkg/UefiDevicePathLib: Add sanity check fo= r > FilePath device path >=20 >=20 >=20 > > -----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 ; Kin= ney, > > Michael D > > Subject: [PATCH v2 1/2] MdePkg/UefiDevicePathLib: Add sanity check for > > FilePath device path > > > > > v2: fix wrong detection of FilePath device path > > > > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1497 > > > > 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. > > > > 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(+) > > > > 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 termina= ted > string? > What if the buffer contains some padding bytes after null terminated stri= ng? >=20 > To handle this case, can we convert the DevicePath to FILEPATH_DEVICE_PAT= H > and use logic similar as below? >=20 > FILEPATH_DEVICE_PATH *FilePath; > FilePath =3D (FILEPATH_DEVICE_PATH *) DevicePath; > MaxSize =3D (NodeLength - sizeof (EFI_DEVICE_PATH_PROTOCOL)) / sizeof > (CHAR16); > If (StrnLenS (FilePath->PathName, MaxSize) =3D=3D MaxSize) { > Return FALSE; > } >=20 I did think about your implementation and I agree it might be the best way from compatibility perspective. But I have three considerations: 1. It's not a good programming habit to pass unwanted data around and shoul= d not be encouraged to do so. 2. It might leave potential security hole (maybe I'm a little too cautious) 3. The UEFI spec has following statement on this type of device path (ch10.= 3.6.4). " A NULL-terminated Path string including directory and file names. The len= gth of this string n can be determined by subtracting 4 from the Length entry." But I'm still open to your suggestion, if all agree that compatibility is m= ore important. Regards, Jian >=20 >=20 > > + return FALSE; > > + } > > } > > > > // > > -- > > 2.17.1.windows.2