Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1127578rwb; Thu, 15 Dec 2022 06:46:30 -0800 (PST) X-Google-Smtp-Source: AA0mqf5N+WuEILJB3FV2ZnVwNLmqPRVJfl5WY4Jxuhq0AsKCN/62qEr8vtpSrv2Ne9evoCb2N6XC X-Received: by 2002:a17:903:1d0:b0:188:f5de:891f with SMTP id e16-20020a17090301d000b00188f5de891fmr37997178plh.11.1671115589881; Thu, 15 Dec 2022 06:46:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671115589; cv=none; d=google.com; s=arc-20160816; b=rjuB8jf6S1pJ9qqYw6Yv9PZlgOA6BFR8ZMOtotQi6NKhmfPTd6V1OJ3r9a8CQbVAbT iL3k8SOxaGQRuqrPA67qU8hAFagwPYaF7yws8BoE7oUPzh/tJPNP0SBOnfa7UCQxGqJT oO/hqhm3nIOZK56FCJFkwU5waXpnIaj/0XTfKgLMqQ2Kf0Zyb1vuiWxS5Zb5TLk3dWCb LbhHpa7juic1B1Qz3OAcuOhncJKwN7nIn3DrHdaf52f0HquStIeovcawKFdgDGnlfBDi oBZ4kdDHrBiCB6NcXb0vTG/k+fPHzmFZsKSTZu6ZPESjSDAeNtbs1wjj4zm+MLOk18E/ 9hlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=c0ZeZrgSVWHTcIpRsB0S0g4iAzmT0ygD3nkVTl3/R7o=; b=XuzKv2DzMAQAuNJrygiBLf9a6IVjmxR7dvgbtcp6lBbH03djzXe2OW2HU9BSc2vB2P NTFLEsToH6geCjD7V8RCMRu2oecdz9NzUzK+kdiiurYQlSFbVmXuTIGjZ3dxSRCI4ozT YlmREkPiUyqtCMlJT5cMTLwcMIR+psJE+CwBsrIXiTcj3LMiqpYrbDfhVEUeQ6y3HKXT ezcPuSdNAhR72vyZieVbt5RdTVnbbuSDmq1MrS98OUI9fdyyPioSNaMOCg9bv5pmRYJo bCBWwlboXxd0TbvH2npHldEzlkoLMQxUsZfQyDEtBLdwWlwuh3CX7ZFZEBza6p9HO00s FnmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oE1vDLoQ; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg12-20020a17090326cc00b0017dcda20fefsi5602477plb.232.2022.12.15.06.46.21; Thu, 15 Dec 2022 06:46:29 -0800 (PST) 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=@linaro.org header.s=google header.b=oE1vDLoQ; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229731AbiLON72 (ORCPT + 68 others); Thu, 15 Dec 2022 08:59:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229964AbiLON7M (ORCPT ); Thu, 15 Dec 2022 08:59:12 -0500 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DABF2FBF5 for ; Thu, 15 Dec 2022 05:59:11 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id g14so9970013ljh.10 for ; Thu, 15 Dec 2022 05:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=c0ZeZrgSVWHTcIpRsB0S0g4iAzmT0ygD3nkVTl3/R7o=; b=oE1vDLoQyL8C7RmGbteghPvnTtN6f2g55eK9T9ekTRj00Vlzw8iPpSCD8cr3iofpE+ WKmQsU3IM5/ybZ0a1oJCj09Yms4JjyCIwABTcpX9d7U+hnYtOH12sjQuzXA3IPErcBUB imKpzn2HvVydR/VyHLS3rO5vM4wvr9qCoolTYDVA0wpPuqL/VYKIgqlgqzzp+Q0wlL+3 ob5m051OIuXKoOeI/AK9ZCve/efarmrOskzR4WBQ8OTDkqGEU/uFTFNwWQp04zInSHMH Uk3AFasWDXO8HtqE5wgMqSbqcwxyF/Wd9sjwRUFWKfIO5lVyoIiwNlGuJ9qBPwxMyDM3 WSvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c0ZeZrgSVWHTcIpRsB0S0g4iAzmT0ygD3nkVTl3/R7o=; b=hMvxfp6kVq9APsfsTbDsKxCzvLnJHralOESXuz1E/DFHmEtMO868th7Pt88C59mbnW bNPRdGLuO7tyyz1ATVsB3XlRgAJMlb7//C9E/w3d1ji1RT51QuW3O71rgeUYIv+N5ggj oY2iMEXbQvIgpLfv2u+vIs/gf1y1xl86WaUD6qEO7eVPAbdC0+0F0aM8KgfrTkwaUKd1 3X8y8Xk0ZHU/IwfgdnzX4Lkw2xeFRMRn0i63zYjveX8bOZiCttostOFAPjCqjFMjiKIC o18Tmo3oahKIrlpwkg8nl7J+2cM81ujKprxzfd0AWUl9h4S5/oknVkTvRPvP7OP0x9+q OA/g== X-Gm-Message-State: ANoB5pl4Kq4SxiBssN70iAtbXT+v+iqf86oWFqkQPj1CWzpjuD5mjB+S 2qXM0b02YJULZEq7Uf4YcQkKDOUCvHv4jIJ9sTUUGg== X-Received: by 2002:a2e:a806:0:b0:277:4b35:d94a with SMTP id l6-20020a2ea806000000b002774b35d94amr22176731ljq.21.1671112749659; Thu, 15 Dec 2022 05:59:09 -0800 (PST) MIME-Version: 1.0 References: <20221214022058.3625300-1-jun.nie@linaro.org> In-Reply-To: From: Jun Nie Date: Thu, 15 Dec 2022 21:59:05 +0800 Message-ID: Subject: Re: [PATCH net v2] net: sched: ematch: reject invalid data To: Paolo Abeni Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Paolo Abeni =E4=BA=8E2022=E5=B9=B412=E6=9C=8815=E6=97= =A5=E5=91=A8=E5=9B=9B 20:50=E5=86=99=E9=81=93=EF=BC=9A > > On Wed, 2022-12-14 at 10:20 +0800, Jun Nie wrote: > > syzbot reported below bug. Refuse to compare for invalid data case to f= ix > > it. > > > > general protection fault, probably for non-canonical address 0xdffffc00= 00000001: 0000 [#1] PREEMPT SMP KASAN > > KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] > > CPU: 0 PID: 6 Comm: kworker/0:0 Not tainted 5.15.77-syzkaller-00764-g70= 48384c9872 #0 > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS= Google 10/26/2022 > > Workqueue: wg-crypt-wg2 wg_packet_tx_worker > > RIP: 0010:em_cmp_match+0x4e/0x5f0 net/sched/em_cmp.c:25 > > Call Trace: > > > > tcf_em_match net/sched/ematch.c:492 [inline] > > __tcf_em_tree_match+0x194/0x720 net/sched/ematch.c:518 > > tcf_em_tree_match include/net/pkt_cls.h:463 [inline] > > basic_classify+0xd8/0x250 net/sched/cls_basic.c:48 > > __tcf_classify net/sched/cls_api.c:1549 [inline] > > tcf_classify+0x161/0x430 net/sched/cls_api.c:1589 > > prio_classify net/sched/sch_prio.c:42 [inline] > > prio_enqueue+0x1d3/0x6a0 net/sched/sch_prio.c:75 > > dev_qdisc_enqueue net/core/dev.c:3792 [inline] > > __dev_xmit_skb+0x35c/0x1650 net/core/dev.c:3876 > > __dev_queue_xmit+0x8f3/0x1b50 net/core/dev.c:4193 > > dev_queue_xmit+0x17/0x20 net/core/dev.c:4261 > > neigh_hh_output include/net/neighbour.h:508 [inline] > > neigh_output include/net/neighbour.h:522 [inline] > > ip_finish_output2+0xc0f/0xf00 net/ipv4/ip_output.c:228 > > __ip_finish_output+0x163/0x370 > > ip_finish_output+0x20b/0x220 net/ipv4/ip_output.c:316 > > NF_HOOK_COND include/linux/netfilter.h:299 [inline] > > ip_output+0x1e9/0x410 net/ipv4/ip_output.c:430 > > dst_output include/net/dst.h:450 [inline] > > ip_local_out+0x92/0xb0 net/ipv4/ip_output.c:126 > > iptunnel_xmit+0x4a2/0x890 net/ipv4/ip_tunnel_core.c:82 > > udp_tunnel_xmit_skb+0x1b6/0x2c0 net/ipv4/udp_tunnel_core.c:175 > > send4+0x78d/0xd20 drivers/net/wireguard/socket.c:85 > > wg_socket_send_skb_to_peer+0xd5/0x1d0 drivers/net/wireguard/socket.c:1= 75 > > wg_packet_create_data_done drivers/net/wireguard/send.c:251 [inline] > > wg_packet_tx_worker+0x202/0x560 drivers/net/wireguard/send.c:276 > > process_one_work+0x6db/0xc00 kernel/workqueue.c:2313 > > worker_thread+0xb3e/0x1340 kernel/workqueue.c:2460 > > kthread+0x41c/0x500 kernel/kthread.c:319 > > ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:298 > > > > Reported-by: syzbot+963f7637dae8becc038f@syzkaller.appspotmail.com > > Fixes: e7096c131e51 ("net: WireGuard secure network tunnel") > > Very likely this is not the correct fixes tag. > > > Signed-off-by: Jun Nie > > --- > > net/sched/em_cmp.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/net/sched/em_cmp.c b/net/sched/em_cmp.c > > index f17b049ea530..0284394be53f 100644 > > --- a/net/sched/em_cmp.c > > +++ b/net/sched/em_cmp.c > > @@ -22,9 +22,14 @@ static int em_cmp_match(struct sk_buff *skb, struct = tcf_ematch *em, > > struct tcf_pkt_info *info) > > { > > struct tcf_em_cmp *cmp =3D (struct tcf_em_cmp *) em->data; > > - unsigned char *ptr =3D tcf_get_base_ptr(skb, cmp->layer) + cmp->o= ff; > > + unsigned char *ptr; > > u32 val =3D 0; > > > > + if (!cmp) > > + return 0; > > It feels like this is papering over the real issue. Why em->data is > NULL here? why other ematches are not afflicted by this issue? > > is em->data really NULL or some small value instead? KASAN seams to > tell it's a small value, not 0, so this patch should not avoid the > oops. Have you tested it vs the reproducer? > > Thanks, > > Paolo > The test with the reproducer[1] shows it does resolve the issue. The data is NULL so that deferring cmp can be avoided with the patch. I did not investigate why the em->data is NULL in WireGuard secure network tunnel case as I am not familiar with network stack. So you can also call this pat= ch as a workaround. [1] https://syzkaller.appspot.com/bug?id=3Dd96c4958dc8d4da11f56e18471dfc4f64d21= ef6e Regards, Jun