public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ni, Ruiyu" <ruiyu.ni@intel.com>
To: "Robinson, Herbie" <Herbie.Robinson@stratus.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH 1/1] FatPkg/EnhancedFatDxe Fix Double Cluster Allocation
Date: Thu, 13 Sep 2018 02:45:32 +0000	[thread overview]
Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BE071CE@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <DM6PR08MB5436DB2CAC9C0878B5AFEFC1E6000@DM6PR08MB5436.namprd08.prod.outlook.com>

Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>

Thanks/Ray

> -----Original Message-----
> From: edk2-devel <edk2-devel-bounces@lists.01.org> 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
> 
> 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 to
> 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.
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by:Herbie Robinson <Herbie.Robinson@stratus.com>
> ---
> 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  = 0;
> 
>        while (!FAT_END_OF_FAT_CHAIN (Cluster)) {
> -        if (Cluster == FAT_CLUSTER_FREE || Cluster >= FAT_CLUSTER_SPECIAL) {
> +        if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
> 
>            DEBUG (
>              (EFI_D_INIT | EFI_D_ERROR,
> @@ -509,6 +509,11 @@ FatGrowEof (
>          goto Done;
>        }
> 
> +      if (NewCluster < FAT_MIN_CLUSTER || NewCluster > Volume-
> >MaxCluster + 1) {
> +        Status = EFI_VOLUME_CORRUPTED;
> +        goto Done;
> +      }
> +
>        if (LastCluster != 0) {
>          FatSetFatEntry (Volume, LastCluster, NewCluster);
>        } else {
> @@ -518,12 +523,21 @@ FatGrowEof (
> 
>        LastCluster = NewCluster;
>        CurSize += 1;
> +
> +      //
> +      // Terminate the cluster list
> +      //
> +      // Note that we must do this EVERY time we allocate a cluster, because
> +      // FatAllocateCluster scans the FAT looking for a free cluster and
> +      // "LastCluster" is no longer free!  Usually, FatAllocateCluster will
> +      // start looking with the cluster after "LastCluster"; however, when
> +      // 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 = LastCluster;
>      }
> -    //
> -    // Terminate the cluster list
> -    //
> -    FatSetFatEntry (Volume, LastCluster, (UINTN) FAT_CLUSTER_LAST);
> -    OFile->FileLastCluster = LastCluster;
>    }
> 
>    OFile->FileSize = (UINTN) NewSizeInBytes;
> @@ -603,7 +617,7 @@ FatOFilePosition (
>        Cluster = FatGetFatEntry (Volume, Cluster);
>      }
> 
> -    if (Cluster < FAT_MIN_CLUSTER) {
> +    if (Cluster < FAT_MIN_CLUSTER || Cluster > Volume->MaxCluster + 1) {
>        return EFI_VOLUME_CORRUPTED;
>      }
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


  parent reply	other threads:[~2018-09-13  2:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-07  0:07 [PATCH 1/1] FatPkg/EnhancedFatDxe Fix Double Cluster Allocation Robinson, Herbie
2018-09-11 16:02 ` Laszlo Ersek
2018-09-13  2:45 ` Ni, Ruiyu [this message]
  -- strict thread matches above, loose matches on Subject: below --
2018-09-07  3:22 Robinson, Herbie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=734D49CCEBEEF84792F5B80ED585239D5BE071CE@SHSMSX104.ccr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox