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