Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2215959yba; Mon, 22 Apr 2019 02:37:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxt4zN05nsrxsIAiwGvCYal1ZbVLRfoJS/ub/uE37WOtXV+IQv5hPhqJN+PHw0AI49OViVv X-Received: by 2002:a17:902:4101:: with SMTP id e1mr19724345pld.25.1555925857339; Mon, 22 Apr 2019 02:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555925857; cv=none; d=google.com; s=arc-20160816; b=gsKapadyOXWvVfXbNEuyDVFOdliiajmXfukDHxUoCmpA5EhWhv2RyyHosC4PgEuDn1 Yyiep/+8Vanqw2SSxToLKMdG+KhllZrenXKxph26umSiVZbyH5vs3EMXRN3KOlJFzhhD p45CvtWbBkhV5VHCH5T9JgRSX22F0lZtsReFn+x2dT6dPWjlcYQUuzagXA6l3BxMEQ5i YkPNxu3SLB4VefFyQC3pCaF4l7kLTmryCcUVY/VXDM2ZuUbkboNKT7JiW0cAhwd8Qlzm ao1LyeggusXLY8omnwab8n0wuK7uJzm/9H9D3HttERP6/2Pg1bWwcHHu6lTuqipbwx3H YWHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+i0U2zR4ZRRqoYihLPsfGsnjBLtlVFwy2BZSFopCOvQ=; b=juStyvvb4rYtKJKQfrt010kR05NIUZUUvSEqw3gugPwCQ6RXMeeYiSnQr2vsFzqInX XYO7ANMs/FgwTZWIT8jEqkWl35PHGoGHM99zXf4n533A7AaZlsltyp+hzQjSG/1wvCJ+ APssVxi1TZbm9cZ7+tEcihfNuEnUNLmniPNw+LyLudiMm4Mb3/Lcgzn2CRTCX/KlnZyc qguUljbmoZ+U8qYAmt04oWCX2B3e2IByw1gnuv4Xzf1ht1TXccvnOQbtItZ4viReR+p4 DjDpu6njxzVP/6D1wRvA5QWuOGNRpXZao6nnZ0BVxJX75Q8qpSTDdRmUJd98tGXcfMaL U9MA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t10si12737123plr.229.2019.04.22.02.37.22; Mon, 22 Apr 2019 02:37:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727263AbfDVJfP (ORCPT + 99 others); Mon, 22 Apr 2019 05:35:15 -0400 Received: from Chamillionaire.breakpoint.cc ([146.0.238.67]:50622 "EHLO Chamillionaire.breakpoint.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726172AbfDVJfN (ORCPT ); Mon, 22 Apr 2019 05:35:13 -0400 Received: from fw by Chamillionaire.breakpoint.cc with local (Exim 4.89) (envelope-from ) id 1hIVLq-0008UF-HP; Mon, 22 Apr 2019 11:35:02 +0200 Date: Mon, 22 Apr 2019 11:35:02 +0200 From: Florian Westphal To: Rundong Ge Cc: Pablo Neira Ayuso , kadlec@blackhole.kfki.hu, fw@strlen.de, Roopa Prabhu , davem@davemloft.net, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] netfilter: fix dangling pointer access of fake_rtable Message-ID: <20190422093502.36da6z3qf7zxpwny@breakpoint.cc> References: <20190409065612.32652-1-rdong.ge@gmail.com> <20190422083339.ptkxqb66pombgy5g@salvia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rundong Ge wrote: > br_nf_pre_routing will call the NF_INET_PRE_ROUTING hooks, at this > time both entry->state.in and entry->state.out are not bridge device. > > NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, state->net, state->sk, skb, > skb->dev, NULL, > br_nf_pre_routing_finish); skb->dev is munged in setup_prerouting() to be bridge or vlan device on top of bridge. That being said, I think we need this fix at least: diff --git a/net/netfilter/nf_queue.c b/net/netfilter/nf_queue.c --- a/net/netfilter/nf_queue.c +++ b/net/netfilter/nf_queue.c @@ -197,8 +197,15 @@ static int __nf_queue(struct sk_buff *skb, const struct nf_hook_state *state, .size = sizeof(*entry) + route_key_size, }; + if (skb_dst(skb)) { + skb_dst_force(skb); + if (!skb_dst(skb)) { + status = -EHOSTUNREACH; + goto err; + } + } + nf_queue_entry_get_refs(entry); - skb_dst_force(skb); switch (entry->state.pf) { case AF_INET: Then, why not add, in dev_cmp: dst = skb_dst(skb); if (dst && dst->dev->index == index ... ?