public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Invalid read in process_netbsd_elf_note
@ 2020-03-19  3:26 Alan Modra
  2020-03-19 12:05 ` Kamil Rytarowski
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2020-03-19  3:26 UTC (permalink / raw)
  To: binutils

	* readelf.c (process_netbsd_elf_note): Validate descsz before
	accessing descdata.  Formatting.

diff --git a/binutils/readelf.c b/binutils/readelf.c
index a11297845e..c8ca66e52c 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -18402,15 +18402,17 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
   switch (pnote->type)
     {
     case NT_NETBSD_IDENT:
+      if (pnote->descsz < 1)
+	break;
       version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
       if ((version / 10000) % 100)
-        printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
+	printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
 		version, version / 100000000, (version / 1000000) % 100,
 		(version / 10000) % 100 > 26 ? "Z" : "",
 		'A' + (version / 10000) % 26);
       else
 	printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
-	        version, version / 100000000, (version / 1000000) % 100,
+		version, version / 100000000, (version / 1000000) % 100,
 		(version / 100) % 100);
       return TRUE;
 
@@ -18421,6 +18423,8 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
 
 #ifdef   NT_NETBSD_PAX
     case NT_NETBSD_PAX:
+      if (pnote->descsz < 1)
+	break;
       version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
       printf ("  NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz,
 	      ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""),
@@ -18431,12 +18435,11 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
 	      ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
       return TRUE;
 #endif
-
-    default:
-      printf ("  NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
-	      pnote->type);
-      return FALSE;
     }
+
+  printf ("  NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
+	  pnote->descsz, pnote->type);
+  return FALSE;
 }
 
 static const char *

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Invalid read in process_netbsd_elf_note
  2020-03-19  3:26 Invalid read in process_netbsd_elf_note Alan Modra
@ 2020-03-19 12:05 ` Kamil Rytarowski
  0 siblings, 0 replies; 2+ messages in thread
From: Kamil Rytarowski @ 2020-03-19 12:05 UTC (permalink / raw)
  To: Alan Modra, binutils


[-- Attachment #1.1: Type: text/plain, Size: 2154 bytes --]

Looks OK.

On 19.03.2020 04:26, Alan Modra via Binutils wrote:
> 	* readelf.c (process_netbsd_elf_note): Validate descsz before
> 	accessing descdata.  Formatting.
> 
> diff --git a/binutils/readelf.c b/binutils/readelf.c
> index a11297845e..c8ca66e52c 100644
> --- a/binutils/readelf.c
> +++ b/binutils/readelf.c
> @@ -18402,15 +18402,17 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
>    switch (pnote->type)
>      {
>      case NT_NETBSD_IDENT:
> +      if (pnote->descsz < 1)
> +	break;
>        version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
>        if ((version / 10000) % 100)
> -        printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
> +	printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz,
>  		version, version / 100000000, (version / 1000000) % 100,
>  		(version / 10000) % 100 > 26 ? "Z" : "",
>  		'A' + (version / 10000) % 26);
>        else
>  	printf ("  NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz,
> -	        version, version / 100000000, (version / 1000000) % 100,
> +		version, version / 100000000, (version / 1000000) % 100,
>  		(version / 100) % 100);
>        return TRUE;
>  
> @@ -18421,6 +18423,8 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
>  
>  #ifdef   NT_NETBSD_PAX
>      case NT_NETBSD_PAX:
> +      if (pnote->descsz < 1)
> +	break;
>        version = byte_get ((unsigned char *) pnote->descdata, sizeof (version));
>        printf ("  NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz,
>  	      ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""),
> @@ -18431,12 +18435,11 @@ process_netbsd_elf_note (Elf_Internal_Note * pnote)
>  	      ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : ""));
>        return TRUE;
>  #endif
> -
> -    default:
> -      printf ("  NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz,
> -	      pnote->type);
> -      return FALSE;
>      }
> +
> +  printf ("  NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n",
> +	  pnote->descsz, pnote->type);
> +  return FALSE;
>  }
>  
>  static const char *
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-19 12:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-19  3:26 Invalid read in process_netbsd_elf_note Alan Modra
2020-03-19 12:05 ` Kamil Rytarowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).