From: Fernando Fernandez Mancera <fmancera@suse.de>
To: Kacper Kokot <kacper.kokot.44@gmail.com>,
netfilter-devel@vger.kernel.org
Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de,
david.laight.linux@gmail.com, Phil Sutter <phil@nwl.cc>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
coreteam@netfilter.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] netfilter: TCPMSS: fix dropped packets when MSS option is unaligned
Date: Fri, 29 May 2026 09:14:00 +0200 [thread overview]
Message-ID: <381e22d3-fa30-4dde-bd53-705b4a868a90@suse.de> (raw)
In-Reply-To: <20260528223412.27311-1-kacper.kokot.44@gmail.com>
On 5/29/26 12:34 AM, Kacper Kokot wrote:
> Padding TCP options with NOPs is optional, so it is legal to send an
> MSS option that is not aligned to a word boundary and therefore not
> aligned for checksum calculation. The current TCPMSS target is not
> robust to this: when the MSS option is unaligned it produces an
> invalid checksum, and the packet is dropped.
>
> This has not been observed in any real environment. Senders place the
> MSS at the beginning of the options block, where it is naturally
> aligned, but the spec allows unaligned options and the kernel shouldn't
> silently drop legal packets.
>
> When the changed word is not aligned, the modified bytes straddle two
> checksum words, and using the standard incremental update helper
> (which assumes alignment) produces an invalid checksum:
>
> | w1 | w2 |
> OLD | a b | c d |
> NEW | a b' | c' d |
>
> Since b' and c' sit across w1 and w2, we could compute the incremental
> checksum in two operations by recalculating w1 and then w2:
>
> C' = C - w1 + w1' - w2 + w2'
>
> But working it out:
>
> C' = C - w1 - w2 + w1' + w2'
> = C - (a * 2^8 + b) - (c * 2^8 + d)
> + (a * 2^8 + b') + (c' * 2^8 + d)
> = C + 2^8 * (a - a + c' - c) + (b' - b + d - d)
> = C + 2^8 * (c' - c) + (b' - b)
> = C - (2^8 * c + b) + (2^8 * c' + b')
>
> So an unaligned incremental checksum can be done in a single operation
> by byteswapping the changed bytes before passing them to the helper.
> This patch implements that trick for unaligned MSS option updates.
>
> Signed-off-by: Kacper Kokot <kacper.kokot.44@gmail.com>
> ---
Just a couple of nits..
Please use nf-next target, like "[PATCH nf-next v3] netfilter:
xt_TCPMSS: ...". Let's handle this as an enhancement.
> I decided to go with the get_unaligned_be16 suggestion because
> it's idiomatic and it produces shorter assembly on x86-64
> (6 instructions vs 9). SYN processing is a cold path so
> I didn't look into it further.
>
> v2:
> - Use get_unaligned_be16 (Fernando's suggestion)
> - Fix alignment check expression (David)
> - Mention it's a theoretical bug in the commit message
> - Drop cc stable, the bug is only theoretical
>
> net/netfilter/xt_TCPMSS.c | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
> index 80e1634bc51f..32c87a520361 100644
> --- a/net/netfilter/xt_TCPMSS.c
> +++ b/net/netfilter/xt_TCPMSS.c
> @ -117,8 +117,9 @@ tcpmss_mangle_packet(struct sk_buff *skb,
> for (i = sizeof(struct tcphdr); i <= tcp_hdrlen - TCPOLEN_MSS; i += optlen(opt, i)) {
> if (opt[i] == TCPOPT_MSS && opt[i+1] == TCPOLEN_MSS) {
> u_int16_t oldmss;
> + u16 csum_oldmss, csum_newmss;
Please use reversed xmas tree:
+ u16 csum_oldmss, csum_newmss;
u_int16_t oldmss;
Thanks,
Fernando.
next prev parent reply other threads:[~2026-05-29 7:14 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-25 20:11 [PATCH] " Kacper Kokot
2026-05-25 21:28 ` Florian Westphal
2026-05-25 21:44 ` Kacper Kokot
2026-05-25 22:08 ` Fernando Fernandez Mancera
2026-05-26 9:31 ` David Laight
2026-05-26 13:50 ` kernel test robot
2026-05-26 15:18 ` David Laight
2026-05-26 16:46 ` kernel test robot
2026-05-26 23:21 ` Kacper Kokot
2026-05-28 16:31 ` kernel test robot
2026-05-28 18:11 ` kernel test robot
2026-05-28 19:40 ` David Laight
2026-05-28 22:34 ` [PATCH v2] " Kacper Kokot
2026-05-28 22:52 ` Pablo Neira Ayuso
2026-06-08 8:53 ` Kacper Kokot
2026-05-29 7:14 ` Fernando Fernandez Mancera [this message]
2026-06-08 8:56 ` Kacper Kokot
2026-06-21 18:49 ` [PATCH nf-next v3] netfilter: TCPMSS: handle packets with unaligned MSS option Kacper Kokot
2026-06-21 19:46 ` Pablo Neira Ayuso
2026-05-29 20:54 ` [PATCH] netfilter: TCPMSS: fix dropped packets when MSS option is unaligned kernel test robot
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=381e22d3-fa30-4dde-bd53-705b4a868a90@suse.de \
--to=fmancera@suse.de \
--cc=coreteam@netfilter.org \
--cc=davem@davemloft.net \
--cc=david.laight.linux@gmail.com \
--cc=edumazet@google.com \
--cc=fw@strlen.de \
--cc=horms@kernel.org \
--cc=kacper.kokot.44@gmail.com \
--cc=kadlec@netfilter.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pablo@netfilter.org \
--cc=phil@nwl.cc \
/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
Powered by JetHome