netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: nb <nikolay.borisov@virtuozzo.com>
Cc: nhorman@tuxdriver.com, davem@davemloft.net, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org, kernel@openvz.org
Subject: Re: [PATCH net-next v2 1/3] drop_monitor: Implement namespace filtering/reporting for software drops
Date: Mon, 28 Nov 2022 09:54:52 +0200	[thread overview]
Message-ID: <Y4RpTM8141eTNhsD@shredder> (raw)
In-Reply-To: <8c6aee78-2247-bcd5-ea48-b76652745301@virtuozzo.com>

On Thu, Nov 24, 2022 at 01:41:38PM +0200, nb wrote:
> 
> 
> On 23.11.22 г. 20:10 ч., Ido Schimmel wrote:
> > On Wed, Nov 23, 2022 at 05:21:23PM +0200, nb wrote:
> > > 
> > > 
> > > On 23.11.22 г. 17:16 ч., Ido Schimmel wrote:
> > > > On Wed, Nov 23, 2022 at 04:28:15PM +0200, Nikolay Borisov wrote:
> > > > >    static void trace_drop_common(struct sk_buff *skb, void *location)
> > > > >    {
> > > > >    	struct net_dm_alert_msg *msg;
> > > > > @@ -219,7 +233,11 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
> > > > >    	int i;
> > > > >    	struct sk_buff *dskb;
> > > > >    	struct per_cpu_dm_data *data;
> > > > > -	unsigned long flags;
> > > > > +	unsigned long flags, ns_id = 0;
> > > > > +
> > > > > +	if (skb->dev && net_dm_ns &&
> > > > > +	    dev_net(skb->dev)->ns.inum != net_dm_ns)
> > > > 
> > > > I don't think this is going to work, unfortunately. 'skb->dev' is in a
> > > > union with 'dev_scratch' so 'skb->dev' does not necessarily point to a
> > > > valid netdev at all times. It can explode when dev_net() tries to
> > > > dereference it.
> > > > 
> > > > __skb_flow_dissect() is doing something similar, but I believe there the
> > > > code paths were audited to make sure it is safe.
> > > > 
> > > > Did you consider achieving this functionality with a BPF program
> > > > attached to skb::kfree_skb tracepoint? I believe BPF programs are run
> > > > with page faults disabled, so it should be safe to attempt this there.
> > > 
> > > How would that be different than the trace_drop_common which is called as
> > > part of the trace_kfree_skb, as it's really passed as trace point probe via:
> > 
> > Consider this call path:
> > 
> > __udp_queue_rcv_skb()
> >      __udp_enqueue_schedule_skb()
> >          udp_set_dev_scratch() // skb->dev is not NULL, but not a pointer to a netdev either
> > 	// error is returned
> >      kfree_skb_reason() // probe is called
> > 
> > dev_net(skb->dev) in the probe will try to dereference skb->dev and
> > crash.
> 
> This can easily be rectified by using is_kernel() .

The layout of 'struct udp_dev_scratch' is not fixed and it can be
arranged to contain values that make it seem like a valid kernel
address, but does not actually point to a 'struct net_device'.

> 
> > 
> > On the other hand, a BPF program that is registered as another probe on
> > the tracepoint will access the memory via bpf_probe_read_kernel(), which
> > will try to safely read the memory and return an error if it can't. You
> > can do that today without any kernel changes.
> 
> I did a PoC for this and indeed it works, however I'd still like to pursue
> this code provided there is upstream interest.

  reply	other threads:[~2022-11-28  7:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 14:28 [PATCH net-next v2 0/3] Add support for netnamespace filtering in drop monitor Nikolay Borisov
2022-11-23 14:28 ` [PATCH net-next v2 1/3] drop_monitor: Implement namespace filtering/reporting for software drops Nikolay Borisov
2022-11-23 15:16   ` Ido Schimmel
2022-11-23 15:21     ` nb
2022-11-23 18:10       ` Ido Schimmel
2022-11-24 11:41         ` nb
2022-11-28  7:54           ` Ido Schimmel [this message]
2022-11-23 15:33   ` Alexander Lobakin
2022-11-23 16:04     ` nb
2022-11-23 17:16       ` Alexander Lobakin
2022-11-23 14:28 ` [PATCH net-next v2 2/3] drop_monitor: Add namespace filtering/reporting for hardware drops Nikolay Borisov
2022-11-23 15:37   ` Alexander Lobakin
2022-11-23 14:28 ` [PATCH net-next v2 3/3] selftests: net: Add drop monitor tests for namespace filtering functionality Nikolay Borisov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y4RpTM8141eTNhsD@shredder \
    --to=idosch@idosch.org \
    --cc=davem@davemloft.net \
    --cc=kernel@openvz.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=nikolay.borisov@virtuozzo.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).