Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp980545rwb; Thu, 15 Dec 2022 05:08:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf6sLrnXrcMGLy/gROf/hQ17tFQ99dUd69qFUsMPEgnHGE/FpOyWcH+lYhrDbVmwg94YYxhS X-Received: by 2002:a17:902:c183:b0:189:854e:93a3 with SMTP id d3-20020a170902c18300b00189854e93a3mr27842095pld.69.1671109713413; Thu, 15 Dec 2022 05:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671109713; cv=none; d=google.com; s=arc-20160816; b=Xp6a4UZOPO2LlttysFB0lcbzWixJ3a8bUbfM/2w4k50IVOUlG95vIirJVZ4sN+h55r 4awVeIqCe9jIioMRqEvten2wXHGZgTCpDuEYkbvl1YRN/sy/jDtSZiSBUA4AFJoTbYck tHq5MPuAJJ+6yOeT5dcUw7Xf6UwqY/YXfl6vGShWwP/nBqhguIuPabAPyi6o032R+7MB qHgaPoMaO7gAXPmcUTQnMmFmH7//C2gN9WeQb7sI5ZvkED0hcO27qtQ99Wx3vxTfRQNa wC/kN3lVMwRBdIAqrZ9YNIMYvT0iH4BDI+yzT/IzSDdyTxrI18hN9ZXH5tlvCkmXmcZ8 pTaw== 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 :user-agent:references:in-reply-to:date:to:from:subject:message-id :dkim-signature; bh=aBno//7WjcOWMRUrIz42bHzL1ShN20yQGU3sgB16aK0=; b=zWRve7sXUhQlVIogWRUVL6BQDaVboT9IzGshDPr/bDzM+vnmok2W1DCDsksCnULFH1 jIhlKvwwH7XQOl713j4iKmZTc1m+Sv6ENUODJc8xzeRRAYEyZ1NZo1hyM82T4O51YUmL UMPBBP87gqAuNF7ymFeLpd0fF4OshLjfEcsFTCOqiQ8h5ZuxSzvZkTJSEZUmocKMhb/q zhrbKDWPAggK43DuqPmVmoDlhscHq4pkgGgQjspiRoq4snYyJey7ZNbe47Dpmsfimhz7 ts8KvD1H4YZS1YP9g+2x63ek5s3zTWtcDbGqpjrxGMEkVfmM65hJlP54zQp6oyYGPd7p qOfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hm3a1jIo; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h17-20020a170902f55100b0017bcea4e6b6si6448064plf.234.2022.12.15.05.08.24; Thu, 15 Dec 2022 05:08:33 -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=@redhat.com header.s=mimecast20190719 header.b=hm3a1jIo; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229596AbiLOMve (ORCPT + 68 others); Thu, 15 Dec 2022 07:51:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbiLOMvc (ORCPT ); Thu, 15 Dec 2022 07:51:32 -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 13DE323E8C for ; Thu, 15 Dec 2022 04:50:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671108651; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aBno//7WjcOWMRUrIz42bHzL1ShN20yQGU3sgB16aK0=; b=hm3a1jIoN/TuLd2bVkwLiB45xa773vyfUljIfBeH1N5cwNGgJ+gJWoWKGAptw32S+oX93S x7d/hVcUeBzKwXcNLZ+v/5i4XJUhwA0qTu4Yi6o53x+gy6l/WT8PkUXc7OIbgrBMqV1lTc h1pPTjgh4LlMvftUNsd0RgPefo282qI= Received: from mail-vk1-f198.google.com (mail-vk1-f198.google.com [209.85.221.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-15-7nkxPHfXPDuZ7kTC2XxFUA-1; Thu, 15 Dec 2022 07:50:50 -0500 X-MC-Unique: 7nkxPHfXPDuZ7kTC2XxFUA-1 Received: by mail-vk1-f198.google.com with SMTP id n20-20020a1fa414000000b003bc585c7d50so3602665vke.16 for ; Thu, 15 Dec 2022 04:50:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=aBno//7WjcOWMRUrIz42bHzL1ShN20yQGU3sgB16aK0=; b=05nUUOWV7yq6JtdxUx3BZ2kFL/fGjc/t8pWw3Yn8TGSuhpatq26fwYtL8rx+LNssjU yO1PJe37R/vBqQ5CZDyyU6YF1YqiPpoDR9Lmx3o0UBF9wqFrvwPjjaTmZvgoqDIWO+xK t6c25bCOfeJHxm2qJ5YBmh/SWQ1RItewlNjS7Fuha16oR/LOUGptJ5Bal4xONvXIhOCg y6ByDQdMwAjrCTliXvV9zy2Q63HtPQW8mVlFfT89X2rTFaPd/giJG0ym63Pd3TzkOXfa RBRpIPGGNcikefJikvR3n2CnjCdCJS490Y3m6H9n0voYeOFnqrevhpAp+5uhq8ctYLrN F2yg== X-Gm-Message-State: AFqh2krW4BCKriUofUtdKDwmT9XwLsWxYOihzXfoaSj7OkO8z2ic/M9+ aysa1Okj6K/qQb/H4oYNIaorSN6VsXU+zlSVUUFM2EUROmRnPmxMGGBOLrJkX26YVU759iI6rBp zmz7eHcG5sDsa0bUp57APCjr3 X-Received: by 2002:a05:6122:45d:b0:3c6:bdf4:6959 with SMTP id f29-20020a056122045d00b003c6bdf46959mr548677vkk.10.1671108649496; Thu, 15 Dec 2022 04:50:49 -0800 (PST) X-Received: by 2002:a05:6122:45d:b0:3c6:bdf4:6959 with SMTP id f29-20020a056122045d00b003c6bdf46959mr548583vkk.10.1671108647752; Thu, 15 Dec 2022 04:50:47 -0800 (PST) Received: from gerbillo.redhat.com (146-241-97-87.dyn.eolo.it. [146.241.97.87]) by smtp.gmail.com with ESMTPSA id do39-20020a05620a2b2700b006fcc3858044sm11916151qkb.86.2022.12.15.04.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 04:50:47 -0800 (PST) Message-ID: Subject: Re: [PATCH net v2] net: sched: ematch: reject invalid data From: Paolo Abeni To: Jun Nie , 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 Date: Thu, 15 Dec 2022 13:50:43 +0100 In-Reply-To: <20221214022058.3625300-1-jun.nie@linaro.org> References: <20221214022058.3625300-1-jun.nie@linaro.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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, 2022-12-14 at 10:20 +0800, Jun Nie wrote: > syzbot reported below bug. Refuse to compare for invalid data case to fix > it. > > general protection fault, probably for non-canonical address 0xdffffc0000000001: 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-g7048384c9872 #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:175 > 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 = (struct tcf_em_cmp *) em->data; > - unsigned char *ptr = tcf_get_base_ptr(skb, cmp->layer) + cmp->off; > + unsigned char *ptr; > u32 val = 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