GNU bug report logs - #23605
/dev/urandom not seeded across reboots

Previous Next

Package: guix;

Reported by: Leo Famulari <leo <at> famulari.name>

Date: Mon, 23 May 2016 17:59:01 UTC

Severity: normal

Done: Leo Famulari <leo <at> famulari.name>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 23605 in the body.
You can then email your comments to 23605 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Mon, 23 May 2016 17:59:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Leo Famulari <leo <at> famulari.name>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Mon, 23 May 2016 17:59:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: bug-guix <at> gnu.org
Subject: /dev/urandom not seeded across reboots
Date: Mon, 23 May 2016 13:58:32 -0400
[Message part 1 (text/plain, inline)]
I realized that we don't seem to be saving any of the entropy in the
kernel's random pool [0] across reboots.

This means that for some period after boot, /dev/urandom may not be safe
to use. From random(4):

---
If  a seed file is saved across reboots as recommended below (all major
Linux distributions have done this since 2000 at least),
[/dev/urandom's] output is cryptographically  secure against  attackers
without  local  root access as soon as it is reloaded in the boot
sequence, and perfectly adequate for network encryption session  keys.
---

I interpret that text to mean that, without use of a seed file,
urandom's output is *not* adequate for network encryption session keys
(SSH, TLS, etc) until enough entropy has been gathered. I don't know how
long that takes.

I've attached my not-yet-working attempt at a urandom-seed-service. I
tried to get it working on my own but I need the assistance of some more
experienced Guix hackers :)

I've also attached a stand-alone Guile script to illustrate what the
effect of the service should be. This script does seem to work. I'm sure
the use of shell tools could be replaced by Guile.

After applying my patch and attempting `guix system vm ...`, I get the
attached backtrace.

Does anyone have advice about the service? Am I wrong that we need to
seed /dev/urandom to make it work properly?

[0] See the man page for random(4).
[random.scm (text/plain, attachment)]
[urandom-seed.patch (text/x-diff, attachment)]
[backtrace (text/plain, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Tue, 24 May 2016 07:06:02 GMT) Full text and rfc822 format available.

Message #8 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: taylanbayirli <at> gmail.com (Taylan Ulrich Bayırlı/Kammer)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Tue, 24 May 2016 09:05:21 +0200
Leo Famulari <leo <at> famulari.name> writes:

> I realized that we don't seem to be saving any of the entropy in the
> kernel's random pool [0] across reboots.
>
> This means that for some period after boot, /dev/urandom may not be safe
> to use. From random(4):
>
> ---
> If  a seed file is saved across reboots as recommended below (all major
> Linux distributions have done this since 2000 at least),
> [/dev/urandom's] output is cryptographically  secure against  attackers
> without  local  root access as soon as it is reloaded in the boot
> sequence, and perfectly adequate for network encryption session  keys.
> ---
>
> I interpret that text to mean that, without use of a seed file,
> urandom's output is *not* adequate for network encryption session keys
> (SSH, TLS, etc) until enough entropy has been gathered. I don't know how
> long that takes.
>
> I've attached my not-yet-working attempt at a urandom-seed-service. I
> tried to get it working on my own but I need the assistance of some more
> experienced Guix hackers :)
>
> I've also attached a stand-alone Guile script to illustrate what the
> effect of the service should be. This script does seem to work. I'm sure
> the use of shell tools could be replaced by Guile.
>
> After applying my patch and attempting `guix system vm ...`, I get the
> attached backtrace.
>
> Does anyone have advice about the service? Am I wrong that we need to
> seed /dev/urandom to make it work properly?
>
> [0] See the man page for random(4).

Yes, this is necessary under Linux if you want urandom to be random
enough immediately after boot, and all the distros do it as part of
their init.

There's also an interesting implication here about the very first time
you boot the system and don't have a urandom seed file from the last
shutdown yet.  I don't know how this is typically handled, given that
for instance it's quite possible that a user might generate SSH keys
shortly after their first boot of a system.

I heard BSD kernels are smarter: /dev/random and urandom are the same
file and behave as follows: after boot, until there's enough entropy,
they block (behave like Linux /dev/random), and once there's enough
entropy they never block (behave like Linux /dev/urandom).  No idea how
the Hurd does it.

Taylan




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Tue, 24 May 2016 12:26:01 GMT) Full text and rfc822 format available.

Message #11 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Tue, 24 May 2016 14:24:59 +0200
Leo Famulari <leo <at> famulari.name> skribis:

> I realized that we don't seem to be saving any of the entropy in the
> kernel's random pool [0] across reboots.
>
> This means that for some period after boot, /dev/urandom may not be safe
> to use. From random(4):

Good catch!

Some comments:

> +(define %urandom-seed-activation
> +  ;; Activation gexp for the urandom seed
> +  #~(begin
> +      (use-modules (guix build utils))
> +
> +      (mkdir-p "/var/run")
> +      (close-port (open-file "/var/run/urandom-seed" "a0b"))

Or simply ‘open-output-file’.

Maybe do:

  (define %random-seed-file
    "/var/run/random-seed")

to avoid repeating the file name everywhere.

> +         (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”

> +         (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)))
    …)

Thanks for looking into it!

Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Tue, 24 May 2016 16:17:01 GMT) Full text and rfc822 format available.

Message #14 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Taylan Ulrich Bayırlı/Kammer
 <taylanbayirli <at> gmail.com>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Tue, 24 May 2016 12:16:17 -0400
On Tue, May 24, 2016 at 09:05:21AM +0200, Taylan Ulrich Bayırlı/Kammer wrote:
> Leo Famulari <leo <at> famulari.name> writes:
> > Does anyone have advice about the service? Am I wrong that we need to
> > seed /dev/urandom to make it work properly?
> 
> Yes, this is necessary under Linux if you want urandom to be random
> enough immediately after boot, and all the distros do it as part of
> their init.
> 
> There's also an interesting implication here about the very first time
> you boot the system and don't have a urandom seed file from the last
> shutdown yet.  I don't know how this is typically handled, given that
> for instance it's quite possible that a user might generate SSH keys
> shortly after their first boot of a system.

When I boot a GuixSD VM for the first time [0], it requires me to dance
on the keyboard until it has collected ~200 bits of entropy. I assumed
this is to properly bootstrap the CSPRNG in /dev/urandom, but I'm not
sure.

[0] I don't remember if I had to do this on bare metal.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Tue, 24 May 2016 16:27:01 GMT) Full text and rfc822 format available.

Message #17 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: "Thompson, David" <dthompson2 <at> worcester.edu>
To: Leo Famulari <leo <at> famulari.name>
Cc: Taylan Ulrich Bayırlı/Kammer
 <taylanbayirli <at> gmail.com>, 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Tue, 24 May 2016 12:26:29 -0400
On Tue, May 24, 2016 at 12:16 PM, Leo Famulari <leo <at> famulari.name> wrote:
> On Tue, May 24, 2016 at 09:05:21AM +0200, Taylan Ulrich Bayırlı/Kammer wrote:
>> Leo Famulari <leo <at> famulari.name> writes:
>> > Does anyone have advice about the service? Am I wrong that we need to
>> > seed /dev/urandom to make it work properly?
>>
>> Yes, this is necessary under Linux if you want urandom to be random
>> enough immediately after boot, and all the distros do it as part of
>> their init.
>>
>> There's also an interesting implication here about the very first time
>> you boot the system and don't have a urandom seed file from the last
>> shutdown yet.  I don't know how this is typically handled, given that
>> for instance it's quite possible that a user might generate SSH keys
>> shortly after their first boot of a system.
>
> When I boot a GuixSD VM for the first time [0], it requires me to dance
> on the keyboard until it has collected ~200 bits of entropy. I assumed
> this is to properly bootstrap the CSPRNG in /dev/urandom, but I'm not
> sure.

This is just an annoying feature of GNU lsh.  I want to switch my
machines to OpenSSH sometime, partly due to this.

- Dave




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Tue, 24 May 2016 17:24:02 GMT) Full text and rfc822 format available.

Message #20 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: "Thompson, David" <dthompson2 <at> worcester.edu>
Cc: Taylan Ulrich Bayırlı/Kammer
 <taylanbayirli <at> gmail.com>, 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Tue, 24 May 2016 13:23:29 -0400
