Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp5912602rwb; Wed, 7 Sep 2022 09:43:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR50YiBZfkfARuYM6b1Xty4QrhpEvVydWoTH0w6J+tc1nfyqQuXWNnrBIsuVBTEqqya83MJn X-Received: by 2002:a17:907:1c0d:b0:76f:ab7:d0ed with SMTP id nc13-20020a1709071c0d00b0076f0ab7d0edmr2814989ejc.608.1662568981890; Wed, 07 Sep 2022 09:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662568981; cv=none; d=google.com; s=arc-20160816; b=MPVMeVnJvu5jJ81Ai2DGN717LFU06OiWZnpxJh2EwltLUhK+WbyNdo1gxyLXSLQD4e uBeWVVH8tPRNacQ2iI58CZU5foPtDd9VkV+mlqgJqp+ly/zlmEd0ep0/fklA9pP/VVGk u/n/VrWstokMPQKsnJRjN2pWHa9lA4UE3Th949i1RqPVyVg5Wow5vFsKgZts/TBgQCRj mB4b9dU/JGCLgYIkGWf3Pcy4o/bCXY92Eto5ZNb8Z4iFbtQr9p/knfFnrL5XwpLiUfw8 +3CObS83kdXEVqqcWG/g8GgUNslJBXoaHLyASaN9//jMmhyH5HYEAwbfBBQT0OeWY5xI +/Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3zNN3wcgN+vd2wpUDCMnqQdDRuWeI+hRUZA1kdW/gBw=; b=ft5VJKP0JFmKLP6BoOcDQ2e624Mhz0xPIFdQR4Z68WAodVNizsu8E3QuscZld28Eyf oZrW3h3hZM/MPLy4iT5Ll+wtBagSXu9jQHz9JjsjkGaTva6W1y4cg8c1Dgsf0/9+NTZK qyuKieE50WbJLxYRZ1KeKyMtnUYUyY9RhjoT0SJGXK32yQ2g0bq3vlRD3qLDyebDx4oE cilB1bV53t1PXGTxyDnic/C6+JH0aCPMdBFGwYjydHovZS1aHHz6DIDfFnMEd8YZYUyL DIN+jhv3Z5CK+xb4ay+skl9XQBJ5GpvnU/KmX+ANuLXQp8c3Pm7UcSr1xTeShwrqzjPm Yi4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=s0yX+1Ts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a056402278600b0044f2bdfc098si587510ede.532.2022.09.07.09.42.36; Wed, 07 Sep 2022 09:43:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=s0yX+1Ts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbiIGQSu (ORCPT + 99 others); Wed, 7 Sep 2022 12:18:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229682AbiIGQSr (ORCPT ); Wed, 7 Sep 2022 12:18:47 -0400 Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F72AA0334 for ; Wed, 7 Sep 2022 09:18:45 -0700 (PDT) Received: by mail-io1-xd35.google.com with SMTP id r141so11895922iod.4 for ; Wed, 07 Sep 2022 09:18:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=3zNN3wcgN+vd2wpUDCMnqQdDRuWeI+hRUZA1kdW/gBw=; b=s0yX+1Tsw+LGKp/WuH2QNVA6JtpdWfgnp9Uv9TymdUg3eW6kR5/FzIEuoPu5nQqteo w1kMgFQCG2O8ecgqQAEr7t1EsDpVGp2NzdD8btlZStwFyOSIDGMGy7tLEAGxnkenlWtR iOryB9grGozUoWHC8y64+2QMmDxLcb85zFbjBN5bsFfo6+N7Tnwsol5N6TdWXm3MfTNk X2roSYWVOvaBCQfT3bAWemt9UpSTzGFTAvxce+5EdHyzvJALBBOZ0PsFY50SfpISGrKw FQxa+c0r9N5De2B994r220T/VGxDcdpux7x5pc6svCDXkMsoxZqm2ApGffdpT2SXse2U +UQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=3zNN3wcgN+vd2wpUDCMnqQdDRuWeI+hRUZA1kdW/gBw=; b=ZadmS086g6xDyE39IsNwc/sPnIkBIDl6kJ4zYpAm4q0hONRC7EiTf2ZrNhplnfu2J+ 2vXhE9s6lwVuD42+eRd/8OhUEIUZtMjWnsV/GV4Pnxc0GaH6XnPmJwaKAbDDgbNAoItR XNKhNkwrXNr/d6Czd3xkdQr6eNuWEglvoHBvyvOsHGaIFEcm8IexUN+06bEPQ2o0t7Ka 7+dKhYGAneZvY8gc33CgaewTfVslzFVq1QsvQHPQ3/QmhQrT2CYaCQFgbHRS0KTi0GpV 0lbuAdTbIji1E8l8ktcexI+hkbr9dzl6JEdSsi/6QGVdyBH4y7bly2926SsBSChGUbNw ZGYA== X-Gm-Message-State: ACgBeo0t/ZTZTIXZoItrrFIjoCYHnr1hBxrR8Kp7uizOfG+HyREA+TZm c2Od/eAfHSgtxJfzhTnDiMwhCtJt1qs2T0TmLLSJJ5b6d8t5ig== X-Received: by 2002:a05:6638:2042:b0:346:e51a:da4e with SMTP id t2-20020a056638204200b00346e51ada4emr2539678jaj.164.1662567524331; Wed, 07 Sep 2022 09:18:44 -0700 (PDT) MIME-Version: 1.0 References: <20220907101204.255213-1-luwei32@huawei.com> In-Reply-To: <20220907101204.255213-1-luwei32@huawei.com> From: Eric Dumazet Date: Wed, 7 Sep 2022 09:18:33 -0700 Message-ID: Subject: Re: [PATCH net] ipvlan: Fix out-of-bound bugs caused by unset skb->mac_header To: Lu Wei Cc: David Miller , Jakub Kicinski , Paolo Abeni , vulab@iscas.ac.cn, Mahesh Bandewar , netdev , LKML Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 7, 2022 at 3:09 AM Lu Wei wrote: > > If an AF_PACKET socket is used to send packets through ipvlan and the > default xmit function of the AF_PACKET socket is changed from > dev_queue_xmit() to packet_direct_xmit() via setsockopt() with the option > name of PACKET_QDISC_BYPASS, the skb->mac_header may not be reset and > remains as the initial value of 65535, this may trigger slab-out-of-bounds > bugs as following: > > ================================================================= > UG: KASAN: slab-out-of-bounds in ipvlan_xmit_mode_l2+0xdb/0x330 [ipvlan] > > Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.") > Signed-off-by: Lu Wei > --- This was on my TODO list, I had a similar KASAN report, after my recent addition in skb_mac_header() DEBUG_NET_WARN_ON_ONCE(!skb_mac_header_was_set(skb)); Reviewed-by: Eric Dumazet WARNING: CPU: 1 PID: 14752 at include/linux/skbuff.h:2821 skb_mac_header include/linux/skbuff.h:2821 [inline] WARNING: CPU: 1 PID: 14752 at include/linux/skbuff.h:2821 eth_hdr include/linux/if_ether.h:24 [inline] WARNING: CPU: 1 PID: 14752 at include/linux/skbuff.h:2821 ipvlan_xmit_mode_l2 drivers/net/ipvlan/ipvlan_core.c:592 [inline] WARNING: CPU: 1 PID: 14752 at include/linux/skbuff.h:2821 ipvlan_queue_xmit+0xcba/0x19d0 drivers/net/ipvlan/ipvlan_core.c:644 Modules linked in: CPU: 1 PID: 14752 Comm: syz-executor.4 Not tainted 6.0.0-rc3-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/22/2022 RIP: 0010:skb_mac_header include/linux/skbuff.h:2821 [inline] RIP: 0010:eth_hdr include/linux/if_ether.h:24 [inline] RIP: 0010:ipvlan_xmit_mode_l2 drivers/net/ipvlan/ipvlan_core.c:592 [inline] RIP: 0010:ipvlan_queue_xmit+0xcba/0x19d0 drivers/net/ipvlan/ipvlan_core.c:644 Code: 41 0f b7 d6 48 c7 c6 40 c7 75 8a 48 c7 c7 c0 c4 75 8a c6 05 7d 52 d9 08 01 e8 df 0d 4a 04 0f 0b e9 e5 f7 ff ff e8 66 cb 8b fc <0f> 0b e9 ac f8 ff ff e8 6a 35 d8 fc e9 ed f4 ff ff e8 70 35 d8 fc RSP: 0018:ffffc900069b7808 EFLAGS: 00010293 RAX: 0000000000000000 RBX: ffff8880456ea000 RCX: 0000000000000000 RDX: ffff8880214c5880 RSI: ffffffff84f03eca RDI: 0000000000000003 RBP: ffffc900069b79b8 R08: 0000000000000003 R09: 000000000000ffff R10: 000000000000ffff R11: 0000000000000000 R12: ffff888075d62140 R13: 1ffff92000d36f06 R14: 000000000000ffff R15: ffff8880456eaca0 FS: 00007f2302712700(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f23005fe718 CR3: 000000001f461000 CR4: 00000000003506e0 Call Trace: ipvlan_start_xmit+0x45/0x150 drivers/net/ipvlan/ipvlan_main.c:220 __netdev_start_xmit include/linux/netdevice.h:4819 [inline] netdev_start_xmit include/linux/netdevice.h:4833 [inline] __dev_direct_xmit+0x500/0x720 net/core/dev.c:4312 dev_direct_xmit include/linux/netdevice.h:3021 [inline] packet_direct_xmit+0x1b3/0x2c0 net/packet/af_packet.c:282 packet_snd net/packet/af_packet.c:3073 [inline] packet_sendmsg+0x3354/0x5500 net/packet/af_packet.c:3104 sock_sendmsg_nosec net/socket.c:714 [inline] sock_sendmsg+0xcf/0x120 net/socket.c:734 __sys_sendto+0x236/0x340 net/socket.c:2117 __do_sys_sendto net/socket.c:2129 [inline] __se_sys_sendto net/socket.c:2125 [inline] __x64_sys_sendto+0xdd/0x1b0 net/socket.c:2125 do_syscall_x64 arch/x86/entry/common.c:50 [inline] do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 entry_SYSCALL_64_after_hwframe+0x63/0xcd RIP: 0033:0x7f2301689279 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f2302712168 EFLAGS: 00000246 ORIG_RAX: 000000000000002c RAX: ffffffffffffffda RBX: 00007f230179c120 RCX: 00007f2301689279 RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000003 RBP: 00007f23016e3189 R08: 00000000200000c0 R09: 0000000000000014 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f2301ccfb1f R14: 00007f2302712300 R15: 0000000000022000