Skip to content

Commit

Permalink
Update Glibc musl rejection patch
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Aug 17, 2020
1 parent f76ffa0 commit 77f197a
Showing 1 changed file with 51 additions and 49 deletions.
100 changes: 51 additions & 49 deletions G/Glibc/bundled/patches/glibc_musl_rejection.patch
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
diff --git a/elf/dl-load.c b/elf/dl-load.c
index a5318f9..2bd9920 100644
index f972524421..c0c79bddbc 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -45,6 +45,7 @@
#include <dl-machine-reject-phdr.h>
#include <dl-sysdep-open.h>
@@ -73,6 +73,8 @@ struct filebuf
#include <dl-prop.h>
#include <not-cancel.h>

+#include <ldconfig.h>
+
#include <endian.h>
#if BYTE_ORDER == BIG_ENDIAN
@@ -1439,6 +1440,61 @@ print_search_path (struct r_search_path_elem **list,
# define byteorder ELFDATA2MSB
@@ -1442,7 +1444,61 @@ print_search_path (struct r_search_path_elem **list,
else
_dl_debug_printf_c ("\t\t(%s)\n", what);
}
-
+
+struct known_names
+{
Expand Down Expand Up @@ -69,10 +71,10 @@ index a5318f9..2bd9920 100644
+ return 0;
+}
+

/* Open a file and verify it is an ELF file for this architecture. We
ignore only ELF files for other architectures. Non-ELF files and
@@ -1484,6 +1540,8 @@ open_verify (const char *name, int fd,
ELF files with different header information cause fatal errors since
@@ -1487,6 +1543,8 @@ open_verify (const char *name, int fd,
} expected_note = { 4, 16, 1, "GNU" };
/* Initialize it to make the compiler happy. */
const char *errstring = NULL;
Expand All @@ -81,79 +83,79 @@ index a5318f9..2bd9920 100644
int errval = 0;

#ifdef SHARED
@@ -1675,8 +1733,15 @@ open_verify (const char *name, int fd,
@@ -1680,8 +1738,14 @@ open_verify (const char *name, int fd,
loader, fd)))
goto close_and_out;

+ dynamic_addr = 0;
+ dynamic_size = 0;
/* Check .note.ABI-tag if present. */
- /* Check .note.ABI-tag if present. */
- for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph)
+ for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph) {
+ if (ph->p_type == PT_DYNAMIC)
+ {
+ dynamic_addr = ph->p_offset;
+ dynamic_size = ph->p_filesz;
+ }
+ dynamic_addr = 0;
+ dynamic_size = 0;
+ /* Check .note.ABI-tag if present. */
+ for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph) {
+ if (ph->p_type == PT_DYNAMIC) {
+ dynamic_addr = ph->p_offset;
+ dynamic_size = ph->p_filesz;
+ }
if (ph->p_type == PT_NOTE && ph->p_filesz >= 32 && ph->p_align >= 4)
{
ElfW(Addr) size = ph->p_filesz;
@@ -1724,6 +1789,20 @@ open_verify (const char *name, int fd,

@@ -1756,7 +1820,21 @@ open_verify (const char *name, int fd,
break;
}
+ }
+ /* Check the dynamic section */
+ if (dynamic_addr != 0) {
+ int err = validate_lib(fd, dynamic_addr, dynamic_size);
+ if (err == -2) {
+ errstring = N_("failed to read file");
+ goto call_lose;
+ }
+ else if (err != 0) {
+ __close (fd);
+ __set_errno (ENOENT);
+ fd = -1;
+ }
+ }
free (abi_note_malloced);
+ /* Check the dynamic section */
+ if (dynamic_addr != 0) {
+ int err = validate_lib(fd, dynamic_addr, dynamic_size);
+ if (err == -2) {
+ errstring = N_("failed to read file");
+ goto call_lose;
+ }
+ else if (err != 0) {
+ __close (fd);
+ __set_errno (ENOENT);
+ fd = -1;
+ }
+ }
}
+ }

return fd;
}
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 99caf9e..d0d7ca1 100644
index 206cd51df6..5ad7e32812 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -888,6 +888,16 @@ search_dir (const struct dir_entry *entry)
@@ -875,6 +875,15 @@ search_dir (const struct dir_entry *entry)
add_to_aux_cache (&lstat_buf, flag, osversion, soname);
}

