[edk2] [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT

Yonghong Zhu posted 1 patch 5 years, 10 months ago
Failed in applying to current master (apply log)
BaseTools/Source/C/GenFw/Elf32Convert.c | 10 +++++++++-
BaseTools/Source/C/GenFw/Elf64Convert.c | 11 ++++++++++-
2 files changed, 19 insertions(+), 2 deletions(-)
[edk2] [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT
Posted by Yonghong Zhu 5 years, 10 months ago
From: Yunhua Feng <yunhuax.feng@intel.com>

Add the logic to check whether mCoffAlignment is larger than
MAX_COFF_ALIGNMENT, and report error for it.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/C/GenFw/Elf32Convert.c | 10 +++++++++-
 BaseTools/Source/C/GenFw/Elf64Convert.c | 11 ++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
index 14fe4a2..e0f6491 100644
--- a/BaseTools/Source/C/GenFw/Elf32Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
@@ -1,9 +1,9 @@
 /** @file
 Elf32 Convert solution
 
-Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
 distribution.  The full text of the license may be found at
@@ -382,10 +382,18 @@ ScanSections32 (
       mCoffAlignment = (UINT32)shdr->sh_addralign;
     }
   }
 
   //
+  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
+  //
+  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
+    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
+    assert (FALSE);
+  }
+
+  //
   // Move the PE/COFF header right before the first section. This will help us
   // save space when converting to TE.
   //
   if (mCoffAlignment > mCoffOffset) {
     mNtHdrOffset += mCoffAlignment - mCoffOffset;
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
index c39bdff..9e68d22 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -1,9 +1,9 @@
 /** @file
 Elf64 convert solution
 
-Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
 distribution.  The full text of the license may be found at
@@ -375,10 +375,19 @@ ScanSections64 (
       mCoffAlignment = (UINT32)shdr->sh_addralign;
     }
   }
 
   //
+  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
+  //
+  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
+    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
+    assert (FALSE);
+  }
+
+
+  //
   // Move the PE/COFF header right before the first section. This will help us
   // save space when converting to TE.
   //
   if (mCoffAlignment > mCoffOffset) {
     mNtHdrOffset += mCoffAlignment - mCoffOffset;
-- 
2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Re: [edk2] [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT
Posted by Gao, Liming 5 years, 10 months ago
Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Zhu, Yonghong
> Sent: Thursday, June 7, 2018 10:03 AM
> To: edk2-devel@lists.01.org
> Cc: Feng, YunhuaX <yunhuax.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT
> 
> From: Yunhua Feng <yunhuax.feng@intel.com>
> 
> Add the logic to check whether mCoffAlignment is larger than
> MAX_COFF_ALIGNMENT, and report error for it.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
> ---
>  BaseTools/Source/C/GenFw/Elf32Convert.c | 10 +++++++++-
>  BaseTools/Source/C/GenFw/Elf64Convert.c | 11 ++++++++++-
>  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
> index 14fe4a2..e0f6491 100644
> --- a/BaseTools/Source/C/GenFw/Elf32Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
> @@ -1,9 +1,9 @@
>  /** @file
>  Elf32 Convert solution
> 
> -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
>  Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
> 
>  This program and the accompanying materials are licensed and made available
>  under the terms and conditions of the BSD License which accompanies this
>  distribution.  The full text of the license may be found at
> @@ -382,10 +382,18 @@ ScanSections32 (
>        mCoffAlignment = (UINT32)shdr->sh_addralign;
>      }
>    }
> 
>    //
> +  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
> +  //
> +  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
> +    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
> +    assert (FALSE);
> +  }
> +
> +  //
>    // Move the PE/COFF header right before the first section. This will help us
>    // save space when converting to TE.
>    //
>    if (mCoffAlignment > mCoffOffset) {
>      mNtHdrOffset += mCoffAlignment - mCoffOffset;
> diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
> index c39bdff..9e68d22 100644
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -1,9 +1,9 @@
>  /** @file
>  Elf64 convert solution
> 
> -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
>  Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
> 
>  This program and the accompanying materials are licensed and made available
>  under the terms and conditions of the BSD License which accompanies this
>  distribution.  The full text of the license may be found at
> @@ -375,10 +375,19 @@ ScanSections64 (
>        mCoffAlignment = (UINT32)shdr->sh_addralign;
>      }
>    }
> 
>    //
> +  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
> +  //
> +  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
> +    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
> +    assert (FALSE);
> +  }
> +
> +
> +  //
>    // Move the PE/COFF header right before the first section. This will help us
>    // save space when converting to TE.
>    //
>    if (mCoffAlignment > mCoffOffset) {
>      mNtHdrOffset += mCoffAlignment - mCoffOffset;
> --
> 2.6.1.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel