netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: "Fabian Bläse" <fabian@blaese.de>,
	netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	"Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: Re: [PATCH v3] icmp: fix icmp_ndo_send address translation for reply direction
Date: Thu, 28 Aug 2025 14:15:53 +0200	[thread overview]
Message-ID: <aLBIeS4_x7dbrL-j@strlen.de> (raw)
In-Reply-To: <aLBE2Ee7pUBzUupH@calendula>

Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> On Thu, Aug 28, 2025 at 11:14:35AM +0200, Fabian Bläse wrote:
> > The icmp_ndo_send function was originally introduced to ensure proper
> > rate limiting when icmp_send is called by a network device driver,
> > where the packet's source address may have already been transformed
> > by SNAT.
> > 
> > However, the original implementation only considers the
> > IP_CT_DIR_ORIGINAL direction for SNAT and always replaced the packet's
> > source address with that of the original-direction tuple. This causes
> > two problems:
> > 
> > 1. For SNAT:
> >    Reply-direction packets were incorrectly translated using the source
> >    address of the CT original direction, even though no translation is
> >    required.
> > 
> > 2. For DNAT:
> >    Reply-direction packets were not handled at all. In DNAT, the original
> >    direction's destination is translated. Therefore, in the reply
> >    direction the source address must be set to the reply-direction
> >    source, so rate limiting works as intended.
> > 
> > Fix this by using the connection direction to select the correct tuple
> > for source address translation, and adjust the pre-checks to handle
> > reply-direction packets in case of DNAT.
> > 
> > Additionally, wrap the `ct->status` access in READ_ONCE(). This avoids
> > possible KCSAN reports about concurrent updates to `ct->status`.
> 
> I think such concurrent update cannot not happen, NAT bits are only
> set for the first packet of a connection, which sets up the nat
> configuration, so READ_ONCE() can go away.

Yes, the NAT bits stay in place but not other flags in ->status, e.g.
DYING, ASSURED, etc.

So I believe its needed, concurrent update of ->status is possible and
KCSAN would warn.  Other spots either use READ_ONCE or use test_bit().

  reply	other threads:[~2025-08-28 12:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-25 20:17 [PATCH] icmp: fix icmp_ndo_send address translation for reply direction Fabian Bläse
2025-08-25 20:38 ` [PATCH v2] " Fabian Bläse
2025-08-27  9:05   ` Florian Westphal
2025-08-27 17:12     ` Fabian Bläse
2025-08-27 17:25       ` Florian Westphal
2025-08-28  9:14   ` [PATCH v3] " Fabian Bläse
2025-08-28 12:00     ` Pablo Neira Ayuso
2025-08-28 12:15       ` Florian Westphal [this message]
2025-08-28 12:33         ` Pablo Neira Ayuso
2025-08-28 12:48           ` Florian Westphal
2025-08-28 12:48     ` Florian Westphal
2025-09-01 20:20     ` patchwork-bot+netdevbpf

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=aLBIeS4_x7dbrL-j@strlen.de \
    --to=fw@strlen.de \
    --cc=Jason@zx2c4.com \
    --cc=fabian@blaese.de \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /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).