rng-tools: add udev rule for virtio-rng
Subsystems (2)
cover rng-tools: add udev rule for virtio-rng
Hello,
I didn't find a mailing list for rng-tools, so CC'ing the kernel lists and the last few committers.
The first patch in this series adds a udev rule to start rngd for guests that have a virtio-rng device available.
The second patch attempts to add autoconf magic to install the udev rule in the system dirs. However, installing as non-root will obviously fail. Prefixes are also not honoured. I don't know of a better way, and we probably should leave this to distributions. However, if someone has a better idea on how to expand this, please suggest.
Amit Shah (2):
rngd: add udev rule to source from hwrng if virtio-rng present Install udev rules in system-default directory
90-virtio-rng.rules | 1 + Makefile.am | 1 + configure.ac | 8 ++++++++ 3 files changed, 10 insertions(+) create mode 100644 90-virtio-rng.rules
Signature · 1 line
1.9.3
PATCH 1/2 rngd: add udev rule to source from hwrng if virtio-rng present
On KVM guests where the virtio-rng device is available, and set as the current rng, this udev rule will start rngd which will feed in the host-provided entropy to /dev/random.
--- 90-virtio-rng.rules | 1 + 1 file changed, 1 insertion(+) create mode 100644 90-virtio-rng.rules
90-virtio-rng.rules new file +1 -0
@@ -0,0 +1 @@ +KERNEL=="hw_random", ATTR{rng_current}=="virtio*", RUN+="/sbin/rngd -r /dev/hwrng"
Signature · 1 line
1.9.3
PATCH 2/2 Install udev rules in system-default directory
In reply to Amit Shah--- Makefile.am | 1 + configure.ac | 8 ++++++++ 2 files changed, 9 insertions(+)
Makefile.am +1 -0
@@ -8,6 +8,7 @@ sbin_PROGRAMS = rngd bin_PROGRAMS = rngtest man_MANS = rngd.8 rngtest.1 noinst_LIBRARIES = librngd.a +udevrules_DATA = 90-virtio-rng.rules rngd_SOURCES = rngd.h rngd.c rngd_entsource.h rngd_entsource.c \ rngd_linux.h rngd_linux.c util.c \
configure.ac +8 -0
@@ -32,6 +32,14 @@ AC_ARG_WITH([libgcrypt], [with_libgcrypt=check] ) +PKG_PROG_PKG_CONFIG + +AC_ARG_WITH([udevrulesdir], + AS_HELP_STRING([--with-udevrulesdir=DIR], [Directory for udev rules]), + [], + [with_udevrulesdir=$($PKG_CONFIG --variable=udevdir udev)"/rules.d"]) +AC_SUBST([udevrulesdir], [$with_udevrulesdir]) + dnl Make sure anyone changing configure.ac/Makefile.am has a clue AM_MAINTAINER_MODE
Signature · 1 line
1.9.3
PATCH 2/2 Install udev rules in system-default directory
In reply to Amit Shah--- Makefile.am | 1 + configure.ac | 8 ++++++++ 2 files changed, 9 insertions(+)
Makefile.am +1 -0
@@ -8,6 +8,7 @@ sbin_PROGRAMS = rngd bin_PROGRAMS = rngtest man_MANS = rngd.8 rngtest.1 noinst_LIBRARIES = librngd.a +udevrules_DATA = 90-virtio-rng.rules rngd_SOURCES = rngd.h rngd.c rngd_entsource.h rngd_entsource.c \ rngd_linux.h rngd_linux.c util.c \
configure.ac +8 -0
@@ -32,6 +32,14 @@ AC_ARG_WITH([libgcrypt], [with_libgcrypt=check] ) +PKG_PROG_PKG_CONFIG + +AC_ARG_WITH([udevrulesdir], + AS_HELP_STRING([--with-udevrulesdir=DIR], [Directory for udev rules]), + [], + [with_udevrulesdir=$($PKG_CONFIG --variable=udevdir udev)"/rules.d"]) +AC_SUBST([udevrulesdir], [$with_udevrulesdir]) + dnl Make sure anyone changing configure.ac/Makefile.am has a clue AM_MAINTAINER_MODE
Signature · 1 line
1.9.3
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
In reply to Amit ShahQuoted 17 lines · Amit Shah
On KVM guests where the virtio-rng device is available, and set as the current rng, this udev rule will start rngd which will feed in the host-provided entropy to
/dev/random.Signed-off-by Amit Shah <[email protected]>--- 90-virtio-rng.rules | 1 + 1 file changed, 1 insertion(+) create mode 100644 90-virtio-rng.rules90-virtio-rng.rules new file +0
-0
90-virtio-rng.rules line 1
Quoted 1 line
90-virtio-rng.rules new file +1
-0@@ -0,0 +1 @@ +KERNEL=="hw_random", ATTR{rng_current}=="virtio*", RUN+="/sbin/rngd -r /dev/hwrng"
I'm not sure this is really right. rngd can receive input from a number of sources, and I suspect it would be better to rngd to be started much earlier and perhaps get sent a SIGHUP to reconfigure when a hw_random device appears ... not just the virtio one.
Currently rngd exits if there is no daemon. There are a few ways to deal with that: one is to run rngd on changes and leave a pid file around; the rngd can try to signal the old rngd or launch itself; another option would be to have a different rngd for each source. To some degree the above is obsolete when we get khwrngd widely deployed, but that is a new-kernel-only kind of thing.
-hpa
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
In reply to Amit ShahQuoted 17 lines · Amit Shah
On KVM guests where the virtio-rng device is available, and set as the current rng, this udev rule will start rngd which will feed in the host-provided entropy to
/dev/random.Signed-off-by Amit Shah <[email protected]>--- 90-virtio-rng.rules | 1 + 1 file changed, 1 insertion(+) create mode 100644 90-virtio-rng.rules90-virtio-rng.rules new file +0
-0
90-virtio-rng.rules line 1
Quoted 1 line
90-virtio-rng.rules new file +1
-0@@ -0,0 +1 @@ +KERNEL=="hw_random", ATTR{rng_current}=="virtio*", RUN+="/sbin/rngd -r /dev/hwrng"
I'm not sure this is really right. rngd can receive input from a number of sources, and I suspect it would be better to rngd to be started much earlier and perhaps get sent a SIGHUP to reconfigure when a hw_random device appears ... not just the virtio one.
Currently rngd exits if there is no daemon. There are a few ways to deal with that: one is to run rngd on changes and leave a pid file around; the rngd can try to signal the old rngd or launch itself; another option would be to have a different rngd for each source. To some degree the above is obsolete when we get khwrngd widely deployed, but that is a new-kernel-only kind of thing.
-hpa
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
Quoted 11 lines · H. Peter Anvin
Quoted 10 lines · Amit Shah
On KVM guests where the virtio-rng device is available, and set as the current rng, this udev rule will start rngd which will feed in the host-provided entropy to
/dev/random.Signed-off-by Amit Shah <[email protected]>--- 90-virtio-rng.rules | 1 + 1 file changed, 1 insertion(+) create mode 100644 90-virtio-rng.rules
Quoted 13 lines
90-virtio-rng.rules line 1
Quoted 8 lines
90-virtio-rng.rules new file +1
-0@@ -0,0 +1 @@ +KERNEL=="hw_random", ATTR{rng_current}=="virtio*", RUN+="/sbin/rngd -r /dev/hwrng"I'm not sure this is really right. rngd can receive input from a number of sources, and I suspect it would be better to rngd to be started much earlier and perhaps get sent a SIGHUP to reconfigure when a
hw_randomdevice appears ... not just the virtio one.
Right - yea. Modern distros do start rngd by default (at least Fedora and RHEL do), so this does make sense.
But as you note below, not all distros may start rngd...
Quoted 4 lines
Currently rngd exits if there is no daemon. There are a few ways to deal with that: one is to run rngd on changes and leave a pid file around; the rngd can try to signal the old rngd or launch itself; another option would be to have a different rngd for each source.
Currently the kernel can only have one rng_current, which is a pity. So in the current case, rngd only needs one instance -- and it'll always accept stuff from /dev/hwrng and it doesn't matter if the rng_current is changed as long as there's some rng there.
Quoted 3 lines
To
some degree the above is obsolete when we get khwrngd widely deployed, but that is a new-kernel-only kind of thing.
Right - I'm wondering if any such changes as propsed here are now obsolted already by khwrngd?
Thanks,
Amit
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
Quoted 9 lines · Amit Shah
Quoted 5 lines
To
some degree the above is obsolete when we get khwrngd widely deployed, but that is a new-kernel-only kind of thing.Right - I'm wondering if any such changes as propsed here are now obsolted already by khwrngd?
In this case, yes, khwrngd would be a better solution for current kernels.
-hpa
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
In reply to Amit ShahQuoted 9 lines · Amit Shah
Quoted 5 lines
To
some degree the above is obsolete when we get khwrngd widely deployed, but that is a new-kernel-only kind of thing.Right - I'm wondering if any such changes as propsed here are now obsolted already by khwrngd?
In this case, yes, khwrngd would be a better solution for current kernels.
-hpa
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Amit Shah
Quoted 5 lines
To
some degree the above is obsolete when we get khwrngd widely deployed, but that is a new-kernel-only kind of thing.
Quoted 5 lines
Quoted 3 lines
Right - I'm wondering if any such changes as propsed here are now obsolted already by khwrngd?
In this case, yes, khwrngd would be a better solution for current kernels.
I think that's OK with me.
What's the suggested value for rng->quality, though, for virtio-rng that I can use to ensure the kthread starts?
Should I use the 700 (70%) as proposed in the original patchset? I'm not exactly sure how that value will be used as well..
Amit
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
Quoted 6 lines · Amit Shah
What's the suggested value for
rng->quality, though, for virtio-rng that I can use to ensure the kthread starts?Should I use the 700 (70%) as proposed in the original patchset? I'm not exactly sure how that value will be used as well..
There is no such thing as a suggested value, every number is wrong to some degree. The quality is an estimation of how random your source really is; it's a property of your hardware. If the device is virtual you're in trouble ;-)
Either you have a way to query the underlying real hardware, or you do your whitening and entropy estimation in the backend driver -- then you can claim 100%.
Torsten
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
In reply to Amit ShahQuoted 6 lines · Amit Shah
What's the suggested value for
rng->quality, though, for virtio-rng that I can use to ensure the kthread starts?Should I use the 700 (70%) as proposed in the original patchset? I'm not exactly sure how that value will be used as well..
There is no such thing as a suggested value, every number is wrong to some degree. The quality is an estimation of how random your source really is; it's a property of your hardware. If the device is virtual you're in trouble ;-)
Either you have a way to query the underlying real hardware, or you do your whitening and entropy estimation in the backend driver -- then you can claim 100%.
Torsten
Re: [PATCH 1/2] rngd: add udev rule to source from hwrng if virtio-rng present
Quoted 8 lines · Torsten Duwe
Quoted 6 lines · Amit Shah
What's the suggested value for
rng->quality, though, for virtio-rng that I can use to ensure the kthread starts?Should I use the 700 (70%) as proposed in the original patchset? I'm not exactly sure how that value will be used as well..
Quoted 9 lines
There is no such thing as a suggested value, every number is wrong to some degree. The quality is an estimation of how random your source really is; it's a property of your hardware. If the device is virtual you're in trouble ;-)
Either you have a way to query the underlying real hardware, or you do your whitening and entropy estimation in the backend driver -- then you can claim 100%.
virtio-rng I feel we could rank at 100%; it is supposed to feed /dev/random-quality randomness from the VMM. If the VMM is hostile you have already lost anyway.
-hpa
Re: [PATCH 2/2] Install udev rules in system-default directory
In reply to Amit ShahIl 07/08/2014 15:09, Amit Shah ha scritto:
Quoted 1 line
+udevrules_DATA = 90-virtio-rng.rules
If rng-tools is packaged with "make dist" you need this to be
dist_udevrules_DATA = 90-virtio-rng.rules
or alternatively
EXTRA_DIST = 90-virtio-rng.rulesudevrules_DATA = 90-virtio-rng.rules
configure.ac AC_ARG_WITH([libgcrypt], · line 41
Quoted 5 lines
configure.ac +5
-0+AC_ARG_WITH([udevrulesdir], + AS_HELP_STRING([--with-udevrulesdir=DIR], [Directory for udev rules]), + [], + [with_udevrulesdir=$($PKG_CONFIG --variable=udevdir udev)"/rules.d"]) +AC_SUBST([udevrulesdir], [$with_udevrulesdir])
You can use AM_CONDITIONAL to skip the installation if $with_udevrulesdir is "no" (aka --without-udevrulesdir). Then you'd have
EXTRA_DIST = 90-virtio-rng.rules
if INSTALL_UDEV_RULESudevrules_DATA = 90-virtio-rng.rules
endif
I don't know offhand if this works:
if INSTALL_UDEV_RULESdist_udevrules_DATA = 90-virtio-rng.rules
endif
but I think so; you can check with "./configure --without-udevrulesdir && make && make dist".
Thanks,
Paolo
Re: [PATCH 2/2] Install udev rules in system-default directory
Quoted 26 lines · Paolo Bonzini
Il 07/08/2014 15:09, Amit Shah ha scritto:
Quoted 1 line
+udevrules_DATA = 90-virtio-rng.rules
If rng-tools is packaged with "make dist" you need this to be
dist_udevrules_DATA= 90-virtio-rng.rulesor alternatively
EXTRA_DIST= 90-virtio-rng.rulesudevrules_DATA= 90-virtio-rng.rulesconfigure.ac AC_ARG_WITH([libgcrypt], · line 41
Quoted 5 lines
configure.ac +5
-0+AC_ARG_WITH([udevrulesdir], + AS_HELP_STRING([--with-udevrulesdir=DIR], [Directory for udev rules]), + [], + [with_udevrulesdir=$($PKG_CONFIG --variable=udevdir udev)"/rules.d"]) +AC_SUBST([udevrulesdir], [$with_udevrulesdir])You can use
AM_CONDITIONALto skip the installation if $with_udevrulesdir is "no" (aka --without-udevrulesdir). Then you'd have
EXTRA_DIST= 90-virtio-rng.rules
ifINSTALL_UDEV_RULESudevrules_DATA= 90-virtio-rng.rules
endif
Quoted 8 lines
I don't know offhand if this works:
if
INSTALL_UDEV_RULESdist_udevrules_DATA= 90-virtio-rng.rules
endifbut I think so; you can check with "./configure --without-udevrulesdir && make && make dist".
Thanks! Will give this a shot for curiosity's sake. The khwrngd-based patch has already been merged upstream, so this is now obsolete.
Amit