Fix msan false positive swl swr uninit read#2033
Draft
EngineersBox wants to merge 65 commits into
Draft
Conversation
… msan check for sub-32 bit init Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
…o constant compile-time optimised args Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
…wing for sub-32-bit MSAN triggers Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
…mediate value instead of mask from LUT Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
…s and inline duplications per-compilation unit Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
… calls Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
…ure consistent setup with event bus Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
…ure consistent setup with event bus Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
Signed-off-by: EngineersBox <35655145+EngineersBox@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Addresses #1928 by fix MSAN false positives on
swl/swruninitialised read for non-32-bit read before write. Also fixeslsl/lsrnot validating for sub-32-bit writes fromswl/swrinitialisation.Masking
This adds masking variants of
read32/write32to allow for sub-32-bit masks. For the store instructions we have the following byte layouts (ri= register byte indexed byifrom LSB,mi= same but for memory), with the matching byte mask for which bytes are modifying memory, the unset mask values are the bytes that were read from memory. The mask is used with the MSAN write check to mark which bytes have been initialised, and which have not.swl:Imm0m3m2m1r300011m3m2r3r200112m3r3r2r101113r3r2r1r01111Mask expression:
0b1111 >> (3 - Imm)swr:Imm0r3r2r1r011111r2r1r0m011102r1r0m1m011003r0m2m1m01000Mask expression:
(0b1111 << Imm) & 0b1111In the case of the load instructions, the byte mask is the same except that it is used with the read check instead. The mask indicates which bytes are being read from memory and need to validate usability and initialisation.
lwl:Imm0m0r2r1r000011m1m0r1r000112m2m1m0r001113m3m2m1m01111Mask expression:
0b1111 >> (3 - Imm)lwr:Imm0m3m2m1m011111r3m3m2m111102r3r2m3m211003r3r2r1m31000Mask expression:
(0b1111 << Imm) & 0b1111MSAN Read Check
In the current MSAN check, we check whether the bytes being access in the read have been allocated and initialised via a bit mask. This is computed as follows:
To make this generic, we apply an additional mask to the
bitmaskvalue, provided as an argument.By default his additional mask is
UINT32_MAXwhich leaves it unchanged. For theswr/swl/lwr/lwlinstructions, this will be their respective read mask calculated for the instruction immediate value. Hence, this becomes:MSAN Write Check
Similar to the read check, the write check validates the bytes being accessed have been allocated and then updates the initialisation bitmap. The same logic applies here for modifying the bitmask to apply the write mask calculated using the isntruction immediate, the default mask is also
UINT32_MAXhere as well.MSAN Partial Initialisation Status
Since the
swl/swrinstructions allow for partial initialisation of a 32-bit memory entry (i.e. 1-3 bytes only initialised), we should disambiguate this from a fully uninitialised read. Doing so will help users debug the write sizes that are candidates for the source of partial initialisation, or determine the read is too wide for the desired memory location.This done by checking the initialised bitmask of the memory area being accessed and comparing it to a zero-value. If all bits are unset, then it is a fully uninitialised read, otherwise it is a partially initialised read. This relies on a prior assumption that we've already checked for a fully initialised read (i.e. all bits set).
Note
The MSAN viewer ImGUI widget already supports per-byte calculations for initialisation and usability.
Thus we don't need to support any additional infrastructure for those calculations with these MSAN changes.
TODO