libfdt: Fix undefined behaviour in fdt_offset_ptr()
authorDavid Gibson <david@gibson.dropbear.id.au>
Tue, 17 Mar 2020 15:18:57 +0000 (16:18 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 17 Mar 2020 15:18:57 +0000 (16:18 +0100)
commit66fb1406568c7e582dbd5ffd8f3b8a8350146960
tree632505c4e4d2fb4a926f6e33d0ad6bdb928d4df0
parent75c5fc0c7cefe50b6052c0b933186c4597ade70f
libfdt: Fix undefined behaviour in fdt_offset_ptr()

Using pointer arithmetic to generate a pointer outside a known object is,
technically, undefined behaviour in C.  Unfortunately, we were using that
in fdt_offset_ptr() to detect overflows.

To fix this we need to do our bounds / overflow checking on the offsets
before constructing pointers from them.

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
[upstream commit d0b3ab0a0f46ac929b4713da46f7fdcd893dd3bd]
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
xen/common/libfdt/fdt.c