+ /* Don't try to load MUSL-dependent libraries */
+ if ((flag & FLAG_TYPE_MASK) == FLAG_ELF_MUSL)
+ {
+/* Don't try to load MUSL-dependent libraries */
+ if ((flag & FLAG_TYPE_MASK) == FLAG_ELF_MUSL) {
+ if (real_name != real_file_name)
+ free (real_name);
+ if (opt_verbose)
+ error (0, 0, _("Skipping musl-linked library %s"), file_name);
+ continue;
+ }
+ }
+
if (soname == NULL)
soname = implicit_soname (direntry->d_name, flag);

diff --git a/sysdeps/generic/ldconfig.h b/sysdeps/generic/ldconfig.h
index a61ce5c..6aae9a2 100644
index 2e9ca92c23..2d6529784a 100644
--- a/sysdeps/generic/ldconfig.h
+++ b/sysdeps/generic/ldconfig.h
@@ -27,6 +27,7 @@
#define FLAG_ELF 0x0001
#define FLAG_ELF_LIBC5 0x0002
#define FLAG_ELF_LIBC6 0x0003
+#define FLAG_ELF_MUSL 0x0004
+#define FLAG_ELF_MUSL 0x0004
#define FLAG_REQUIRED_MASK 0xff00
#define FLAG_SPARC_LIB64 0x0100
#define FLAG_IA64_LIB64 0x0200
diff --git a/sysdeps/unix/sysv/linux/aarch64/ldconfig.h b/sysdeps/unix/sysv/linux/aarch64/ldconfig.h
index e1c334c..db85947 100644
index cc7e855e8f..04f4e417f3 100644
--- a/sysdeps/unix/sysv/linux/aarch64/ldconfig.h
+++ b/sysdeps/unix/sysv/linux/aarch64/ldconfig.h
@@ -27,4 +27,5 @@
Expand All @@ -164,7 +166,7 @@ index e1c334c..db85947 100644
+ { "libm.so.6", FLAG_ELF_LIBC6 }, \
+ { "libc.musl-aarch64.so.1", FLAG_ELF_MUSL },
diff --git a/sysdeps/unix/sysv/linux/arm/ldconfig.h b/sysdeps/unix/sysv/linux/arm/ldconfig.h
index a9a467c..cb27b1b 100644
index 040e33ca0d..14b16c1bd3 100644
--- a/sysdeps/unix/sysv/linux/arm/ldconfig.h
+++ b/sysdeps/unix/sysv/linux/arm/ldconfig.h
@@ -22,4 +22,5 @@
Expand All @@ -173,9 +175,9 @@ index a9a467c..cb27b1b 100644
{ "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
+ { "libm.so.6", FLAG_ELF_LIBC6 }, \
+ { "libc.musl-armhf.so.1", FLAG_ELF_MUSL }
+ { "libc.musl-armhf.so.1", FLAG_ELF_MUSL },
diff --git a/sysdeps/unix/sysv/linux/i386/ldconfig.h b/sysdeps/unix/sysv/linux/i386/ldconfig.h
index 7112cb2..07fe905 100644
index 79d156902d..713b6e2e72 100644
--- a/sysdeps/unix/sysv/linux/i386/ldconfig.h
+++ b/sysdeps/unix/sysv/linux/i386/ldconfig.h
@@ -21,4 +21,5 @@
Expand All @@ -184,9 +186,9 @@ index 7112cb2..07fe905 100644
{ "libc.so.5", FLAG_ELF_LIBC5 }, \
- { "libm.so.5", FLAG_ELF_LIBC5 },
+ { "libm.so.5", FLAG_ELF_LIBC5 }, \
+ { "libc.musl-i386.so.1", FLAG_ELF_MUSL }
+ { "libc.musl-i386.so.1", FLAG_ELF_MUSL },
diff --git a/sysdeps/unix/sysv/linux/x86_64/ldconfig.h b/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
index 3a7a75b..e04826a 100644
index 111180a63f..510817b424 100644
--- a/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
+++ b/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
@@ -23,4 +23,5 @@
Expand All @@ -195,4 +197,4 @@ index 3a7a75b..e04826a 100644
{ "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
+ { "libm.so.6", FLAG_ELF_LIBC6 }, \
+ { "libc.musl-x86_64.so.1", FLAG_ELF_MUSL }
+ { "libc.musl-x86_64.so.1", FLAG_ELF_MUSL },

0 comments on commit 77f197a

Please sign in to comment.