Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove haveged to save space and resources #6781

Merged
merged 7 commits into from
Jun 27, 2024

Conversation

alexl83
Copy link
Contributor

@alexl83 alexl83 commented Jun 22, 2024

Starting from Linux kernel v5.4, the HAVEGED inspired algorithm has been included in the Linux kernel, see the LKML article and the Linux Kernel commit.
Additionally, since v5.6, as soon as the CRNG (the Linux cryptographic-strength random number generator) gets ready, /dev/random does not block on reads anymore: see this commit.

SOURCE: jirka-h/haveged

How Has This Been Tested?

  • Succesfully built nanopi-r5c BRANCH="current" RELEASE="jammy, bookworm, noble, trixie"

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings

alexl83 and others added 2 commits June 22, 2024 15:36
Starting from Linux kernel v5.4, the HAVEGED inspired algorithm has been included in the Linux kernel, see the [LKML article](https://lore.kernel.org/lkml/alpine.DEB.2.21.1909290010500.2636@nanos.tec.linutronix.de/T/) and the Linux Kernel [commit](torvalds/linux@50ee752).
Additionally, since v5.6, as soon as the CRNG (the Linux cryptographic-strength random number generator) gets ready, /dev/random does not block on reads anymore: see this [commit](torvalds/linux@30c08ef).

SOURCE: [jirka-h/haveged](https://github.com/jirka-h/haveged/blob/master/README.md)
@github-actions github-actions bot added size/small PR with less then 50 lines Hardware Hardware related like kernel, U-Boot, ... Framework Framework components labels Jun 22, 2024
@alexl83 alexl83 changed the title Remove haveged to save space and rsources Remove haveged to save space and resources Jun 22, 2024
Copy link
Member

@rpardini rpardini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not convinced -- prove me wrong

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 22, 2024

not convinced -- prove me wrong

Hi! I'm not sure I understand specifically what I should prove wrong, but I can break down some facts:

To sum it up:

  • it adds no performance advantage
  • it takes space
  • Some distros already removed from default installation/startup (also whistleblowing-supporting ones)
  • Linux mainline integrated HAVEGE algorithm since version 5.4 (many releases ago)
  • removing it doesn't break linux from working while saving space
  • users can install it manually should they see fit
  • Author himself discourages usage as daemon
  • Debian is discussing about removing the package from their repo after bookworm

To be honest the initial material listed offered a decent overview, nevertheless I'm not expecting or demanding removal: just proposing it - no offence taken should you decide otherwise :)

Grazie 🙏🏻
Ale

@alexl83 alexl83 requested a review from rpardini June 22, 2024 16:02
@rpardini
Copy link
Member

Excellent. I'm 99% convinced, except: does it all apply to armhf/arm64/riscv64? A cursory look revealed x86 arch stuff so I'm reticent. I've been bit by lack of entropy and random, really hard to diagnose hangs too many times so excuse my trauma showing.

But I've my reasons: see the "default scheduler" fiasco/success from a few weeks ago.

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 22, 2024

Excellent. I'm 99% convinced, except: does it all apply to armhf/arm64/riscv64? A cursory look revealed x86 arch stuff so I'm reticent. I've been bit by lack of entropy and random, really hard to diagnose hangs too many times so excuse my trauma showing.

But I've my reasons: see the "default scheduler" fiasco/success from a few weeks ago.

Now I understand the root doubt, thanks: there are some similar doubts on the lkl thread along with some testing code and some benchmark runs to prove robustness.

Now, if logic serves me well (and I don't take it for granted as probabilistic/deterministic stuff is complex), if HAVEGE algorithm isn't fit for armhf/arm64/riscv64, it shouldn't matter if it's running off a library/daemon or from kernel

@ColorfulRhino
Copy link
Collaborator

ColorfulRhino commented Jun 24, 2024

The linked readme states:

It means that HAVEGED service is now less relevant. However, it's still useful in the following situations, when you

  • need randomness early in the boot process, before the CRNG in the Linux kernel gets fully initialized.

I believe U-Boot can do this for us. Need to have a look at what e.g. kaslrseed actually provides.

  • want to deploy an additional entropy source. HAVEGED now inserts entropy into the kernel every 60 seconds, regardless of the entropy level reported by Linux Kernel. It does not affect the /dev/random read speed but it diversifies the entropy sources, making the Linux Kernel CRNG more robust.
  • you are looking for userspace RNG to generate random numbers. See man -S8 haveged for examples or try running haveged -n 0 | pv > /dev/null

Users can install their fav tool for RNG if needed

  • and last but not least, most Linux installations are still running on the older kernel versions.

Irrelevant today.

The project seems to not have been updated in a while. Looks to me as dropping this package is totally fine.

@rpardini
Copy link
Member

Did a few tests. All my systems run fine without haveged (and have been so for a few years, actually -- silly me)
Adding it does not increase available entropy or its quality at all.
Go ahead -- I'm fully convinced.

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 24, 2024

Did a few tests. All my systems run fine without haveged (and have been so for a few years, actually -- silly me) Adding it does not increase available entropy or its quality at all. Go ahead -- I'm fully convinced.

🙏🏻

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 24, 2024

I believe U-Boot can do this for us. Need to have a look at what e.g. kaslrseed actually provides.

Actually I'm interested too - tried to delve a bit it seems it needs some nodes in DTB - with a random seed coming from bootloader kaslr would kick in - whatever that is - possibly some randomization of kernel memory
Quite out of my league to fully grasp it

@ColorfulRhino
Copy link
Collaborator

I believe U-Boot can do this for us. Need to have a look at what e.g. kaslrseed actually provides.

Actually I'm interested too - tried to delve a bit it seems it needs some nodes in DTB - with a random seed coming from bootloader kaslr would kick in - whatever that is - possibly some randomization of kernel memory Quite out of my league to fully grasp it

Ah I didn't know that this needed a special device tree node. RK35** devices do have a hardware RNG generator, so maybe this could be used somehow in U-Boot?

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 24, 2024

@ColorfulRhino - it's implemented in some nanopi board - look at this pr #4352
Seems an u-boot command that should be enabled/compiled in

@ColorfulRhino
Copy link
Collaborator

@ColorfulRhino - it's implemented in some nanopi board - look at this pr #4352 Seems an u-boot command that should be enabled/compiled in

Yeah this is a requirement, U-Boot has to be compiled to have the kaslrseed command available AND the command needs to be called in the script.

The PR you linked actually is not the best implementation imo since on so many boards it currently does output an error message on boot like "error: kaslrseed not available" 😆

@igorpecovnik igorpecovnik added Ready to merge Reviewed, tested and ready for merge 08 Milestone: Third quarter release labels Jun 25, 2024
@ColorfulRhino
Copy link
Collaborator

ColorfulRhino commented Jun 26, 2024

What's your cat /proc/sys/kernel/random/entropy_avail by the way?

On NanoPi R6C it seems stuck on 256 which is really low (without this PR applied).

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 26, 2024

What's your cat /proc/sys/kernel/random/entropy_avail by the way?

On NanoPi R6C it seems stuck on 256 which is really low (without this PR applied).

nanopi-r5c

 18:13:11 up 18:26,  0 user,  load average: 1,09, 1,28, 1,33
256

smeels like hardcoded
No change with haveged daemon running - makes no sense

@ColorfulRhino
Copy link
Collaborator

smeels like hardcoded No change with haveged daemon running - makes no sense

Yeah this is unrelated to haveged, I just commented here because the topic seemed similar :)

In theory, the hardware based RNG generator should be active on RK35xx in the edge kernel. Maybe something is not correct here. Investigation needed, I will open an issue.

@alexl83
Copy link
Contributor Author

alexl83 commented Jun 27, 2024

smeels like hardcoded No change with haveged daemon running - makes no sense

Yeah this is unrelated to haveged, I just commented here because the topic seemed similar :)

In theory, the hardware based RNG generator should be active on RK35xx in the edge kernel. Maybe something is not correct here. Investigation needed, I will open an issue.

on my nanopi I'm running current 6.6 - kali patches aren't yet ported to post-6.8
Will test a vanilla kernel later today after work :)

@igorpecovnik igorpecovnik added Work in progress Unfinished / work in progress and removed Ready to merge Reviewed, tested and ready for merge labels Jun 27, 2024
@ColorfulRhino
Copy link
Collaborator

on my nanopi I'm running current 6.6 - kali patches aren't yet ported to post-6.8 Will test a vanilla kernel later today after work :)

It's probably the same on 6.10 :)

Maybe this behaviour is wanted, see #6806

Also, apologies, I did not want to hold up this PR. It's still ready to merge, the discussion has not much to do with haveged. We can move the discussion to #6806

@ColorfulRhino ColorfulRhino added Ready to merge Reviewed, tested and ready for merge and removed Work in progress Unfinished / work in progress labels Jun 27, 2024
@igorpecovnik igorpecovnik merged commit 7b42317 into armbian:main Jun 27, 2024
8 checks passed
@sfx2000
Copy link
Collaborator

sfx2000 commented Jun 28, 2024

smeels like hardcoded No change with haveged daemon running - makes no sense

Yeah this is unrelated to haveged, I just commented here because the topic seemed similar :)

In theory, the hardware based RNG generator should be active on RK35xx in the edge kernel. Maybe something is not correct here. Investigation needed, I will open an issue.

Not a big fan of HWRNG's as unlike SW, they cannot be audited...

The current RNG in the kernel is more that sufficient

@ColorfulRhino
Copy link
Collaborator

Not a big fan of HWRNG's as unlike SW, they cannot be audited...

True, but you can only do so much with software.

The current RNG in the kernel is more that sufficient

I'm not sure if HWRNG on Rockchip automatically replaces software RNG if enabled in the kernel config.

@sfx2000
Copy link
Collaborator

sfx2000 commented Jun 28, 2024

Not a big fan of HWRNG's as unlike SW, they cannot be audited...

True, but you can only do so much with software.

The current RNG in the kernel is more that sufficient

I'm not sure if HWRNG on Rockchip automatically replaces software RNG if enabled in the kernel config.

IIRC it just creates the device, e.g. /dev/hwrng

To actually use it, one has to also include the rng-tools package and configure rngd to use the hwrng device.

https://github.com/nhorman/rng-tools

Otherwise the kernel should always prefer the internal software based RNG

As I mentioned, things like HWRNG's and onboard crypto accelerators/offload are always a concern... how random are they, and how can one confidently test it? If it is even slightly less than random, it's a big security risk.

Anyways, the other benefit of just using the kernel's RNG is that it's just a lot less maintaining - and that's always a win.

Remember that haveged was there to address issues with /dev/random (it's blocking) and things like VM's that are slow to fill the pool - the RNG in 5.19 addresses the same concerns.

@alexl83 alexl83 deleted the remove_haveged branch June 29, 2024 22:02
@adrelanos
Copy link

Adding it does not increase available entropy or its quality at all.

Or did you test entropy quality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
08 Milestone: Third quarter release Framework Framework components Hardware Hardware related like kernel, U-Boot, ... Ready to merge Reviewed, tested and ready for merge size/small PR with less then 50 lines
Development

Successfully merging this pull request may close these issues.

6 participants