@samitouri / QOSamiQemu / commits / 029f10e852

linux-user: fix off-by-one in host_to_target_for_each_rtattr()

host_to_target_for_each_rtattr() uses "len > sizeof(struct rtattr)" as its loop condition. When the last rtattr in a netlink message has exactly sizeof(struct rtattr) (4) bytes remaining, the loop exits without byte-swapping its rta_len and rta_type. A big-endian guest then reads rta_len in the wrong byte order and fails validation. The companion function target_to_host_for_each_rtattr() correctly uses ">=" (added in commit fa2229dbf8). The kernel's RTA_OK macro also uses ">=". Fix the host_to_target direction to match. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2485 Signed-off-by: Yixin Wei <yixinwei@meta.com> Fixes: 6c5b5645ae0 ("linux-user: add rtnetlink(7) support") Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Helge Deller <deller@gmx.de> Cc: qemu-stable@nongnu.org

Yixin Wei committed Apr 9, 2026 at 17:49 UTC 029f10e852780da846d3e7f1691c495474683b73
1 file changed +1 -1
linux-user/fd-trans.c
+1 -1
@@ -480,7 +480,7 @@ static abi_long host_to_target_for_each_rtattr(struct rtattr *rtattr,
480 unsigned short aligned_rta_len;
481 abi_long ret;
482
483 - while (len > sizeof(struct rtattr)) {
483 + while (len >= sizeof(struct rtattr)) {
484 rta_len = rtattr->rta_len;
485 if (rta_len < sizeof(struct rtattr) ||
486 rta_len > len) {