-
Notifications
You must be signed in to change notification settings - Fork 73
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
map_anon()
can unsoundly create overlarge slices in safe code
#48
Comments
I guess you're referring to:
An assertions would be too sporadic. I guess we should simply return an error and update the docs. |
I cannot find how |
@adamreichold Hi! Can you comment on this one? It fills like half of the bugs we had are 32-bit related. But disabling its support completely would be too much. |
Following the call chain,
Even if it fails to get the file size, it |
Nice find! I guess I will borrow this function. |
I think it is a straight-forward error on our side. We do have the necessary check for file-based mappings in |
I think our check in |
On
i686-unknown-linux-gnu
,mmap()
withMAP_ANONYMOUS
is able to serve requests of 0x80000000 or more bytes.MmapMut::map_anon()
and<MmapMut as Deref>::deref()
can create a slice of this length in safe code:However,
<MmapMut as Deref>::deref()
usesstd::slice::from_raw_parts()
, which has this safety precondition:Since
isize::MAX == 0x7fffffff
oni686-unknown-linux-gnu
and other 32-bit targets, it is undefined behavior to create this 0x80000000-byte slice usingstd::slice::from_raw_parts()
. Compiler optimizations can behave erratically if this precondition is violated.The most straightforward solution would be to add assertions to
MmapOptions::map()
,MmapOptions::map_exec()
,MmapOptions::map_mut()
,MmapOptions::map_copy()
, andMmapOptions::map_copy_read_only()
, andMmapOptions::map_anon()
that the provided or computed length is no greater thanisize::MAX
.MmapOptions::map_raw()
does not need this assertion, sinceMmapRaw
does not provide slices in safe code. (It may also be worthwhile to add a method that produces an anonymousMmapRaw
not checked againstisize::MAX
.)The text was updated successfully, but these errors were encountered: