From mboxrd@z Thu Jan 1 00:00:00 1970 From: Leo Famulari Subject: bug#23605: /dev/urandom not seeded across reboots Date: Wed, 25 May 2016 12:38:15 -0400 Message-ID: <20160525163815.GA19996@jasmine> References: <20160523175832.GA10646@jasmine> <87d1obabj8.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="IS0zKkzwUGydFO0o" Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59119) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5bpr-000188-1c for bug-guix@gnu.org; Wed, 25 May 2016 12:39:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5bpm-0003Na-1R for bug-guix@gnu.org; Wed, 25 May 2016 12:39:06 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:54388) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5bpl-0003NK-TX for bug-guix@gnu.org; Wed, 25 May 2016 12:39:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1b5bpl-0002pU-MT for bug-guix@gnu.org; Wed, 25 May 2016 12:39:01 -0400 Sender: "Debbugs-submit" Resent-Message-ID: Content-Disposition: inline In-Reply-To: <87d1obabj8.fsf@gnu.org> List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 23605@debbugs.gnu.org --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Tue, May 24, 2016 at 02:24:59PM +0200, Ludovic Courtès wrote: > Leo Famulari skribis: > > + (mkdir-p "/var/run") > > + (close-port (open-file "/var/run/urandom-seed" "a0b")) > > Or simply ‘open-output-file’. Done in the attached diff. > Maybe do: > > (define %random-seed-file > "/var/run/random-seed") Done. > > + (start #~(lambda _ > > + (exec-command > > + (zero? > > + (system (string-append "cat " > > + "/var/run/urandom-seed" > > + " > /dev/urandom")))))) > > Instead of spawning ‘cat’, we can do: > > (when (file-exists? #$%random-seed-file) > (call-with-input-file #$%random-seed-file > (lambda (seed) > (call-with-output-file "/dev/urandom" > (lambda (random) > (dump-port seed random)))))) > #t ;service successfully “started” I think I've done this correctly, as attached, but I can't test it yet since I still get an error: "service: Wrong number of arguments in form (service urandom-seed-service-type)". > > + (stop #~(lambda _ > > + (exec-command > > + (zero? > > + (system* "dd" "if=/dev/urandom" > > + (string-append "of=" "/var/run/urandom-seed") > > + "count=1" "bs=512")))))))) > > Likewise, I would suggest using: > > (let ((buf (make-bytevector 512))) > (call-with-input-file "/dev/urandom" > (lambda (random) > (get-bytevector-n! random buf 512))) > …) I tried to fill in the …, but again, I'm struggling here :p More advice requested! :) --IS0zKkzwUGydFO0o Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="urandom-seed-service.patch" diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 96bf8da..b26fee1 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -93,6 +93,8 @@ gpm-service-type gpm-service + urandom-seed-service + %base-services)) ;;; Commentary: @@ -1200,6 +1202,55 @@ extra rules from the packages listed in @var{rules}." "Return a service that uses @var{device} as a swap device." (service swap-service-type device)) +(define %random-seed-file + "/var/run/random-seed") + +(define %urandom-seed-activation + ;; Activation gexp for the urandom seed + #~(begin + (use-modules (guix build utils)) + + (mkdir-p (dirname %random-seed-file)) + (close-port (open-output-file %random-seed-file)) + (chmod %random-seed-file #o600))) + +(define (urandom-seed-shepherd-service) + "Return a shepherd service for the /dev/urandom seed." + (list (shepherd-service + (documentation "Preserve entropy across reboots for /dev/urandom.") + (provision '(urandom-seed)) + (requirement '(user-processes)) ; whatever provides file-system /var + (start #~(lambda _ + (when (file-exists? #$%random-seed-file) + (call-with-input-file #$%random-seed-file + (lambda (seed) + (call-with-output-file "/dev/urandom" + (lambda (urandom) + (dump-port seed urandom)))))) + #t)) + (stop #~(lambda _ + (let ((buf (make-bytevector 512))) + (call-with-input-file "/dev/urandom" + (lambda (urandom) + (get-bytevector-n! urandom buf 0 512) + (call-with-output-file #$%random-seed-file + (lambda (seed) + (dump-port buf seed))) + #t)))))))) + +(define urandom-seed-service-type + (service-type (name 'urandom-seed) + (extensions + (list (service-extension shepherd-root-service-type + urandom-seed-shepherd-service) + (service-extension activation-service-type + (const %urandom-seed-activation)) + ;; Add urandom-seed to the system profile + ;; Where is profile-service-type defined? + (service-extension profile-service-type list))))) + +(define (urandom-seed-service) + (service urandom-seed-service-type)) (define-record-type* gpm-configuration make-gpm-configuration gpm-configuration? @@ -1281,6 +1332,7 @@ This is the GNU operating system, welcome!\n\n"))) (static-networking-service "lo" "127.0.0.1" #:provision '(loopback)) (syslog-service) + (urandom-seed-service) (guix-service) (nscd-service) --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=backtrace $ ./pre-inst-env guix system vm --no-substitutes ~/work/guix/doc/os-config-bare-bones.texi ;;; note: source file /home/leo/work/guix/gnu/services/base.scm ;;; newer than compiled /home/leo/work/guix/gnu/services/base.go ;;; note: source file /home/leo/work/guix/gnu/services/base.scm ;;; newer than compiled /home/leo/.cache/guile/ccache/2.0-LE-8-2.0/home/leo/work/guix/gnu/services/base.scm.go ice-9/psyntax.scm:1422:32: In procedure expand-macro: ice-9/psyntax.scm:1422:32: Syntax error: gnu/services/base.scm:1253:2: service: Wrong number of arguments in form (service urandom-seed-service-type) --IS0zKkzwUGydFO0o--