From nobody Wed Nov 19 07:03:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615392108; cv=none; d=zohomail.com; s=zohoarc; b=e9a8aUIXmuEkgrMPF5/QFLwksEXExhSbACZCvxPyRYhyL21wKQvywQQC/XjdBTMH+MCwaHdXRNsPLj6dYVxNC+u00KDr2rzFnQedGOv/dLwE0YNlAlG9FRgtecI025LXVQ+AqGJRSvTvEIZJ7xPpsBDLVLqXZP2I5qkakLmW7+c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392108; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=JZa/iUsT9VQagkte3HBQwGL7dr2S/uC8iYuWuLSPUy0=; b=SUrJPcyHI1h4oF18yy18QnD/YrqrNc8kb+adyMN6aXo1VQVXIVu3QWjyllYQf0QGbyqI8vQ+/a3+Owhpyz9GklIExBDVNIii5ZUcROABK4dJJpBsjHuGKMI97O4xCEqGkEcDzueAmxu4AJlsZdE8oXgPx43XwhFUrhec+bt0CRA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615392108371960.6912854540087; Wed, 10 Mar 2021 08:01:48 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-304-iJERpoQlOH2bjai_nKn6dg-1; Wed, 10 Mar 2021 11:01:45 -0500 Received: by mail-ed1-f69.google.com with SMTP id r19so8180607edv.3 for ; Wed, 10 Mar 2021 08:01:44 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id k22sm10655534edv.33.2021.03.10.08.01.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:01:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392106; 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=JZa/iUsT9VQagkte3HBQwGL7dr2S/uC8iYuWuLSPUy0=; b=IyWuK8XekNbG3U8s9zMDSQONnNYNegsWsa4ZxkNZcbrKeQEtpkzbisa1TBbz5nM+/oY1sP j4QrrUai63vbNb4jgM8KJVLKHAg2d4gsaCXL/nOq35U07L+FloyMCREqfKLELucb8Rq2/x A85jbYwGVIRdMkase/F1FNSJyjGCiUA= X-MC-Unique: iJERpoQlOH2bjai_nKn6dg-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=JZa/iUsT9VQagkte3HBQwGL7dr2S/uC8iYuWuLSPUy0=; b=Jwh58SwTxHBulUB6xNbp8tPzu3eUZawv1FTkkQmTNEGQDaFqNxB5OGTiLxxwNvbANL CPZB3kHY00exEJa2sljquvK+DKd5nHFmaIxnUZM0VW8Cv9g5XZLvCcVuk3l3InWhm8pn wCCk80Tba9o9E0pgcK9jcVSPjgqRbMcWEBt5BFMepLdTthwvmPAscHmlR/vfnK4XDE9l GHLbsk4EUY+cpp/ERkPlboxrUw6Hmjyf0EaAaLjGKreNVkJkgijg3jULjvL3Fx9blcf0 1xaNC2RKu6fRA+iG6pbGaIsPWB65BJbbEzX0W42MPe92vPWoKzWXpoP8WorH060W5AtP T5/g== X-Gm-Message-State: AOAM5326h4UUdi7Goitsps/iIt3nhRTRgDos/eb3bPtWND0O1E9Pbkc4 lKlH4MBu9OnKke27DuUWKNcqoCK4W4f/cLcChSq6xm8uJGFkxoR0AESzaAhV9wn/BwtnvcBEi11 JyvBHQCCz4PTP1Q== X-Received: by 2002:a05:6402:b2d:: with SMTP id bo13mr4080114edb.120.1615392103910; Wed, 10 Mar 2021 08:01:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJzR3y5hYmJwuPJml+zR2w9ggexfPD05svapJOST+b9+HHSuI3COa2QZG5klY80vcuD9Vlvjlg== X-Received: by 2002:a05:6402:b2d:: with SMTP id bo13mr4080033edb.120.1615392103179; Wed, 10 Mar 2021 08:01:43 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 1/7] net/eth: Simplify _eth_get_rss_ex_dst_addr() Date: Wed, 10 Mar 2021 17:01:29 +0100 Message-Id: <20210310160135.1148272-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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 Reviewed-by: Stefano Garzarella 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 Wed Nov 19 07:03:52 2025 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=1615392119; cv=none; d=zohomail.com; s=zohoarc; b=h/hp13tKQi55mvTTtgHfCAS9IJhhM5FCHcFWzYscvVNJVoL/COJ7oDaOtFFIb/9KggikZNRQS9eMeODSLTB0RvrEfQNcjeI/dukOLvUmGfW7TYMfyQtqBW+PNnrJ8KZId/UwBV5mkt/SpI/uyp7Db19DmxGllN1dcqTfRxwpang= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392119; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=o4IDrBOrBdc79jZ9ab97ouOR74cgvk509Hp9kOypaec=; b=FhijAE98zXXzOCQZHbuDXBF153c9zdD3MygyLhXzhtdqyhB2s6qZ4KAeowzTHqqatuK7hnqTnf9xFuUu7tXQklBmBzMtlHAwyx5AL5dRO1ZJ1sxLXaWjGzxn47FQpbLSIyXmRNGLPcxi2wY7StVaKsxpIvMBOFRjpn02Wd8dV4s= 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 1615392119424264.5230098295767; Wed, 10 Mar 2021 08:01:59 -0800 (PST) Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-173-tTeOiLeWOuemmhD25XwaGw-1; Wed, 10 Mar 2021 11:01:56 -0500 Received: by mail-ej1-f72.google.com with SMTP id di5so7423636ejc.1 for ; Wed, 10 Mar 2021 08:01:55 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id ho11sm9907130ejc.112.2021.03.10.08.01.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392117; 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=o4IDrBOrBdc79jZ9ab97ouOR74cgvk509Hp9kOypaec=; b=R41fxkyimM+t6Bq+fkdTMXk9phS58vuHDJh0CYPAQAhN/SaRVLUqiHcqlrUGjHMtsWKyS9 tCLcr/jNwr5qRZ4Hmw5EWM7TdxXK9nNCFvkkz9+990LYCDx8Cq5oyAkZ3rB7NUl74jJjiq 9MAGHvkd1CfSDCJwnWjW/b9WuY6YdQE= X-MC-Unique: tTeOiLeWOuemmhD25XwaGw-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=o4IDrBOrBdc79jZ9ab97ouOR74cgvk509Hp9kOypaec=; b=KSjrDmi/tqQZJmFFzJ5varHc2CeaIZeCIuLKNlFw3yPE49MQC7bhsWm4MjZrxLLNi0 nj6hg9UIs2YTIUsV8ukAWxkZRre0AqRqggoyVXMtVe3xPOJxpIX17eBYadNIe7mE4+Mj +6HrmOxjzUek5kDIhwQeRWqPJOgOpDrv7EPuT5I6GshqUlR7nX0aTI2vHdMkIYwnaHY4 HIJtciEreELGg7waN+8hFnuGdr2r2EiIdjmS+oorvcYSt9a9nCH1NJqsxkI1/iGaCJSm VA35/frMPO62wdU2NM7iRbQx92ffwlTWOLuIYE/YexrpJX7LPZF/+9n9lceEGRORu6h2 3M5Q== X-Gm-Message-State: AOAM5335GXDjIZBW27RBTSCL2l6v7MIeaSKArW84Ct/dZ7g8HJ8TX/Gw T9LfqyzCNc0WsPeRfIcQtcLWBcrP3//mCDNnhYwU2QpbLuCVOtn+YWsczyuzLx1d+gTWYMX0J6t ePBt4p/hb9fYCYw== X-Received: by 2002:a17:906:9243:: with SMTP id c3mr4582481ejx.388.1615392113973; Wed, 10 Mar 2021 08:01:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJwshEyQD5OOAxhL+9S0JWpdZzEgb6dt3if4I7T53s82MWq/jTX5P6wVuUr755mnoZ1LPnzDMg== X-Received: by 2002:a17:906:9243:: with SMTP id c3mr4582008ejx.388.1615392108920; Wed, 10 Mar 2021 08:01:48 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 2/7] net/eth: Better describe _eth_get_rss_ex_dst_addr's offset argument Date: Wed, 10 Mar 2021 17:01:30 +0100 Message-Id: <20210310160135.1148272-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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 'offset' argument represents the offset to the ip6_ext_hdr header, rename it as 'ext_hdr_offset'. Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- net/eth.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/eth.c b/net/eth.c index 7d4dd48c1ff..6a5a1d04e0b 100644 --- a/net/eth.c +++ b/net/eth.c @@ -401,7 +401,7 @@ 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) { @@ -412,12 +412,12 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int= pkt_frags, size_t input_size =3D iov_size(pkt, pkt_frags); size_t bytes_read; =20 - if (input_size < rthdr_offset + sizeof(*ext_hdr)) { + if (input_size < ext_hdr_offset + sizeof(*ext_hdr)) { return false; } =20 bytes_read =3D iov_to_buf(pkt, pkt_frags, - rthdr_offset + sizeof(*ext_hdr), + ext_hdr_offset + sizeof(*ext_hdr), dst_addr, sizeof(*dst_addr)); =20 return bytes_read =3D=3D sizeof(*dst_addr); --=20 2.26.2 From nobody Wed Nov 19 07:03:52 2025 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=1615392139; cv=none; d=zohomail.com; s=zohoarc; b=kjiYkDQGtjW3wHMMAM64x6dI/1Z6D40MSUwNBOOfuwralXJ4bWkS0dfuiBVtXcZzChPlq2kBFyIIGEQTSXDKpP2al7nvyELzp4OAOxdB52puDFDX/R7uXfD39cZqEJKBJFe5Zztma5yQoexAvfpbwfP04ZbF6lVoZzTeOTIeNfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392139; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=B3xaH0TWbEO7Mh01q5cRC27I0HaUzq5ELvE0IDN8LPc=; b=I13SpSpGbbsSK5P0rhH/M5eVJhAjTtsP9MQIYfUQy3y0dIgn0pa5mdYNXEnGu5FNt6IYayO7R6w3jYWD42yv3oDjm7QyQZYFySRCh33SQ2H9/SIEIqqdg5FfNZ/2zi7uLuS+0wj78SGMJXKJISpvjX6b4rUuF08UBet3mWzJN8U= 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 1615392139024325.74188253045816; Wed, 10 Mar 2021 08:02:19 -0800 (PST) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-NO2S_9cWMs-fj1fk9WKiMA-1; Wed, 10 Mar 2021 11:02:15 -0500 Received: by mail-ej1-f69.google.com with SMTP id n25so7422092ejd.5 for ; Wed, 10 Mar 2021 08:02:04 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id e26sm11940282edj.29.2021.03.10.08.01.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:01:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392137; 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=B3xaH0TWbEO7Mh01q5cRC27I0HaUzq5ELvE0IDN8LPc=; b=VcUI3X8fmtyOMyxrxKR33BsIlR2aoM6pSzV9YrRncXL5lmgJacj6LoHFwFeOPbz/Uo/up7 CZyQNjnvvzP1U7XB++oNXKRdpmOWj1f6HEoQ/TX7FKOREDj++pnOcIiNH4CbMVdCAv9hbA 6QE1iCO9bZETiAaQD9tNA2aRmCH5Px8= X-MC-Unique: NO2S_9cWMs-fj1fk9WKiMA-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=B3xaH0TWbEO7Mh01q5cRC27I0HaUzq5ELvE0IDN8LPc=; b=rdO4pFRCf6PTgaszWWiFDvdP1EIq4SoB8C8BHDcn6j7QXZYOyAkhZpbzGZu+tNjsXm 3w6OKIUiLujrepdMG6UHH0giEOAW/eKBSVQ5sFb0xNhmB7CSBJZvkq4W+W07VFngZ0gz Nf0AGLk/GNNSvyYuKJoyZ6crzBlZGeDFTP1781ACn++naOkQ8V+iW7W5lHokpcdKH1Vd zfYoMETR5Vc2aqY4wxTDQY6ZH2ltId4OL6/3O/UeDxXn2rbtCjR+vBuVxVjdOPfpz1H5 tl6AVlBOfQslaOUjbUgtnFDx6hFHN/gRCpAH+KnbH3KVQHtuTDqvgO25VrZJ7/8kxY+g isTg== X-Gm-Message-State: AOAM531K/k+VlEWjTte7Lh5fx1IYDy73O6eUjHQW+V5uy0uHbaz5GhGx weiL3+sW0kXRCvr598BHE5t8j2okv88l1vbTSu8FcgihtazRM1fkPo3NDb8nz4yAc1GvajviOrx M2o/xFZLsrAolVg== X-Received: by 2002:a17:906:684b:: with SMTP id a11mr4252465ejs.329.1615392118260; Wed, 10 Mar 2021 08:01:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJya64dRK5SMgu8YnTkmqmESDBriI7BUsWzsvLm+e3mD1nvxOWGHfnNrQ5WFAKM3XvdVx4ATgA== X-Received: by 2002:a17:906:684b:: with SMTP id a11mr4252033ejs.329.1615392114018; Wed, 10 Mar 2021 08:01:54 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 3/7] net/eth: Make ip6_ext_hdr *ext_hdr pointer to const Date: Wed, 10 Mar 2021 17:01:31 +0100 Message-Id: <20210310160135.1148272-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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) As the callee doesn't need to modify the ext_hdr buffer, mark it const. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- net/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/eth.c b/net/eth.c index 6a5a1d04e0b..7c47a267a7a 100644 --- a/net/eth.c +++ b/net/eth.c @@ -402,7 +402,7 @@ eth_is_ip6_extension_header_type(uint8_t hdr_type) static bool _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int pkt_frags, size_t ext_hdr_offset, - struct ip6_ext_hdr *ext_hdr, + const 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; --=20 2.26.2 From nobody Wed Nov 19 07:03:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615392127; cv=none; d=zohomail.com; s=zohoarc; b=MEL34ZAuVgUOhWYa+BhtNzQ4x77vIcV3rPXGB2C4m0j9m7yrbJWlQMUrVYJTMjG4mPb8jYCRrB0unfDUavpW6/ygY020eiDjzVn43b6EhmeuwhyUfw4S6Sug5szYyVCwYiOn9zeyIa6Xnq5wgvT3WzBwmhFLlOaoYf+yLyfUGXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392127; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=z7STKW13AjGU8of8784VkFijz8VFi7Qj7fyPQfQCuSc=; b=Ye9bIXNSuyuCNtE3nRBWGLjWEU0/uMgh70lcpUBXV3g9mxTlGuNkSuSCMc6KJRpoIhz//TARD1K+slGfmMMXcR8t99zvU9ak4qEIBIfzMAoQsnoVuUmxVJ2+WmP8wcvXyqLaMyFir9elznlrDXR6aiCadFmLgGNZo03cuWfxyrA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615392127724896.9567124999126; Wed, 10 Mar 2021 08:02:07 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-362-5TZK3YSZNXCrOy-RdiPwAw-1; Wed, 10 Mar 2021 11:02:04 -0500 Received: by mail-ed1-f69.google.com with SMTP id w16so8594063edc.22 for ; Wed, 10 Mar 2021 08:02:04 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id g26sm899475ejz.70.2021.03.10.08.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:01:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392126; 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=z7STKW13AjGU8of8784VkFijz8VFi7Qj7fyPQfQCuSc=; b=jC/IgXXY940/vbP7qFKIAjah2fGastm3jMHA4qs1UoMemgpxAvfmTIjQGeH5oYfiVIY6Rl 7t4/Qhjk+3/c2U9UvA6kD+rB4ES/T+m0x6OeSWNDL5nGxvUr07/UwnTB47BHvxA/2k53il eCrrgxhVuLjMijUVZiu7BeonTeB8Whk= X-MC-Unique: 5TZK3YSZNXCrOy-RdiPwAw-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=z7STKW13AjGU8of8784VkFijz8VFi7Qj7fyPQfQCuSc=; b=Eeuw/PXdJlzzDtPLMU6pXxWuD6I4Gsj0pmTMdbX0AwKHYVS3AiKCADeBwvYPbbFN9T AnMAWOcN/WFE0O9f/ttdQxLBcTniFwhS8pWYZr0hhVrQBWvl7aJHJ5D+s/iM8tNYiBpX Q4YvyxPPNsaaLNS7WvOWL9XAXTxTnXMEtGmXvOr86pFQu+0BYlUG49YdbXmzgYNEmQQX TVV4ePECnD70bVkUu+rlwODfpO4L/ZRNCtEME+TonseceR5AaLPnrGNGiJy5qpL4F9MR Qr0R2C6CFrIfTCGhqPo5xpi2f72uCOmQuVRXfq34okN7Zh8nnwU1ZqGbFrRURTkja84q SF9A== X-Gm-Message-State: AOAM533dQpSP8c5e3lNjjuOczvtniarLJeHav4GCKfR4UFzt4+cVaPz4 rJNAPV/f6/ay4iQaGRjIU93AnEBaXLC1pqJ3SVq2rfawyKNP6SKDhyGscfg3ddmyeDIxAUGfDu1 r3HTjL1iGO3CdDQ== X-Received: by 2002:aa7:cc94:: with SMTP id p20mr4150144edt.353.1615392123738; Wed, 10 Mar 2021 08:02:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJwOH5owravIZco1LO5HGj2WOFn+55hGHiAodM7YqXyPpnXRdkEZH4mBWKQGs6m+2c/MfM6EOQ== X-Received: by 2002:aa7:cc94:: with SMTP id p20mr4149664edt.353.1615392119230; Wed, 10 Mar 2021 08:01:59 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 4/7] net/eth: Check the size earlier Date: Wed, 10 Mar 2021 17:01:32 +0100 Message-Id: <20210310160135.1148272-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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) Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- net/eth.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/eth.c b/net/eth.c index 7c47a267a7a..e870d02b0df 100644 --- a/net/eth.c +++ b/net/eth.c @@ -406,16 +406,14 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int= pkt_frags, struct in6_address *dst_addr) { struct ip6_ext_hdr_routing *rthdr =3D (struct ip6_ext_hdr_routing *) e= xt_hdr; + size_t input_size =3D iov_size(pkt, pkt_frags); + size_t bytes_read; + + if (input_size < ext_hdr_offset + sizeof(*ext_hdr)) { + return false; + } =20 if ((rthdr->rtype =3D=3D 2) && (rthdr->segleft =3D=3D 1)) { - - size_t input_size =3D iov_size(pkt, pkt_frags); - size_t bytes_read; - - if (input_size < ext_hdr_offset + sizeof(*ext_hdr)) { - return false; - } - bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset + sizeof(*ext_hdr), dst_addr, sizeof(*dst_addr)); --=20 2.26.2 From nobody Wed Nov 19 07:03:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1615392138; cv=none; d=zohomail.com; s=zohoarc; b=RwwN6jg+Gm7mxTLcaKNG2KeuYBzTemqJAoQu4/b8s5mUcw7Yph0IthHvY9DgI2F59qLtP7URfyZ0OQ2hity0J4bbvQOKhm+UFOpNjf6ga7zRWLrL2YmdMG4qoOBNsSglEMlwrNVTRw20GKEI7IQcjqDR+6vKmXyUShdYE5HonJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392138; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=0zxcBphhiOETeSJ3HAp76zLwbki6XNRBCYQIOVB2vCU=; b=InF9d4QExwLSMOVGk4f4hAhDU9xDn1utdyJCPrng5BwZRT2nkVyLD94l+srfkHdpbJyZwUCCEnIlkCOXyR4CEtcXeA85u/W0OBxRFrLztHgd4i4tf2NA5+Nkb2LXzNz4/3HZheKIJDTvsVrdUgEni/aIRVg//tFKMVRakAcGx6M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1615392138958579.0303165063902; Wed, 10 Mar 2021 08:02:18 -0800 (PST) Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-246-VRtpb5NHPLuu9UfTAxeJkg-1; Wed, 10 Mar 2021 11:02:16 -0500 Received: by mail-ej1-f72.google.com with SMTP id jo6so7417181ejb.13 for ; Wed, 10 Mar 2021 08:02:15 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id w18sm10194493ejn.23.2021.03.10.08.02.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:02:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392137; 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=0zxcBphhiOETeSJ3HAp76zLwbki6XNRBCYQIOVB2vCU=; b=STeJDMAOb6yLnRz1QBvV5bIjuu13o3ljNzz48aptdSQ8dSd/Qlv2Iwoh0MsxQBnPMphwjg vX0h/doKrifHIGwyu7h0Cg127CeVC079+UuFufjsfdDctn19GP/JzBUwcwqE3YoBvHu3ZR BPO3IAVZz6SJ57s5ef0Gn1BeJcEMH2Q= X-MC-Unique: VRtpb5NHPLuu9UfTAxeJkg-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=0zxcBphhiOETeSJ3HAp76zLwbki6XNRBCYQIOVB2vCU=; b=FDsgVMxvixpqN2YoYZibuSVF9dyuiinpawFBnJ08c/85H2Y5x2DukwmCRpoSTpnlTi 1Pl+EvWXeEg91BEVoM32YnkVOt0Rxf0VEPUikmV6YLk3SysFxUFNK+prhNnljH9h2+6p ZZyLtSV2aekwfg1INM7d3rnHtQAuZMtcirsKZKfLDNNMLn/UBOE7vha4Pam2npJXoqx1 u7+/4vTRFaFzuxh8+HC+dIOY8TjyOTDpUD1Ur2BNlvLibyA2+o0/R4gXFo7CCiNeHHb9 P7p8eXslzWv7oiqrW0jU61gnocv9ehT0LglrR1NSYZ7O3JlsWXdekBvCyKDDnjOFD727 v31Q== X-Gm-Message-State: AOAM530p6vh2FSeig83qTVTR2I2PfZQfK4d8F+9sNEgUi8ewalL9OpT2 KaB482LyqNxshoE1e1G+jMUhDYoyeN65vR0M1YyK34HZVl7bsYGhySRoXjQek94iPaUgnVOfzix ksd/2v+iovMvCTw== X-Received: by 2002:a17:906:94ca:: with SMTP id d10mr4372209ejy.107.1615392130165; Wed, 10 Mar 2021 08:02:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJyQDDoDqFQvJ/MhGgNGsJegguM7SM+nDrBu9m6mmuFSl9OYZYU6/QgAPFOGYMuO6YxPmbEjFg== X-Received: by 2002:a17:906:94ca:: with SMTP id d10mr4371599ejy.107.1615392124499; Wed, 10 Mar 2021 08:02:04 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 5/7] net/eth: Check iovec has enough data earlier Date: Wed, 10 Mar 2021 17:01:33 +0100 Message-Id: <20210310160135.1148272-6-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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) We want to check fields from ip6_ext_hdr_routing structure and if correct read the full in6_address. Let's directly check if our iovec contains enough data for everything, else return early. Suggested-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- net/eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/eth.c b/net/eth.c index e870d02b0df..28cdc843a69 100644 --- a/net/eth.c +++ b/net/eth.c @@ -409,7 +409,7 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int p= kt_frags, size_t input_size =3D iov_size(pkt, pkt_frags); size_t bytes_read; =20 - if (input_size < ext_hdr_offset + sizeof(*ext_hdr)) { + if (input_size < ext_hdr_offset + sizeof(*rthdr) + sizeof(*dst_addr)) { return false; } =20 --=20 2.26.2 From nobody Wed Nov 19 07:03:52 2025 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=1615392146; cv=none; d=zohomail.com; s=zohoarc; b=Mqba2ar+dCpLgRBsCKpwR0MIw/b8NYVMgtTqVwyD/GsMRwR5cpDnpKyJn0A+CWZziIYBqLrO0M9Mxmph+ZVLP00920AD9A3mK7zUrNDUJR4iF5hqRe0rshcnb31z/wm1fXwLhOjo5tHrLxOvr/QSeYNibv5B3KfeUsmKbvL+5pc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392146; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=25ztEiZcqxp+zOkHWGr4v893OqwgDdVjRchgWM6TO/U=; b=LppOEYGJ/O/UxdYgoGx0mLlqOi/GywvLaXCALJL8Sn+6BhRnTGnj18BLplb5JioJ285DBjaUXvNN4XnlwH75K4Z4u7Tr4ff6OOeBGbTfyWpIZMo1+TWUKcQC59yNONkGxlrPkeysIzDK0/TmZUmQhouA9WS7D+kqnIAXaRoXIs8= 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 1615392146575103.3128956708988; Wed, 10 Mar 2021 08:02:26 -0800 (PST) Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-1-Cvo42pg7Pr-8lVbuh2s90w-1; Wed, 10 Mar 2021 11:02:18 -0500 Received: by mail-ej1-f69.google.com with SMTP id bg7so1376853ejb.12 for ; Wed, 10 Mar 2021 08:02:17 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id c20sm10105473eja.22.2021.03.10.08.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:02:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392145; 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=25ztEiZcqxp+zOkHWGr4v893OqwgDdVjRchgWM6TO/U=; b=Qyc66GipSfOrquO+AqWtoCf+qtSza9i7x5ca/xXNS3SpFq5ecSaSg1+XLZ6xH8szAnb0Ty LvNHtccJORjHf+as4nGcFDWLqKqybJTrbtS86UGsVL/LTTUuWUeqanV4o1CHahiHkGZWCj CLNwLQkWU/Na7hTOx4rC5adQQwwLaY4= X-MC-Unique: Cvo42pg7Pr-8lVbuh2s90w-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=25ztEiZcqxp+zOkHWGr4v893OqwgDdVjRchgWM6TO/U=; b=Ta5v+QPUfyhu/qZZIyr0PlXQSAXmEP+4J2/KdfVDsllDVWAbP+LlGGyfrCY/320PkN yMCYs/IJwGaFIFyqur9e9dV24bWsdzAuc9I82GbOW+unuC4bSIY7JWWKpw6+7OLv1yI7 p0ZYS5Bh8VuP92L4ZGcEFLdlwBbE0jk/eIsrEKYpgM3OzumvlwAjmTmKqMj3OoMI6GUX RFE6nw8S/PRvGW4IQqL5HzYs90L7eqrorfdZP1XUyLWtXzMm69jQqmnGdVMEa/KGV0Wj PyQ8MLV2LcgxKf37z18GtTDbVPNLpp0vkzCyhbPrxw9bEjh0tRNmhWrc2so/JFPTuECa zL5w== X-Gm-Message-State: AOAM5322GNcFRKh9K/WXd2xWTxDmB43iVZmG5QEBizadttNY6TrHZ4DT fHiaPOEfLYkDyfEQoNPxYKl9Xh2Q7O1ffsEvgvKXzkM0V7wzG/4hWJyfFe5x5hgjhGW0U/GlrFh n7UCM3YqG5Es5WQ== X-Received: by 2002:aa7:dd05:: with SMTP id i5mr4105698edv.300.1615392131991; Wed, 10 Mar 2021 08:02:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwM7Jp38llrDD25N/CSY/X/zqHnyqgFL8Mvg0Lzi5yNnXm3x0VX9AxyKopqzyoCFJzGnptr6w== X-Received: by 2002:aa7:dd05:: with SMTP id i5mr4105503edv.300.1615392130339; Wed, 10 Mar 2021 08:02:10 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-stable@nongnu.org, Alexander Bulekov , Thomas Huth , Laurent Vivier Subject: [PATCH v5 6/7] net/eth: Read ip6_ext_hdr_routing buffer before accessing it Date: Wed, 10 Mar 2021 17:01:34 +0100 Message-Id: <20210310160135.1148272-7-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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) We can't know the caller read enough data in the memory pointed by ext_hdr to cast it as a ip6_ext_hdr_routing. Declare rt_hdr on the stack and fill it again from the iovec. Since we already checked there is enough data in the iovec buffer, simply add an assert() call to consume the bytes_read variable. This fix a 2 bytes buffer overrun in eth_parse_ipv6_hdr() reported by QEMU fuzzer: $ 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 Add the corresponding qtest case with the fuzzer reproducer. FWIW GCC 11 similarly reported: 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; | ^~~~~~~ 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") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- net/eth.c | 10 +++++-- tests/qtest/fuzz-e1000e-test.c | 53 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + tests/qtest/meson.build | 1 + 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tests/qtest/fuzz-e1000e-test.c diff --git a/net/eth.c b/net/eth.c index 28cdc843a69..b150d73c13a 100644 --- a/net/eth.c +++ b/net/eth.c @@ -405,15 +405,19 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int= pkt_frags, const 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 (input_size < ext_hdr_offset + sizeof(*rthdr) + sizeof(*dst_addr)) { + if (input_size < ext_hdr_offset + sizeof(rt_hdr) + sizeof(*dst_addr)) { return false; } =20 - if ((rthdr->rtype =3D=3D 2) && (rthdr->segleft =3D=3D 1)) { + bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset, + &rt_hdr, sizeof(rt_hdr)); + assert(bytes_read =3D=3D sizeof(rt_hdr)); + + if ((rt_hdr.rtype =3D=3D 2) && (rt_hdr.segleft =3D=3D 1)) { bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset + sizeof(*ext_hdr), dst_addr, sizeof(*dst_addr)); 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 738786146d6..cc5f3aa6b60 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2003,6 +2003,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 58efc46144e..7997d895449 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -60,6 +60,7 @@ (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-test'] : [= ]) + \ (config_all_devices.has_key('CONFIG_TPM_TIS_ISA') ? ['tpm-tis-swtpm-test= '] : []) + \ (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : [= ]) + \ + (config_all_devices.has_key('CONFIG_E1000E_PCI_EXPRESS') ? ['fuzz-e1000e= -test'] : []) + \ qtests_pci + = \ ['fdc-test', 'ide-test', --=20 2.26.2 From nobody Wed Nov 19 07:03:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1615392142; cv=none; d=zohomail.com; s=zohoarc; b=ka6qgS9iIB/zf9J3n6rw+Q+j4k2Sk/u3L+7EzHvK75jTSExXkW6f8AZ3cASxlrWKO9M6zzBvbvnBDExFCsthYubixZYQnkGfoOiRUod6RcbS9ZPLo/vZ/G5bqJ4BI6Sv186VcwtRHP24liAoj9MJNrA7V6258u5eEbnFZMTbGuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615392142; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=dWqF+QRXjws0etT3d7idRupG4kdERl+87BNUQyCGg08=; b=WFbueJ8FUHrdrO7+H4P+SHVPl9vqzYVQ2TavS6IWeR6BYm4y1usrSRsLucSho8SebauWWWNlTUBvlNEVaVFUKo9C3SGA4CFdh+ga0AmGFLI6nrhPGlgP62gFBYFM3PIwNXg58iepeMFXte76w9vy8poab5qN1y8OYstxERlEhU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 161539214242571.26859321989377; Wed, 10 Mar 2021 08:02:22 -0800 (PST) Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-160-iiAc5UWXMEq-XohSlowNDw-1; Wed, 10 Mar 2021 11:02:19 -0500 Received: by mail-ed1-f69.google.com with SMTP id v27so8597268edx.1 for ; Wed, 10 Mar 2021 08:02:19 -0800 (PST) Return-Path: Return-Path: Received: from x1w.redhat.com (68.red-83-57-175.dynamicip.rima-tde.net. [83.57.175.68]) by smtp.gmail.com with ESMTPSA id p9sm1225756eds.66.2021.03.10.08.02.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:02:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615392140; 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=dWqF+QRXjws0etT3d7idRupG4kdERl+87BNUQyCGg08=; b=GaSJnrLGNPRo0kgDQDohq/cQR3xHOJCHiE6hfsvmv2Xz1GCi63A9fNbjIhz54WkFsJ8f+w T2ZI+pW39xZ8ZIrIdjYKPbnuIDD0OEqfVHI0SK/KFEoQL7wNnQIMrgFjNjt8tApKK8uzqP JId61JCyblf6ChYSIAXwy/yNWPB6oQw= X-MC-Unique: iiAc5UWXMEq-XohSlowNDw-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=dWqF+QRXjws0etT3d7idRupG4kdERl+87BNUQyCGg08=; b=gHiJciOFUwIzrXXDq4Alt2OCTOFUjrsKKVhbJQx4Ts++dGUOBZnJQgLUQ+oPno3smY cYK1zC7YzMB3iYygGF9NrV1wPrHXnU+O3om6y+QhgZzHZH0AmIiqKLqI+oFsCob98irQ P2Bym0BSvHIB+SgrLiuyzhQqoNP7s62ofoRLI8Vn5VX4KYMlPM0LSVg4cfNIm8TKT3ep bIbtN3o98lqB3ww/EKsaEP6aCpzSNwwGSyNtP293PX5mtDY/Hmm7fgKgziA6WBkcjy9f bzfFpvwmpTSYME6lRXBIr/5P8M/qN5oz4Yhqada+uZjNG2fqFrK4BZ56ei41LsbrkybJ wCKA== X-Gm-Message-State: AOAM530dUHLUhHoqcIS5Ysh2kaL4cSfeTsZ4xHVVdIFob+aw8/GoTzgU /6QfqHciDYgCKHNlEuh2hcv8ivHq5wmFp3RejqcyBd97JSAft1qAV1lBzcz+glul3W6bTfERd4E xzeWczQ7DhVhbWA== X-Received: by 2002:a17:906:5797:: with SMTP id k23mr4526768ejq.515.1615392135681; Wed, 10 Mar 2021 08:02:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJyodObdZLcjX2jXPfIqYovta4vHSS15YC8kxw0WH9M25h2VAUIToiumsK9emk+Cwym6tF58WA== X-Received: by 2002:a17:906:5797:: with SMTP id k23mr4526749ejq.515.1615392135546; Wed, 10 Mar 2021 08:02:15 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Stefano Garzarella , Dmitry Fleytman , Paolo Bonzini , Miroslav Rezanina , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v5 7/7] net/eth: Add an assert() and invert if() statement to simplify code Date: Wed, 10 Mar 2021 17:01:35 +0100 Message-Id: <20210310160135.1148272-8-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210310160135.1148272-1-philmd@redhat.com> References: <20210310160135.1148272-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) To simplify the function body, invert the if() statement, returning earlier. Since we already checked there is enough data in the iovec buffer, simply add an assert() call to consume the bytes_read variable. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefano Garzarella --- net/eth.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/net/eth.c b/net/eth.c index b150d73c13a..c0a5ca12be2 100644 --- a/net/eth.c +++ b/net/eth.c @@ -416,16 +416,14 @@ _eth_get_rss_ex_dst_addr(const struct iovec *pkt, int= pkt_frags, bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset, &rt_hdr, sizeof(rt_hdr)); assert(bytes_read =3D=3D sizeof(rt_hdr)); - - if ((rt_hdr.rtype =3D=3D 2) && (rt_hdr.segleft =3D=3D 1)) { - bytes_read =3D iov_to_buf(pkt, pkt_frags, - ext_hdr_offset + sizeof(*ext_hdr), - dst_addr, sizeof(*dst_addr)); - - return bytes_read =3D=3D sizeof(*dst_addr); + if ((rt_hdr.rtype !=3D 2) || (rt_hdr.segleft !=3D 1)) { + return false; } + bytes_read =3D iov_to_buf(pkt, pkt_frags, ext_hdr_offset + sizeof(rt_h= dr), + dst_addr, sizeof(*dst_addr)); + assert(bytes_read =3D=3D sizeof(*dst_addr)); =20 - return false; + return true; } =20 static bool --=20 2.26.2