Linux Documentation
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: toddfreed@meta.com
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	andrew+netdev@lunn.ch, bjorn@kernel.org, bpf@vger.kernel.org,
	daniel@iogearbox.net, daniel.zahka@gmail.com,
	donald.hunter@gmail.com, edumazet@kernel.org, kuba@kernel.org,
	jhs@mojatatu.com, jiri@resnulli.us, john.fastabend@gmail.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org, linux-rdma@vger.kernel.org,
	martin.lau@linux.dev, pabeni@redhat.com, saeedm@nvidia.com,
	horms@kernel.org, tariqt@nvidia.com, weiwan@google.com,
	willemdebruijn.kernel@gmail.com
Subject: Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress
Date: Sun, 15 Nov 2026 03:18:20 +0000	[thread overview]
Message-ID: <179471270091.2199510.4320994626979041884@kernel.org> (raw)
In-Reply-To: <20261111005533.6436-8-toddfreed@meta.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] The new check in __bpf_redirect()
  (net/core/filter.c:2232-2233) decides that the skb is on egress, and…
- [Low] The new drop in __bpf_redirect() (net/core/filter.c:2234) uses
  kfree_skb(skb), which records SKB_DROP_REASON_NOT_SPECIFIED.
- [Low] bpf: non-standard multi-line comment style in __bpf_redirect()

--

bpf: don't redirect decrypted skbs from egress to ingress

With this patch, __bpf_redirect() drops skbs that have skb->decrypted set
when they are redirected with BPF_F_INGRESS from outside tc ingress. On
transmit the bit asks the device to encrypt. In a receive path the same
bit would make the packet look like the device decrypted it. This matches
the mirred change from the previous patch.

