public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Remove distinguish library code
@ 2022-02-21 17:59 Adhemerval Zanella
  2022-02-21 17:59 ` [PATCH 1/2] Remove kernel version check Adhemerval Zanella
  2022-02-21 17:59 ` [PATCH 2/2] Remove dl-librecon.h header Adhemerval Zanella
  0 siblings, 2 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2022-02-21 17:59 UTC (permalink / raw)
  To: libc-alpha

First patch removes the kernel version check on Linux, which
is a feature that from times to times cases some issues (such
as [1]).

Second is the distinguish library to handle ancient and long
unused libc5 and aout files.

[1 ]https://github.com/microsoft/WSL/issues/3023

Adhemerval Zanella (2):
  Remove kernel version check
  Remove dl-librecon.h header.

 NEWS                                       |  7 ++
 config.h.in                                |  3 +
 csu/libc-start.c                           |  8 --
 csu/version.c                              |  3 +
 elf/dl-cache.c                             |  3 -
 elf/dl-diagnostics.c                       |  5 --
 elf/dl-load.c                              | 30 ++++---
 elf/dl-support.c                           | 17 +---
 elf/rtld.c                                 | 40 +---------
 sysdeps/generic/dl-librecon.h              | 24 ------
 sysdeps/generic/ldsodefs.h                 |  9 ---
 sysdeps/unix/sysv/linux/configure          |  5 ++
 sysdeps/unix/sysv/linux/configure.ac       |  2 +
 sysdeps/unix/sysv/linux/dl-librecon.h      | 59 --------------
 sysdeps/unix/sysv/linux/dl-osinfo.h        | 25 ------
 sysdeps/unix/sysv/linux/dl-sysdep.c        | 93 ----------------------
 sysdeps/unix/sysv/linux/dl-sysdep.h        |  7 --
 sysdeps/unix/sysv/linux/i386/dl-librecon.h | 61 --------------
 sysdeps/unix/sysv/linux/m68k/dl-librecon.h |  1 -
 19 files changed, 38 insertions(+), 364 deletions(-)
 delete mode 100644 sysdeps/generic/dl-librecon.h
 delete mode 100644 sysdeps/unix/sysv/linux/dl-librecon.h
 delete mode 100644 sysdeps/unix/sysv/linux/i386/dl-librecon.h
 delete mode 100644 sysdeps/unix/sysv/linux/m68k/dl-librecon.h

-- 
2.32.0


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

* [PATCH 1/2] Remove kernel version check
  2022-02-21 17:59 [PATCH 0/2] Remove distinguish library code Adhemerval Zanella
@ 2022-02-21 17:59 ` Adhemerval Zanella
  2022-02-28 19:00   ` Florian Weimer
  2022-02-21 17:59 ` [PATCH 2/2] Remove dl-librecon.h header Adhemerval Zanella
  1 sibling, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2022-02-21 17:59 UTC (permalink / raw)
  To: libc-alpha

The kernel version check is used to avoid glibc to run on older
kernels where some syscall are not available and fallback code are
not enabled to handle graciously fail.  However, it does not prevent
if the kernel does not correctly advertise its version through
vDSO note, uname or procfs.

Also kernel version checks are sometime not desirable by users,
where they want to deploy on different system with different kernel
version knowing the minimum set of syscall is always presented on
such systems.

The kernel version check has been removed along with the
LD_ASSUME_KERNEL environment variable.  The minimum kernel used to
built glibc is still provided through NT_GNU_ABI_TAG ELF note and
also printed when libc.so is issued.

Checked on x86_64-linux-gnu.
---
 NEWS                                       |  5 ++
 config.h.in                                |  3 +
 csu/libc-start.c                           |  8 --
 csu/version.c                              |  3 +
 elf/dl-cache.c                             |  3 -
 elf/dl-diagnostics.c                       |  5 --
 elf/dl-load.c                              | 30 ++++---
 elf/dl-support.c                           |  4 -
 elf/rtld.c                                 | 15 ----
 sysdeps/generic/ldsodefs.h                 |  6 --
 sysdeps/unix/sysv/linux/configure          |  5 ++
 sysdeps/unix/sysv/linux/configure.ac       |  2 +
 sysdeps/unix/sysv/linux/dl-librecon.h      | 59 --------------
 sysdeps/unix/sysv/linux/dl-osinfo.h        | 25 ------
 sysdeps/unix/sysv/linux/dl-sysdep.c        | 93 ----------------------
 sysdeps/unix/sysv/linux/dl-sysdep.h        |  7 --
 sysdeps/unix/sysv/linux/i386/dl-librecon.h |  2 -
 17 files changed, 32 insertions(+), 243 deletions(-)
 delete mode 100644 sysdeps/unix/sysv/linux/dl-librecon.h

diff --git a/NEWS b/NEWS
index 626eeabf5d..bbbcc55b0c 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,11 @@ Deprecated and removed features, and other changes affecting compatibility:
   removal of the LD_TRACE_PRELINKING, and LD_USE_LOAD_BIAS, environment
   variables and their functionality in the dynamic loader.
 
+* The kernel version check has been removed along with the LD_ASSUME_KERNEL
+  environment variable.  The minimum kernel used to built glibc is still
+  provided through NT_GNU_ABI_TAG ELF note and also printed when libc.so
+  is issued directly.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
diff --git a/config.h.in b/config.h.in
index ff8597413d..dd466e102a 100644
--- a/config.h.in
+++ b/config.h.in
@@ -138,6 +138,9 @@
 /* Linux specific: minimum supported kernel version.  */
 #undef	__LINUX_KERNEL_VERSION
 
+/* Linux specific: __LINUX_KERNEL_VERSION as a string.  */
+#undef  __LINUX_KERNEL_VERSION_STR
+
 /* Override abi-tags ABI version if necessary.  */
 #undef  __ABI_TAG_VERSION
 
diff --git a/csu/libc-start.c b/csu/libc-start.c
index e91f996426..6e22c1f19e 100644
--- a/csu/libc-start.c
+++ b/csu/libc-start.c
@@ -316,14 +316,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
   __stack_chk_guard = stack_chk_guard;
 # endif
 
-# ifdef DL_SYSDEP_OSCHECK
-  {
-    /* This needs to run to initiliaze _dl_osversion before TLS
-       setup might check it.  */
-    DL_SYSDEP_OSCHECK (__libc_fatal);
-  }
-# endif
-
   /* Initialize libpthread if linked in.  */
   if (__pthread_initialize_minimal != NULL)
     __pthread_initialize_minimal ();
diff --git a/csu/version.c b/csu/version.c
index 0de4df5b3f..8c0ed79c01 100644
--- a/csu/version.c
+++ b/csu/version.c
@@ -33,6 +33,9 @@ Compiled by GNU CC version "__VERSION__".\n"
 #ifdef LIBC_ABIS_STRING
 LIBC_ABIS_STRING
 #endif
+#ifdef __LINUX_KERNEL_VERSION_STR
+"Minimum supported kernel: " __LINUX_KERNEL_VERSION_STR "\n"
+#endif
 "For bug reporting instructions, please see:\n\
 "REPORT_BUGS_TO".\n";
 
diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 88bf78ad7c..8bbf110d02 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -297,9 +297,6 @@ search_cache (const char *string_table, uint32_t string_table_size,
 
 		      if ((libnew->hwcap & hwcap_exclude) && !named_hwcap)
 			continue;
-		      if (GLRO (dl_osversion)
-			  && libnew->osversion > GLRO (dl_osversion))
-			continue;
 		      if (_DL_PLATFORMS_COUNT
 			  && (libnew->hwcap & _DL_HWCAP_PLATFORM) != 0
 			  && ((libnew->hwcap & _DL_HWCAP_PLATFORM)
diff --git a/elf/dl-diagnostics.c b/elf/dl-diagnostics.c
index d29bdd6904..dd3871b1e0 100644
--- a/elf/dl-diagnostics.c
+++ b/elf/dl-diagnostics.c
@@ -231,10 +231,6 @@ print_version (void)
 void
 _dl_print_diagnostics (char **environ)
 {
-#ifdef HAVE_DL_DISCOVER_OSVERSION
-  _dl_diagnostics_print_labeled_value
-    ("dl_discover_osversion", _dl_discover_osversion ());
-#endif
   _dl_diagnostics_print_labeled_string ("dl_dst_lib", DL_DST_LIB);
   _dl_diagnostics_print_labeled_value ("dl_hwcap", GLRO (dl_hwcap));
   _dl_diagnostics_print_labeled_value ("dl_hwcap_important", HWCAP_IMPORTANT);
@@ -243,7 +239,6 @@ _dl_print_diagnostics (char **environ)
     ("dl_hwcaps_subdirs", _dl_hwcaps_subdirs);
   _dl_diagnostics_print_labeled_value
     ("dl_hwcaps_subdirs_active", _dl_hwcaps_subdirs_active ());
-  _dl_diagnostics_print_labeled_value ("dl_osversion", GLRO (dl_osversion));
   _dl_diagnostics_print_labeled_value ("dl_pagesize", GLRO (dl_pagesize));
   _dl_diagnostics_print_labeled_string ("dl_platform", GLRO (dl_platform));
   _dl_diagnostics_print_labeled_string
diff --git a/elf/dl-load.c b/elf/dl-load.c
index 892e8ef2f6..ba175a0035 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1631,7 +1631,6 @@ open_verify (const char *name, int fd,
       ElfW(Phdr) *phdr, *ph;
       ElfW(Word) *abi_note;
       ElfW(Word) *abi_note_malloced = NULL;
-      unsigned int osversion;
       size_t maplength;
 
       /* We successfully opened the file.  Now verify it is a file
@@ -1695,13 +1694,16 @@ open_verify (const char *name, int fd,
 #endif
 	      )
 	    errstring = N_("invalid ELF header");
+
 	  else if (ehdr->e_ident[EI_CLASS] != ELFW(CLASS))
 	    {
 	      /* This is not a fatal error.  On architectures where
 		 32-bit and 64-bit binaries can be run this might
 		 happen.  */
 	      *found_other_class = true;
-	      goto close_and_out;
+	      __close_nocancel (fd);
+	      __set_errno (ENOENT);
+	      return -1;
 	    }
 	  else if (ehdr->e_ident[EI_DATA] != byteorder)
 	    {
@@ -1736,7 +1738,11 @@ open_verify (const char *name, int fd,
 	  goto lose;
 	}
       if (! __glibc_likely (elf_machine_matches_host (ehdr)))
-	goto close_and_out;
+	{
+	  __close_nocancel (fd);
+	  __set_errno (ENOENT);
+	  return -1;
+	}
       else if (__glibc_unlikely (ehdr->e_type != ET_DYN
 				 && ehdr->e_type != ET_EXEC))
 	{
@@ -1768,7 +1774,11 @@ open_verify (const char *name, int fd,
       if (__glibc_unlikely (elf_machine_reject_phdr_p
 			    (phdr, ehdr->e_phnum, fbp->buf, fbp->len,
 			     loader, fd)))
-	goto close_and_out;
+	{
+	  __close_nocancel (fd);
+	  __set_errno (ENOENT);
+	  return -1;
+	}
 
       /* Check .note.ABI-tag if present.  */
       for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph)
@@ -1820,18 +1830,6 @@ open_verify (const char *name, int fd,
 	    if (size == 0)
 	      continue;
 
-	    osversion = (abi_note[5] & 0xff) * 65536
-			+ (abi_note[6] & 0xff) * 256
-			+ (abi_note[7] & 0xff);
-	    if (abi_note[4] != __ABI_TAG_OS
-		|| (GLRO(dl_osversion) && GLRO(dl_osversion) < osversion))
-	      {
-	      close_and_out:
-		__close_nocancel (fd);
-		__set_errno (ENOENT);
-		fd = -1;
-	      }
-
 	    break;
 	  }
       free (abi_note_malloced);
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 6d2c4baf81..1d648ce3a6 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -394,10 +394,6 @@ _dl_non_dynamic_init (void)
   DL_PLATFORM_INIT;
 #endif
 
-#ifdef DL_OSVERSION_INIT
-  DL_OSVERSION_INIT;
-#endif
-
   /* Now determine the length of the platform string.  */
   if (_dl_platform != NULL)
     _dl_platformlen = strlen (_dl_platform);
diff --git a/elf/rtld.c b/elf/rtld.c
index 19e328f89e..11110cb436 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -384,9 +384,6 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
     ._dl_error_free = _dl_error_free,
     ._dl_tls_get_addr_soft = _dl_tls_get_addr_soft,
     ._dl_libc_freeres = __rtld_libc_freeres,
-#ifdef HAVE_DL_DISCOVER_OSVERSION
-    ._dl_discover_osversion = _dl_discover_osversion
-#endif
   };
 /* If we would use strong_alias here the compiler would see a
    non-hidden definition.  This would undo the effect of the previous
@@ -1715,10 +1712,6 @@ dl_main (const ElfW(Phdr) *phdr,
   /* With vDSO setup we can initialize the function pointers.  */
   setup_vdso_pointers ();
 
-#ifdef DL_SYSDEP_OSCHECK
-  DL_SYSDEP_OSCHECK (_dl_fatal_printf);
-#endif
-
   /* Initialize the data structures for the search paths for shared
      objects.  */
   call_init_paths (&state);
@@ -2644,14 +2637,6 @@ process_envvars (struct dl_main_state *state)
 	    GLRO(dl_dynamic_weak) = 1;
 	  break;
 
-	case 13:
-	  /* We might have some extra environment variable with length 13
-	     to handle.  */
-#ifdef EXTRA_LD_ENVVARS_13
-	  EXTRA_LD_ENVVARS_13
-#endif
-	  break;
-
 	case 14:
 	  /* Where to place the profiling data file.  */
 	  if (!__libc_enable_secure
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 9878e7e87e..97cbe41171 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -563,8 +563,6 @@ struct rtld_global_ro
 /* These two are used only internally.  */
 #define DL_DEBUG_HELP       (1 << 10)
 
-  /* OS version.  */
-  EXTERN unsigned int _dl_osversion;
   /* Platform name.  */
   EXTERN const char *_dl_platform;
   EXTERN size_t _dl_platformlen;
@@ -712,10 +710,6 @@ struct rtld_global_ro
      dlopen.  */
   int (*_dl_find_object) (void *, struct dl_find_object *);
 
-#ifdef HAVE_DL_DISCOVER_OSVERSION
-  int (*_dl_discover_osversion) (void);
-#endif
-
   /* Dynamic linker operations used after static dlopen.  */
   const struct dlfcn_hook *_dl_dlfcn_hook;
 
diff --git a/sysdeps/unix/sysv/linux/configure b/sysdeps/unix/sysv/linux/configure
index 4ff02c9b6d..312055c469 100644
--- a/sysdeps/unix/sysv/linux/configure
+++ b/sysdeps/unix/sysv/linux/configure
@@ -70,6 +70,7 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for kernel header at least $minimum_kernel" >&5
 $as_echo_n "checking for kernel header at least $minimum_kernel... " >&6; }
 decnum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/(\1 * 65536 + \2 * 256 + \3)/'`;
