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=-1.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS 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 51AC4C43381 for ; Thu, 7 Mar 2019 13:56:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22B502081B for ; Thu, 7 Mar 2019 13:56:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726194AbfCGN4v (ORCPT ); Thu, 7 Mar 2019 08:56:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57300 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726120AbfCGN4v (ORCPT ); Thu, 7 Mar 2019 08:56:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C23B630EBE74; Thu, 7 Mar 2019 13:56:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.32.181.77]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D4B35C1B5; Thu, 7 Mar 2019 13:56:48 +0000 (UTC) Message-ID: Subject: Re: [PATCH net 03/16] net/sched: act_csum: validate the control action inside init() From: Davide Caratti To: Cong Wang Cc: "David S. Miller" , Jamal Hadi Salim , Jiri Pirko , Vlad Buslov , Paolo Abeni , Linux Kernel Network Developers In-Reply-To: References: <81d683a7b6ea12e69cb9954b9bad84a9d2a2520f.camel@redhat.com> Organization: red hat Content-Type: text/plain; charset="UTF-8" Date: Thu, 07 Mar 2019 14:56:47 +0100 Mime-Version: 1.0 User-Agent: Evolution 3.30.3 (3.30.3-1.fc29) Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 07 Mar 2019 13:56:51 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri, 2019-03-01 at 16:04 -0800, Cong Wang wrote: > > On Fri, Mar 1, 2019 at 10:02 AM Davide Caratti wrote: > > > > if I well understand the question, you are worried about > > tcf_action_goto_chain_exec(), that can dereference 'oldchain' while we are > > overwriting the action. A call to tcf_chain_put_by_act(oldchain) would > > decrease refcounts and eventually call kfree(oldchain). > > > > But this would result in a use-after-free only in case the chain has only > > refcount held by 1 action (the one we are overwriting), and 0 filters: is > > this a condition where packets can go through this action's data plane? > > Hmm? Isn't goto chain can be arbitrary? Packets can be routed > from this action to any filter chain, so even if the target chain has 0 > filter this action still has traffic as long as itself is not on the same > chain? hi, sorry for the delay: it took some time to verify experimentally if we really need this or not. So, we want to ensure the control path doesn't do tcf_csum_init(..., ovr=1, ...) tcf_chain_put_by_act(oldchain) tcf_chain_destroy(oldchain, ...) kfree(oldchain); while the traffic path of the action is doing res->goto_tp = rcu_dereference_bh(oldchain->filter_chain); I iterated this script many times on a KASAN kernel, # tc chain add dev crash0 chain 42 ingress protocol ip flower ip_proto udp action pass # tc filter add dev crash0 ingress protocol ip flower ip_proto udp action csum udp goto chain 42 index 66 # tc chain del dev crash0 chain 42 ingress (start netperf traffic) # tc action replace action csum udp pass index 66 and reproduced twice the following splat: ================================================================== BUG: KASAN: null-ptr-deref in tcf_action_exec+0x181/0x200 Read of size 8 at addr 0000000000000000 by task netperf/5777 CPU: 0 PID: 5777 Comm: netperf Not tainted 5.0.0-rc7.goto_chain_fix+ #551 Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 Call Trace: dump_stack+0xc7/0x15b ? show_regs_print_info+0x5/0x5 ? _raw_read_lock_irq+0x40/0x40 ? tcf_action_exec+0x181/0x200 ? tcf_action_exec+0x181/0x200 kasan_report+0x176/0x192 ? tcf_action_exec+0x181/0x200 tcf_action_exec+0x181/0x200 ? find_dump_kind+0x170/0x170 ? rcu_irq_exit+0x153/0x210 fl_classify+0x81a/0x830 so, I think that the answer to your question: On Wed, 2019-02-27 at 17:50 -0800, Cong Wang wrote: > > > > + if (oldchain) > > > > + tcf_chain_put_by_act(oldchain); > > > > > > Do we need to respect RCU grace period here? is a "yes, we do". Now I'm trying something similar to what's done in tcf_bpf_init(), to release the bpf program on 'replace' operations: 365 if (res == ACT_P_CREATED) { 366 tcf_idr_insert(tn, *act); 367 } else { 368 /* make sure the program being replaced is no longer executing */ 369 synchronize_rcu(); 370 tcf_bpf_cfg_cleanup(&old); 371 } do you think it's worth going in this direction? thank you in advance! -- davide