From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 96963202E53AC for ; Tue, 19 Feb 2019 05:11:47 -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 orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Feb 2019 05:11:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,388,1544515200"; d="scan'208";a="139810623" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga001.jf.intel.com with ESMTP; 19 Feb 2019 05:11:46 -0800 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 19 Feb 2019 05:11:37 -0800 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 19 Feb 2019 05:11:36 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.102]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.172]) with mapi id 14.03.0415.000; Tue, 19 Feb 2019 21:11:34 +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//+F7QCAALjTIA== Date: Tue, 19 Feb 2019 13:11:34 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5C025DBD@SHSMSX104.ccr.corp.intel.com> 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: 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 13:11:47 -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 6:12 PM > To: Ni, Ray ; 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 > Hi Ray, >=20 > > -----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 > > for FilePath device path > > > > > > > > > -----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 ; > > > Kinney, 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 > > terminated string? > > What if the buffer contains some padding bytes after null terminated st= ring? > > > > 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 (NodeLeng= th > > - 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 wa= y from > compatibility perspective. But I have three considerations: >=20 > 1. It's not a good programming habit to pass unwanted data around and sho= uld > not > be encouraged to do so. > 2. It might leave potential security hole (maybe I'm a little too cautiou= s) 3. The > UEFI spec has following statement on this type of device path (ch10.3.6.4= ). >=20 > " A NULL-terminated Path string including directory and file names. The l= ength > of this string n can be determined by subtracting 4 from the Length entry= ." >=20 With such statement, I am ok to your changes. Reviewed-by: Ray Ni > But I'm still open to your suggestion, if all agree that compatibility is= more > important. >=20 > Regards, > Jian >=20 > > > > > > > + return FALSE; > > > + } > > > } > > > > > > // > > > -- > > > 2.17.1.windows.2