+abinumstr=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1.\2.\3/'`;
 abinum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1,\2,\3/'`;
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
 /* end confdefs.h.  */
@@ -96,6 +97,10 @@ $as_echo "$libc_minimum_kernel" >&6; }
 if test "$libc_minimum_kernel" = ok; then
   cat >>confdefs.h <<_ACEOF
 #define __LINUX_KERNEL_VERSION $decnum
+_ACEOF
+
+  cat >>confdefs.h <<_ACEOF
+#define __LINUX_KERNEL_VERSION_STR "$abinumstr"
 _ACEOF
 
   cat >>confdefs.h <<_ACEOF
diff --git a/sysdeps/unix/sysv/linux/configure.ac b/sysdeps/unix/sysv/linux/configure.ac
index 197b7e66c8..5896d1135b 100644
--- a/sysdeps/unix/sysv/linux/configure.ac
+++ b/sysdeps/unix/sysv/linux/configure.ac
@@ -50,6 +50,7 @@ fi
 AC_MSG_CHECKING(for kernel header at least $minimum_kernel)
 changequote(,)dnl
 decnum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/(\1 * 65536 + \2 * 256 + \3)/'`;
+abinumstr=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1.\2.\3/'`;
 abinum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1,\2,\3/'`;
 changequote([,])dnl
 AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[#include <linux/version.h>
@@ -59,6 +60,7 @@ AC_PREPROC_IFELSE([AC_LANG_PROGRAM([[#include <linux/version.h>
 AC_MSG_RESULT($libc_minimum_kernel)
 if test "$libc_minimum_kernel" = ok; then
   AC_DEFINE_UNQUOTED(__LINUX_KERNEL_VERSION, $decnum)
+  AC_DEFINE_UNQUOTED(__LINUX_KERNEL_VERSION_STR, "$abinumstr")
   AC_DEFINE_UNQUOTED(__ABI_TAG_VERSION, $abinum)
 else
   AC_MSG_ERROR([*** The available kernel headers are older than the requested
diff --git a/sysdeps/unix/sysv/linux/dl-librecon.h b/sysdeps/unix/sysv/linux/dl-librecon.h
deleted file mode 100644
index dfebcea4d8..0000000000
--- a/sysdeps/unix/sysv/linux/dl-librecon.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Optional code to distinguish library flavours.
-   Copyright (C) 2001-2022 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#ifndef _DL_LIBRECON_H
-#define _DL_LIBRECON_H	1
-
-static inline void __attribute__ ((unused, always_inline))
-_dl_osversion_init (char *assume_kernel)
-{
-  unsigned long int i, j, osversion = 0;
-  char *p = assume_kernel, *q;
-
-  for (i = 0; i < 3; i++, p = q + 1)
-    {
-      j = _dl_strtoul (p, &q);
-      if (j >= 255 || p == q || (i < 2 && *q && *q != '.'))
-	{
-	  osversion = 0;
-	  break;
-	}
-      osversion |= j << (16 - 8 * i);
-      if (!*q)
-	break;
-    }
-  if (osversion)
-    GLRO(dl_osversion) = osversion;
-}
-
-/* Recognizing extra environment variables.  */
-#define EXTRA_LD_ENVVARS_13 \
-    if (memcmp (envline, "ASSUME_KERNEL", 13) == 0)			      \
-      {									      \
-	_dl_osversion_init (&envline[14]);				      \
-	break;								      \
-      }
-
-#define DL_OSVERSION_INIT \
-  do {									      \
-    char *assume_kernel = getenv ("LD_ASSUME_KERNEL");			      \
-    if (assume_kernel)							      \
-      _dl_osversion_init (assume_kernel);				      \
-  } while (0)
-
-#endif /* dl-librecon.h */
diff --git a/sysdeps/unix/sysv/linux/dl-osinfo.h b/sysdeps/unix/sysv/linux/dl-osinfo.h
index 349d93e8ed..7888915f12 100644
--- a/sysdeps/unix/sysv/linux/dl-osinfo.h
+++ b/sysdeps/unix/sysv/linux/dl-osinfo.h
@@ -22,31 +22,6 @@
 #include <stdint.h>
 #include <not-cancel.h>
 
-#ifndef MIN
-# define MIN(a,b) (((a)<(b))?(a):(b))
-#endif
-
-#define DL_SYSDEP_OSCHECK(FATAL)					      \
-  do {									      \
-    /* Test whether the kernel is new enough.  This test is only performed    \
-       if the library is not compiled to run on all kernels.  */	      \
-									      \
-    int version = _dl_discover_osversion ();				      \
-    if (__glibc_likely (version >= 0))					      \
-      {									      \
-	if (__builtin_expect (GLRO(dl_osversion) == 0, 1)		      \
-	    || GLRO(dl_osversion) > version)				      \
-	  GLRO(dl_osversion) = version;					      \
-									      \
-	/* Now we can test with the required version.  */		      \
-	if (__LINUX_KERNEL_VERSION > 0 && version < __LINUX_KERNEL_VERSION)   \
-	  /* Not sufficent.  */						      \
-	  FATAL ("FATAL: kernel too old\n");				      \
-      }									      \
-    else if (__LINUX_KERNEL_VERSION > 0)				      \
-      FATAL ("FATAL: cannot determine kernel version\n");		      \
-  } while (0)
-
 static inline uintptr_t __attribute__ ((always_inline))
 _dl_setup_stack_chk_guard (void *dl_random)
 {
diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.c b/sysdeps/unix/sysv/linux/dl-sysdep.c
index 8ad72c4b7b..ae1856a4ef 100644
--- a/sysdeps/unix/sysv/linux/dl-sysdep.c
+++ b/sysdeps/unix/sysv/linux/dl-sysdep.c
@@ -300,96 +300,3 @@ _dl_show_auxv (void)
 }
 
 #endif /* SHARED */
-
-
-int
-attribute_hidden
-_dl_discover_osversion (void)
-{
-#ifdef SHARED
-  if (GLRO(dl_sysinfo_map) != NULL)
-    {
-      /* If the kernel-supplied DSO contains a note indicating the kernel's
-	 version, we don't need to call uname or parse any strings.  */
-
-      static const struct
-      {
-	ElfW(Nhdr) hdr;
-	char vendor[8];
-      } expected_note = { { sizeof "Linux", sizeof (ElfW(Word)), 0 }, "Linux" };
-      const ElfW(Phdr) *const phdr = GLRO(dl_sysinfo_map)->l_phdr;
-      const ElfW(Word) phnum = GLRO(dl_sysinfo_map)->l_phnum;
-      for (uint_fast16_t i = 0; i < phnum; ++i)
-	if (phdr[i].p_type == PT_NOTE)
-	  {
-	    const ElfW(Addr) start = (phdr[i].p_vaddr
-				      + GLRO(dl_sysinfo_map)->l_addr);
-	    const ElfW(Nhdr) *note = (const void *) start;
-	    while ((ElfW(Addr)) (note + 1) - start < phdr[i].p_memsz)
-	      {
-		if (!memcmp (note, &expected_note, sizeof expected_note))
-		  return *(const ElfW(Word) *) ((const void *) note
-						+ sizeof expected_note);
-#define ROUND(len) (((len) + sizeof note->n_type - 1) & -sizeof note->n_type)
-		note = ((const void *) (note + 1)
-			+ ROUND (note->n_namesz) + ROUND (note->n_descsz));
-#undef ROUND
-	      }
-	  }
-    }
-#endif /* SHARED */
-
-  char bufmem[64];
-  char *buf = bufmem;
-  unsigned int version;
-  int parts;
-  char *cp;
-  struct utsname uts;
-
-  /* Try the uname system call.  */
-  if (__uname (&uts))
-    {
-      /* This was not successful.  Now try reading the /proc filesystem.  */
-      int fd = __open64_nocancel ("/proc/sys/kernel/osrelease", O_RDONLY);
-      if (fd < 0)
-	return -1;
-      ssize_t reslen = __read_nocancel (fd, bufmem, sizeof (bufmem));
-      __close_nocancel (fd);
-      if (reslen <= 0)
-	/* This also didn't work.  We give up since we cannot
-	   make sure the library can actually work.  */
-	return -1;
-      buf[MIN (reslen, (ssize_t) sizeof (bufmem) - 1)] = '\0';
-    }
-  else
-    buf = uts.release;
-
-  /* Now convert it into a number.  The string consists of at most
-     three parts.  */
-  version = 0;
-  parts = 0;
-  cp = buf;
-  while ((*cp >= '0') && (*cp <= '9'))
-    {
-      unsigned int here = *cp++ - '0';
-
-      while ((*cp >= '0') && (*cp <= '9'))
-	{
-	  here *= 10;
-	  here += *cp++ - '0';
-	}
-
-      ++parts;
-      version <<= 8;
-      version |= here;
-
-      if (*cp++ != '.' || parts == 3)
-	/* Another part following?  */
-	break;
-    }
-
-  if (parts < 3)
-    version <<= 8 * (3 - parts);
-
-  return version;
-}
diff --git a/sysdeps/unix/sysv/linux/dl-sysdep.h b/sysdeps/unix/sysv/linux/dl-sysdep.h
index cb8bf7e6b1..b3ae5cb637 100644
--- a/sysdeps/unix/sysv/linux/dl-sysdep.h
+++ b/sysdeps/unix/sysv/linux/dl-sysdep.h
@@ -24,10 +24,3 @@
    we aren't making direct use of it.  So enable this across the board.  */
 
 #define NEED_DL_SYSINFO_DSO	1
-
-
-#ifndef __ASSEMBLER__
-/* Get version of the OS.  */
-extern int _dl_discover_osversion (void) attribute_hidden;
-# define HAVE_DL_DISCOVER_OSVERSION	1
-#endif
diff --git a/sysdeps/unix/sysv/linux/i386/dl-librecon.h b/sysdeps/unix/sysv/linux/i386/dl-librecon.h
index 7882679f20..78e3f0d02d 100644
--- a/sysdeps/unix/sysv/linux/i386/dl-librecon.h
+++ b/sysdeps/unix/sysv/linux/i386/dl-librecon.h
@@ -18,8 +18,6 @@
 
 #ifndef _DL_LIBRECON_H
 
-#include <sysdeps/unix/sysv/linux/dl-librecon.h>
-
 #define DISTINGUISH_LIB_VERSIONS \
   do									      \
     {									      \
-- 
2.32.0


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

* [PATCH 2/2] Remove dl-librecon.h header.
  2022-02-21 17:59 [PATCH 0/2] Remove distinguish library code Adhemerval Zanella
  2022-02-21 17:59 ` [PATCH 1/2] Remove kernel version check Adhemerval Zanella
@ 2022-02-21 17:59 ` Adhemerval Zanella
  2022-02-28 19:11   ` Florian Weimer
  1 sibling, 1 reply; 7+ messages in thread
From: Adhemerval Zanella @ 2022-02-21 17:59 UTC (permalink / raw)
  To: libc-alpha

The Linux version used by i686 and m68k provide three overrrides for
generic code:

  1. DISTINGUISH_LIB_VERSIONS to print additional information when
     libc5 is used by a dependency.

  2. EXTRA_LD_ENVVARS to that enabled LD_LIBRARY_VERSION environment
     variable.

  3. EXTRA_UNSECURE_ENVVARS to add two environment variables related
     to aout support.

None are really requires, it has some decades since libc5 or aout
suppported was removed and Linux even remove support for aout files.
The LD_LIBRARY_VERSION is also dead code, dl_correct_cache_id is not
used anywhere.

Checked on x86_64-linux-gnu and i686-linux-gnu.
---
 NEWS                                       |  2 +
 elf/dl-support.c                           | 13 +----
 elf/rtld.c                                 | 25 +--------
 sysdeps/generic/dl-librecon.h              | 24 ---------
 sysdeps/generic/ldsodefs.h                 |  3 --
 sysdeps/unix/sysv/linux/i386/dl-librecon.h | 59 ----------------------
 sysdeps/unix/sysv/linux/m68k/dl-librecon.h |  1 -
 7 files changed, 6 insertions(+), 121 deletions(-)
 delete mode 100644 sysdeps/generic/dl-librecon.h
 delete mode 100644 sysdeps/unix/sysv/linux/i386/dl-librecon.h
 delete mode 100644 sysdeps/unix/sysv/linux/m68k/dl-librecon.h

diff --git a/NEWS b/NEWS
index bbbcc55b0c..2a200164d4 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,8 @@ Deprecated and removed features, and other changes affecting compatibility:
   provided through NT_GNU_ABI_TAG ELF note and also printed when libc.so
   is issued directly.
 
+* On Linux, The LD_LIBRARY_VERSION environment variable has been removed.
+
 Changes to build and runtime requirements:
 
   [Add changes to build and runtime requirements here]
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 1d648ce3a6..fa9fcdbe5a 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -35,7 +35,6 @@
 #include <dl-machine.h>
 #include <libc-lock.h>
 #include <dl-cache.h>
-#include <dl-librecon.h>
 #include <dl-procinfo.h>
 #include <unsecvars.h>
 #include <hp-timing.h>
@@ -158,8 +157,6 @@ struct link_map *_dl_initfirst;
 /* Descriptor to write debug messages to.  */
 int _dl_debug_fd = STDERR_FILENO;
 
-int _dl_correct_cache_id = _DL_CACHE_DEFAULT_ID;
-
 ElfW(auxv_t) *_dl_auxv;
 const ElfW(Phdr) *_dl_phdr;
 size_t _dl_phnum;
@@ -370,15 +367,9 @@ _dl_non_dynamic_init (void)
 
   if (__libc_enable_secure)
     {
-      static const char unsecure_envvars[] =
-	UNSECURE_ENVVARS
-#ifdef EXTRA_UNSECURE_ENVVARS
-	EXTRA_UNSECURE_ENVVARS
-#endif
-	;
-      const char *cp = unsecure_envvars;
+      const char *cp = UNSECURE_ENVVARS;
 
-      while (cp < unsecure_envvars + sizeof (unsecure_envvars))
+      while (cp < UNSECURE_ENVVARS + sizeof (UNSECURE_ENVVARS))
 	{
 	  __unsetenv (cp);
 	  cp = (const char *) __rawmemchr (cp, '\0') + 1;
diff --git a/elf/rtld.c b/elf/rtld.c
index 11110cb436..222109e9f6 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -32,7 +32,6 @@
 #include <fpu_control.h>
 #include <hp-timing.h>
 #include <libc-lock.h>
-#include <dl-librecon.h>
 #include <unsecvars.h>
 #include <dl-cache.h>
 #include <dl-osinfo.h>
@@ -365,7 +364,6 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
     ._dl_sysinfo = DL_SYSINFO_DEFAULT,
 #endif
     ._dl_debug_fd = STDERR_FILENO,
-    ._dl_correct_cache_id = _DL_CACHE_DEFAULT_ID,
 #if !HAVE_TUNABLES
     ._dl_hwcap_mask = HWCAP_IMPORTANT,
 #endif
@@ -1697,10 +1695,6 @@ dl_main (const ElfW(Phdr) *phdr,
       if (main_map->l_ld == NULL)
 	_exit (1);
 
-      /* We allow here some platform specific code.  */
-#ifdef DISTINGUISH_LIB_VERSIONS
-      DISTINGUISH_LIB_VERSIONS;
-#endif
       _exit (has_interp ? 0 : 2);
     }
 
@@ -2654,29 +2648,14 @@ process_envvars (struct dl_main_state *state)
 		= _dl_strtoul (&envline[21], NULL) > 1;
 	    }
 	  break;
-
-	  /* We might have some extra environment variable to handle.  This
-	     is tricky due to the pre-processing of the length of the name
-	     in the switch statement here.  The code here assumes that added
-	     environment variables have a different length.  */
-#ifdef EXTRA_LD_ENVVARS
-	  EXTRA_LD_ENVVARS
-#endif
 	}
     }
 
   /* Extra security for SUID binaries.  Remove all dangerous environment
      variables.  */
-  if (__builtin_expect (__libc_enable_secure, 0))
+  if (__glibc_unlikely (__libc_enable_secure))
     {
-      static const char unsecure_envvars[] =
-#ifdef EXTRA_UNSECURE_ENVVARS
-	EXTRA_UNSECURE_ENVVARS
-#endif
-	UNSECURE_ENVVARS;
-      const char *nextp;
-
-      nextp = unsecure_envvars;
+      const char *nextp = UNSECURE_ENVVARS;
       do
 	{
 	  unsetenv (nextp);
diff --git a/sysdeps/generic/dl-librecon.h b/sysdeps/generic/dl-librecon.h
deleted file mode 100644
index 19fc70cb29..0000000000
--- a/sysdeps/generic/dl-librecon.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Optional code to distinguish library flavours.
-   Copyright (C) 1998-2022 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#ifndef _DL_LIBRECON_H
-#define _DL_LIBRECON_H	1
-
-/* In the general case we don't do anything.  */
-
-#endif /* dl-librecon.h */
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index 97cbe41171..d0d94a0b77 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -601,9 +601,6 @@ struct rtld_global_ro
   /* Default floating-point control word.  */
   EXTERN fpu_control_t _dl_fpu_control;
 
-  /* Expected cache ID.  */
-  EXTERN int _dl_correct_cache_id;
-
   /* Mask for hardware capabilities that are available.  */
   EXTERN uint64_t _dl_hwcap;
 
diff --git a/sysdeps/unix/sysv/linux/i386/dl-librecon.h b/sysdeps/unix/sysv/linux/i386/dl-librecon.h
deleted file mode 100644
index 78e3f0d02d..0000000000
--- a/sysdeps/unix/sysv/linux/i386/dl-librecon.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Optional code to distinguish library flavours.
-   Copyright (C) 1998-2022 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-#ifndef _DL_LIBRECON_H
-
-#define DISTINGUISH_LIB_VERSIONS \
-  do									      \
-    {									      \
-      /* We have to find out whether the binary is linked against	      \
-	 libc 5 or glibc.  We do this by looking at all the DT_NEEDED	      \
-	 entries.  If one is libc.so.5 this is a libc 5 linked binary.  */    \
-      if (main_map->l_info[DT_NEEDED])					      \
-	{								      \
-	  /* We have dependencies.  */					      \
-	  const ElfW(Dyn) *d;						      \
-	  const char *strtab;						      \
-									      \
-	  strtab = (const char *) D_PTR (main_map, l_info[DT_STRTAB]);	      \
-									      \
-	  for (d = main_map->l_ld; d->d_tag != DT_NULL; ++d)		      \
-	    if (d->d_tag == DT_NEEDED					      \
-		&& strcmp (strtab + d->d_un.d_val, "libc.so.5") == 0)	      \
-	      break;							      \
-									      \
-	  /* We print a `5' or `6' depending on the outcome.  */	      \
-	  _dl_printf (d->d_tag != DT_NULL ? "5\n" : "6\n");		      \
-	}								      \
-    }									      \
-  while (0)
-
-/* Recognizing extra environment variables.  */
-#define EXTRA_LD_ENVVARS \
-  case 15:								      \
-    if (memcmp (envline, "LIBRARY_VERSION", 15) == 0)			      \
-      GLRO(dl_correct_cache_id) = envline[16] == '5' ? 2 : 3;		      \
-    break;								      \
-
-/* Extra unsecure variables.  The names are all stuffed in a single
-   string which means they have to be terminated with a '\0' explicitly.  */
-#define EXTRA_UNSECURE_ENVVARS \
-  "LD_AOUT_LIBRARY_PATH\0"						      \
-  "LD_AOUT_PRELOAD\0"
-
-#endif /* dl-librecon.h */
diff --git a/sysdeps/unix/sysv/linux/m68k/dl-librecon.h b/sysdeps/unix/sysv/linux/m68k/dl-librecon.h
deleted file mode 100644
index dbb4e75712..0000000000
--- a/sysdeps/unix/sysv/linux/m68k/dl-librecon.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/dl-librecon.h>
-- 
2.32.0


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

* Re: [PATCH 1/2] Remove kernel version check
  2022-02-21 17:59 ` [PATCH 1/2] Remove kernel version check Adhemerval Zanella
@ 2022-02-28 19:00   ` Florian Weimer
  2022-03-04 12:42     ` Adhemerval Zanella
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2022-02-28 19:00 UTC (permalink / raw)
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> The kernel version check is used to avoid glibc to run on older
> kernels where some syscall are not available and fallback code are
> not enabled to handle graciously fail.  However, it does not prevent
> if the kernel does not correctly advertise its version through
> vDSO note, uname or procfs.
>
> Also kernel version checks are sometime not desirable by users,
> where they want to deploy on different system with different kernel
> version knowing the minimum set of syscall is always presented on
> such systems.
>
> The kernel version check has been removed along with the
> LD_ASSUME_KERNEL environment variable.  The minimum kernel used to
> built glibc is still provided through NT_GNU_ABI_TAG ELF note and
> also printed when libc.so is issued.

Missing Linux: prefix in the commit subject, I would.

> diff --git a/NEWS b/NEWS
> index 626eeabf5d..bbbcc55b0c 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -17,6 +17,11 @@ Deprecated and removed features, and other changes affecting compatibility:
>    removal of the LD_TRACE_PRELINKING, and LD_USE_LOAD_BIAS, environment
>    variables and their functionality in the dynamic loader.
>  
> +* The kernel version check has been removed along with the LD_ASSUME_KERNEL
> +  environment variable.  The minimum kernel used to built glibc is still
> +  provided through NT_GNU_ABI_TAG ELF note and also printed when libc.so
> +  is issued directly.

Mention “Linux” here?

> index 892e8ef2f6..ba175a0035 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -1631,7 +1631,6 @@ open_verify (const char *name, int fd,
>        ElfW(Phdr) *phdr, *ph;
>        ElfW(Word) *abi_note;
>        ElfW(Word) *abi_note_malloced = NULL;
> -      unsigned int osversion;
>        size_t maplength;
>  
>        /* We successfully opened the file.  Now verify it is a file
> @@ -1695,13 +1694,16 @@ open_verify (const char *name, int fd,
>  #endif
>  	      )
>  	    errstring = N_("invalid ELF header");
> +
>  	  else if (ehdr->e_ident[EI_CLASS] != ELFW(CLASS))
>  	    {
>  	      /* This is not a fatal error.  On architectures where
>  		 32-bit and 64-bit binaries can be run this might
>  		 happen.  */
>  	      *found_other_class = true;
> -	      goto close_and_out;
> +	      __close_nocancel (fd);
> +	      __set_errno (ENOENT);
> +	      return -1;
>  	    }
>  	  else if (ehdr->e_ident[EI_DATA] != byteorder)
>  	    {
> @@ -1736,7 +1738,11 @@ open_verify (const char *name, int fd,
>  	  goto lose;
>  	}
>        if (! __glibc_likely (elf_machine_matches_host (ehdr)))
> -	goto close_and_out;
> +	{
> +	  __close_nocancel (fd);
> +	  __set_errno (ENOENT);
> +	  return -1;
> +	}
>        else if (__glibc_unlikely (ehdr->e_type != ET_DYN
>  				 && ehdr->e_type != ET_EXEC))
>  	{
> @@ -1768,7 +1774,11 @@ open_verify (const char *name, int fd,
>        if (__glibc_unlikely (elf_machine_reject_phdr_p
>  			    (phdr, ehdr->e_phnum, fbp->buf, fbp->len,
>  			     loader, fd)))
> -	goto close_and_out;
> +	{
> +	  __close_nocancel (fd);
> +	  __set_errno (ENOENT);
> +	  return -1;
> +	}
>  
>        /* Check .note.ABI-tag if present.  */
>        for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph)
> @@ -1820,18 +1830,6 @@ open_verify (const char *name, int fd,
>  	    if (size == 0)
>  	      continue;
>  
> -	    osversion = (abi_note[5] & 0xff) * 65536
> -			+ (abi_note[6] & 0xff) * 256
> -			+ (abi_note[7] & 0xff);
> -	    if (abi_note[4] != __ABI_TAG_OS
> -		|| (GLRO(dl_osversion) && GLRO(dl_osversion) < osversion))
> -	      {
> -	      close_and_out:
> -		__close_nocancel (fd);
> -		__set_errno (ENOENT);
> -		fd = -1;
> -	      }
> -
>  	    break;
>  	  }
>        free (abi_note_malloced);

Hmm.  I think you can delete the entire program header loop now?
Nothing reads abi_note after these changes.

And there's now an unused

unsigned int _dl_osversion;

in elf/dl-support.c.

I assume you want to handle the ldconfig changes separately?  I think we
discussed that during Monday's call last week.

Thanks,
Florian


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

* Re: [PATCH 2/2] Remove dl-librecon.h header.
  2022-02-21 17:59 ` [PATCH 2/2] Remove dl-librecon.h header Adhemerval Zanella
@ 2022-02-28 19:11   ` Florian Weimer
  2022-03-04 12:42     ` Adhemerval Zanella
  0 siblings, 1 reply; 7+ messages in thread
From: Florian Weimer @ 2022-02-28 19:11 UTC (permalink / raw)
  To: Adhemerval Zanella via Libc-alpha

* Adhemerval Zanella via Libc-alpha:

> diff --git a/elf/dl-support.c b/elf/dl-support.c
> index 1d648ce3a6..fa9fcdbe5a 100644
> --- a/elf/dl-support.c
> +++ b/elf/dl-support.c

> @@ -370,15 +367,9 @@ _dl_non_dynamic_init (void)
>  
>    if (__libc_enable_secure)
>      {
> -      static const char unsecure_envvars[] =
> -	UNSECURE_ENVVARS
> -#ifdef EXTRA_UNSECURE_ENVVARS
> -	EXTRA_UNSECURE_ENVVARS
> -#endif
> -	;
> -      const char *cp = unsecure_envvars;
> +      const char *cp = UNSECURE_ENVVARS;
>  
> -      while (cp < unsecure_envvars + sizeof (unsecure_envvars))
> +      while (cp < UNSECURE_ENVVARS + sizeof (UNSECURE_ENVVARS))
>  	{
>  	  __unsetenv (cp);
>  	  cp = (const char *) __rawmemchr (cp, '\0') + 1;

Please keep unsecure_envvars.  I think C does not guarantee that there
is just one array for UNSECURE_ENVVARS.

Rest looks okay to me.

Thanks,
Florian


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

* Re: [PATCH 1/2] Remove kernel version check
  2022-02-28 19:00   ` Florian Weimer
@ 2022-03-04 12:42     ` Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2022-03-04 12:42 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 28/02/2022 16:00, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> The kernel version check is used to avoid glibc to run on older
>> kernels where some syscall are not available and fallback code are
>> not enabled to handle graciously fail.  However, it does not prevent
>> if the kernel does not correctly advertise its version through
>> vDSO note, uname or procfs.
>>
>> Also kernel version checks are sometime not desirable by users,
>> where they want to deploy on different system with different kernel
>> version knowing the minimum set of syscall is always presented on
>> such systems.
>>
>> The kernel version check has been removed along with the
>> LD_ASSUME_KERNEL environment variable.  The minimum kernel used to
>> built glibc is still provided through NT_GNU_ABI_TAG ELF note and
>> also printed when libc.so is issued.
> 
> Missing Linux: prefix in the commit subject, I would.
> 
>> diff --git a/NEWS b/NEWS
>> index 626eeabf5d..bbbcc55b0c 100644
>> --- a/NEWS
>> +++ b/NEWS
>> @@ -17,6 +17,11 @@ Deprecated and removed features, and other changes affecting compatibility:
>>    removal of the LD_TRACE_PRELINKING, and LD_USE_LOAD_BIAS, environment
>>    variables and their functionality in the dynamic loader.
>>  
>> +* The kernel version check has been removed along with the LD_ASSUME_KERNEL
>> +  environment variable.  The minimum kernel used to built glibc is still
>> +  provided through NT_GNU_ABI_TAG ELF note and also printed when libc.so
>> +  is issued directly.
> 
> Mention “Linux” here?

I changed to "The Linux kernel version check ..."

> 
>> index 892e8ef2f6..ba175a0035 100644
>> --- a/elf/dl-load.c
>> +++ b/elf/dl-load.c
>> @@ -1631,7 +1631,6 @@ open_verify (const char *name, int fd,
>>        ElfW(Phdr) *phdr, *ph;
>>        ElfW(Word) *abi_note;
>>        ElfW(Word) *abi_note_malloced = NULL;
>> -      unsigned int osversion;
>>        size_t maplength;
>>  
>>        /* We successfully opened the file.  Now verify it is a file
>> @@ -1695,13 +1694,16 @@ open_verify (const char *name, int fd,
>>  #endif
>>  	      )
>>  	    errstring = N_("invalid ELF header");
>> +
>>  	  else if (ehdr->e_ident[EI_CLASS] != ELFW(CLASS))
>>  	    {
>>  	      /* This is not a fatal error.  On architectures where
>>  		 32-bit and 64-bit binaries can be run this might
>>  		 happen.  */
>>  	      *found_other_class = true;
>> -	      goto close_and_out;
>> +	      __close_nocancel (fd);
>> +	      __set_errno (ENOENT);
>> +	      return -1;
>>  	    }
>>  	  else if (ehdr->e_ident[EI_DATA] != byteorder)
>>  	    {
>> @@ -1736,7 +1738,11 @@ open_verify (const char *name, int fd,
>>  	  goto lose;
>>  	}
>>        if (! __glibc_likely (elf_machine_matches_host (ehdr)))
>> -	goto close_and_out;
>> +	{
>> +	  __close_nocancel (fd);
>> +	  __set_errno (ENOENT);
>> +	  return -1;
>> +	}
>>        else if (__glibc_unlikely (ehdr->e_type != ET_DYN
>>  				 && ehdr->e_type != ET_EXEC))
>>  	{
>> @@ -1768,7 +1774,11 @@ open_verify (const char *name, int fd,
>>        if (__glibc_unlikely (elf_machine_reject_phdr_p
>>  			    (phdr, ehdr->e_phnum, fbp->buf, fbp->len,
>>  			     loader, fd)))
>> -	goto close_and_out;
>> +	{
>> +	  __close_nocancel (fd);
>> +	  __set_errno (ENOENT);
>> +	  return -1;
>> +	}
>>  
>>        /* Check .note.ABI-tag if present.  */
>>        for (ph = phdr; ph < &phdr[ehdr->e_phnum]; ++ph)
>> @@ -1820,18 +1830,6 @@ open_verify (const char *name, int fd,
>>  	    if (size == 0)
>>  	      continue;
>>  
>> -	    osversion = (abi_note[5] & 0xff) * 65536
>> -			+ (abi_note[6] & 0xff) * 256
>> -			+ (abi_note[7] & 0xff);
>> -	    if (abi_note[4] != __ABI_TAG_OS
>> -		|| (GLRO(dl_osversion) && GLRO(dl_osversion) < osversion))
>> -	      {
>> -	      close_and_out:
>> -		__close_nocancel (fd);
>> -		__set_errno (ENOENT);
>> -		fd = -1;
>> -	      }
>> -
>>  	    break;
>>  	  }
>>        free (abi_note_malloced);
> 
> Hmm.  I think you can delete the entire program header loop now?
> Nothing reads abi_note after these changes.

Indeed, I will removed it as well.

> 
> And there's now an unused
> 
> unsigned int _dl_osversion;
> 
> in elf/dl-support.c.

Ack.

> 
> I assume you want to handle the ldconfig changes separately?  I think we
> discussed that during Monday's call last week.

Yes, I forget to clean up this up. I will add another patch to do so.

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

* Re: [PATCH 2/2] Remove dl-librecon.h header.
  2022-02-28 19:11   ` Florian Weimer
@ 2022-03-04 12:42     ` Adhemerval Zanella
  0 siblings, 0 replies; 7+ messages in thread
From: Adhemerval Zanella @ 2022-03-04 12:42 UTC (permalink / raw)
  To: Florian Weimer, Adhemerval Zanella via Libc-alpha



On 28/02/2022 16:11, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> diff --git a/elf/dl-support.c b/elf/dl-support.c
>> index 1d648ce3a6..fa9fcdbe5a 100644
>> --- a/elf/dl-support.c
>> +++ b/elf/dl-support.c
> 
>> @@ -370,15 +367,9 @@ _dl_non_dynamic_init (void)
>>  
>>    if (__libc_enable_secure)
>>      {
>> -      static const char unsecure_envvars[] =
>> -	UNSECURE_ENVVARS
>> -#ifdef EXTRA_UNSECURE_ENVVARS
>> -	EXTRA_UNSECURE_ENVVARS
>> -#endif
>> -	;
>> -      const char *cp = unsecure_envvars;
>> +      const char *cp = UNSECURE_ENVVARS;
>>  
>> -      while (cp < unsecure_envvars + sizeof (unsecure_envvars))
>> +      while (cp < UNSECURE_ENVVARS + sizeof (UNSECURE_ENVVARS))
>>  	{
>>  	  __unsetenv (cp);
>>  	  cp = (const char *) __rawmemchr (cp, '\0') + 1;
> 
> Please keep unsecure_envvars.  I think C does not guarantee that there
> is just one array for UNSECURE_ENVVARS.
> 

Ack.

> Rest looks okay to me.
> 


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

end of thread, other threads:[~2022-03-04 12:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-21 17:59 [PATCH 0/2] Remove distinguish library code Adhemerval Zanella
2022-02-21 17:59 ` [PATCH 1/2] Remove kernel version check Adhemerval Zanella
2022-02-28 19:00   ` Florian Weimer
2022-03-04 12:42     ` Adhemerval Zanella
2022-02-21 17:59 ` [PATCH 2/2] Remove dl-librecon.h header Adhemerval Zanella
2022-02-28 19:11   ` Florian Weimer
2022-03-04 12:42     ` Adhemerval Zanella

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).