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

Implement VirtIO RNG device #70

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

shengwen-tw
Copy link
Collaborator

@shengwen-tw shengwen-tw commented Jan 26, 2025

Overview

This commit introduces the VirtIO entropy device, also known as virtio-rng in QEMU and the Linux kernel.

Randomness is a precious resource in the system. Without sufficient entropy, functions like arc4random_buf() in the standard C library may not work properly since they rely on the blocking device /dev/random.

Closed #68.

Prerequisites

  1. Enable CONFIG_OD in BusyBox
$ cd buildroot/output/build/busybox-1.36.1/
$ make menuconfig
  1. Rebuild buildroot
$ cd buildroot/
$ make busybox-rebuild
$ make -j$(nproc)
  1. Replace rootfs.cpio
$ cd semu
$ cp -f buildroot/output/images/rootfs.cpio ./

Test procedures

  1. Launch semu:
cd semu/
make check
  1. Read /dev/random with od command
Welcome to Buildroot
buildroot login: root
# od /dev/random
0000000 126370 025274 055514 014745 051051 073714 156246 140301
0000020 157561 167176 122602 015767 107243 120045 136313 176061
0000040 115122 170566 107766 011777 057377 105023 152157 147260
0000060 130220 064322 160762 057245 153463 141757 046574 122202
0000100 174113 136630 120230 143307 073562 077302 017507 073016
0000120 062537 012454 100047 114555 140204 040440 172507 075066
0000140 040442 073115 161077 100450 037510 166327 163375 133510
0000160 176100 103667 010651 077154 077252 122605 046415 067073
0000200 042206 016216 101214 106563 161454 053741 016273 031322
0000220 166247 017356 066413 041563 124027 031751 054160 122432
...

Without virtio-rng, the od command will just hang due to the aforementioned issue.

This commit introduces the VirtIO entropy device, also known as virtio-rng in
QEMU or the Linux kernel.

Randomness is a precious resource in the system. Without sufficient entropy,
functions like arc4random_buf() in the standard C library may not work properly
since they rely on the blocking device /dev/random.

Closed sysprog21#68.
@ChinYikMing
Copy link
Collaborator

Can you upload the newly built rootfs.cpio here for quick testing? Thanks!

@shengwen-tw
Copy link
Collaborator Author

Can you upload the newly built rootfs.cpio here for quick testing? Thanks!

You could try this: rootfs.cpio.zip

Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Improve the descriptions in git commit messages by quoting the man page for entropy. Also, always use Close #68 instead of Closed #68 to emphasize the intention.

@ChinYikMing
Copy link
Collaborator

I try on machine x86-64, compiled with gcc 12.3.0.

Procedure:

  1. $ make check
  2. login with root
  3. # od /dev/random

Result:

...

[    3.884043] Run /init as init process
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
Starting network: OK

Welcome to Buildroot
buildroot login: root 
# od /dev/random



Nothing is output (blocked), is it normal? I think the /dev/random should not be blocked?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VirtIO RNG and unexpected behavior of arc4random_buf() standard function of C
3 participants