Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 481254 - sys-apps/rng-tools - Init script cannot handle the presence of two hwrng nodes under /dev
Summary: sys-apps/rng-tools - Init script cannot handle the presence of two hwrng node...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Göktürk Yüksek
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 555100
  Show dependency tree
 
Reported: 2013-08-16 05:30 UTC by Martin Dummer
Modified: 2015-10-08 05:20 UTC (History)
5 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
/etc/init.d/rngd (file_481254.txt,267 bytes, patch)
2013-08-16 08:56 UTC, Tom Wijsman (TomWij) (RETIRED)
Details | Diff
Proposed fix for rngd init (rng-tools-rngd-initd-random-device-fix.patch,1004 bytes, patch)
2015-07-17 00:29 UTC, Göktürk Yüksek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Dummer 2013-08-16 05:30:49 UTC
When I try to start rngd on my computer the init script does not start saying

 * Starting rngd ...
rngd: Too many arguments
Try `rngd --help' or `rngd --usage' for more information.
 * start-stop-daemon: failed to start `/usr/sbin/rngd'
 * Failed to start rngd                           [ !! ]
 * ERROR: rngd failed to start


Reproducible: Always




The reason is that the find_device() function in the init script finds two devices on my computer. So there are two ways to fix the problem:
- edit /etc/conf.d/rngd adding a proper "DEVICE=/dev/blah" 

or fix the find_device() that it will quit searching when the first device from the list is found


--- /etc/init.d/rngd.orig       2013-08-16 00:31:58.910311131 +0200
+++ /etc/init.d/rngd    2013-08-16 00:34:37.547016321 +0200
@@ -11,12 +11,13 @@
 
 # Do NOT add /dev/tpm to this.
 DEFAULT_DEVICE="/dev/hw_random* /dev/hwrandom* /dev/i810_rng /dev/hwrng*"
+DEFAULT_DEVICE="/dev/lala /dev/lzlz /dev/hw_random* /dev/hwrandom* /dev/i810_rng /dev/hwrng*"
 
 find_device() {
        local d
        # The echo is to cause globbing
        for d in $(echo ${DEFAULT_DEVICE}) ; do
-               [ -e "${d}" ] && echo "${d}"
+               [ -e "${d}" ] && echo "${d}" && break
        done
 }
 



The second fix works well for me.
Comment 1 Martin Dummer 2013-08-16 05:33:39 UTC
The previous patch contains a line from my tests.... the correct patch is



--- /etc/init.d/rngd.orig       2013-08-16 00:31:58.910311131 +0200
+++ /etc/init.d/rngd    2013-08-16 07:32:18.411627177 +0200
@@ -16,7 +16,7 @@
        local d
        # The echo is to cause globbing
        for d in $(echo ${DEFAULT_DEVICE}) ; do
-               [ -e "${d}" ] && echo "${d}"
+               [ -e "${d}" ] && echo "${d}" && break
        done
 }
 


sorry for the confusion.
Comment 2 Tom Wijsman (TomWij) (RETIRED) gentoo-dev 2013-08-16 08:56:04 UTC
Created attachment 356180 [details, diff]
/etc/init.d/rngd

Please attach patches in the future, thank you.
Comment 3 Fedja Beader 2014-07-09 22:15:18 UTC
I've hit the same problem today with sys-apps/rng-tools-4-r5 on x86.

Notice below that --rng-device gets passed two parameters (both exist on my system).

Martin Dummer's  '&& break' fix works


 * Starting rngd ...
+ yesno ''
+ '[' -z '' ']'
+ return 1
+ yesno ''
+ '[' -z '' ']'
+ return 1
+ eval start-stop-daemon --start --exec /usr/sbin/rngd --pidfile /var/run/rngd.pid --wait 1000 -- --pid-file /var/run/rngd.pid --background --random-step 64 --fill-watermark 2048 --rng-device /dev/hw_random /dev/hwrng
++ start-stop-daemon --start --exec /usr/sbin/rngd --pidfile /var/run/rngd.pid --wait 1000 -- --pid-file /var/run/rngd.pid --background --random-step 64 --fill-watermark 2048 --rng-device /dev/hw_random /dev/hwrng
rngd: Too many arguments
Try `rngd --help' or `rngd --usage' for more information.
 * start-stop-daemon: failed to start `/usr/sbin/rngd'
+ eend 1 'Failed to start rngd'
 * Failed to start rngd                                                                                                                                                    [ !! ]
+ yesno ''
+ '[' -z '' ']'
+ return 1
+ return 1
+ exit 1
 * ERROR: rngd failed to start
Comment 4 Fedja Beader 2014-07-09 22:45:15 UTC
I am not sure if doing && break is appropriate, because
1) rngd may be able to use more devices at the same time (passing --rnd-device twice does not produce errors)


2) the first device found provides less entropy than the second
On my machine, they seem to be the same:
l /dev/hw*
crw-rw---- 1 root root 10, 183 Jul  8 12:56 /dev/hw_random
crw------- 1 root root 10, 183 Jul  8 12:56 /dev/hwrng

on others, there may be more sources, a simple -e file check will not do in the init script.


Someone needs to review the security implications of this "trivial" fix.
Comment 5 Göktürk Yüksek archtester gentoo-dev 2015-07-16 17:04:08 UTC
(In reply to Fedja Beader from comment #4)
> I am not sure if doing && break is appropriate, because
> 1) rngd may be able to use more devices at the same time (passing
> --rnd-device twice does not produce errors)
> 
> 
> 2) the first device found provides less entropy than the second
> On my machine, they seem to be the same:
> l /dev/hw*
> crw-rw---- 1 root root 10, 183 Jul  8 12:56 /dev/hw_random
> crw------- 1 root root 10, 183 Jul  8 12:56 /dev/hwrng
> 
> on others, there may be more sources, a simple -e file check will not do in
> the init script.
> 
> 
> Someone needs to review the security implications of this "trivial" fix.

I don't think you have two devices. If you look at the (major, minor), both devices have (10,183). They seem to be aliases to the same device.

Also, if you pass two --rnd-device to rngd, the second one will override the first.
Comment 6 Göktürk Yüksek archtester gentoo-dev 2015-07-16 21:50:02 UTC
hwrandom provides a unified interface for multiple RNGs and as such there can be only one hwrandom device node under /dev. It is possible to query available RNGs by reading '/sys/class/misc/hw_random/rng_available' and current RNG by reading '/sys/class/misc/hw_random/rng_current'.

The proposed patch should fix the issue. Perhaps a better way to check is to see if /dev/char/10:38 is available rather than trying a combination of strings.
Comment 7 Göktürk Yüksek archtester gentoo-dev 2015-07-17 00:29:41 UTC
Created attachment 406952 [details, diff]
Proposed fix for rngd init

The name change from "hw_random" to "hwrng" introduced by the commit d405640539555b601e52f7d18f1f0b1345d18bf5 roughly 6 years ago[1]. I am not sure why there are two device nodes for some people. Could it be that "hw_random" statically created with mknod some years ago and never deleted?

I propose the removal of find_device() function altogether. The kernel by default creates it under '/dev/hwrng' and people with custom setups can still utilize '/etc/conf.d/rngd' to specify the device.

[1] https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=d405640539555b601e52f7d18f1f0b1345d18bf5
Comment 8 Ian Delaney (RETIRED) gentoo-dev 2015-07-17 08:57:14 UTC
To err on the side of caution I have made a files/rngd-initd-r1-4.1 and added it and edited the ebuild accordingly. Setting to TEST-REQUEST to allow for any fine tuning.

grief this was made for rng-tools-4-r6 which has been purged and -r7 made stable.
For now just revbumping rng-tools-5.ebuild.

*rng-tools-5-r1 (17 Jul 2015)

  17 Jul 2015; Ian Delaney <idella4@gentoo.org> +files/rngd-initd-r1-4.1,
  +rng-tools-5-r1.ebuild, metadata.xml:
  rebump; fix to init script, patch by new proxy maintainer via Bug #481254,
  metadata.xml updated accordingly

Members of base-system <herd>base-system</herd> are welcome to comment here.
Suggested plan; Confirmation of new patch, advice re revbumping rng-tools-4-r7, make the revbumped rng-tools-5 stable and purge old versions and broken init script.
Comment 9 Ian Delaney (RETIRED) gentoo-dev 2015-07-17 09:00:49 UTC
Oops needed to CC base-system
Comment 10 Göktürk Yüksek archtester gentoo-dev 2015-07-18 03:51:39 UTC
Changing the title as this bug applies to both rng-tools-4 and rng-tools-5 per shared init script.
Comment 11 Göktürk Yüksek archtester gentoo-dev 2015-09-19 02:02:06 UTC
I did a fresh amd64 install this week and I also see two device nodes, namely "hw_random" and "hwrng". I did another gentoo install few weeks ago and that one doesn't suffer from this. I think it's important to pinpoint why this is happening. Not sure if it's related but the one with two nodes uses gentoo-sources whereas the other uses vanilla-sources.
Comment 12 Göktürk Yüksek archtester gentoo-dev 2015-09-22 07:43:23 UTC
The culprit is mdev, which is included in initramfs by genkernel. When mdev is invoked to populate /dev (mdev -s), it scans /sys/class, finds the entry '/sys/class/misc/hw_random/dev' and creates /dev/hw_random. However, the kernel uses 'hw_random' for /sys entries and 'hwrng' for the dev node. When combined with the kernel option 'CONFIG_DEVTMPFS', this results in having two nodes under /dev (namely 'hw_random' and 'hwrng) that point to the same device.
Comment 13 Göktürk Yüksek archtester gentoo-dev 2015-09-22 08:26:02 UTC
Genkernel has been notified with bug 561102.

mdev users who don't enable CONFIG_DEVTMPFS in their kernel will always end up with '/dev/hw_random' as opposed to '/dev/hwrng'. However, per gentoo wiki [1], enabling CONFIG_DEVTMPFS_MOUNT is part of the setup. The proposed fix still applies.

[1] https://wiki.gentoo.org/wiki/Mdev
Comment 14 Göktürk Yüksek archtester gentoo-dev 2015-10-01 08:31:25 UTC
Pull request submitted: https://github.com/gentoo/gentoo/pull/95