svn commit: r295366 - stable/10/sys/kern

Konstantin Belousov kib at FreeBSD.org
Sun Feb 7 09:51:23 UTC 2016


Author: kib
Date: Sun Feb  7 09:51:22 2016
New Revision: 295366
URL: https://svnweb.freebsd.org/changeset/base/295366

Log:
  MFC r295277:
  When matching brand to the ELF binary by notes, try to find a brand
  with interpreter name exactly matching one wanted by the binary.
  
  Approved by:	re (delphij)

Modified:
  stable/10/sys/kern/imgact_elf.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/kern/imgact_elf.c
==============================================================================
--- stable/10/sys/kern/imgact_elf.c	Sun Feb  7 05:15:51 2016	(r295365)
+++ stable/10/sys/kern/imgact_elf.c	Sun Feb  7 09:51:22 2016	(r295366)
@@ -261,7 +261,7 @@ __elfN(get_brandinfo)(struct image_param
     int interp_name_len, int32_t *osrel)
 {
 	const Elf_Ehdr *hdr = (const Elf_Ehdr *)imgp->image_header;
-	Elf_Brandinfo *bi;
+	Elf_Brandinfo *bi, *bi_m;
 	boolean_t ret;
 	int i;
 
@@ -273,6 +273,7 @@ __elfN(get_brandinfo)(struct image_param
 	 */
 
 	/* Look for an ".note.ABI-tag" ELF section */
+	bi_m = NULL;
 	for (i = 0; i < MAX_BRANDS; i++) {
 		bi = elf_brand_list[i];
 		if (bi == NULL)
@@ -280,10 +281,28 @@ __elfN(get_brandinfo)(struct image_param
 		if (hdr->e_machine == bi->machine && (bi->flags &
 		    (BI_BRAND_NOTE|BI_BRAND_NOTE_MANDATORY)) != 0) {
 			ret = __elfN(check_note)(imgp, bi->brand_note, osrel);
+			/*
+			 * If note checker claimed the binary, but the
+			 * interpreter path in the image does not
+			 * match default one for the brand, try to
+			 * search for other brands with the same
+			 * interpreter.  Either there is better brand
+			 * with the right interpreter, or, failing
+			 * this, we return first brand which accepted
+			 * our note and, optionally, header.
+			 */
+			if (ret && bi_m == NULL && (strlen(bi->interp_path) +
+			    1 != interp_name_len || strncmp(interp,
+			    bi->interp_path, interp_name_len) != 0)) {
+				bi_m = bi;
+				ret = 0;
+			}
 			if (ret)
 				return (bi);
 		}
 	}
+	if (bi_m != NULL)
+		return (bi_m);
 
 	/* If the executable has a brand, search for it in the brand list. */
 	for (i = 0; i < MAX_BRANDS; i++) {


More information about the svn-src-stable-10 mailing list