Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp540384rdh; Thu, 23 Nov 2023 10:47:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHn898p4T+DV0nBrrf02bgzU4GX1klvlwFpaOUXGyEg8bz2wJkyGsy8Ygc4+SAuWIYCJF5t X-Received: by 2002:a05:6a20:c18e:b0:18b:b02d:886 with SMTP id bg14-20020a056a20c18e00b0018bb02d0886mr628153pzb.28.1700765253566; Thu, 23 Nov 2023 10:47:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700765253; cv=none; d=google.com; s=arc-20160816; b=Nj4s7KcukWoG+8HKLJZP69X85AR1mAhxlhNWb9sEg6MarXj3CgtCOA9pt3AxWL7ujO ZM+3awGS2h4EghXrtg3eC3NLnDJ2pEYChFxi161yhbkyYyjK8ce/twccDcQ6TC50V4aQ rmzDUbZAH0z0IZdnMdBBR23ouNRGoAeD1p3vgQ3I3hIdZYqGo7ZEAfHr3ClNlHAEuDEa vs558OzvyKeAffQ5Jqe2aEHz1uP7ADNug3XHhmvJI5jWUfk8hf3HGqZI/31ToI0s/AH/ uq5m4L5oHOCiT30PwrrVffPgI99xDbcetgzzSho5sCxGguA8jInv0LGN04GL9pE6aWpZ vMtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=MZcj6fHanb3mUK8r75E4vy8tt1GEMX0UQXL1edeKG8c=; fh=JII4fwoREbdSvjAJDvmSDYolzdsjA/UZKBO5kicEeQg=; b=UYwjk57e7PZOuKrkXWXPjU0okX1XOoxCpqThSn7dpX1dBMrdnO93kwf74jWR03GoM6 gRbYPjCshmCVLXLiMbUbDmUopAP8gUXpKp0IguiM3vQ26PagWlgv/FdN8RVeAv1SncK0 NDsZMDySUkvjYhVsugD35SeFCEBaCEIz2xmekVMwUJxy0Iv9TMIe2d9R6Gk/JcwIe/Tm Ovb92X3ivJV5/xvHUlyTwYdwxpFi4Uk6BE7xdbdq+2pTLWNjuwuivWqV1hSxLC0gTdvb pLl89zz+hb1ZXpEkkdsZYoUveniIL4ZAhNV1eb0PI8mlDlNQ/qPn4nzE3UcDUv+bd8qm 6adw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YcFm3tLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id o9-20020a17090aac0900b0028526101cc6si2262982pjq.51.2023.11.23.10.47.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 10:47:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YcFm3tLt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 2232D808A940; Thu, 23 Nov 2023 10:47:23 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjKWSje (ORCPT + 99 others); Thu, 23 Nov 2023 13:39:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbjKWSjd (ORCPT ); Thu, 23 Nov 2023 13:39:33 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 710E7F9 for ; Thu, 23 Nov 2023 10:39:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700764779; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=MZcj6fHanb3mUK8r75E4vy8tt1GEMX0UQXL1edeKG8c=; b=YcFm3tLtm8F8FMn/3D0peiyjFuEQkmTJ8iaADR7CkhdGbskyKpjHRVz1y+sFW5uAPGleor xtWu7RmtKN4qxKXglhN98XyfMAQoDV1ep3oMG50j4h+qLyIg5PJJayCj5v3v0IEJ/tZSro 3Q0UXuQyT3K8m1N69GSP+fUkv+LDdR0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-cTUNmn_TOK-r0VEDioyo3w-1; Thu, 23 Nov 2023 13:39:36 -0500 X-MC-Unique: cTUNmn_TOK-r0VEDioyo3w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB341185A782; Thu, 23 Nov 2023 18:39:35 +0000 (UTC) Received: from mpattric.remote.csb (unknown [10.22.33.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 40B7C5028; Thu, 23 Nov 2023 18:39:35 +0000 (UTC) From: Mike Pattrick To: netdev@vger.kernel.org Cc: willemdebruijn.kernel@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, Mike Pattrick Subject: [PATCH net-next] packet: Account for VLAN_HLEN in csum_start when virtio_net_hdr is enabled Date: Thu, 23 Nov 2023 13:38:35 -0500 Message-Id: <20231123183835.635210-1-mkp@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 23 Nov 2023 10:47:23 -0800 (PST) Af_packet provides checksum offload offsets to usermode applications through struct virtio_net_hdr when PACKET_VNET_HDR is enabled on the socket. For skbuffs with a vlan being sent to a SOCK_RAW socket, af_packet will include the link level header and so csum_start needs to be adjusted accordingly. Fixes: fd3a88625844 ("net: in virtio_net_hdr only add VLAN_HLEN to csum_start if payload holds vlan") Signed-off-by: Mike Pattrick --- net/packet/af_packet.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index a84e00b5904b..f6b602ffe383 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -2092,15 +2092,23 @@ static unsigned int run_filter(struct sk_buff *skb, } static int packet_rcv_vnet(struct msghdr *msg, const struct sk_buff *skb, - size_t *len, int vnet_hdr_sz) + size_t *len, int vnet_hdr_sz, + const struct sock *sk) { struct virtio_net_hdr_mrg_rxbuf vnet_hdr = { .num_buffers = 0 }; + int vlan_hlen; if (*len < vnet_hdr_sz) return -EINVAL; *len -= vnet_hdr_sz; - if (virtio_net_hdr_from_skb(skb, (struct virtio_net_hdr *)&vnet_hdr, vio_le(), true, 0)) + if (sk->sk_type == SOCK_RAW && skb_vlan_tag_present(skb)) + vlan_hlen = VLAN_HLEN; + else + vlan_hlen = 0; + + if (virtio_net_hdr_from_skb(skb, (struct virtio_net_hdr *)&vnet_hdr, + vio_le(), true, vlan_hlen)) return -EINVAL; return memcpy_to_msg(msg, (void *)&vnet_hdr, vnet_hdr_sz); @@ -2368,13 +2376,21 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, __set_bit(slot_id, po->rx_ring.rx_owner_map); } - if (vnet_hdr_sz && - virtio_net_hdr_from_skb(skb, h.raw + macoff - - sizeof(struct virtio_net_hdr), - vio_le(), true, 0)) { - if (po->tp_version == TPACKET_V3) - prb_clear_blk_fill_status(&po->rx_ring); - goto drop_n_account; + if (vnet_hdr_sz) { + int vlan_hlen; + + if (sk->sk_type == SOCK_RAW && skb_vlan_tag_present(skb)) + vlan_hlen = VLAN_HLEN; + else + vlan_hlen = 0; + + if (virtio_net_hdr_from_skb(skb, h.raw + macoff - + sizeof(struct virtio_net_hdr), + vio_le(), true, vlan_hlen)) { + if (po->tp_version == TPACKET_V3) + prb_clear_blk_fill_status(&po->rx_ring); + goto drop_n_account; + } } if (po->tp_version <= TPACKET_V2) { @@ -3464,7 +3480,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, packet_rcv_try_clear_pressure(pkt_sk(sk)); if (vnet_hdr_len) { - err = packet_rcv_vnet(msg, skb, &len, vnet_hdr_len); + err = packet_rcv_vnet(msg, skb, &len, vnet_hdr_len, sk); if (err) goto out_free; } -- 2.40.1