On Tue, May 24, 2016 at 12:26:29PM -0400, Thompson, David wrote:
> On Tue, May 24, 2016 at 12:16 PM, Leo Famulari <leo <at> famulari.name> wrote:
> > On Tue, May 24, 2016 at 09:05:21AM +0200, Taylan Ulrich Bayırlı/Kammer wrote:
> >> Leo Famulari <leo <at> famulari.name> writes:
> >> > Does anyone have advice about the service? Am I wrong that we need to
> >> > seed /dev/urandom to make it work properly?
> >>
> >> Yes, this is necessary under Linux if you want urandom to be random
> >> enough immediately after boot, and all the distros do it as part of
> >> their init.
> >>
> >> There's also an interesting implication here about the very first time
> >> you boot the system and don't have a urandom seed file from the last
> >> shutdown yet.  I don't know how this is typically handled, given that
> >> for instance it's quite possible that a user might generate SSH keys
> >> shortly after their first boot of a system.
> >
> > When I boot a GuixSD VM for the first time [0], it requires me to dance
> > on the keyboard until it has collected ~200 bits of entropy. I assumed
> > this is to properly bootstrap the CSPRNG in /dev/urandom, but I'm not
> > sure.
> 
> This is just an annoying feature of GNU lsh.  I want to switch my
> machines to OpenSSH sometime, partly due to this.

Well, it seems that this feature might be protecting us against using
weak SSH session keys on first boot, if it's doing what I think it's
doing...




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Tue, 24 May 2016 17:30:02 GMT) Full text and rfc822 format available.

Message #23 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: "Thompson, David" <dthompson2 <at> worcester.edu>
To: Leo Famulari <leo <at> famulari.name>
Cc: Taylan Ulrich Bayırlı/Kammer
 <taylanbayirli <at> gmail.com>, 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Tue, 24 May 2016 13:29:44 -0400
On Tue, May 24, 2016 at 1:23 PM, Leo Famulari <leo <at> famulari.name> wrote:
> On Tue, May 24, 2016 at 12:26:29PM -0400, Thompson, David wrote:
>> On Tue, May 24, 2016 at 12:16 PM, Leo Famulari <leo <at> famulari.name> wrote:
>> > On Tue, May 24, 2016 at 09:05:21AM +0200, Taylan Ulrich Bayırlı/Kammer wrote:
>> >> Leo Famulari <leo <at> famulari.name> writes:
>> >> > Does anyone have advice about the service? Am I wrong that we need to
>> >> > seed /dev/urandom to make it work properly?
>> >>
>> >> Yes, this is necessary under Linux if you want urandom to be random
>> >> enough immediately after boot, and all the distros do it as part of
>> >> their init.
>> >>
>> >> There's also an interesting implication here about the very first time
>> >> you boot the system and don't have a urandom seed file from the last
>> >> shutdown yet.  I don't know how this is typically handled, given that
>> >> for instance it's quite possible that a user might generate SSH keys
>> >> shortly after their first boot of a system.
>> >
>> > When I boot a GuixSD VM for the first time [0], it requires me to dance
>> > on the keyboard until it has collected ~200 bits of entropy. I assumed
>> > this is to properly bootstrap the CSPRNG in /dev/urandom, but I'm not
>> > sure.
>>
>> This is just an annoying feature of GNU lsh.  I want to switch my
>> machines to OpenSSH sometime, partly due to this.
>
> Well, it seems that this feature might be protecting us against using
> weak SSH session keys on first boot, if it's doing what I think it's
> doing...

It impedes automated provisioning of servers, which OpenSSH does not do.

- Dave




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Wed, 25 May 2016 16:39:01 GMT) Full text and rfc822 format available.

Message #26 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Wed, 25 May 2016 12:38:15 -0400
[Message part 1 (text/plain, inline)]
On Tue, May 24, 2016 at 02:24:59PM +0200, Ludovic Courtès wrote:
> Leo Famulari <leo <at> famulari.name> 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! :)
[urandom-seed-service.patch (text/x-diff, attachment)]
[backtrace (text/plain, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Wed, 25 May 2016 16:56:03 GMT) Full text and rfc822 format available.

Message #29 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Wed, 25 May 2016 18:54:58 +0200
Leo Famulari <leo <at> famulari.name> skribis:

> On Tue, May 24, 2016 at 02:24:59PM +0200, Ludovic Courtès wrote:

[...]

>> 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)".

