From: Florian Westphal <fw@strlen.de>
To: Sunny73Cr <Sunny73Cr@protonmail.com>
Cc: Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>,
"netfilter@vger.kernel.org" <netfilter@vger.kernel.org>
Subject: Re: Raw Payload Expressions - out of bounds write?
Date: Sun, 9 Feb 2025 02:47:53 +0100 [thread overview]
Message-ID: <20250209014753.GA1766@breakpoint.cc> (raw)
In-Reply-To: <omRiDfO4yHw_nf-Xsk390UcpY_66yoc_oOELR6Fwu94Nr4QtjOT_1tcjVT_wOaaVW5QwqNRBvQonQbXXayhp1CFTAKEF3Qz0ToC7HenQBpk=@protonmail.com>
Sunny73Cr <Sunny73Cr@protonmail.com> wrote:
> I noticed there may be a floating point error or another miscellaneous approximation error when calculating the mask for raw payload expressions. It is somewhat related to this thread.
There is no approximation. And no floating point math is involved.
> using nft -d all (debug all); I found:
>
> inet filter output 5 4
> [ payload load 2b @ inner header + 6 => reg 1 ]
> [ bitwise reg 1 = ( reg 1 & 0x0000c0ff ) ^ 0x00000000 ]
>
> After careful consideration, I realised that here; '2b' indicates two bytes, not two bits. I suggest it should read '2 Bytes'. Additionally, the "+ 6" section should really read as "+ 6 Bytes". "2B" or "6B" may get misread as 28, or 68; if the user makes a poor choice in font. Poor choice in font is not my concern, particularly; but fault-tolerant design is always nice.
>
> Anyhow, with the alterations to expression; I can then match it (2 bytes, offset of 6 bytes) to the 'mangled' input of @ih,48,16
>
> > [ bitwise reg 1 = ( reg 1 & 0x0000c0ff ) ^ 0x00000000 ]
>
> Assuming that the mask is stored in a 32-bit integer field, the length of the string is fine. Otherwise, the mask of "0x0000c0ff" equates to 49,407 bits.
0x0c0ff in decimal notation is 49407. But I do not know how "0x0000c0ff"
equates to "49407 bits".
> Since raw payload expression includes the starting position in payload expressions; it is really 49,408 bits to match.
I don't know what that is supposed to mean.
> Via empirical calculation, the closest base 2 logarithm I can find for 49,407 (bits) is approximately ~15.5924570373.
> If the mask is intended to cover 16 bits; should it not equate to 65,535 bits; or "0x0000ffff".
>
> Though, the intent was not to read and set the same value; rather, it was to redact 6 bits of data. Considering the intent of my input statement (@ih,58,6); I think the mask should be ((2^16) - (2^6)); or 65,472 in decimal; or 0xfff9 in hexadecimal.
I have no idea what you mean.
The mask cannot be computed by ((2^16) - (2^6)).
The location (offset) matters, not just the amount of bits
to retain/zero out.
> This leaves us with an output statement of (little endian mask, as it seems is the case):
>
> @ih,48,16 set @ih,48,16 & 0xfff9
>
> The statement:
>
> > [ bitwise reg 1 = ( reg 1 & 0x0000c0ff ) ^ 0x00000000 ]
>
> Should then read:
>
> > [ bitwise reg 1 = ( reg 1 & 0x0000fff9 ) ^ 0x00000000 ]
That mask is 1111100111111111 which translates to '@ih,53,2 set ...'
Please show a real bug, i.e.:
1. the rule you made
2. a text explaining what you wanted the rule to do
3. a packet capture showing packet after mangling
4. a text explaing what yhe packet capture SHOULD have
shown instead
else I will never be able to help.
next prev parent reply other threads:[~2025-02-09 1:48 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 3:31 Raw Payload Expressions - out of bounds write? Sunny73Cr
2025-01-26 13:50 ` Florian Westphal
2025-01-26 18:08 ` Sunny73Cr
2025-01-28 0:37 ` Florian Westphal
2025-01-28 4:19 ` Sunny73Cr
2025-01-28 12:02 ` Jeremy Sowden
2025-01-28 12:12 ` Sunny73Cr
2025-01-28 12:41 ` Pablo Neira Ayuso
2025-01-30 11:27 ` Sunny73Cr
2025-02-08 20:26 ` Sunny73Cr
2025-02-09 1:47 ` Florian Westphal [this message]
2025-02-09 3:12 ` Sunny73Cr
2025-02-09 22:23 ` Pablo Neira Ayuso
2025-02-09 22:45 ` Sunny73Cr
2025-12-02 5:22 ` Sunny73Cr
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=20250209014753.GA1766@breakpoint.cc \
--to=fw@strlen.de \
--cc=Sunny73Cr@protonmail.com \
--cc=netfilter@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