[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZXCkgoVQCn6bMoKT@calendula>
Date: Wed, 6 Dec 2023 17:42:42 +0100
From: Pablo Neira Ayuso <pablo@...filter.org>
To: Phil Sutter <phil@....cc>, Jann Horn <jannh@...gle.com>,
Jozsef Kadlecsik <kadlec@...filter.org>,
Florian Westphal <fw@...len.de>,
netfilter-devel <netfilter-devel@...r.kernel.org>,
coreteam@...filter.org, Christian Brauner <brauner@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Network Development <netdev@...r.kernel.org>,
kernel list <linux-kernel@...r.kernel.org>
Subject: Re: Is xt_owner's owner_mt() racy with sock_orphan()? [worse with
new TYPESAFE_BY_RCU file lifetime?]
On Tue, Dec 05, 2023 at 10:40:15PM +0100, Phil Sutter wrote:
> Hi,
>
> On Tue, Dec 05, 2023 at 06:08:29PM +0100, Jann Horn wrote:
> > On Tue, Dec 5, 2023 at 5:40 PM Jann Horn <jannh@...gle.com> wrote:
> > >
> > > Hi!
> > >
> > > I think this code is racy, but testing that seems like a pain...
> > >
> > > owner_mt() in xt_owner runs in context of a NF_INET_LOCAL_OUT or
> > > NF_INET_POST_ROUTING hook. It first checks that sk->sk_socket is
> > > non-NULL, then checks that sk->sk_socket->file is non-NULL, then
> > > accesses the ->f_cred of that file.
> > >
> > > I don't see anything that protects this against a concurrent
> > > sock_orphan(), which NULLs out the sk->sk_socket pointer, if we're in
> >
> > Ah, and all the other users of ->sk_socket in net/netfilter/ do it
> > under the sk_callback_lock... so I guess the fix would be to add the
> > same in owner_mt?
>
> Sounds reasonable, although I wonder how likely a socket is to
> orphan while netfilter is processing a packet it just sent.
>
> How about the attached patch? Not sure what hash to put into a Fixes:
> tag given this is a day 1 bug and ipt_owner/ip6t_owner predate git.
>
> Thanks, Phil
> From 3e28490e43b04d49e6e7f145a70fff7dd42c8cc5 Mon Sep 17 00:00:00 2001
> From: Phil Sutter <phil@....cc>
> Date: Tue, 5 Dec 2023 21:58:12 +0100
> Subject: [nf PATCH] netfilter: xt_owner: Fix for unsafe access of sk->sk_socket
>
> A concurrently running sock_orphan() may NULL the sk_socket pointer in
> between check and deref. Follow other users (like nft_meta.c for
> instance) and acquire sk_callback_lock before dereferencing sk_socket.
For the record, I have placed this patch in nf.git
Thanks.
Powered by blists - more mailing lists