Page MenuHomeFreeBSD

netpfil/ipfw: use arc4random() instead of random()
AbandonedPublic

Authored by pfg on Dec 25 2019, 7:06 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 17, 5:59 AM
Unknown Object (File)
Dec 25 2023, 7:34 PM
Unknown Object (File)
Dec 20 2023, 6:05 AM
Unknown Object (File)
Nov 2 2023, 6:18 AM
Unknown Object (File)
Sep 6 2023, 10:52 AM
Unknown Object (File)
Jun 14 2023, 11:31 AM
Unknown Object (File)
Jan 12 2023, 5:44 AM
Unknown Object (File)
Dec 21 2022, 8:42 PM
Subscribers

Details

Reviewers
cem
melifaro
ae
Group Reviewers
network
Summary

This makes better use of the unsigned values improving the randomness.
It should make little, if any, difference from a user view point though.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 28320
Build 26423: arc lint + arc unit

Event Timeline

sys/netpfil/ipfw/ip_dn_io.c
408–417

Forwarding my remarks from the earlier review: I don't believe unpredictability matters here.

I also don't believe there is any significant benefit outside of unpredictability for this use. (Although, yikes, random(9) is actually rand(3), not random(3). Perhaps we should replace random(9) with a better PRNG.)

I may be mistaken on either or both counts.

514–515

This is now half as likely to happen, due to the differing ranges of the random(9) and arc4random(9) functions. I believe that violates the intent of the code.

sys/netpfil/ipfw/ip_dn_io.c
408–417

I'll add: if we do actually want arc4random-quality entropy, and only need 16 bits, we can waste a few less cycles by using fewer bytes: arc4random_buf(&q->random, 2) (paired with apropriate resizing of dn_queue::random from int to uint16_t).

This is basically insignificant with today's arc4random(9) but would be more significant if this was a significant consumer of arc4random(9) and we adopted the buffered approach arc4random(3) uses today.

Add some developers that are more likely to know the code better.

I am abandoning this line of changes: it doesnt bring any advantage.