Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try_access: use checked_add instead of overflowing_add #273

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Nov 28, 2023

  1. try_access: use checked_add instead of overflowing_add

    We were allowing overflows if the overflow value would've been 0.
    This can be problematic if there is a memory region that starts
    at GuestAddress(0x0), but the access was not intended to spill
    into that region. We don't consider memory to be a circular ring
    buffer which would be the only situation in which we should allow
    overflowing accesses.
    
    While at it, also refactor the checked_add for the toal number of
    bytes to use `ok_or` instead of a match pattern, as this is
    easier to read.
    
    Writing a regression test for the overflowing add is not possible
    with the current infrastructure because GuestMemoryMmap does not
    allow creating memory regions with an access that would overflow
    (i.e. having a memory region starting at u64::MAX of size 1).
    Also, we cannot call try_access with a size bigger than the
    memory region size because we only allow accesses that fit in
    the memory region.
    
    Signed-off-by: Andreea Florescu <[email protected]>
    andreeaflorescu committed Nov 28, 2023
    Configuration menu
    Copy the full SHA
    6319451 View commit details
    Browse the repository at this point in the history