e354a5
This is a custom downstream RHEL 8 patch which rebuilds three
e354a5
GLIBC_PRIVATE interfaces locally for use by libnss_files.so.2
e354a5
and libnss_compat.so.2.
e354a5
e354a5
The shared objects needs the following 3 functions:
e354a5
__nss_readline
e354a5
__nss_parse_line_result
e354a5
__nss_files_fopen (only requirement for libnss_compat.so.2)
e354a5
e354a5
They are implemented in:
e354a5
nss/nss_parse_line_result.c
e354a5
nss/nss_readline.c
e354a5
nss/nss_files_fopen.c
e354a5
e354a5
We create wrappers for those functions, recompile, and link directly
e354a5
into the shared objects:
e354a5
nss/nss_parse_line_result_int.c
e354a5
nss/nss_readline_int.c
e354a5
nss/nss_files_fopen_int.c
e354a5
e354a5
After building the new shared objects there are no longer any undefined
e354a5
global function references to __nss_readline@GLIBC_PRIVATE,
e354a5
__nss_parse_line_result@GLIBC_PRIVATE or
e354a5
__nss_files_fopen@GLIBC_PRIVATE.
e354a5
e354a5
Instead we see local function definitions in the shared object e.g.
e354a5
Symbol table '.symtab' contains 628 entries:
e354a5
...
e354a5
   486: 0000000000008ce0    92 FUNC    LOCAL  DEFAULT   15 __nss_parse_line_result
e354a5
...
e354a5
   494: 0000000000008b70    72 FUNC    LOCAL  DEFAULT   15 __nss_readline_seek
e354a5
...
e354a5
   497: 0000000000008bc0   279 FUNC    LOCAL  DEFAULT   15 __nss_readline
e354a5
...
e354a5
   510: 0000000000008ce0    82 FUNC    LOCAL  DEFAULT   15 __nss_files_fopen
e354a5
e354a5
The remaining GLIBC_PRIVATE references in the shared objects are all
e354a5
pre-existing and do not impact upgrade scenarios.
e354a5
e354a5
For reference the existing and present GLIBC_PRIVATE interfaces are:
e354a5
__libc_alloc_buffer_alloc_array@@GLIBC_PRIVATE
e354a5
__libc_alloc_buffer_copy_string@@GLIBC_PRIVATE
e354a5
__libc_alloc_buffer_create_failure@@GLIBC_PRIVATE
e354a5
__libc_dynarray_emplace_enlarge@@GLIBC_PRIVATE
e354a5
__libc_scratch_buffer_grow@@GLIBC_PRIVATE
e354a5
__resp@@GLIBC_PRIVATE
e354a5
_nss_files_parse_grent@@GLIBC_PRIVATE
e354a5
_nss_files_parse_pwent@@GLIBC_PRIVATE
e354a5
_nss_files_parse_sgent@@GLIBC_PRIVATE
e354a5
_nss_files_parse_spent@@GLIBC_PRIVATE
e354a5
errno@@GLIBC_PRIVATE
e354a5
__nss_database_lookup2@GLIBC_PRIVATE
e354a5
__nss_lookup_function@GLIBC_PRIVATE
e354a5
e354a5
Each was checked for existence in libc.so.6.
e354a5
e354a5
A small reproducer was used in testing this patch, included here:
e354a5
cat >> tst-rhbz1927040.c <
e354a5
#include <stdio.h>
e354a5
#include <stdlib.h>
e354a5
#include <sys/types.h>
e354a5
#include <errno.h>
e354a5
#include <pwd.h>
e354a5
#include <string.h>
e354a5
e354a5
int
e354a5
main (void)
e354a5
{
e354a5
  struct passwd *res;
e354a5
e354a5
  /* Only lookup via files.  */
e354a5
  printf ("INFO: Upgrade glibc, then press ENTER to see if libnss_files.so.2 loads.");
e354a5
  getchar ();
e354a5
e354a5
  /* Try to get one entry.  */
e354a5
  printf ("INFO: Looking up first password entry.\n");
e354a5
  setpwent ();
e354a5
  errno = 0;
e354a5
  res = getpwent ();
e354a5
  if (res == NULL && errno != 0)
e354a5
    {
e354a5
      printf ("FAIL: Could not get entry (%s).\n", strerror(errno));
e354a5
      exit (1);
e354a5
    }
e354a5
  printf ("INFO: First entry passwd.pw_name = \"%s\"\n", res->pw_name);
e354a5
  printf ("PASS: Call to getpwent succeeded.\n");
e354a5
  endpwent ();
e354a5
  exit (0);
e354a5
}
e354a5
EOF
e354a5
e354a5
Testing RHEL upgrade
e354a5
from: glibc-2.28-127.el8_3.2
e354a5
to: glibc-2.28-148.el8
e354a5
e354a5
./tst-rhbz1927040
e354a5
INFO: Upgrade glibc, then press ENTER to see if libnss_files.so.2 loads.
e354a5
INFO: Looking up first password entry.
e354a5
INFO: Result was NULL.
e354a5
PASS: Call to getpwent succeeded.
e354a5
e354a5
With LD_DEBUG=all you can observe:
e354a5
     22697:     /lib64/libnss_files.so.2: error: symbol lookup error: undefined symbol: __nss_files_fopen, version GLIBC_PRIVATE (fatal)
e354a5
e354a5
Which is the indication that the upgrade caused the transient IdM lookup failure.
e354a5
e354a5
Running again succeeds:
e354a5
INFO: Upgrade glibc, then press ENTER to see if libnss_files.so.2 loads.
e354a5
INFO: Looking up first password entry.
e354a5
INFO: First entry passwd.pw_name = "root"
e354a5
PASS: Call to getpwent succeeded.
e354a5
e354a5
diff --git a/nss/Makefile b/nss/Makefile
e354a5
index 7359da38feb65618..d5c28a6b5ed3661c 100644
e354a5
--- a/nss/Makefile
e354a5
+++ b/nss/Makefile
e354a5
@@ -92,9 +92,19 @@ extra-libs-others	= $(extra-libs)
e354a5
 subdir-dirs = $(services:%=nss_%)
e354a5
 vpath %.c $(subdir-dirs) ../locale/programs ../intl
e354a5
 
e354a5
-
e354a5
+# In RHEL we add nss_readline, nss_parse_line_result, and
e354a5
+# nss_files_fopen to the libnss_files-routines in order to avoid the
e354a5
+# case where a long running process (having never used NSS) attemps to
e354a5
+# load an NSS module for the first time and that NSS module needs a
e354a5
+# newer GLIBC_PRIVATE interface.  In effect we must make the NSS modules
e354a5
+# self-sufficient and not rely on a GLIBC_PRIVATE interface.
e354a5
+# See: https://bugzilla.redhat.com/show_bug.cgi?id=1927040
e354a5
+# Note: We must recompile the objects to get the correct global symbol
e354a5
+#       references, which is why we have the *_int.c wrappers.
e354a5
 libnss_files-routines	:= $(addprefix files-,$(databases)) \
e354a5
-			   files-initgroups files-init
e354a5
+			   files-initgroups files-init \
e354a5
+			   nss_readline_int nss_parse_line_result_int \
e354a5
+			   nss_files_fopen_int
e354a5
 
e354a5
 libnss_db-dbs		:= $(addprefix db-,\
e354a5
 				       $(filter-out hosts network key alias,\
e354a5
@@ -104,8 +114,10 @@ libnss_db-routines	:= $(libnss_db-dbs) db-open db-init hash-string
e354a5
 generated		+= $(filter-out db-alias.c db-netgrp.c, \
e354a5
 					$(addsuffix .c,$(libnss_db-dbs)))
e354a5
 
e354a5
+# See note above regarding nss_files_fopen.
e354a5
 libnss_compat-routines	:= $(addprefix compat-,grp pwd spwd initgroups) \
e354a5
-			   nisdomain
e354a5
+			   nisdomain \
e354a5
+			   nss_files_fopen_int
e354a5
 
e354a5
 install-others		+= $(inst_vardbdir)/Makefile
e354a5
 
e354a5
diff --git a/nss/nss_files_fopen_int.c b/nss/nss_files_fopen_int.c
e354a5
new file mode 100644
e354a5
index 0000000000000000..fa518084fd609b52
e354a5
--- /dev/null
e354a5
+++ b/nss/nss_files_fopen_int.c
e354a5
@@ -0,0 +1,3 @@
e354a5
+/* Include a local internal copy of __nss_files_fopen to make the NSS
e354a5
+   module self-contained.  */
e354a5
+#include <nss_files_fopen.c>
e354a5
diff --git a/nss/nss_parse_line_result_int.c b/nss/nss_parse_line_result_int.c
e354a5
new file mode 100644
e354a5
index 0000000000000000..bc0ee7a251743c9a
e354a5
--- /dev/null
e354a5
+++ b/nss/nss_parse_line_result_int.c
e354a5
@@ -0,0 +1,3 @@
e354a5
+/* Include a local internal copy of __nss_parse_line_result to make the
e354a5
+   NSS module self-contained.  */
e354a5
+#include <nss_parse_line_result.c>
e354a5
diff --git a/nss/nss_readline_int.c b/nss/nss_readline_int.c
e354a5
new file mode 100644
e354a5
index 0000000000000000..0e7bd259733673c9
e354a5
--- /dev/null
e354a5
+++ b/nss/nss_readline_int.c
e354a5
@@ -0,0 +1,3 @@
e354a5
+/* Include a local internal copy of __nss_readline and
e354a5
+   __nss_readline_seek to make the NSS module self-contained.  */
e354a5
+#include <nss_readline.c>