Blame SOURCES/file-5.33-static-PIE-binaries-3.patch

092ea1
From 27c951adbd5d7ebe95f08c18257ea031bdd59ee1 Mon Sep 17 00:00:00 2001
092ea1
From: Vincent Mihalkovic <vmihalko@redhat.com>
092ea1
Date: Mon, 6 Feb 2023 15:00:16 +0100
092ea1
Subject: [PATCH] For dynamic binaries let the df_1 pie flag determine if we
092ea1
 are pie or a shared object, and ignore the mode bits.
092ea1
092ea1
upstream commit: 03084b161cf888b5286dbbcd964c31ccad4f64d9
092ea1
---
092ea1
 src/readelf.c | 4 +++-
092ea1
 1 file changed, 3 insertions(+), 1 deletion(-)
092ea1
092ea1
diff --git a/src/readelf.c b/src/readelf.c
092ea1
index 94cdaca..9c75c0a 100644
092ea1
--- a/src/readelf.c
092ea1
+++ b/src/readelf.c
092ea1
@@ -1058,7 +1058,7 @@ dodynamic(struct magic_set *ms, void *vbuf, size_t offset, size_t size,
092ea1
 
092ea1
 	switch (xdh_tag) {
092ea1
 	case DT_FLAGS_1:
092ea1
-		if (xdh_val == DF_1_PIE)
092ea1
+		if (xdh_val & DF_1_PIE)
092ea1
 			ms->mode |= 0111;
092ea1
 		else
092ea1
 			ms->mode &= ~0111;
092ea1
@@ -1611,6 +1611,8 @@ dophn_exec(struct magic_set *ms, int clazz, int swap, int fd, off_t off,
092ea1
 		switch (xph_type) {
092ea1
 		case PT_DYNAMIC:
092ea1
 			offset = 0;
092ea1
+                        // Let DF_1 determine if we are PIE or not.
092ea1
+                        ms->mode &= ~0111;
092ea1
 			for (;;) {
092ea1
 				if (offset >= (size_t)bufsize)
092ea1
 					break;
092ea1
-- 
092ea1
2.39.1
092ea1