× NETGEAR will be terminating ReadyCLOUD service by July 1st, 2023. For more details click here.
Orbi WiFi 7 RBE973
Reply

Haveged on ReadyNas Ultra ?

Callesoroe
Aspirant

Haveged on ReadyNas Ultra ?

I am running LMS (squeezebox) on my readynas ultra. There is a problem with the Random mix. The problem is that it isn't very random.
The problem could be this that I have read about:

http://www.issihosts.com/haveged/

Is it possible to get Haveged to run on a ReadyNas. And if. How ?

If this really is a problem in the kernel software. Will this not be fixed ????
Message 1 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

Callesoroe wrote:
I am running LMS (squeezebox) on my readynas ultra. There is a problem with the Random mix. The problem is that it isn't very random.
The problem could be this that I have read about:
http://www.issihosts.com/haveged/

I thought that that was unlikely, and I was about to post a response saying so... But then I checked my Pro Pioneer's available entropy and discovered that it was REALLY low -- single digits or low double digits -- and I took those measurements while I was logged in and right after I'd performed some filesystem commands that should have produced a large increase in available entropy.

Maybe there's something on my system that is voraciously consuming entropy; I'll have to investigate further. But I guess it is possible that an additional entropy source like havege could be helpful.
Message 2 of 24
chirpa
Luminary

Re: Haveged on ReadyNas Ultra ?

Tested on an Ultra 4 running RAIDiator-x86 4.2.23:
# cat /proc/sys/kernel/random/entropy_avail                                        
221
# cat /proc/sys/kernel/random/entropy_avail
131
# wget http://http.us.debian.org/debian/pool/main/h/haveged/haveged_1.4-4_i386.deb
# dpkg -i haveged_1.4-4_i386.deb
Setting up haveged (1.4-4) ...
# cat /proc/sys/kernel/random/entropy_avail
3968
# cat /proc/sys/kernel/random/entropy_avail
3712
Message 3 of 24
chirpa
Luminary

Re: Haveged on ReadyNas Ultra ?

Tested on Ultra 4 running ReadyNAS OS 6.1.3:
# cat /proc/sys/kernel/random/entropy_avail 
203
# cat /proc/sys/kernel/random/entropy_avail
134
# wget http://http.us.debian.org/debian/pool/main/h/haveged/haveged_1.4-4_amd64.deb
# dpkg -i haveged_1.4-4_amd64.deb
Setting up haveged (1.4-4) ...
[ ok ] Starting haveged (via systemctl): haveged.service.
# cat /proc/sys/kernel/random/entropy_avail
2339
# cat /proc/sys/kernel/random/entropy_avail
2211
Message 4 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

chirpa wrote:

# cat /proc/sys/kernel/random/entropy_avail 
203
# cat /proc/sys/kernel/random/entropy_avail
134

On my Pro Pioneer running 4.2.24, after 7 hours of uptime, my first read was 3 and I never got a value above 120 bits even after lots of file-access-induced hardware randomness.

Chirpa, I notice that even with haveged running, each of your "cat" invocations seemed to consume around 100 bits of entropy. If you do something like "watch cat /proc/sys/kernel/random/entropy_avail" with haveged running, does the available entropy stay high (or refill when it gets below the read threshold), or does it fall all the way to single digits as it would without haveged?
Message 5 of 24
chirpa
Luminary

Re: Haveged on ReadyNas Ultra ?

When it drops below 1024 (default), it refills back up to 4000.
# cat /etc/default/haveged
# Configuration file for haveged
# Options to pass to haveged
# -w sets low entropy watermark (in bits)
DAEMON_ARGS="-w 1024"
# while true; do cat /proc/sys/kernel/random/entropy_avail; sleep 1; done
1408
1152
3840
3584
3328
3072
2816
2630
2374
2118
1862
1606
1248
1072
3968
3712
3456
^C
Message 6 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

chirpa wrote:
When it drops below 1024 (default), it refills back up to 4000.

Good. Thanks for checking, Chirpa.

Callesoroe: If you have SSH root access to your NAS, you can install the package as Chirpa did, with these commands:

wget http://http.us.debian.org/debian/pool/main/h/haveged/haveged_1.4-4_i386.deb
dpkg -i haveged_1.4-4_i386.deb
Message 7 of 24
Callesoroe
Aspirant

Re: Haveged on ReadyNas Ultra ?

THANK YOU GUYS 🙂
It is installed an running now. I made some random selections on my LMS, and it really seems to work. Again thank you 🙂
Message 8 of 24
Callesoroe
Aspirant

Re: Haveged on ReadyNas Ultra ?

nas-C1-71-AE:~# cat /proc/sys/kernel/random/entropy_avail
3466

🙂
Message 9 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

Callesoroe wrote:
nas-C1-71-AE:~# cat /proc/sys/kernel/random/entropy_avail
3466

Another test you can do is
cat /dev/random

/dev/random blocks while the entropy pool is low, so if haveged is not running you'll see random bytes being generated VERY slowly: a burst of 8 characters every few seconds, or even slower. With haveged running, random characters will be generated almost as fast as your terminal can display them.

Hit ctrl-c to stop the random-character display.
Message 10 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

Oh, and by the way... Going back to your original problem, it still seems odd that LMS should be affected by this issue.

I use MusicIP or Michael Herger's SmartMix plugins for my "random" mixes, so I haven't seen the problem you've described, but I would expect LMS to get its random numbers from /dev/urandom, which should be basically unaffected by the available entropy. The behavior you were seeing, though, seems to indicate that LMS is getting its random stream from /dev/random instead.

It might be worth posting a bug on the slimdevices (or logitech or whatever) bug tracker.
Message 11 of 24
RichieB1
Aspirant

Re: Haveged on ReadyNas Ultra ?

This is Slimdevices bug id 8310: http://bugs.slimdevices.com/show_bug.cgi?id=8310
With LMS 7.6.x I went trough the code and it used a default MySQL random feature, which (I'm sure) uses /dev/random or /dev/urandom. LMS 7.7.x and 7.8.x use SQLite, and I haven't checked how the random playlists are created.

Using /dev/urandom instead of /dev/random does not give you more randomness. If not enough random bits are available /dev/urandom will reuse the random bits to generate more pseudo random bits. This will likely cause repeats like the ones we were seeing with LMS. See http://en.wikipedia.org/wiki//dev/random

I have been running haveged on my QNAP TS-459 Pro+ for a week now, and it positively solves this issue.
Message 12 of 24
Callesoroe
Aspirant

Re: Haveged on ReadyNas Ultra ?

Another question.

When haveged is installed. Does it "survive" a new firmware upgrade, so that I won't have to install it again??
Message 13 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

RichieB wrote:
Using /dev/urandom instead of /dev/random does not give you more randomness.

Thank you, RichieB. I shouldn't post at 4:00 in the morning.

I think that what I wanted (and failed) to say was that I would expect LMS to seed its own (long period) PRNG from dev/random or dev/urandom just once, but that instead it looks as though it is using dev/urandom directly, or maybe re-seeding its PRNG repeatedly with the same value from /dev/random.

RichieB wrote:
With LMS 7.6.x I went trough the code and it used a default MySQL random feature, which (I'm sure) uses /dev/random or /dev/urandom. LMS 7.7.x and 7.8.x use SQLite, and I haven't checked how the random playlists are created.
....
I have been running haveged on my QNAP TS-459 Pro+ for a week now, and it positively solves this issue.

If 7.7 and 7.8 use sqlite's built-in random() function to select a random sequence of rows, I don't see how increasing the available entropy would fix the problem. As far as I know, the random() function returns the output of a PRNG based on RC4 which is seeded only once from /dev/urandom.

But I'm no expert on any of this. I guess the important thing is that it works, not why it works.
Message 14 of 24
RichieB1
Aspirant

Re: Haveged on ReadyNas Ultra ?

I took another look at the code (current 7.8 nightly). In Slim/Plugin/RandomPlay/Plugin.pm on line 571 this funtion is called:
Slim::Utils::OSDetect->getOS()->sqlHelperClass()->randomFunction()
In Slim/Utils/SQLiteHelper.pm on line 229 this funtion is defined as 'RANDOM()'.
So it indeed (still) uses the internal SQL random function. A quick look at the sqlite 3.8.1 source code indeed mentions a PRNG implementation in the comments. Very strange.
Message 15 of 24
RichieB1
Aspirant

Re: Haveged on ReadyNas Ultra ?

Ok, got it. winRandomness() in sqlite3.c is a PRNG, but unixRandomness() uses /dev/urandom every time. This makes sense to me.. why use your own PRNG when the OS provides one that potentially is a lot better.
Message 16 of 24
chirpa
Luminary

Re: Haveged on ReadyNas Ultra ?

fastfwd, nice job on the add-on; viewtopic.php?p=411166#p411166
Message 17 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

Thanks, Chirpa.

The addon, for OS4 x86 devices only, is available at https://www.dropbox.com/s/m3mob6firvpw24o/HAVEGED_1.7b-x86-1.0.bin. No warranty of fitness for any purpose, etc., etc., but it's installed on my Pro 6 and Ultra 2 Plus and it seems to be running fine.
Message 18 of 24
F_L_
Tutor

Re: Haveged on ReadyNas Ultra ?

Is this needed on OS6 6.1.5?

Running cat on entropy_avail I´m getting pretty high values compared to what I had on OS4 before.



# cat /proc/sys/kernel/random/entropy_avail
2005
# cat /proc/sys/kernel/random/entropy_avail
2560

Message 19 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

F.L. wrote:
Is this needed on OS6 6.1.5?

I don't have an OS6 box, so I can't tell. (And, of course, the addon I built for OS4 won't work on OS6 anyway; if you wanted to install haveged, you'd have to do so manually or by building an OS6 addon.)

F.L. wrote:
Running cat on entropy_avail I´m getting pretty high values compared to what I had on OS4 before.

# cat /proc/sys/kernel/random/entropy_avail
2005
# cat /proc/sys/kernel/random/entropy_avail
2560

Let this run for a minute or two and see whether the entropy_avail value stays up in that high range:
watch -n 1 cat /proc/sys/kernel/random/entropy_avail

or run this and see whether the stream of random hex values scrolls continuously up the screen:
hexdump /dev/random

If the number displayed by the first test falls to a low number and stays down in a low range, or if the stream in the second test pauses for a second or more after every line, your machine's entropy pool is easily depleted and might benefit from the installation of haveged.
Message 20 of 24
StephenB
Guru

Re: Haveged on ReadyNas Ultra ?

F.L. wrote:
Is this needed on OS6 6.1.5?
My RN102 reports values between 100-200 - similar to what fastfwd saw before he did the add-on.
Message 21 of 24
F_L_
Tutor

Re: Haveged on ReadyNas Ultra ?

StephenB wrote:
F.L. wrote:
Is this needed on OS6 6.1.5?
My RN102 reports values between 100-200 - similar to what fastfwd saw before he did the add-on.


Strange, now I have low values again.
And
watch -n 1 cat /proc/sys/kernel/random/entropy_avail
gives me low values too.
Wonder why I had high values before...

Anyway. I installed haveged using apt and now it seems OK again.
Message 22 of 24
fastfwd
Virtuoso

Re: Haveged on ReadyNas Ultra ?

F.L. wrote:
Strange, now I have low values again.
And
watch -n 1 cat /proc/sys/kernel/random/entropy_avail
gives me low values too.
Wonder why I had high values before...

If nothing is using dev/random or dev/urandom, the entropy pool gradually fills. Presumably, your system wasn't doing much that needed random numbers, so the pool filled to 2000+ bits.

Every time a new process is launched, the operating system reads from dev/urandom in order to randomize the process's address space layout (to protect from buffer overflow attacks), so when you repeatedly invoked cat once per second with that watch command, the available entropy decreased faster than it could be replenished.
Message 23 of 24
F_L_
Tutor

Re: Haveged on ReadyNas Ultra ?

fastfwd wrote:
F.L. wrote:
Strange, now I have low values again.
And
watch -n 1 cat /proc/sys/kernel/random/entropy_avail
gives me low values too.
Wonder why I had high values before...

If nothing is using dev/random or dev/urandom, the entropy pool gradually fills. Presumably, your system wasn't doing much that needed random numbers, so the pool filled to 2000+ bits.

Every time a new process is launched, the operating system reads from dev/urandom in order to randomize the process's address space layout (to protect from buffer overflow attacks), so when you repeatedly invoked cat once per second with that watch command, the available entropy decreased faster than it could be replenished.



Thank you fastfwd for the explanation!
Message 24 of 24
Top Contributors
Discussion stats
  • 23 replies
  • 3040 views
  • 0 kudos
  • 6 in conversation
Announcements