> diff --git a/net/core/filter.c b/net/core/filter.c
> index aca8160b26a1a..a178a9dd30070 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2226,6 +2226,15 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
>  static int __bpf_redirect(struct sk_buff *skb, struct net_device *dev,
>  			  u32 flags)
>  {
> +	/* On transmit, decrypted asks the device to encrypt the packet. Sent
> +	 * to ingress, the packet would read as decrypted by the device.
> +	 */
> +	if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
> +		     skb_is_decrypted(skb))) {

[Severity: Low]
This isn't a bug, but could the new comment in __bpf_redirect() use
the multi-line comment style that BPF code prefers?

net/core/filter.c is covered by the BPF comment style. There the
opening /* goes on its own line and the text starts on the next line,
even where the surrounding code still uses the older networking style.
The added comment puts "On transmit, decrypted asks the device ..." on
the same line as the opening delimiter. Moving that text down one line
would match the preferred form:

	/*
	 * On transmit, decrypted asks the device to encrypt the packet.
	 * Sent to ingress, the packet would read as decrypted by the
	 * device.
	 */

[Severity: Medium]
Is skb_at_tc_ingress() a reliable direction signal for every caller of
__bpf_redirect()?

tcf_mirred_act() only checks this inside a tc hook, where tc_at_ingress
is always current. But __bpf_redirect() is also reached from LWT xmit
programs. lwt_xmit_func_proto() gives those programs bpf_redirect() and
bpf_clone_redirect(), and BPF_F_INGRESS is an accepted flag:

ip_finish_output2()
  lwtunnel_xmit()
    run_lwt_bpf()
      skb_do_redirect()
        __bpf_redirect(skb, dev, flags)

This runs before __dev_queue_xmit(), the only place on transmit that
clears the bit:

net/core/dev.c:__dev_queue_xmit() {
    ...
	tcx_set_ingress(skb, false);
    ...
}

The only place that sets the bit is sch_handle_ingress(), and only when
the input device has a tcx/clsact ingress entry. skb_scrub_packet() does
not touch it. For a forwarded skb, tc_at_ingress at the LWT xmit hook is
whatever the input device left behind.

Here is one way to get a forwarded skb whose decrypted bit means "please
encrypt". psp_validate_xmit() accepts any device whose psp_dev matches
the association, including dev-assoc veth/netkit devices. A PSP socket in
a container can then cross the veth with decrypted=1, and the host-side
peer forwards it.

Say the host-side veth has a tc ingress hook. Then tc_at_ingress=1
reaches the LWT xmit hook, and bpf_redirect(X, BPF_F_INGRESS) passes this
check. The packet enters X's receive path through __bpf_rx_skb() with
decrypted=1.

Without a tc ingress hook on the host-side veth, the same packet and the
same program get -EINVAL, and the packet is dropped.

Doesn't that make the result depend on unrelated tc configuration on the
input device, rather than on the direction of the hook calling the
helper? Neither the comment ("On transmit, ...") nor the commit message
("drop decrypted skbs which bpf redirects from egress to ingress")
describes this case.

The socket-less PSP case through act_psp encap on tc egress looks fine,
since tc_at_ingress is 0 there. Could the caller pass the direction
instead (LWT xmit is always egress), or could the LWT path be handled
explicitly?

> +		kfree_skb(skb);
> +		return -EINVAL;

[Severity: Low]
This isn't a bug, but could this use kfree_skb_reason() with a specific
drop reason?

kfree_skb() records SKB_DROP_REASON_NOT_SPECIFIED. For bpf_redirect(),
the program has already returned TC_ACT_REDIRECT, and the callers of
skb_do_redirect() ignore its return value:

net/core/dev.c:sch_handle_egress() {
    ...
		skb_do_redirect(skb);
		*ret = NET_XMIT_SUCCESS;
    ...
}

run_lwt_bpf() and netkit ignore it too. Neither the program nor the
sender learns about this new policy drop. In drop_monitor or the
kfree_skb tracepoint it looks like any other generic drop.

The matching mirred drop in the previous patch returns TC_ACT_SHOT and is
recorded as SKB_DROP_REASON_TC_EGRESS. The series also already defines
SKB_DROP_REASON_PSP_OUTPUT for related PSP policy drops.

[ ... ]

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com

  reply	other threads:[~2026-11-15  3:18 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  0:55 [PATCH net-next v1 00/15] psp: introduce socket-less associations Todd Freed
2026-11-11  0:55 ` [PATCH net-next v1 01/15] psp: get netns from net_device instead of sock Todd Freed
2026-11-11  0:55 ` [PATCH net-next v1 02/15] psp: take the psp nexthdr from the packet on encap Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 03/15] psp: declare psp_assoc_set_tx() in psp.h Todd Freed
2026-11-11  0:55 ` [PATCH net-next v1 04/15] psp: add support for socket-less psp associations Todd Freed
2026-11-11 16:49   ` Daniel Zahka
2026-11-11 18:23     ` Todd Bert Freed
2026-11-11 19:01       ` Daniel Zahka
2026-11-11 21:49         ` Todd Bert Freed
2026-11-12  0:51     ` Todd Bert Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 05/15] net: add METADATA_PSP dst to carry a psp association on an skb Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 06/15] net/sched: act_mirred: don't send decrypted skbs from egress to ingress Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 07/15] bpf: don't redirect " Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko [this message]
2026-11-11  0:55 ` [PATCH net-next v1 08/15] psp: only give time-wait sockets of psp connections a validator Todd Freed
2026-11-11 11:37   ` Daniel Zahka
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 09/15] net/sched: add act_psp for psp transport mode Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 10/15] net/sched: flower: add psp_spi, psp_ver, and psp_dev matches Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 11/15] selftests: drv-net: psp: test socket-less associations and the tc psp action Todd Freed
2026-11-11  0:55 ` [PATCH net-next v1 12/15] selftests: drv-net: psp: test that software encap on ingress drops Todd Freed
2026-11-11  0:55 ` [PATCH net-next v1 13/15] selftests: tc-testing: run dependsOn probes outside the test namespace Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 14/15] selftests: tc-testing: add tests for the psp action Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11  0:55 ` [PATCH net-next v1 15/15] Documentation: networking: psp: document socket-less associations Todd Freed
2026-11-15  3:18   ` netdev-bot+sashiko
2026-11-11 17:01 ` [PATCH net-next v1 00/15] psp: introduce " Daniel Zahka
2026-11-12 19:35   ` Todd Bert Freed
2026-11-13 15:45 ` Jamal Hadi Salim
2026-11-13 16:21   ` Jamal Hadi Salim
2026-11-13 19:08     ` Todd Bert Freed

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=179471270091.2199510.4320994626979041884@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=bjorn@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel.zahka@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=saeedm@nvidia.com \
    --cc=tariqt@nvidia.com \
    --cc=toddfreed@meta.com \
    --cc=weiwan@google.com \
    --cc=willemdebruijn.kernel@gmail.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