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)
Mar 4 2024, 4:24 AM
Unknown Object (File)
Dec 31 2023, 2:38 PM
Unknown Object (File)
Dec 22 2023, 10:24 PM
Unknown Object (File)
Dec 2 2023, 5:58 AM
Unknown Object (File)
Nov 25 2023, 8:30 PM
Unknown Object (File)
Nov 22 2023, 10:30 PM
Unknown Object (File)
Nov 22 2023, 6:34 PM
Unknown Object (File)
Nov 13 2023, 2:21 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.