Yes, it’s:

  (service TYPE VALUE)

but I think there’s no meaningful value for this service, so you could
do:

  (service urandom-seed-service-type #f)

[...]

> +(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.")

I think you’ll need to specify that additional modules are needed (for
‘make-bytevector’, ‘put-bytevector’, etc.):

  (shepherd-service
    ;; …
    (modules `((rnrs bytevectors)
               (rnrs io ports)
               ,@%default-modules)))

(See (gnu services shepherd) for the definition of ‘%default-modules’.)

> +         (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
                             ^^
Misleading indent here.

> +                             (lambda (seed)
> +                               (dump-port buf seed)))

‘dump-port’ from (guix build utils) takes an input port as its 1st
argument, and an output port as its 2nd argument.  Here BUF is a
bytevector, not a port.

So instead, this should be:

  (lambda (seed)
    (put-bytevector seed buf))

Sounds like you’re pretty much there!  :-)

Thanks,
Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Wed, 25 May 2016 21:54:01 GMT) Full text and rfc822 format available.

Message #32 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: "Thompson\, David" <dthompson2 <at> worcester.edu>
Cc: 23605 <at> debbugs.gnu.org, Leo Famulari <leo <at> famulari.name>
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Wed, 25 May 2016 23:53:33 +0200
"Thompson, David" <dthompson2 <at> worcester.edu> skribis:

> On Tue, May 24, 2016 at 12:16 PM, Leo Famulari <leo <at> famulari.name> wrote:

[...]

>> When I boot a GuixSD VM for the first time [0], it requires me to dance
>> on the keyboard until it has collected ~200 bits of entropy. I assumed
>> this is to properly bootstrap the CSPRNG in /dev/urandom, but I'm not
>> sure.
>
> This is just an annoying feature of GNU lsh.  I want to switch my
> machines to OpenSSH sometime, partly due to this.

It’s actually ‘lsh-make-seed’ that does that (info "(lsh)
lsh-make-seed"), and it’s invoked from our ‘lsh-service’ when
#:initialize? is #t (the default).

It’s possible to set #:initialize? to #f, but then you still need to
create (or provide) the random seed at some point.  At the time people
felt that having it default to #t would be less surprising.

> It impedes automated provisioning of servers, which OpenSSH does not do.

Maybe OpenSSH assumes that the kernel-provided randomness is good
enough?

Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Thu, 26 May 2016 16:48:01 GMT) Full text and rfc822 format available.

Message #35 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Thu, 26 May 2016 12:47:07 -0400
[Message part 1 (text/plain, inline)]
On Wed, May 25, 2016 at 06:54:58PM +0200, Ludovic Courtès wrote:
> 
> Yes, it’s:
> 
>   (service TYPE VALUE)
> 
> but I think there’s no meaningful value for this service, so you could
> do:
> 
>   (service urandom-seed-service-type #f)

I'm struggling to make this work. Do I need to alter the definition of
urandom-seed-shepherd-service to accept the boolean?

With the attached diff, building a VM fails like this (full backtrace
attached):

[...]
 573: 2 [loop #<<service> type: # parameters: ()>]
In srfi/srfi-1.scm:
 578: 1 [map #<procedure 519cc20 at gnu/services.scm:562:4 (service)> (# # # # ...)]
In gnu/services/base.scm:
1217: 0 [urandom-seed-shepherd-service #f]

gnu/services/base.scm:1217:0: In procedure urandom-seed-shepherd-service:
gnu/services/base.scm:1217:0: Wrong number of arguments to #<procedure urandom-seed-shepherd-service ()>

> Sounds like you’re pretty much there!  :-)

Almost, I hope! Thanks for your help :)
[backtrace (text/plain, attachment)]
[urandom-seed-service.patch (text/x-diff, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 01:06:01 GMT) Full text and rfc822 format available.

Message #38 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: bug-guix <at> gnu.org
Subject: Re: /dev/urandom not seeded across reboots
Date: Fri, 27 May 2016 21:05:01 -0400
[Message part 1 (text/plain, inline)]
Okay, I finally have some code that works! (attached)

I tested it by using `inotifywait -m /dev/urandom` [0] to see that
/dev/urandom was indeed being open and closed for writing when running
`herd {start, stop} urandom-seed`. If you can suggest a way to see
exactly what is being written to /dev/urandom, I would like to verify it
more fully.

If you test it, don't be surprised that the random-seed is empty the
first time you start the service. It is `touch`-ed at boot but filled
during shutdown.

The big caveat is that the only way I could make it work was to use the
old service API. I just couldn't figure out how to use the extensible
service API for a service that takes to arguments.

If this is a problem, then your help is wanted!

I also had to change the location of %random-seed-file from
/var/run/random-seed to /var/lib/random-seed, because /var/run is
cleared upon reboot. This is specified in the FHS standard [1]. Debian
puts it at /var/lib/urandom/random-seed.

[0] From the inotify-tools package

[1]
http://www.pathname.com/fhs/pub/fhs-2.3.html#VARRUNRUNTIMEVARIABLEDATA
[0001-services-Add-urandom-seed-service.patch (text/x-diff, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 01:12:01 GMT) Full text and rfc822 format available.

Message #41 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Ben Woodcroft <b.woodcroft <at> uq.edu.au>
To: Leo Famulari <leo <at> famulari.name>, 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 11:11:20 +1000
Hi Leo,

On 28/05/16 11:05, Leo Famulari wrote:
> Okay, I finally have some code that works! (attached)
Is your patch incomplete?

ben




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 01:13:02 GMT) Full text and rfc822 format available.

Message #44 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Fri, 27 May 2016 21:12:01 -0400
On Tue, May 24, 2016 at 02:24:59PM +0200, Ludovic Courtès wrote:
> Leo Famulari <leo <at> famulari.name> skribis:
> 
> > I realized that we don't seem to be saving any of the entropy in the
> > kernel's random pool [0] across reboots.
> >
> > This means that for some period after boot, /dev/urandom may not be safe
> > to use. From random(4):
> 
> Good catch!
> 
> Some comments:
> 
> > +(define %urandom-seed-activation
> > +  ;; Activation gexp for the urandom seed
> > +  #~(begin
> > +      (use-modules (guix build utils))
> > +
> > +      (mkdir-p "/var/run")
> > +      (close-port (open-file "/var/run/urandom-seed" "a0b"))
> 
> Or simply ‘open-output-file’.

I don't see a way to use (open-output-file) in "append" mode as with
(open-file).  Without that, the file is cleared before it is read in the
following lines.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 01:46:02 GMT) Full text and rfc822 format available.

Message #47 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ben Woodcroft <b.woodcroft <at> uq.edu.au>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Fri, 27 May 2016 21:45:22 -0400
On Sat, May 28, 2016 at 11:11:20AM +1000, Ben Woodcroft wrote:
> Hi Leo,
> 
> On 28/05/16 11:05, Leo Famulari wrote:
> > Okay, I finally have some code that works! (attached)
> Is your patch incomplete?

What do you mean? Does it not apply to your source tree?

Otherwise, I expect that it's incomplete in the sense that it will
require some more revision before being merged into the master branch on
Savannah.

Your comments are welcome :)




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 09:41:01 GMT) Full text and rfc822 format available.

Message #50 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Ben Woodcroft <b.woodcroft <at> uq.edu.au>
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 19:40:29 +1000

On 28/05/16 11:45, Leo Famulari wrote:
> On Sat, May 28, 2016 at 11:11:20AM +1000, Ben Woodcroft wrote:
>> Hi Leo,
>>
>> On 28/05/16 11:05, Leo Famulari wrote:
>>> Okay, I finally have some code that works! (attached)
>> Is your patch incomplete?
> What do you mean? Does it not apply to your source tree?

Oh, nevermind, sorry for the noise. Thunderbird was tripping up on the 
strange character and not showing me the full diff.
ben




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 13:53:02 GMT) Full text and rfc822 format available.

Message #53 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 15:51:58 +0200
Leo Famulari <leo <at> famulari.name> skribis:

> On Tue, May 24, 2016 at 02:24:59PM +0200, Ludovic Courtès wrote:
>> Leo Famulari <leo <at> famulari.name> skribis:
>> 
>> > I realized that we don't seem to be saving any of the entropy in the
>> > kernel's random pool [0] across reboots.
>> >
>> > This means that for some period after boot, /dev/urandom may not be safe
>> > to use. From random(4):
>> 
>> Good catch!
>> 
>> Some comments:
>> 
>> > +(define %urandom-seed-activation
>> > +  ;; Activation gexp for the urandom seed
>> > +  #~(begin
>> > +      (use-modules (guix build utils))
>> > +
>> > +      (mkdir-p "/var/run")
>> > +      (close-port (open-file "/var/run/urandom-seed" "a0b"))
>> 
>> Or simply ‘open-output-file’.
>
> I don't see a way to use (open-output-file) in "append" mode as with
> (open-file).  Without that, the file is cleared before it is read in the
> following lines.

You’re right, sorry for the confusion.

Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 13:58:02 GMT) Full text and rfc822 format available.

Message #56 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 15:57:06 +0200
Leo Famulari <leo <at> famulari.name> skribis:

> On Wed, May 25, 2016 at 06:54:58PM +0200, Ludovic Courtès wrote:
>> 
>> Yes, it’s:
>> 
>>   (service TYPE VALUE)
>> 
>> but I think there’s no meaningful value for this service, so you could
>> do:
>> 
>>   (service urandom-seed-service-type #f)

[...]

> gnu/services/base.scm:1217:0: In procedure urandom-seed-shepherd-service:
> gnu/services/base.scm:1217:0: Wrong number of arguments to #<procedure urandom-seed-shepherd-service ()>

[...]

> +(define (urandom-seed-shepherd-service)

[...]

> +(define urandom-seed-service-type
> +  (service-type (name 'urandom-seed)
> +                (extensions
> +                 (list (service-extension shepherd-root-service-type
> +                                          urandom-seed-shepherd-service)

Service extension procedures are called with one argument, which is the
service’s value (info "(guix) Service Reference").

Usually, the service’s value is a configuration object, but in this
case, the service’s value doesn’t matter, so you could simply write:

  (define (urandom-seed-shepherd-service _)
    …)

> +                       ;; Add urandom-seed to the system profile
> +                       (service-extension profile-service-type list)))))

The ‘profile-service-type’ represents the system profile, i.e.,
/run/current-system/profile.  Extending it means adding a package to
it.

But here, IIUC, there’s no package to be added to the profile, so you
should just remove it.

Last round and we’re done!  :-)

Thanks for persevering, and sorry it’s not easier.  Maybe you’ll have
ideas on how to improve the manual and/or the API?

Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 18:06:02 GMT) Full text and rfc822 format available.

Message #59 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 14:05:35 -0400
[Message part 1 (text/plain, inline)]
On Sat, May 28, 2016 at 03:57:06PM +0200, Ludovic Courtès wrote:
> Leo Famulari <leo <at> famulari.name> skribis:
> > On Wed, May 25, 2016 at 06:54:58PM +0200, Ludovic Courtès wrote:
> Usually, the service’s value is a configuration object, but in this
> case, the service’s value doesn’t matter, so you could simply write:
> 
>   (define (urandom-seed-shepherd-service _)
>     …)
> 
> > +                       ;; Add urandom-seed to the system profile
> > +                       (service-extension profile-service-type list)))))
> 
> The ‘profile-service-type’ represents the system profile, i.e.,
> /run/current-system/profile.  Extending it means adding a package to
> it.
> 
> But here, IIUC, there’s no package to be added to the profile, so you
> should just remove it.
> 
> Last round and we’re done!  :-)

Please find my latest patch attached. It seems to work for me!
[0001-services-Add-urandom-seed-service.patch (text/x-diff, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 18:11:02 GMT) Full text and rfc822 format available.

Message #62 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 14:10:09 -0400
On Sat, May 28, 2016 at 02:05:35PM -0400, Leo Famulari wrote:
> Please find my latest patch attached. It seems to work for me!

I forgot to add a copyright line for myself in this version. I'll put it
in for the next patch or when merging.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 18:27:02 GMT) Full text and rfc822 format available.

Message #65 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 14:26:23 -0400
On Sat, May 28, 2016 at 02:05:35PM -0400, Leo Famulari wrote:
> Please find my latest patch attached. It seems to work for me!

I'm currently reconfiguring my GuixSD system with this patch to make
sure bad things don't happen the first time the user halts and the seed
file does not exist. Or something like that. Just to see what happens.

So far, I tested this by generating VM images.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 20:42:02 GMT) Full text and rfc822 format available.

Message #68 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 16:41:01 -0400
On Sat, May 28, 2016 at 02:26:23PM -0400, Leo Famulari wrote:
> On Sat, May 28, 2016 at 02:05:35PM -0400, Leo Famulari wrote:
> > Please find my latest patch attached. It seems to work for me!
> 
> I'm currently reconfiguring my GuixSD system with this patch to make
> sure bad things don't happen the first time the user halts and the seed
> file does not exist. Or something like that. Just to see what happens.

No problems. After reconfiguring, the service is started and there is a
zero-byte file at /var/lib/random-seed.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sat, 28 May 2016 20:54:01 GMT) Full text and rfc822 format available.

Message #71 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 22:53:08 +0200
Leo Famulari <leo <at> famulari.name> skribis:

> Please find my latest patch attached. It seems to work for me!

\o/

> From 18979451b1af7eebaa354c1753ad4c90af288589 Mon Sep 17 00:00:00 2001
> From: Leo Famulari <leo <at> famulari.name>
> Date: Sat, 28 May 2016 13:41:21 -0400
> Subject: [PATCH] services: Add urandom-seed-service.

Add “Fixes <http://bugs.gnu.org/23605>.”

> * gnu/services/base.scm (urandom-seed-service): New procedure.
> (%random-seed-file, urandom-seed-service-type): New variables.
> (%urandom-seed-shepherd-service): New procedure.

Mention the addition to ‘%base-services’ too.

> * doc/guix.texi (Base Services): Document it.

[...]

> +@deftp {Data Type} %random-seed-file

Should be:

  @defvr {Scheme Variable} %random-seed-file

> +This is where some random bytes are saved by @var{urandom-seed-service}

s/This is where/This is the name of the file where/

> +to seed @file{/dev/urandom} when rebooting.

Maybe add “It defaults to @file{/var/run/…}.”

OK with these changes.

Thanks a lot!

Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sun, 29 May 2016 00:02:02 GMT) Full text and rfc822 format available.

Message #74 received at 23605 <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: 23605 <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 20:00:58 -0400
On Sat, May 28, 2016 at 10:53:08PM +0200, Ludovic Courtès wrote:
> 
> OK with these changes.

Done as a535e12226!




Reply sent to Leo Famulari <leo <at> famulari.name>:
You have taken responsibility. (Sun, 29 May 2016 00:05:02 GMT) Full text and rfc822 format available.

Notification sent to Leo Famulari <leo <at> famulari.name>:
bug acknowledged by developer. (Sun, 29 May 2016 00:05:02 GMT) Full text and rfc822 format available.

Message #79 received at 23605-done <at> debbugs.gnu.org (full text, mbox):

From: Leo Famulari <leo <at> famulari.name>
To: 23605-done <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sat, 28 May 2016 20:04:31 -0400
On Sat, May 28, 2016 at 08:00:58PM -0400, Leo Famulari wrote:
> On Sat, May 28, 2016 at 10:53:08PM +0200, Ludovic Courtès wrote:
> > 
> > OK with these changes.
> 
> Done as a535e12226!




Information forwarded to bug-guix <at> gnu.org:
bug#23605; Package guix. (Sun, 29 May 2016 20:24:02 GMT) Full text and rfc822 format available.

Message #82 received at 23605-done <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Leo Famulari <leo <at> famulari.name>
Cc: 23605-done <at> debbugs.gnu.org
Subject: Re: bug#23605: /dev/urandom not seeded across reboots
Date: Sun, 29 May 2016 22:23:14 +0200
Leo Famulari <leo <at> famulari.name> skribis:

> On Sat, May 28, 2016 at 10:53:08PM +0200, Ludovic Courtès wrote:
>> 
>> OK with these changes.
>
> Done as a535e12226!

Thank you!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 27 Jun 2016 11:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 276 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.