From patchwork Tue Mar 30 23:43:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 12174011 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1BD2C433DB for ; Tue, 30 Mar 2021 23:44:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B1242614A7 for ; Tue, 30 Mar 2021 23:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbhC3XoR (ORCPT ); Tue, 30 Mar 2021 19:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231650AbhC3Xns (ORCPT ); Tue, 30 Mar 2021 19:43:48 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FCD8C061574 for ; Tue, 30 Mar 2021 16:43:48 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id x21-20020a17090a5315b029012c4a622e4aso273743pjh.2 for ; Tue, 30 Mar 2021 16:43:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9xu9V02jfQDUUMS+pOJHv3jfVSzzAQWWHadNZ3WxTEA=; b=RYE18RWxKWt9VGhUgftOsNZurCnvUHqo5fv5nnrn+0jpcQ8SWncPtty8hT7wBM6iUG 4RGoqc71XjqNQKRbf+NWBvZ8fEFM8aqLA4cx4iLXur8ye+SHKqIZI+SvA0MtDGLhhEqP /MonkB4G6imWDXZnfx0fIXhuoaTYTMZSD5iC8QwDLd4bE/gbH9SYRrGwNbXNb9aQhW7H DJMGBPNvXrg0w6THAgn7o8SssSI/kU9Gs2DX+cahVkl/9cX/V9IJoLsOzaKeAYrSXOGG 7IKq2SqPit/QS+KDuUGv5UNmTUAABhzle/Euzru16FsTqil/6Swo2x4gCpE7kLTBzn4s CxQA== 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:mime-version :content-transfer-encoding; bh=9xu9V02jfQDUUMS+pOJHv3jfVSzzAQWWHadNZ3WxTEA=; b=sqiU0WWLVjF58CkXxTOoxi0C/QEqRjHpuV3KcYJEtvWwXB0KHg8v3TvBQZKAKBBQsC acR3i/d7eORq5ivS3SZyljY7B2AtNYzL1bjykGTOq4lCAXAIb8yNBfFJ8aEwXdKoW5PO TqU+stdFGGpPhEwxErdRQRFMtBGouLKOfPZa85qFMmCfPbK4cbrje+1QuaOorVe8o9UZ VF97/qWgPqBj/es9WrVBctjFpt5bUrstVUx2LFujtA/NsswPDvjbYEbjXGU0XYVM6QJY hogL8vTKpqqF+tfWNKtU7UUn19/o2wpPvy/6ceOLeAOlkyHgYo80ymQLdfulegdOF/Y2 LYhw== X-Gm-Message-State: AOAM532Xgcrq+y+/BhHAaE3NJWXpj/A/LPuOcu0tjxawBiSDtAiDgCJU YQx+RDxqGdQOEKs+1vEJ1rM= X-Google-Smtp-Source: ABdhPJybSWlDcFXYpDB5DT4NBKBLrl0nQgkpu36tcHFGv5sB6vGCvM2yQt6cLGgg3HdA34X+Yt+esA== X-Received: by 2002:a17:90a:5413:: with SMTP id z19mr684240pjh.137.1617147827755; Tue, 30 Mar 2021 16:43:47 -0700 (PDT) Received: from edumazet1.svl.corp.google.com ([2620:15c:2c4:201:7943:6407:20df:4b55]) by smtp.gmail.com with ESMTPSA id h7sm139382pfo.45.2021.03.30.16.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Mar 2021 16:43:47 -0700 (PDT) From: Eric Dumazet To: "David S . Miller" , Jakub Kicinski Cc: netdev , Eric Dumazet , Eric Dumazet , Balazs Nemeth , Willem de Bruijn , syzbot Subject: [PATCH net] net: ensure mac header is set in virtio_net_hdr_to_skb() Date: Tue, 30 Mar 2021 16:43:43 -0700 Message-Id: <20210330234343.3273561-1-eric.dumazet@gmail.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Eric Dumazet Commit 924a9bc362a5 ("net: check if protocol extracted by virtio_net_hdr_set_proto is correct") added a call to dev_parse_header_protocol() but mac_header is not yet set. This means that eth_hdr() reads complete garbage, and syzbot complained about it [1] This patch resets mac_header earlier, to get more coverage about this change. Audit of virtio_net_hdr_to_skb() callers shows that this change should be safe. [1] BUG: KASAN: use-after-free in eth_header_parse_protocol+0xdc/0xe0 net/ethernet/eth.c:282 Read of size 2 at addr ffff888017a6200b by task syz-executor313/8409 CPU: 1 PID: 8409 Comm: syz-executor313 Not tainted 5.12.0-rc2-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:79 [inline] dump_stack+0x141/0x1d7 lib/dump_stack.c:120 print_address_description.constprop.0.cold+0x5b/0x2f8 mm/kasan/report.c:232 __kasan_report mm/kasan/report.c:399 [inline] kasan_report.cold+0x7c/0xd8 mm/kasan/report.c:416 eth_header_parse_protocol+0xdc/0xe0 net/ethernet/eth.c:282 dev_parse_header_protocol include/linux/netdevice.h:3177 [inline] virtio_net_hdr_to_skb.constprop.0+0x99d/0xcd0 include/linux/virtio_net.h:83 packet_snd net/packet/af_packet.c:2994 [inline] packet_sendmsg+0x2325/0x52b0 net/packet/af_packet.c:3031 sock_sendmsg_nosec net/socket.c:654 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:674 sock_no_sendpage+0xf3/0x130 net/core/sock.c:2860 kernel_sendpage.part.0+0x1ab/0x350 net/socket.c:3631 kernel_sendpage net/socket.c:3628 [inline] sock_sendpage+0xe5/0x140 net/socket.c:947 pipe_to_sendpage+0x2ad/0x380 fs/splice.c:364 splice_from_pipe_feed fs/splice.c:418 [inline] __splice_from_pipe+0x43e/0x8a0 fs/splice.c:562 splice_from_pipe fs/splice.c:597 [inline] generic_splice_sendpage+0xd4/0x140 fs/splice.c:746 do_splice_from fs/splice.c:767 [inline] do_splice+0xb7e/0x1940 fs/splice.c:1079 __do_splice+0x134/0x250 fs/splice.c:1144 __do_sys_splice fs/splice.c:1350 [inline] __se_sys_splice fs/splice.c:1332 [inline] __x64_sys_splice+0x198/0x250 fs/splice.c:1332 do_syscall_64+0x2d/0x70 arch/x86/entry/common.c:46 Fixes: 924a9bc362a5 ("net: check if protocol extracted by virtio_net_hdr_set_proto is correct") Signed-off-by: Eric Dumazet Cc: Balazs Nemeth Cc: Willem de Bruijn Reported-by: syzbot --- include/linux/virtio_net.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h index 6b5fcfa1e5553576b0e853ae31a2df655c04204b..98775d7fa69632e2c2da30b581a666f7fbb94b64 100644 --- a/include/linux/virtio_net.h +++ b/include/linux/virtio_net.h @@ -62,6 +62,8 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb, return -EINVAL; } + skb_reset_mac_header(skb); + if (hdr->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) { u16 start = __virtio16_to_cpu(little_endian, hdr->csum_start); u16 off = __virtio16_to_cpu(little_endian, hdr->csum_offset);