summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2025-12-14 00:29:44 +0100
committerLudovic Courtès <ludo@gnu.org>2025-12-19 00:05:43 +0100
commit3e2bd2e30bcb183804e853b6cc611387c05712e1 (patch)
tree7a2e2d0715edfd0962dbaacbcc03237087994dc1
parent55bf53fe92fac2b98e117b6f01fddd7db0285529 (diff)
services: nscd: Cause PID 1 to drop nscd database mappings on shutdown.
Partly fixes guix/guix#4269. Fixes a bug whereby shepherd (PID 1) could retain memory mappings for /var/run/nscd/dbXXX, which are created by glibc’s NSS from database file descriptors sent by nscd. Those mappings could then prevent ‘root-file-system’ from re-mounting the root file system as read-write. This change causes PID 1 to drop these mappings. PID 1 typically calls libc database functions such as ‘getgr’ when dealing with AF_UNIX endpoints for socket-activated services, to look up the socket’s owner and group. This is where the bug would manifest. The regression may have been introduced by 85ac164c41fc4c93d3cb2a5d3321c63598c2855f, which caused nscd to handle the password and group databases. * gnu/services/base.scm (nscd-shepherd-service): In ‘stop’ procedure, call ‘getpw’, ‘getgr’, and ‘getaddrinfo’. * gnu/tests/base.scm (run-root-unmount-test) <"open libc NSS database">: New test. (%test-root-unmount): Add #:imported-modules. Change-Id: I197cc8c82165c631f857415898137412ce9bd439 Reported-by: Rutherther <rutherther@ditigal.xyz> Signed-off-by: Ludovic Courtès <ludo@gnu.org> Merges: #4828
-rw-r--r--gnu/services/base.scm16
-rw-r--r--gnu/tests/base.scm17
2 files changed, 31 insertions, 2 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index c43f39fe320..062364bf81f 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -1557,7 +1557,21 @@ the tty to run, among other things."
1557 (string-append dir "/lib")) 1557 (string-append dir "/lib"))
1558 (list #$@name-services)) 1558 (list #$@name-services))
1559 ":"))))) 1559 ":")))))
1560 (stop #~(make-kill-destructor)) 1560 (stop #~(let ((terminate (make-kill-destructor)))
1561 (lambda (process)
1562 (terminate process)
1563
1564 ;; PID 1 might have mapped nscd database files via
1565 ;; '__nscd_get_mapping'. Call the relevant libc
1566 ;; functions (those with a corresponding GETFD* request
1567 ;; type) to cause PID 1 to notice that those mappings
1568 ;; are stale and to unmap them. Failure to do so would
1569 ;; prevent the root file system from being remounted
1570 ;; read-only when shutting down.
1571 (false-if-exception (getpw "root"))
1572 (false-if-exception (getgr "root"))
1573 (false-if-exception (getaddrinfo "localhost" "http"))
1574 #f)))
1561 (modules `((ice-9 popen) ;for the actions 1575 (modules `((ice-9 popen) ;for the actions
1562 (ice-9 rdelim) 1576 (ice-9 rdelim)
1563 (ice-9 match) 1577 (ice-9 match)
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index dc51880d8ed..86fa6374efc 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -827,6 +827,18 @@ in a loop. See <http://bugs.gnu.org/26931>.")
827 ,witness-size)))))) 827 ,witness-size))))))
828 marionette)) 828 marionette))
829 829
830 ;; Cause PID 1 to create a mapping to nscd's database files.
831 ;; Those mappings used to prevent 'root-file-system' to remount
832 ;; read-only on shutdown. See
833 ;; <https://codeberg.org/guix/guix/issues/4269>.
834 (test-equal "open libc NSS database"
835 "root"
836 (marionette-eval '(begin
837 (use-modules (gnu services herd))
838 (start-service 'nscd) ;wait for nscd
839 (eval-there '(passwd:name (getgr "root"))))
840 marionette))
841
830 ;; Halt the system. 842 ;; Halt the system.
831 (marionette-eval '(system* "/run/current-system/profile/sbin/halt") 843 (marionette-eval '(system* "/run/current-system/profile/sbin/halt")
832 marionette) 844 marionette)
@@ -891,7 +903,10 @@ in a loop. See <http://bugs.gnu.org/26931>.")
891 "Make sure the root file system is cleanly unmounted when the system is 903 "Make sure the root file system is cleanly unmounted when the system is
892halted.") 904halted.")
893 (value 905 (value
894 (let ((os (marionette-operating-system %simple-os))) 906 (let ((os (marionette-operating-system
907 %simple-os
908 #:imported-modules '((gnu services herd)
909 (guix combinators)))))
895 (run-root-unmount-test os))))) 910 (run-root-unmount-test os)))))
896 911
897 912