mbox series

[nf-next,v4,0/5] Netfilter egress hook

Message ID cover.1611304190.git.lukas@wunner.de
Headers show
Series Netfilter egress hook | expand

Message

Lukas Wunner Jan. 22, 2021, 8:47 a.m. UTC
Netfilter egress hook, 4th iteration:

Previously traffic control suffered a performance degradation with this
series applied.  Not anymore, see patch [1/5].

Pablo added netfilter egress handling to af_packet, patch [5/5].

Pablo also moved the netfilter egress hook behind traffic control to
address an objection from Daniel Borkmann, see patch [4/5].  The commit
message was amended with Laura's and Pablo's use cases to make it clear
that the series is no longer motivated by an out-of-tree module.
A bunch of small performance improvements and bugfixes were applied.

Please review and test.  Thanks!

Link to previous version:
https://lore.kernel.org/netfilter-devel/cover.1598517739.git.lukas@wunner.de/


Lukas Wunner (4):
  net: sched: Micro-optimize egress handling
  netfilter: Rename ingress hook include file
  netfilter: Generalize ingress hook include file
  netfilter: Introduce egress hook

Pablo Neira Ayuso (1):
  af_packet: Introduce egress hook

 include/linux/netdevice.h         |   4 ++
 include/linux/netfilter_ingress.h |  58 ----------------
 include/linux/netfilter_netdev.h  | 112 ++++++++++++++++++++++++++++++
 include/uapi/linux/netfilter.h    |   1 +
 net/core/dev.c                    |  16 +++--
 net/netfilter/Kconfig             |   8 +++
 net/netfilter/core.c              |  34 ++++++++-
 net/netfilter/nft_chain_filter.c  |   4 +-
 net/packet/af_packet.c            |  35 ++++++++++
 9 files changed, 206 insertions(+), 66 deletions(-)
 delete mode 100644 include/linux/netfilter_ingress.h
 create mode 100644 include/linux/netfilter_netdev.h

Comments

Willem de Bruijn Jan. 22, 2021, 4:13 p.m. UTC | #1
On Fri, Jan 22, 2021 at 4:44 AM Lukas Wunner <lukas@wunner.de> wrote:
>
> From: Pablo Neira Ayuso <pablo@netfilter.org>
>
> Add egress hook for AF_PACKET sockets that have the PACKET_QDISC_BYPASS
> socket option set to on, which allows packets to escape without being
> filtered in the egress path.
>
> This patch only updates the AF_PACKET path, it does not update
> dev_direct_xmit() so the XDP infrastructure has a chance to bypass
> Netfilter.
>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> [lukas: acquire rcu_read_lock, fix typos, rebase]
> Signed-off-by: Lukas Wunner <lukas@wunner.de>

Isn't the point of PACKET_QDISC_BYPASS to skip steps like this?
Lukas Wunner Jan. 24, 2021, 11:14 a.m. UTC | #2
On Fri, Jan 22, 2021 at 11:13:19AM -0500, Willem de Bruijn wrote:
> On Fri, Jan 22, 2021 at 4:44 AM Lukas Wunner <lukas@wunner.de> wrote:

> > Add egress hook for AF_PACKET sockets that have the PACKET_QDISC_BYPASS

> > socket option set to on, which allows packets to escape without being

> > filtered in the egress path.

> >

> > This patch only updates the AF_PACKET path, it does not update

> > dev_direct_xmit() so the XDP infrastructure has a chance to bypass

> > Netfilter.

> 

> Isn't the point of PACKET_QDISC_BYPASS to skip steps like this?


I suppose PACKET_QDISC_BYPASS "was introduced to bypass qdisc,
not to bypass everything."

(The quote is taken from this message by Eric Dumazet:
https://lore.kernel.org/netfilter-devel/a9006cf7-f4ba-81b1-fca1-fd2e97939fdc@gmail.com/
)

Thanks,

Lukas
Willem de Bruijn Jan. 24, 2021, 4:18 p.m. UTC | #3
On Sun, Jan 24, 2021 at 6:14 AM Lukas Wunner <lukas@wunner.de> wrote:
>

> On Fri, Jan 22, 2021 at 11:13:19AM -0500, Willem de Bruijn wrote:

> > On Fri, Jan 22, 2021 at 4:44 AM Lukas Wunner <lukas@wunner.de> wrote:

> > > Add egress hook for AF_PACKET sockets that have the PACKET_QDISC_BYPASS

> > > socket option set to on, which allows packets to escape without being

> > > filtered in the egress path.

> > >

> > > This patch only updates the AF_PACKET path, it does not update

> > > dev_direct_xmit() so the XDP infrastructure has a chance to bypass

> > > Netfilter.

> >

> > Isn't the point of PACKET_QDISC_BYPASS to skip steps like this?

>

> I suppose PACKET_QDISC_BYPASS "was introduced to bypass qdisc,

> not to bypass everything."

>

> (The quote is taken from this message by Eric Dumazet:

> https://lore.kernel.org/netfilter-devel/a9006cf7-f4ba-81b1-fca1-fd2e97939fdc@gmail.com/

> )


I see. I don't understand the value of a short-cut fast path if we
start chipping away at its characteristic feature.

It also bypasses sch_handle_egress and packet sockets. This new
feature seems broadly similar to the first?
Lukas Wunner Jan. 30, 2021, 4:26 p.m. UTC | #4
On Sun, Jan 24, 2021 at 11:18:00AM -0500, Willem de Bruijn wrote:
> On Sun, Jan 24, 2021 at 6:14 AM Lukas Wunner <lukas@wunner.de> wrote:

> > On Fri, Jan 22, 2021 at 11:13:19AM -0500, Willem de Bruijn wrote:

> > > On Fri, Jan 22, 2021 at 4:44 AM Lukas Wunner <lukas@wunner.de> wrote:

> > > > Add egress hook for AF_PACKET sockets that have the PACKET_QDISC_BYPASS

> > > > socket option set to on, which allows packets to escape without being

> > > > filtered in the egress path.

> > > >

> > > > This patch only updates the AF_PACKET path, it does not update

> > > > dev_direct_xmit() so the XDP infrastructure has a chance to bypass

> > > > Netfilter.

> > >

> > > Isn't the point of PACKET_QDISC_BYPASS to skip steps like this?

> >

> > I suppose PACKET_QDISC_BYPASS "was introduced to bypass qdisc,

> > not to bypass everything."

> >

> > (The quote is taken from this message by Eric Dumazet:

> > https://lore.kernel.org/netfilter-devel/a9006cf7-f4ba-81b1-fca1-fd2e97939fdc@gmail.com/

> > )

> 

> I see. I don't understand the value of a short-cut fast path if we

> start chipping away at its characteristic feature.


The point is to filter traffic coming in through af_packet.
Exempting PACKET_QDISC_BYPASS from filtering would open up a
trivial security hole.

Thanks,

Lukas
Willem de Bruijn Jan. 30, 2021, 4:58 p.m. UTC | #5
On Sat, Jan 30, 2021 at 11:26 AM Lukas Wunner <lukas@wunner.de> wrote:
>

> On Sun, Jan 24, 2021 at 11:18:00AM -0500, Willem de Bruijn wrote:

> > On Sun, Jan 24, 2021 at 6:14 AM Lukas Wunner <lukas@wunner.de> wrote:

> > > On Fri, Jan 22, 2021 at 11:13:19AM -0500, Willem de Bruijn wrote:

> > > > On Fri, Jan 22, 2021 at 4:44 AM Lukas Wunner <lukas@wunner.de> wrote:

> > > > > Add egress hook for AF_PACKET sockets that have the PACKET_QDISC_BYPASS

> > > > > socket option set to on, which allows packets to escape without being

> > > > > filtered in the egress path.

> > > > >

> > > > > This patch only updates the AF_PACKET path, it does not update

> > > > > dev_direct_xmit() so the XDP infrastructure has a chance to bypass

> > > > > Netfilter.

> > > >

> > > > Isn't the point of PACKET_QDISC_BYPASS to skip steps like this?

> > >

> > > I suppose PACKET_QDISC_BYPASS "was introduced to bypass qdisc,

> > > not to bypass everything."

> > >

> > > (The quote is taken from this message by Eric Dumazet:

> > > https://lore.kernel.org/netfilter-devel/a9006cf7-f4ba-81b1-fca1-fd2e97939fdc@gmail.com/

> > > )

> >

> > I see. I don't understand the value of a short-cut fast path if we

> > start chipping away at its characteristic feature.

>

> The point is to filter traffic coming in through af_packet.

> Exempting PACKET_QDISC_BYPASS from filtering would open up a

> trivial security hole.


Sure. But that argument is no different for TC_EGRESS.

That's why packet sockets require CAP_NET_RAW. It is perhaps
unfortunately that it is ns_capable instead of capable. But there is
nothing netfilter specific about this.