Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp334340rwb; Thu, 1 Dec 2022 02:51:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf5rQrlC68FfxpL3TeZZYNSlN3gVgtB3Xc2AA0By38TMFOV5vVnofhASqvUsqYowDHOqlENL X-Received: by 2002:a05:6a00:808:b0:575:41a4:ba52 with SMTP id m8-20020a056a00080800b0057541a4ba52mr18203444pfk.75.1669891879170; Thu, 01 Dec 2022 02:51:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669891879; cv=none; d=google.com; s=arc-20160816; b=soBaMzhjJzKTvkRclWWWqJgSaOYDRj3k1Oop/m1GZ4/gkzd8YKK14my939wef4uNHc h7hDGoBGNpf/qFmHcnrpvdh69/xrCaAtgGl9bm/va3itDiqnpBbD5JTfLiKdUouknKRJ OcBtIigcJlNLDaHGPZRT1Qz/E7G79ODAM/N3f5XQwATz4F1LR44XbLwl77rs9MQh4nd1 WUYh0uIkVnmJHX22B+VD/r7APOK6Z8+UJqKPpbdJXNRmObzfV98sqGB6aMYe++ZpEfYl 77OK4na93DFezutAMM8HvfFMpu1ARLxKT2uwDs9XvG1Fydr7bAU1RkszYAbMYs8M+GPC xPZA== 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:cc:to:from:subject :message-id:dkim-signature; bh=bmBnBm4vsYyGCCu3ovFDuG2h1IVfzb0MiBStdNV5Cdw=; b=OQ8ADIJhncB0gdjllEZLqWjb3pcm+gmAEhJfN6l/mQbEr/8LIhYMIWWX3/CHD6yWfv LZUDgDxQiIZcRx5TyCqnKn9vZWMJCwU1o2f8Vs1Z9ksM2h+c0JTJBXyWKe4G+9SToF9b 0ERuiXI7QgVRQ1NeGOnexEo3iz6kNPPLgRjFrXTUI9IQ6VLjFKrQoJeiuVvNwgjfSgb1 IeVVs6uJ/bvmxuq+QK7ohGlyCqhI1Pi3ocbQhEOI0wivCdhShosMBHtgWtk0qvwuN3Xg iL31qXEfPWsgBlPN4N584inC7wxCPaeU3Zy/uSpOjE985wAfzm/4DKOYv6BIj8PW8Veh 4F9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ggbibyN8; 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 k7-20020a056a00168700b005747a147929si4679598pfc.21.2022.12.01.02.51.08; Thu, 01 Dec 2022 02:51:19 -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=ggbibyN8; 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 S229840AbiLAKZi (ORCPT + 83 others); Thu, 1 Dec 2022 05:25:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbiLAKZW (ORCPT ); Thu, 1 Dec 2022 05:25:22 -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 BEF8A5AE1C for ; Thu, 1 Dec 2022 02:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669890264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmBnBm4vsYyGCCu3ovFDuG2h1IVfzb0MiBStdNV5Cdw=; b=ggbibyN856NQk8CZgiGmvGYmCMt6SMRY+R9a2f1Nvpququ1+9I6XykH+8f7pUwkVP05ew8 mEXx7mi8JurHxTt9IN/xh/JWKQTiMfMPe6YmLSRUHRteDWN0louiegHzX0j2vlRPvB6U8z w9Bnh48sQQ+PcrwOvPA+rmJQr5kWuAw= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-589--XmCby0yPMW2vJTVMHI-6A-1; Thu, 01 Dec 2022 05:24:23 -0500 X-MC-Unique: -XmCby0yPMW2vJTVMHI-6A-1 Received: by mail-qv1-f72.google.com with SMTP id nk7-20020a056214350700b004c68c912c93so3776775qvb.16 for ; Thu, 01 Dec 2022 02:24:22 -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:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bmBnBm4vsYyGCCu3ovFDuG2h1IVfzb0MiBStdNV5Cdw=; b=MKaWra1talTvBmrCnfl92qlkISDEVzGYk6Ye4Rxa+eylkcpF5cRjVS5ei39XETf2tF 9ypQ4Xwn58/19x/xAl47ARhSPg4Bn9XRqfdjn+/MgWkZrHi3k0nMdBK92EXeIFAPxTq/ 8t4C5oyL4zkSzibVFgBdquqjrmISwgAxyorAFTRlLGQSWvH5n6p5bXp0qGnacXe4jSzh bzp7BYhQaIDI09VIJHRbg8juXzUxKFPrKMUIHjxwvcl2oQhRtKhwnOd+5ArMaHdS85nG F8GPD/neiF81s1rtK8GlGCPlHXiHLer/wTHroDYjZ8ZDdtehVWbd/p+YqHz3fRoGM5cg UVhQ== X-Gm-Message-State: ANoB5pluc5Cp0X/sLr69nDYBNLqeZ9XJ2/I++l04cQu0wEeYbgRH4mj3 twCYPBf4f7gzJYK5RmihbPn/9TtbSpZo++GlthMa7OTuMOw7wMCNPrcF6I8u2QOTKq700I8vdZO Jv4mk33VtfsuE0JirJ1J4D04n X-Received: by 2002:ac8:48d1:0:b0:3a5:c86a:aa46 with SMTP id l17-20020ac848d1000000b003a5c86aaa46mr43891819qtr.534.1669890262346; Thu, 01 Dec 2022 02:24:22 -0800 (PST) X-Received: by 2002:ac8:48d1:0:b0:3a5:c86a:aa46 with SMTP id l17-20020ac848d1000000b003a5c86aaa46mr43891791qtr.534.1669890262052; Thu, 01 Dec 2022 02:24:22 -0800 (PST) Received: from gerbillo.redhat.com (146-241-120-203.dyn.eolo.it. [146.241.120.203]) by smtp.gmail.com with ESMTPSA id s18-20020a05620a29d200b006fba0a389a4sm3309399qkp.88.2022.12.01.02.24.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 02:24:21 -0800 (PST) Message-ID: Subject: Re: [PATCH v3] net: sched: fix memory leak in tcindex_set_parms From: Paolo Abeni To: Hawkins Jiawei , Jamal Hadi Salim , Cong Wang , Jiri Pirko , "David S. Miller" , Eric Dumazet , Jakub Kicinski Cc: 18801353760@163.com, syzbot+232ebdbd36706c965ebf@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, Cong Wang , Dmitry Vyukov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Date: Thu, 01 Dec 2022 11:24:17 +0100 In-Reply-To: <20221129025249.463833-1-yin31149@gmail.com> References: <20221129025249.463833-1-yin31149@gmail.com> 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: 7bit 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 Tue, 2022-11-29 at 10:52 +0800, Hawkins Jiawei wrote: > Syzkaller reports a memory leak as follows: > ==================================== > BUG: memory leak > unreferenced object 0xffff88810c287f00 (size 256): > comm "syz-executor105", pid 3600, jiffies 4294943292 (age 12.990s) > hex dump (first 32 bytes): > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > backtrace: > [] kmalloc_trace+0x20/0x90 mm/slab_common.c:1046 > [] kmalloc include/linux/slab.h:576 [inline] > [] kmalloc_array include/linux/slab.h:627 [inline] > [] kcalloc include/linux/slab.h:659 [inline] > [] tcf_exts_init include/net/pkt_cls.h:250 [inline] > [] tcindex_set_parms+0xa7/0xbe0 net/sched/cls_tcindex.c:342 > [] tcindex_change+0xdf/0x120 net/sched/cls_tcindex.c:553 > [] tc_new_tfilter+0x4f2/0x1100 net/sched/cls_api.c:2147 > [] rtnetlink_rcv_msg+0x4dc/0x5d0 net/core/rtnetlink.c:6082 > [] netlink_rcv_skb+0x87/0x1d0 net/netlink/af_netlink.c:2540 > [] netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline] > [] netlink_unicast+0x397/0x4c0 net/netlink/af_netlink.c:1345 > [] netlink_sendmsg+0x396/0x710 net/netlink/af_netlink.c:1921 > [] sock_sendmsg_nosec net/socket.c:714 [inline] > [] sock_sendmsg+0x56/0x80 net/socket.c:734 > [] ____sys_sendmsg+0x178/0x410 net/socket.c:2482 > [] ___sys_sendmsg+0xa8/0x110 net/socket.c:2536 > [] __sys_sendmmsg+0x105/0x330 net/socket.c:2622 > [] __do_sys_sendmmsg net/socket.c:2651 [inline] > [] __se_sys_sendmmsg net/socket.c:2648 [inline] > [] __x64_sys_sendmmsg+0x24/0x30 net/socket.c:2648 > [] 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 > ==================================== > > Kernel uses tcindex_change() to change an existing > filter properties. During the process of changing, > kernel uses tcindex_alloc_perfect_hash() to newly > allocate filter results, uses tcindex_filter_result_init() > to clear the old filter result. > > Yet the problem is that, kernel clears the old > filter result, without destroying its tcf_exts structure, > which triggers the above memory leak. > > Considering that there already extis a tc_filter_wq workqueue > to destroy the old tcindex_data by tcindex_partial_destroy_work() > at the end of tcindex_set_parms(), this patch solves this memory > leak bug by removing this old filter result clearing part, > and delegating it to the tc_filter_wq workqueue. > > [Thanks to the suggestion from Jakub Kicinski, Cong Wang, Paolo Abeni > and Dmitry Vyukov] > > Fixes: b9a24bb76bf6 ("net_sched: properly handle failure case of tcf_exts_init()") > Link: https://lore.kernel.org/all/0000000000001de5c505ebc9ec59@google.com/ > Reported-by: syzbot+232ebdbd36706c965ebf@syzkaller.appspotmail.com > Tested-by: syzbot+232ebdbd36706c965ebf@syzkaller.appspotmail.com > Cc: Cong Wang > Cc: Jakub Kicinski > Cc: Paolo Abeni > Cc: Dmitry Vyukov > Signed-off-by: Hawkins Jiawei The patch looks correct to me, but we are very late in this release cycle, and I fear there is a chance of introducing some regression. The issue addressed here is present since quite some time, I suggest to postpone this fix to the beginning of the next release cycle. Please, repost this patch after that 6.1 is released, thanks! (And feel free to add my Acked-by). Paolo