mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
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 commitfa2229dbf8). 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:6c5b5645ae("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
This commit is contained in:
@@ -480,7 +480,7 @@ static abi_long host_to_target_for_each_rtattr(struct rtattr *rtattr,
|
|||||||
unsigned short aligned_rta_len;
|
unsigned short aligned_rta_len;
|
||||||
abi_long ret;
|
abi_long ret;
|
||||||
|
|
||||||
while (len > sizeof(struct rtattr)) {
|
while (len >= sizeof(struct rtattr)) {
|
||||||
rta_len = rtattr->rta_len;
|
rta_len = rtattr->rta_len;
|
||||||
if (rta_len < sizeof(struct rtattr) ||
|
if (rta_len < sizeof(struct rtattr) ||
|
||||||
rta_len > len) {
|
rta_len > len) {
|
||||||
|
|||||||
Reference in New Issue
Block a user