From 8cc46344d291f110df325880deaea623d6188565 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 11 Nov 2011 13:55:13 +0000 Subject: [PATCH 1/2] . OBS-URL: https://build.opensuse.org/package/show/Base:System/bash?expand=0&rev=91 --- bash-4.2-endpw.dif | 125 +++++++++++++++++++++++++++++++++++++++++ bash.changes | 6 ++ bash.spec | 5 ++ readline-6.2-endpw.dif | 65 +++++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 bash-4.2-endpw.dif create mode 100644 readline-6.2-endpw.dif diff --git a/bash-4.2-endpw.dif b/bash-4.2-endpw.dif new file mode 100644 index 00000000..eeeed1bd --- /dev/null +++ b/bash-4.2-endpw.dif @@ -0,0 +1,125 @@ +--- bashline.c ++++ bashline.c 2011-11-11 13:22:00.119146416 +0000 +@@ -2148,10 +2148,10 @@ bash_groupname_completion_function (text + if (gnamelen == 0 || (STREQN (gname, grent->gr_name, gnamelen))) + break; + } ++ endgrent (); + + if (grent == 0) + { +- endgrent (); + return ((char *)NULL); + } + +--- examples/loadables/finfo.c ++++ examples/loadables/finfo.c 2011-11-11 13:21:12.319218165 +0000 +@@ -269,9 +269,11 @@ struct stat *st; + printmode((int) st->st_mode); + printf("Link count: %d\n", (int) st->st_nlink); + pw = getpwuid(st->st_uid); ++ endpwent(); + owner = pw ? pw->pw_name : "unknown"; + printf("Uid of owner: %d (%s)\n", (int) st->st_uid, owner); + gr = getgrgid(st->st_gid); ++ endgrent(); + owner = gr ? gr->gr_name : "unknown"; + printf("Gid of owner: %d (%s)\n", (int) st->st_gid, owner); + printf("Device type: %d\n", (int) st->st_rdev); +@@ -348,12 +350,14 @@ int flags; + printf("%o\n", getperm(st->st_mode) & pmask); + else if (flags & OPT_UID) { + pw = getpwuid(st->st_uid); ++ endpwent(); + if (flags & OPT_ASCII) + printf("%s\n", pw ? pw->pw_name : "unknown"); + else + printf("%d\n", st->st_uid); + } else if (flags & OPT_GID) { + gr = getgrgid(st->st_gid); ++ endgrent(); + if (flags & OPT_ASCII) + printf("%s\n", gr ? gr->gr_name : "unknown"); + else +--- examples/loadables/id.c ++++ examples/loadables/id.c 2011-11-11 13:19:36.515148229 +0000 +@@ -42,6 +42,7 @@ + + #if !defined (HAVE_GETPW_DECLS) + extern struct passwd *getpwuid (); ++extern void endpwent (); + #endif + extern struct group *getgrgid (); + +@@ -146,6 +147,7 @@ inituser (uname) + builtin_error ("%s: no such user", uname); + return -1; + } ++ endpwent (); + ruid = euid = pwd->pw_uid; + rgid = egid = pwd->pw_gid; + } +@@ -173,6 +175,7 @@ id_pruser (uid) + pwd = getpwuid (uid); + if (pwd == NULL) + r = 1; ++ endpwent (); + } + if (pwd) + printf ("%s", pwd->pw_name); +@@ -197,6 +200,7 @@ id_prgrp (gid) + grp = getgrgid (gid); + if (grp == NULL) + r = 1; ++ endgrent (); + } + + if (grp) +@@ -307,6 +311,8 @@ id_prall (uname) + else + printf ("(%s)", grp->gr_name); + } ++ endpwent (); ++ endgrent (); + + return r; + } +--- lib/tilde/shell.c ++++ lib/tilde/shell.c 2011-11-11 13:12:35.932960442 +0000 +@@ -45,7 +45,12 @@ + #include + + #if !defined (HAVE_GETPW_DECLS) ++# if defined (HAVE_GETPWUID) + extern struct passwd *getpwuid (); ++# endif ++# if defined (HAVE_GETPWENT) ++extern void endpwent (); ++# endif + #endif /* !HAVE_GETPW_DECLS */ + + char * +@@ -62,8 +67,13 @@ get_home_dir () + struct passwd *entry; + + home_dir = (char *)NULL; ++#if defined (HAVE_GETPWUID) + entry = getpwuid (getuid ()); + if (entry) + home_dir = entry->pw_dir; ++#endif ++#if defined (HAVE_GETPWENT) ++ endpwent (); ++#endif + return (home_dir); + } +--- lib/tilde/tilde.c ++++ lib/tilde/tilde.c 2011-11-11 13:10:07.375646928 +0000 +@@ -61,6 +61,7 @@ extern struct passwd *getpwuid PARAMS((u + # endif + # if defined (HAVE_GETPWNAM) + extern struct passwd *getpwnam PARAMS((const char *)); ++extern void endpwent (); + # endif + #endif /* !HAVE_GETPW_DECLS */ + diff --git a/bash.changes b/bash.changes index 16ca4203..53caed12 100644 --- a/bash.changes +++ b/bash.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Nov 11 13:45:40 UTC 2011 - werner@suse.de + +- Always close get(pw|gr)func with endpw() respectivly with endgr() + to avoid memory mapped passwd/groups of cache files from nscd + ------------------------------------------------------------------- Wed Nov 2 08:23:24 UTC 2011 - werner@suse.de diff --git a/bash.spec b/bash.spec index e936df8a..246efb9b 100644 --- a/bash.spec +++ b/bash.spec @@ -59,6 +59,7 @@ Patch2: bash-4.0-security.patch Patch3: bash-4.2-2.4.4.patch Patch4: bash-3.0-evalexp.patch Patch5: bash-3.0-warn-locale.patch +Patch6: bash-4.2-endpw.dif Patch7: bash-3.0-decl.patch Patch8: bash-4.0-async-bnc523667.dif Patch9: bash-4.0-extended_quote.patch @@ -74,6 +75,7 @@ Patch21: readline-4.3-input.dif Patch22: readline-6.1-wrap.patch Patch23: readline-5.2-conf.patch Patch24: readline-6.2-metamode.patch +Patch25: readline-6.2-endpw.dif Patch30: readline-6.2-destdir.patch Patch40: bash-4.1-bash.bashrc.dif Patch46: man2html-no-timestamp.patch @@ -270,6 +272,7 @@ unset p %patch3 -p0 -b .2.4.4 %patch4 -p0 -b .evalexp %patch5 -p0 -b .warnlc +%patch6 -p0 -b .endpw %patch7 -p0 -b .decl %patch8 -p0 -b .async %patch9 -p0 -b .extended_quote @@ -284,6 +287,7 @@ unset p %patch22 -p0 -b .wrap %patch23 -p0 -b .conf %patch24 -p0 -b .metamode +%patch25 -p0 -b .endpw %patch40 -p0 -b .bashrc %patch46 -p0 -b .notimestamp %patch0 -p0 -b .0 @@ -297,6 +301,7 @@ done %patch22 -p2 -b .wrap %patch23 -p2 -b .conf %patch24 -p2 -b .metamode +%patch25 -p2 -b .endpw %patch30 -p0 -b .destdir %patch20 -p0 -b .0 diff --git a/readline-6.2-endpw.dif b/readline-6.2-endpw.dif new file mode 100644 index 00000000..2a69e81b --- /dev/null +++ b/readline-6.2-endpw.dif @@ -0,0 +1,65 @@ +--- lib/readline/complete.c ++++ lib/readline/complete.c 2011-11-11 13:16:05.635147670 +0000 +@@ -83,6 +83,7 @@ typedef int QSFUNC (); + defined. */ + #if defined (HAVE_GETPWENT) && (!defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE)) + extern struct passwd *getpwent PARAMS((void)); ++extern void endpwent (); + #endif /* HAVE_GETPWENT && (!HAVE_GETPW_DECLS || _POSIX_SOURCE) */ + + /* If non-zero, then this is the address of a function to call when +@@ -2049,12 +2050,12 @@ rl_username_completion_function (text, s + break; + } + #endif ++#if defined (HAVE_GETPWENT) ++ endpwent (); ++#endif + + if (entry == 0) + { +-#if defined (HAVE_GETPWENT) +- endpwent (); +-#endif + return ((char *)NULL); + } + else +--- lib/readline/shell.c ++++ lib/readline/shell.c 2011-11-11 13:14:02.683147026 +0000 +@@ -61,9 +61,14 @@ + #include "rlshell.h" + #include "xmalloc.h" + +-#if defined (HAVE_GETPWUID) && !defined (HAVE_GETPW_DECLS) ++#if !defined (HAVE_GETPW_DECLS) ++# if defined (HAVE_GETPWUID) + extern struct passwd *getpwuid PARAMS((uid_t)); +-#endif /* HAVE_GETPWUID && !HAVE_GETPW_DECLS */ ++# endif ++# if defined (HAVE_GETPWENT) ++extern void endpwent (); ++# endif ++#endif /* !HAVE_GETPW_DECLS */ + + #ifndef NULL + # define NULL 0 +@@ -168,6 +173,9 @@ sh_get_home_dir () + if (entry) + home_dir = entry->pw_dir; + #endif ++#if defined (HAVE_GETPWENT) ++ endpwent (); ++#endif + return (home_dir); + } + +--- lib/readline/tilde.c ++++ lib/readline/tilde.c 2011-11-11 13:09:48.843646721 +0000 +@@ -61,6 +61,7 @@ extern struct passwd *getpwuid PARAMS((u + # endif + # if defined (HAVE_GETPWNAM) + extern struct passwd *getpwnam PARAMS((const char *)); ++extern void endpwent (); + # endif + #endif /* !HAVE_GETPW_DECLS */ + From acde7fa1ce2dd048218412b3752884472348476c Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 11 Nov 2011 15:29:47 +0000 Subject: [PATCH 2/2] . OBS-URL: https://build.opensuse.org/package/show/Base:System/bash?expand=0&rev=92 --- bash-4.2-nscdunmap.dif | 49 ++++++++++++++++++++++++++++++++++++++++++ bash.changes | 6 ++++++ bash.spec | 2 ++ 3 files changed, 57 insertions(+) create mode 100644 bash-4.2-nscdunmap.dif diff --git a/bash-4.2-nscdunmap.dif b/bash-4.2-nscdunmap.dif new file mode 100644 index 00000000..a39f6e64 --- /dev/null +++ b/bash-4.2-nscdunmap.dif @@ -0,0 +1,49 @@ +--- shell.c ++++ shell.c 2011-11-11 15:08:39.479158014 +0000 +@@ -39,8 +39,8 @@ + #include + #include "filecntl.h" + #include +- + #if defined (HAVE_UNISTD_H) ++# include + # include + #endif + +@@ -1630,6 +1630,28 @@ init_interactive_script () + expand_aliases = interactive_shell = startup_state = 1; + } + ++static void ++maybe_unmap_nscd (void) ++{ ++ unsigned long start, end, off; ++ char path[PATH_MAX]; ++ FILE *maps; ++ ++ if (getppid() != 1) ++ return; ++ if ((maps = fopen("/proc/self/maps", "r")) == NULL) ++ return; ++ ++ while (fscanf(maps, "%lx-%lx %*s %lx %*x:%*x %*lu %s", &start, &end, &off, &path[0]) == 4) ++ { ++ if (strncmp(path, "/var/run/nscd/", 14) != 0) ++ continue; ++ munmap((void*)start, end - start); ++ } ++ ++ fclose(maps); ++} ++ + void + get_current_user_info () + { +@@ -1655,6 +1677,7 @@ get_current_user_info () + current_user.home_dir = savestring ("/"); + } + endpwent (); ++ maybe_unmap_nscd (); + } + } + diff --git a/bash.changes b/bash.changes index 53caed12..a362fb16 100644 --- a/bash.changes +++ b/bash.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Fri Nov 11 15:27:12 UTC 2011 - werner@suse.de + +- Avoid memory mapped /var/run/nscd/passwd at shutdown by simply + unmapping this only used area if parent is systemd or SysVinit + ------------------------------------------------------------------- Fri Nov 11 13:45:40 UTC 2011 - werner@suse.de diff --git a/bash.spec b/bash.spec index 246efb9b..ff088d36 100644 --- a/bash.spec +++ b/bash.spec @@ -66,6 +66,7 @@ Patch9: bash-4.0-extended_quote.patch Patch10: bash-3.2-printf.patch Patch11: bash-4.0-loadables.dif Patch12: bash-4.1-completion.dif +Patch13: bash-4.2-nscdunmap.dif Patch14: bash-4.2-sigrestart.patch Patch15: bash-3.2-longjmp.dif Patch16: bash-4.0-setlocale.dif @@ -279,6 +280,7 @@ unset p %patch10 -p0 -b .printf %patch11 -p0 -b .plugins %patch12 -p0 -b .completion +%patch13 -p0 -b .nscdunmap %patch14 -p0 -b .sigrestart %patch15 -p0 -b .longjmp %patch16 -p0 -b .setlocale