Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2243891yba; Mon, 22 Apr 2019 03:12:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvWw2qvv0fMB25ttiuDJZtfz8ZPJTbROJ2jdFweTH0NfajW1BlEBUrc4bjZVn2vLbGSiRE X-Received: by 2002:a63:b0b:: with SMTP id 11mr18452580pgl.445.1555927973573; Mon, 22 Apr 2019 03:12:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555927973; cv=none; d=google.com; s=arc-20160816; b=I7zxkLuIwNmzHAqM19WUp5XRk3YQSy6McabaOd9v5FwmhVoS656nBlcAkWZ7DZYRjW weFLHBxgbs5K31Ld4C5SSr4cnjAYf0XJwmyqK8CF06jkt3XLxdfIv/fzeuUMad6sxgQd 0je7T+4VTO5SMh7ZBqMiEQk9HlAyfeDmlEwYRfV9lsl5AupZKC+Dd+AUp0dBmMLLhuhV 6GtJGFznYDvbw++VOFVxpx3+O2o5RSrw2CbFC7UGpH2d/MIKtq2QFOaQIJA3ZLhSP73A BZUXQzpObvJ992xhpDEtsx2EA15xe6oW98OBbOuqg13NnuGgtDc8cBixVuZu/LQcCwtg oA2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=GS8Z05FvTre7FCsFIiOVI1Bi+GxPI+23vAvfcOwLHNA=; b=Iubv/UVyxgLK/+IHse2NEtxDP6+1yUnyFq4Y6/HsAacYQwSbCQqlzC2e/paA0o3KBi GVIXf3/dj3KDRHJ9urlyPRfGgFx2LLZmSbxHbKycsMwSPP/DwyjzwJTHoRqaBM/ru/UM 4YFw29vX+zoOln4crXdwmtUilHWGhZPoqLzEjU5wxMp4sUmMHIy4mjrljoGy5gyCoTM5 SPVKD/KgiNUR5hBfWvYbqUHtXQ6OUeTLXNr8Ght4kuIxsW0sPoN12OhAcTtX18X99tva Md7ODqyInwmIBG/35HBujiF2uvKAilWN5U2qG13m9mAooX8SzBQ7pmBgpdPeUPIDEyd/ Et6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lY+mBgoE; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e96si9800809plb.0.2019.04.22.03.12.38; Mon, 22 Apr 2019 03:12:53 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lY+mBgoE; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727170AbfDVKKU (ORCPT + 99 others); Mon, 22 Apr 2019 06:10:20 -0400 Received: from mail-vs1-f65.google.com ([209.85.217.65]:45456 "EHLO mail-vs1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726617AbfDVKKT (ORCPT ); Mon, 22 Apr 2019 06:10:19 -0400 Received: by mail-vs1-f65.google.com with SMTP id o10so5923414vsp.12; Mon, 22 Apr 2019 03:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=GS8Z05FvTre7FCsFIiOVI1Bi+GxPI+23vAvfcOwLHNA=; b=lY+mBgoE0p20JUSjcnD2UwgZE20ZrDbCZf6O5w7lOAbhpm5BUENGlPM0HFVx+DU8cq cfoVoNdDMn7QTYZDxT6AZVg28SUrzwSEj74YQeyjLsdH8hs7UPFBT20l4VAsJCaBmU/i GDjEkH6pbciPLrRtek9sSFcHnCyM8F+FM/5JpVPCEYyjpFflVKqEMMUYZbsznystj9bK TQQN0lC3qRLPZ0dkbfaAV0VTPHoopNwPC7I18P16NLZ9bbj3FHT3itsWQg774E2iiN9V Irgw0N6/0ZXV41Fmk73I54txNNBN0ll1WjnF1Muz9YYrytInP7U1fude8vkCzQbRGRYo M88Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=GS8Z05FvTre7FCsFIiOVI1Bi+GxPI+23vAvfcOwLHNA=; b=o1FEZsvTz0xjmtY5iFlet2y77G0X/MLUMdyUIZcpkJVX5V9yTfQDsnYHiAXtD5iYPU Sb35LPJYbT9WfSmX35r2xzNfBcTG3WZ4fEaF+G1siRWMsrSvJ+r1eGOFhbuPHDuIfaQz xhyAzAp2JhfrO81mMLxKNzdFqr2tOiRVNSXSzwxJfJxCMrqzcO45tYEKLzxxknCQ93j9 D6wPMWvNAanmCTFz8vCN8HmDKw6nfY3ShMHzsi00nI2wXzRgmN7QAhuYo4Gk5UOXSwsK FBN1yAIroO/TryZKQm5PHLSvb8CbLSaf/EkPCh74NGKhIOrJQzvFQnfJQOzy+lJhKuts i/Tw== X-Gm-Message-State: APjAAAW/GxAXc9jOvtgDYO4PDSSUhanGyVNXRofHe2CuhVzWRuP7c2mj 5Yi5MwAckZ1Zw9U4kmmUE38HC3PvL1v4bRF3Ug== X-Received: by 2002:a67:fad8:: with SMTP id g24mr9471060vsq.231.1555927817631; Mon, 22 Apr 2019 03:10:17 -0700 (PDT) MIME-Version: 1.0 References: <20190409065612.32652-1-rdong.ge@gmail.com> <20190422083339.ptkxqb66pombgy5g@salvia> <20190422093502.36da6z3qf7zxpwny@breakpoint.cc> In-Reply-To: From: Rundong Ge Date: Mon, 22 Apr 2019 18:10:06 +0800 Message-ID: Subject: Re: [PATCH] netfilter: fix dangling pointer access of fake_rtable To: Florian Westphal Cc: Pablo Neira Ayuso , kadlec@blackhole.kfki.hu, Roopa Prabhu , davem@davemloft.net, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The hook in my testcase is at NF_BR_FORWARD, and priority is -2. And at this hook point both the entry->out and entry->in are not bridge device. But the dst was set to the bridge's fake_rtable. Rundong Ge =E4=BA=8E2019=E5=B9=B44=E6=9C=8822=E6=97=A5= =E5=91=A8=E4=B8=80 =E4=B8=8B=E5=8D=885:51=E5=86=99=E9=81=93=EF=BC=9A > > skb->dev is munged in setup_prerouting() to be bridge or vlan device on > top of bridge. > --Yes, but br_nf_pre_routing_finish will set the skb->dev back to the ph= yindev. > > Florian Westphal =E4=BA=8E2019=E5=B9=B44=E6=9C=8822=E6=97= =A5=E5=91=A8=E4=B8=80 =E4=B8=8B=E5=8D=885:35=E5=86=99=E9=81=93=EF=BC=9A > > > > 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 s= truct nf_hook_state *state, > > .size =3D sizeof(*entry) + route_key_size, > > }; > > > > + if (skb_dst(skb)) { > > + skb_dst_force(skb); > > + if (!skb_dst(skb)) { > > + status =3D -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 =3D skb_dst(skb); > > if (dst && dst->dev->index =3D=3D index ... > > > > ?