Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xen: avoid UB in guest handle field accessors
Much like noted in 43d5c5d ("xen: avoid UB in guest handle arithmetic"), address calculations involved in accessing a struct field can overflow, too. Cast respective pointers to "unsigned long" and convert type checking accordingly. Remaining arithmetic is, despite there possibly being mathematical overflow, okay as per the C99 spec: "A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting type." The overflow that we need to guard against is checked for in array_access_ok(). While there add the missing (see {,__}copy_to_guest_offset()) is-not- const checks to {,__}copy_field_to_guest(). Typically, but not always, no change to generated code; code generation (register allocation) is different for at least common/grant_table.c. Signed-off-by: Jan Beulich <[email protected]> Acked-by: Andrew Cooper <[email protected]> Release-Acked-by: Oleksii Kurochko <[email protected]>
- Loading branch information