[1/3] elf: Remove excessive p_align check on PT_LOAD segments [BZ #28688]

Message ID 20211221215438.3084053-2-hjl.tools@gmail.com
State Committed
Commit 163f625cf9becbb82dfec63a29e566324129c0cd
Headers
Series Remove excessive p_align check on PT_LOAD segments |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

H.J. Lu Dec. 21, 2021, 9:54 p.m. UTC
  p_align does not have to be a multiple of the page size.  Only PT_LOAD
segment layout should be aligned to the page size.

1: Remove p_align check against the page size.
2. Use the page size, instead of p_align, to check PT_LOAD segment layout.
---
 elf/dl-load.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
  

Comments

Florian Weimer Dec. 22, 2021, 10:44 a.m. UTC | #1
* H. J. Lu:

> p_align does not have to be a multiple of the page size.  Only PT_LOAD
> segment layout should be aligned to the page size.
>
> 1: Remove p_align check against the page size.
> 2. Use the page size, instead of p_align, to check PT_LOAD segment layout.
> ---
>  elf/dl-load.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index e61515771a..8d89ab81d1 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -1134,16 +1134,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
>  	case PT_LOAD:
>  	  /* A load command tells us to map in part of the file.
>  	     We record the load commands and process them all later.  */
> -	  if (__glibc_unlikely ((ph->p_align & (GLRO(dl_pagesize) - 1)) != 0))
> -	    {
> -	      errstring = N_("ELF load command alignment not page-aligned");
> -	      goto lose;
> -	    }
>  	  if (__glibc_unlikely (((ph->p_vaddr - ph->p_offset)
> -				 & (ph->p_align - 1)) != 0))
> +				 & (GLRO(dl_pagesize) - 1)) != 0))
>  	    {
>  	      errstring
> -		= N_("ELF load command address/offset not properly aligned");
> +		= N_("ELF load command address/offset not page-aligned");
>  	      goto lose;
>  	    }

It would be nice if we could include the run-time page size in the error
message, but the current structure of the code makes that quite
difficult.

Reviewed-by: Florian Weimer <fweimer@redhat.com>

Thanks,
Florian
  

Patch

diff --git a/elf/dl-load.c b/elf/dl-load.c
index e61515771a..8d89ab81d1 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1134,16 +1134,11 @@  _dl_map_object_from_fd (const char *name, const char *origname, int fd,
 	case PT_LOAD:
 	  /* A load command tells us to map in part of the file.
 	     We record the load commands and process them all later.  */
-	  if (__glibc_unlikely ((ph->p_align & (GLRO(dl_pagesize) - 1)) != 0))
-	    {
-	      errstring = N_("ELF load command alignment not page-aligned");
-	      goto lose;
-	    }
 	  if (__glibc_unlikely (((ph->p_vaddr - ph->p_offset)
-				 & (ph->p_align - 1)) != 0))
+				 & (GLRO(dl_pagesize) - 1)) != 0))
 	    {
 	      errstring
-		= N_("ELF load command address/offset not properly aligned");
+		= N_("ELF load command address/offset not page-aligned");
 	      goto lose;
 	    }