acrn-kernel/drivers/infiniband
Kees Cook 4e11ac106f RDMA/cma: Distinguish between sockaddr_in and sockaddr_in6 by size
[ Upstream commit 876e480da2 ]

Clang can do some aggressive inlining, which provides it with greater
visibility into the sizes of various objects that are passed into
helpers. Specifically, compare_netdev_and_ip() can see through the type
given to the "sa" argument, which means it can generate code for "struct
sockaddr_in" that would have been passed to ipv6_addr_cmp() (that expects
to operate on the larger "struct sockaddr_in6"), which would result in a
compile-time buffer overflow condition detected by memcmp(). Logically,
this state isn't reachable due to the sa_family assignment two callers
above and the check in compare_netdev_and_ip(). Instead, provide a
compile-time check on sizes so the size-mismatched code will be elided
when inlining. Avoids the following warning from Clang:

../include/linux/fortify-string.h:652:4: error: call to '__read_overflow' declared with 'error' attribute: detected read beyond size of object (1st parameter)
                        __read_overflow();
                        ^
note: In function 'cma_netevent_callback'
note:   which inlined function 'node_from_ndev_ip'
1 error generated.

When the underlying object size is not known (e.g. with GCC and older
Clang), the result of __builtin_object_size() is SIZE_MAX, which will also
compile away, leaving the code as it was originally.

Link: https://lore.kernel.org/r/20230208232549.never.139-kees@kernel.org
Link: https://github.com/ClangBuiltLinux/linux/issues/1687
Signed-off-by: Kees Cook <keescook@chromium.org>
Tested-by: Nathan Chancellor <nathan@kernel.org> # build
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-11 13:55:40 +01:00
..
core RDMA/cma: Distinguish between sockaddr_in and sockaddr_in6 by size 2023-03-11 13:55:40 +01:00
hw IB/hfi1: Update RMT size calculation 2023-03-11 13:55:32 +01:00
sw RDMA/siw: Fix user page pinning accounting 2023-03-10 09:34:11 +01:00
ulp IB/IPoIB: Fix legacy IPoIB due to wrong number of queues 2023-02-14 19:11:43 +01:00
Kconfig
Makefile