Page MenuHomeFreeBSD

Use osreldate to check the existence of getrandom(2).
ClosedPublic

Authored by delphij on Aug 20 2018, 12:44 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Dec 10, 7:57 PM
Unknown Object (File)
Nov 14 2024, 4:56 PM
Unknown Object (File)
Nov 14 2024, 4:40 PM
Unknown Object (File)
Nov 14 2024, 11:41 AM
Unknown Object (File)
Nov 5 2024, 2:17 AM
Unknown Object (File)
Oct 30 2024, 12:29 AM
Unknown Object (File)
Oct 3 2024, 12:05 AM
Unknown Object (File)
Oct 1 2024, 6:17 PM
Subscribers

Details

Summary

In r331279 the code used ENOSYS to check the existence of getrandom(2).
This will only work if the caller already handles SIGSYS, which is not
always the case.

Address this by checking osreldate instead. Note that because there
was not __FreeBSD_version bump when the system call was added, use
1200061 (r332100) which is the first bump after the introduction of
the system call.

PR: 230762

Test Plan

Run the code against a kernel older than r331279.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Good find, thank you. Fix looks good to me.

lib/libc/gen/getentropy.c
113 ↗(On Diff #46949)

We have lost our ENOSYS handling for programs that mask SIGSYS and are in the small range of revisions between introduction of the syscall and GETRANDOM_FIRST, but I think that is probably ok.

135–136 ↗(On Diff #46949)

I'd suggest reordering this as if (!have_getrandom) return (...fallback()); to avoid the extra indentation in the normal case.

This revision is now accepted and ready to land.Aug 20 2018, 1:03 AM
delphij added inline comments.
lib/libc/gen/getentropy.c
113 ↗(On Diff #46949)

Yeah, the only way to do it would be to create a SIGSYS handler for >= 1200060 and < 1200061, but since it's -CURRENT it's probably not worth the effort.

135–136 ↗(On Diff #46949)

I think it's against style(9). Let's revisit this at a later time.

delphij marked an inline comment as done.

Update comment, no functional change.

This revision now requires review to proceed.Aug 20 2018, 2:02 AM

Oops, omit change in stdlib.h.

This revision was not accepted when it landed; it landed in state Needs Review.Aug 20 2018, 2:18 AM
This revision was automatically updated to reflect the committed changes.
lib/libc/gen/getentropy.c
135–136 ↗(On Diff #46949)

Why do you think it's against style(9)? I don't believe it is. Thanks.