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.93; helo=mga11.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 0EB8D2112B1E9 for ; Wed, 12 Sep 2018 19:48:06 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Sep 2018 19:48:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,367,1531810800"; d="scan'208";a="90009723" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga001.jf.intel.com with ESMTP; 12 Sep 2018 19:47:53 -0700 Received: from fmsmsx157.amr.corp.intel.com (10.18.116.73) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 12 Sep 2018 19:47:48 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX157.amr.corp.intel.com (10.18.116.73) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 12 Sep 2018 19:47:48 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.143]) by shsmsx102.ccr.corp.intel.com ([169.254.2.226]) with mapi id 14.03.0319.002; Thu, 13 Sep 2018 10:46:00 +0800 From: "Ni, Ruiyu" To: "Robinson, Herbie" , "edk2-devel@lists.01.org" Thread-Topic: [PATCH 1/1] FatPkg/EnhancedFatDxe Fix Double Cluster Allocation Thread-Index: AdRGNugzdHiNHJwCSQCZ7Ap4/Z5afQE1Nylw Date: Thu, 13 Sep 2018 02:45:32 +0000 Deferred-Delivery: Thu, 13 Sep 2018 02:46:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BE071CE@SHSMSX104.ccr.corp.intel.com> References: 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 1/1] FatPkg/EnhancedFatDxe Fix Double Cluster Allocation 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: Thu, 13 Sep 2018 02:48:07 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: edk2-devel On Behalf Of > Robinson, Herbie > Sent: Friday, September 7, 2018 8:07 AM > To: edk2-devel@lists.01.org > Subject: [edk2] [PATCH 1/1] FatPkg/EnhancedFatDxe Fix Double Cluster > Allocation >=20 > This is a fix for a double cluster allocation when the disk is full. The= double > allocation happens because FatGrowEof calls FatAllocateCluster without > immediately marking the each returned cluster as allocated. The fix is t= o > move the FatSetFatEntry call inside the loop. I've also include some > improvements to the sanity checks that I added while tracking this down. > They are optional. >=20 > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by:Herbie Robinson > --- > diff --git a/FatPkg/EnhancedFatDxe/FileSpace.c > b/FatPkg/EnhancedFatDxe/FileSpace.c > index 1254cd6..e17d3b6 100644 > --- a/FatPkg/EnhancedFatDxe/FileSpace.c > +++ b/FatPkg/EnhancedFatDxe/FileSpace.c > @@ -467,7 +467,7 @@ FatGrowEof ( > ClusterCount =3D 0; >=20 > while (!FAT_END_OF_FAT_CHAIN (Cluster)) { > - if (Cluster =3D=3D FAT_CLUSTER_FREE || Cluster >=3D FAT_CLUSTER_= SPECIAL) { > + if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + = 1) { >=20 > DEBUG ( > (EFI_D_INIT | EFI_D_ERROR, > @@ -509,6 +509,11 @@ FatGrowEof ( > goto Done; > } >=20 > + if (NewCluster < FAT_MIN_CLUSTER || NewCluster > Volume- > >MaxCluster + 1) { > + Status =3D EFI_VOLUME_CORRUPTED; > + goto Done; > + } > + > if (LastCluster !=3D 0) { > FatSetFatEntry (Volume, LastCluster, NewCluster); > } else { > @@ -518,12 +523,21 @@ FatGrowEof ( >=20 > LastCluster =3D NewCluster; > CurSize +=3D 1; > + > + // > + // Terminate the cluster list > + // > + // Note that we must do this EVERY time we allocate a cluster, bec= ause > + // FatAllocateCluster scans the FAT looking for a free cluster and > + // "LastCluster" is no longer free! Usually, FatAllocateCluster w= ill > + // start looking with the cluster after "LastCluster"; however, wh= en > + // there is only one free cluster left, it will find "LastCluster" > + // a second time. There are other, less predictable scenarios > + // where this could happen, as well. > + // > + FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST); > + OFile->FileLastCluster =3D LastCluster; > } > - // > - // Terminate the cluster list > - // > - FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST); > - OFile->FileLastCluster =3D LastCluster; > } >=20 > OFile->FileSize =3D (UINTN) NewSizeInBytes; > @@ -603,7 +617,7 @@ FatOFilePosition ( > Cluster =3D FatGetFatEntry (Volume, Cluster); > } >=20 > - if (Cluster < FAT_MIN_CLUSTER) { > + if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) { > return EFI_VOLUME_CORRUPTED; > } >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel