Skip to content

getrandom_msan flag masks bugs in underlying implementations #677

@briansmith

Description

@briansmith

In PR #521 and PR #571, the getrandom_msan configuration flag was added, which causes getrandom to mark the resulting buffer unpoisoned for Memory Sanitizer, if the underlying implementation returned Ok. This masks bugs in the underlying implementation in the situation where it returned Ok without actually writing the entire output into the buffer.

Instead, each backend should do the unpoisoning if/when required. Further, the implementation should do it immediately after calling the syscall (or whatever) that writes to the buffer, inside any loops, and not after the short-read processing loop exits.

For example, let's say we want to use memory sanitizer to verify that we properly handle the operating system doing a "short read" where it returns less data than we expected. Such validation will be thwarted by the current implementation.

In particular, in the case of a custom backend, the custom backend should do its own unpoisoning. Note that many custom implementations will implicitly unpoison the buffer as they write data into it, so usually they won't need to do anything.

To test this, register a custom implementation that unconditionally returns Ok without doing anything.

A side-benefit of this is that we will reduce the number of targets where we actually need the msan library to be linked to the minimum (maybe just Linux)?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions