-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Slices that cover the last byte of the address space are invalid #83996
Copy link
Copy link
Open
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-iteratorsArea: IteratorsArea: IteratorsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-iteratorsArea: IteratorsArea: IteratorsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The current implementation uses
pointer::addto compute the end pointer for the bounds check:rust/library/core/src/slice/iter.rs
Lines 88 to 102 in 69e1d22
The method requires that the calculation will not overflow a
usize, however that is not always the case. For instance, an allocator might return the last available page (0xfffff000on x86) and correctly return a slice ofu8(with size 4096 on x86). If a program now iterates over the slice, the end pointer will overflow, wrapping around the address space and thus creating UB.This behaviour is extremely unlikely and only occurs with
no_stdas most kernels reserve the higher half of the address space anyway.Solutions