[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220527120217.GG7680@breakpoint.cc>
Date: Fri, 27 May 2022 14:02:17 +0200
From: Florian Westphal <fw@...len.de>
To: Kumar Kartikeya Dwivedi <memxor@...il.com>
Cc: Florian Westphal <fw@...len.de>,
Lorenzo Bianconi <lorenzo@...nel.org>, bpf@...r.kernel.org,
netdev@...r.kernel.org, ast@...nel.org, daniel@...earbox.net,
andrii@...nel.org, davem@...emloft.net, kuba@...nel.org,
edumazet@...gle.com, pabeni@...hat.com, pablo@...filter.org,
netfilter-devel@...r.kernel.org, lorenzo.bianconi@...hat.com,
brouer@...hat.com, toke@...hat.com, yhs@...com
Subject: Re: [PATCH v4 bpf-next 06/14] bpf: Whitelist some fields in nf_conn
for BPF_WRITE
Kumar Kartikeya Dwivedi <memxor@...il.com> wrote:
> On Fri, May 27, 2022 at 03:15:58AM IST, Florian Westphal wrote:
> > Lorenzo Bianconi <lorenzo@...nel.org> wrote:
> > > From: Kumar Kartikeya Dwivedi <memxor@...il.com>
> > >
> > > Since we want to allow user to set some fields in nf_conn after it is
> > > allocated but before it is inserted, we can permit BPF_WRITE for normal
> > > nf_conn, and then mark return value as read only on insert, preventing
> > > further BPF_WRITE. This way, nf_conn can be written to using normal
> > > BPF instructions after allocation, but not after insertion.
> > >
> > > Note that we special nf_conn a bit here, inside the btf_struct_access
> > > callback for XDP and TC programs. Since this is the only struct for
> > > these programs requiring such adjustments, making this mechanism
> > > more generic has been left as an exercise for a future patch adding
> > > custom callbacks for more structs.
> >
> > Are you sure this is safe?
> > As far as I can see this allows nf_conn->status = ~0ul.
> > I'm fairly sure this isn't a good idea, see nf_ct_delete() for example.
>
> This only allows writing to an allocated but not yet inserted nf_conn. The idea
> was that insert checks whether ct->status only has permitted bits set before
> making the entry visible, and then we make nf_conn pointer read only, however
> the runtime check seems to be missing right now in patch 12; something to fix in
> v5. With that sorted, would it be fine?
Its fragile, e.g. what if I set TEMPLATE bit? If refcount goes down to
0, object is released via kfree() instead of kmem_cache_free.
What if I clear SNAT_DONE bit? Would it leave the (freed) entry on the
bysource hash list (see nf_nat_core.c)?
Or is there some magic that prevents this from happening? I have no
idea how processing pipeline looks like...
Powered by blists - more mailing lists