From nobody Mon May 13 05:32:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610723497; cv=none; d=zohomail.com; s=zohoarc; b=LJXAm+w55WXjvXxENylmYc7V06REa87ZODKzmuOFl2nu30SOaD+03booayGBeiL2fQP/kTpzxsFLxZWIcKzKfhmCNwVQJufGZctizpL9SYrSAurF7EZjpxrAkaSl3yViuNy63ftKq6l8Q4Dl0rTM/3G1Th+figAUgDbluQBtlFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610723497; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=3PM3c1hDQViy2jaBMDNzLZyG4cMXsFVA914IRG0X4aE=; b=KmunRqITY+a7LHK06+7ECQ+G6c5Pan5aQGIcf3mmhv9pCXJjrKsSPNu/olJCXB6r5jwWSpyvvTzgVaj7bBxwSKQX3bXIU1Ao2EI3vZDLnr1VTxVg4kwBQebdQT4KBzA4GHLswFV8Ji0vfKT0pFOqYcrKvtYU6IMx1dD2luVrd7Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1610723497991522.2686370523707; Fri, 15 Jan 2021 07:11:37 -0800 (PST) Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-267-7daGl4ZfPmCscXGwDosy2w-1; Fri, 15 Jan 2021 10:11:35 -0500 Received: by mail-ed1-f72.google.com with SMTP id dh21so3963806edb.6 for ; Fri, 15 Jan 2021 07:11:35 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (13.red-83-57-169.dynamicip.rima-tde.net. [83.57.169.13]) by smtp.gmail.com with ESMTPSA id n2sm3687044ejj.24.2021.01.15.07.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 07:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610723496; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3PM3c1hDQViy2jaBMDNzLZyG4cMXsFVA914IRG0X4aE=; b=OBCS/lk7TAF/OLl4dbnOejxFCUtmwxabmijcnVhZUZa0G+iCYhnRFYncRfhWQhsZX4h3jo 7+xf8wNvqRwhQhZkshrh27mq0cbqLMIV2lVM/kWRJpAVVg9ov7+BMQw+WN/aInYLqLM5rT y/nRhXH11qYLZBP+92jU/eEq1hYy8JA= X-MC-Unique: 7daGl4ZfPmCscXGwDosy2w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3PM3c1hDQViy2jaBMDNzLZyG4cMXsFVA914IRG0X4aE=; b=CyGCth2kWuS9M5V/gb1l0kGq9blkCsp++hZBl38yKg6mKjv7xqYir0TGeqgclHWCWF 6IJ1WmgSSzDFLoQ/Ai84yr5Xh/Gf1Z+iDBs3wtG4vU3l39fIPGyZGcLNAOo6jwjHsZ53 w9oveeAqUfn7a0h6MIEEVsccuZFiotakx/zGbXHDE7gYozDwgEM82LT8s8u7xIzHO3Tr AFha6UREQAN1JobVwtsEwIVImOxoexY/6zE+6bDr6zErk3yb3oQurszcRIFPqQ0943GT MMEgtw6U5T9Y1YFCfEEBn4v1adScZG3Mk9QJYHbNjWSn+lkKc1N3PQ+mlyqQiCGn3Dbm rEkA== X-Gm-Message-State: AOAM531J+r8ft2a/XyH1F0DF6nS5x3stc+IKjWi5Aex7TpyeQEORc9uw Rmb9u7VK3GmATUSikkraQPIeg4KgEk6PzKr3VtWpEZ48pAK3UTWKOZ9TbIsHgdVVPE+piPkb73o 0oy7d7lJGkwwnPw== X-Received: by 2002:aa7:cf8f:: with SMTP id z15mr9983946edx.17.1610723494087; Fri, 15 Jan 2021 07:11:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGG5WFa98szbRYtdHYJooNykcw+TMtNUae42zrxemdVkW7aD5lVRkUJlBfEauO5r9KCeQzog== X-Received: by 2002:aa7:cf8f:: with SMTP id z15mr9983927edx.17.1610723493947; Fri, 15 Jan 2021 07:11:33 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Prasad J Pandit , Miroslav Rezanina , Laurent Vivier , Paolo Bonzini , Thomas Huth , Dmitry Fleytman , Alexander Bulekov , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 1/2] net/eth: Simplify _eth_get_rss_ex_dst_addr() Date: Fri, 15 Jan 2021 16:11:25 +0100 Message-Id: <20210115151126.3334333-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115151126.3334333-1-philmd@redhat.com> References: <20210115151126.3334333-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) The length field is already contained in the ip6_ext_hdr structure. Check it direcly in eth_parse_ipv6_hdr() before calling _eth_get_rss_ex_dst_addr(), which gets a bit simplified. Reviewed-by: Miroslav Rezanina Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- net/eth.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/net/eth.c b/net/eth.c index 1e0821c5f81..7d4dd48c1ff 100644 --- a/net/eth.c +++ b/net/eth.c @@ -407,9 +407,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int p= kt_frags, { struct ip6_ext_hdr_routing *rthdr =3D (struct ip6_ext_hdr_routing *) e= xt_hdr; =20 - if ((rthdr->rtype =3D=3D 2) && - (rthdr->len =3D=3D sizeof(struct in6_address) / 8) && - (rthdr->segleft =3D=3D 1)) { + if ((rthdr->rtype =3D=3D 2) && (rthdr->segleft =3D=3D 1)) { =20 size_t input_size =3D iov_size(pkt, pkt_frags); size_t bytes_read; @@ -528,10 +526,12 @@ bool eth_parse_ipv6_hdr(const struct iovec *pkt, int = pkt_frags, } =20 if (curr_ext_hdr_type =3D=3D IP6_ROUTING) { - info->rss_ex_dst_valid =3D - _eth_get_rss_ex_dst_addr(pkt, pkt_frags, - ip6hdr_off + info->full_hdr_len, - &ext_hdr, &info->rss_ex_dst); + if (ext_hdr.ip6r_len =3D=3D sizeof(struct in6_address) / 8) { + info->rss_ex_dst_valid =3D + _eth_get_rss_ex_dst_addr(pkt, pkt_frags, + ip6hdr_off + info->full_hdr_l= en, + &ext_hdr, &info->rss_ex_dst); + } } else if (curr_ext_hdr_type =3D=3D IP6_DESTINATON) { info->rss_ex_src_valid =3D _eth_get_rss_ex_src_addr(pkt, pkt_frags, --=20 2.26.2 From nobody Mon May 13 05:32:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1610723506; cv=none; d=zohomail.com; s=zohoarc; b=Fsl9GuJBAwPpZ/8rBqFoJLSucA6AXJTSrt1F0PhCWvxpSt//h69m9fM1gQFH1wANWi3OE+FGEvXU1YxCp7VcpY5xyMJy3SgpH7Pu6YOf9BTGjBwbroPXaibEXzJTnBfLTZ6KfOt1JPcAo7QguCd8Zy04+dT0nWVFKJsdUES1YrA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610723506; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=i/iF2tnKMM96C+fRtwtThoQLmbFfyERCjXSGGrtMZTQ=; b=gKJWo6G7d2mUFAyZpzXsEDBeHYVgctz+MSa+7ZzcpMfVOoypgVsihW7vg8YHEej58KY950Gxo5J9yOXMb6DLyVhk71fVT9822zJ9iebJUH4ftJ5XQdGk7j9D3JILvU1EEG0tSTZe4hWTEl/je0JOPpxTOCexOOBwq4D/8yt+hVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1610723506294647.8978658125363; Fri, 15 Jan 2021 07:11:46 -0800 (PST) Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-161-Pq31TqxbNyS6l5M-6pBnFA-1; Fri, 15 Jan 2021 10:11:41 -0500 Received: by mail-ed1-f71.google.com with SMTP id dg17so3726311edb.11 for ; Fri, 15 Jan 2021 07:11:41 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (13.red-83-57-169.dynamicip.rima-tde.net. [83.57.169.13]) by smtp.gmail.com with ESMTPSA id b14sm4046584edu.3.2021.01.15.07.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 07:11:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610723505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i/iF2tnKMM96C+fRtwtThoQLmbFfyERCjXSGGrtMZTQ=; b=af0ix0qZkqilSWMU9tHh5wlGt2r91L/Joi/FXLwL1/Td0T8CZ/Gf9/zMPCOO3mezYIHbo+ j/QUjXQRhbWC7V92e4Iza6ShbMrrq40k24wJ1QH2uhDkNS21rVW4qox+nbdmO2pbwYw3WK xzbUcgZf/tXuZefuzTmQbYaB2V9HJaQ= X-MC-Unique: Pq31TqxbNyS6l5M-6pBnFA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i/iF2tnKMM96C+fRtwtThoQLmbFfyERCjXSGGrtMZTQ=; b=NDXPNxcQHzsVpouvmwgicBl+Zw2QDs2nY5NPedZXlI4Wtaz/5GHphJLDkQ4XxJVxe+ x7YKt8ayBrycxPSqGOfbRi8h7ABbUEAWmQ6cp7FZdcklvoNaD6LwQg2b6rre9R62EP42 fWwFKVSMCL5dsiKpurn2+WAThx8DTWd3hxwmN0UPugn3rHx4NcHpFyaYxKAXi7EmrBNf FHt1m4WWb5+5hhnEoKJtT9gID1mLJrvgnxpaPpLuJp/tpbxlN7hURn4d7ErbnlkSIafI M3pgmpMvjAKTsDw3OQ2dwjzsolji0g5MeaelTnJ9B0ynJbADuoCeIOVE4N/zR7as0DNW qALA== X-Gm-Message-State: AOAM5313rGWz+uL6UJFNiqP8cZznOJ6bMf6WIg+W2eFMOAv64a9kRXzQ nAaIHsQ9Qarny1LOCyoPIKKBacz/lBRUxuMXl0Y0ZBVx8CktUqj9/LmGJD6bfOXOB04KBg4l3w3 9jWH42ZmLoul/Tw== X-Received: by 2002:a50:9310:: with SMTP id m16mr9970230eda.94.1610723499724; Fri, 15 Jan 2021 07:11:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9dYn6gT580nyXUnVVACDx3j94Eq9vuw0W1LbmOE/x9r3XIlg101YKgKcNGrCAWmnT40lVkA== X-Received: by 2002:a50:9310:: with SMTP id m16mr9970198eda.94.1610723499423; Fri, 15 Jan 2021 07:11:39 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Prasad J Pandit , Miroslav Rezanina , Laurent Vivier , Paolo Bonzini , Thomas Huth , Dmitry Fleytman , Alexander Bulekov , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org Subject: [PATCH v2 2/2] net/eth: Fix stack-buffer-overflow in _eth_get_rss_ex_dst_addr() Date: Fri, 15 Jan 2021 16:11:26 +0100 Message-Id: <20210115151126.3334333-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115151126.3334333-1-philmd@redhat.com> References: <20210115151126.3334333-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) QEMU fuzzer reported a buffer overflow in _eth_get_rss_ex_dst_addr() reproducible as: $ cat << EOF | ./qemu-system-i386 -M pc-q35-5.0 \ -accel qtest -monitor none \ -serial none -nographic -qtest stdio outl 0xcf8 0x80001010 outl 0xcfc 0xe1020000 outl 0xcf8 0x80001004 outw 0xcfc 0x7 write 0x25 0x1 0x86 write 0x26 0x1 0xdd write 0x4f 0x1 0x2b write 0xe1020030 0x4 0x190002e1 write 0xe102003a 0x2 0x0807 write 0xe1020048 0x4 0x12077cdd write 0xe1020400 0x4 0xba077cdd write 0xe1020420 0x4 0x190002e1 write 0xe1020428 0x4 0x3509d807 write 0xe1020438 0x1 0xe2 EOF =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D2859770=3D=3DERROR: AddressSanitizer: stack-buffer-overflow on addr= ess 0x7ffdef904902 at pc 0x561ceefa78de bp 0x7ffdef904820 sp 0x7ffdef904818 READ of size 1 at 0x7ffdef904902 thread T0 #0 0x561ceefa78dd in _eth_get_rss_ex_dst_addr net/eth.c:410:17 #1 0x561ceefa41fb in eth_parse_ipv6_hdr net/eth.c:532:17 #2 0x561cef7de639 in net_tx_pkt_parse_headers hw/net/net_tx_pkt.c:228= :14 #3 0x561cef7dbef4 in net_tx_pkt_parse hw/net/net_tx_pkt.c:273:9 #4 0x561ceec29f22 in e1000e_process_tx_desc hw/net/e1000e_core.c:730:= 29 #5 0x561ceec28eac in e1000e_start_xmit hw/net/e1000e_core.c:927:9 #6 0x561ceec1baab in e1000e_set_tdt hw/net/e1000e_core.c:2444:9 #7 0x561ceebf300e in e1000e_core_write hw/net/e1000e_core.c:3256:9 #8 0x561cef3cd4cd in e1000e_mmio_write hw/net/e1000e.c:110:5 Address 0x7ffdef904902 is located in stack of thread T0 at offset 34 in f= rame #0 0x561ceefa320f in eth_parse_ipv6_hdr net/eth.c:486 This frame has 1 object(s): [32, 34) 'ext_hdr' (line 487) <=3D=3D Memory access at offset 34 over= flows this variable HINT: this may be a false positive if your program uses some custom stack= unwind mechanism, swapcontext or vfork (longjmp and C++ exceptions *are* supported) SUMMARY: AddressSanitizer: stack-buffer-overflow net/eth.c:410:17 in _eth= _get_rss_ex_dst_addr Shadow bytes around the buggy address: 0x10003df188d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df188e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df188f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18910: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1 =3D>0x10003df18920:[02]f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18930: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x10003df18970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Stack left redzone: f1 Stack right redzone: f3 =3D=3D2859770=3D=3DABORTING Similarly GCC 11 reports: net/eth.c: In function 'eth_parse_ipv6_hdr': net/eth.c:410:15: error: array subscript 'struct ip6_ext_hdr_routing[0]' = is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Werror=3Darray-= bounds] 410 | if ((rthdr->rtype =3D=3D 2) && (rthdr->segleft =3D=3D 1)) { | ~~~~~^~~~~~~ net/eth.c:485:24: note: while referencing 'ext_hdr' 485 | struct ip6_ext_hdr ext_hdr; | ^~~~~~~ net/eth.c:410:38: error: array subscript 'struct ip6_ext_hdr_routing[0]' = is partly outside array bounds of 'struct ip6_ext_hdr[1]' [-Werror=3Darray-= bounds] 410 | if ((rthdr->rtype =3D=3D 2) && (rthdr->segleft =3D=3D 1)) { | ~~~~~^~~~~~~~~ net/eth.c:485:24: note: while referencing 'ext_hdr' 485 | struct ip6_ext_hdr ext_hdr; | ^~~~~~~ In eth_parse_ipv6_hdr() we called iov_to_buf() to fill the 2 bytes of the 'ext_hdr' buffer, then _eth_get_rss_ex_dst_addr() tries to access beside the 2 filled bytes. Fix by reworking the function, filling the full rt_hdr buffer on the stack calling iov_to_buf() again. Add the corresponding qtest case with the fuzzer reproducer. Cc: qemu-stable@nongnu.org Buglink: https://bugs.launchpad.net/qemu/+bug/1879531 Reported-by: Alexander Bulekov Reported-by: Miroslav Rezanina Fixes: eb700029c78 ("net_pkt: Extend packet abstraction as required by e100= 0e functionality") Reviewed-by: Miroslav Rezanina Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Thomas Huth --- v2: Do no run test if device not available --- net/eth.c | 25 +++++++--------- tests/qtest/fuzz-e1000e-test.c | 53 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 4 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 tests/qtest/fuzz-e1000e-test.c diff --git a/net/eth.c b/net/eth.c index 7d4dd48c1ff..ae4db37888e 100644 --- a/net/eth.c +++ b/net/eth.c @@ -401,26 +401,23 @@ eth_is_ip6_extension_header_type(uint8_t hdr_type) =20 static bool _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags, - size_t rthdr_offset, + size_t ext_hdr_offset, struct ip6_ext_hdr *ext_hdr, struct in6_address *dst_addr) { - struct ip6_ext_hdr_routing *rthdr =3D (struct ip6_ext_hdr_routing *) e= xt_hdr; + struct ip6_ext_hdr_routing rt_hdr; + size_t input_size =3D iov_size(pkt, pkt_frags); + size_t bytes_read; =20 - if ((rthdr->rtype =3D=3D 2) && (rthdr->segleft =3D=3D 1)) { + if (input_size < ext_hdr_offset + sizeof(rt_hdr)) { + return false; + } =20 - size_t input_size =3D iov_size(pkt, pkt_frags); - size_t bytes_read; + bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset, + &rt_hdr, sizeof(rt_hdr)); =20 - if (input_size < rthdr_offset + sizeof(*ext_hdr)) { - return false; - } - - bytes_read =3D iov_to_buf(pkt, pkt_frags, - rthdr_offset + sizeof(*ext_hdr), - dst_addr, sizeof(*dst_addr)); - - return bytes_read =3D=3D sizeof(*dst_addr); + if ((rt_hdr.rtype =3D=3D 2) && (rt_hdr.segleft =3D=3D 1)) { + return bytes_read =3D=3D sizeof(*ext_hdr) + sizeof(*dst_addr); } =20 return false; diff --git a/tests/qtest/fuzz-e1000e-test.c b/tests/qtest/fuzz-e1000e-test.c new file mode 100644 index 00000000000..66229e60964 --- /dev/null +++ b/tests/qtest/fuzz-e1000e-test.c @@ -0,0 +1,53 @@ +/* + * QTest testcase for e1000e device generated by fuzzer + * + * Copyright (c) 2021 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" + +#include "libqos/libqtest.h" + +/* + * https://bugs.launchpad.net/qemu/+bug/1879531 + */ +static void test_lp1879531_eth_get_rss_ex_dst_addr(void) +{ + QTestState *s; + + s =3D qtest_init("-nographic -monitor none -serial none -M pc-q35-5.0"= ); + + qtest_outl(s, 0xcf8, 0x80001010); + qtest_outl(s, 0xcfc, 0xe1020000); + qtest_outl(s, 0xcf8, 0x80001004); + qtest_outw(s, 0xcfc, 0x7); + qtest_writeb(s, 0x25, 0x86); + qtest_writeb(s, 0x26, 0xdd); + qtest_writeb(s, 0x4f, 0x2b); + + qtest_writel(s, 0xe1020030, 0x190002e1); + qtest_writew(s, 0xe102003a, 0x0807); + qtest_writel(s, 0xe1020048, 0x12077cdd); + qtest_writel(s, 0xe1020400, 0xba077cdd); + qtest_writel(s, 0xe1020420, 0x190002e1); + qtest_writel(s, 0xe1020428, 0x3509d807); + qtest_writeb(s, 0xe1020438, 0xe2); + qtest_writeb(s, 0x4f, 0x2b); + qtest_quit(s); +} + +int main(int argc, char **argv) +{ + const char *arch =3D qtest_get_arch(); + + g_test_init(&argc, &argv, NULL); + + if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { + qtest_add_func("fuzz/test_lp1879531_eth_get_rss_ex_dst_addr", + test_lp1879531_eth_get_rss_ex_dst_addr); + } + + return g_test_run(); +} diff --git a/MAINTAINERS b/MAINTAINERS index fcbe3ac79a8..54d0e0c5cd9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1968,6 +1968,7 @@ e1000e M: Dmitry Fleytman S: Maintained F: hw/net/e1000e* +F: tests/qtest/fuzz-e1000e-test.c =20 eepro100 M: Stefan Weil diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index fedce3ee3c1..840bd144b1b 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -7,6 +7,7 @@ qtests_generic =3D \ (config_all_devices.has_key('CONFIG_MEGASAS_SCSI_PCI') ? ['fuzz-megasas-= test'] : []) + \ (config_all_devices.has_key('CONFIG_VIRTIO_SCSI') ? ['fuzz-virtio-scsi-t= est'] : []) + \ + (config_all_devices.has_key('CONFIG_E1000E_PCI_EXPRESS') ? ['fuzz-e1000e= -test'] : []) + \ [ 'cdrom-test', 'device-introspect-test', --=20 2.26.2