From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Sangho Lee <kudo3228@gmail.com>
Cc: netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>,
Phil Sutter <phil@nwl.cc>,
netdev@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net] netfilter: nf_conntrack_h323: fix get_bitmap() overread
Date: Tue, 18 Aug 2026 00:50:06 +0200 [thread overview]
Message-ID: <aoOQHtBE1GNDaPou@chamomile> (raw)
In-Reply-To: <20260722125714.1389705-1-kudo3228@gmail.com>
On Wed, Jul 22, 2026 at 09:57:14PM +0900, Sangho Lee wrote:
> get_bitmap() first consumes the complete bytes covered by the current bit
> offset and the requested bitmap length. For totals below 32 bits, it then
> unconditionally reads one more byte for the partial-byte remainder.
>
> When the total is already byte aligned, there is no remainder. The
> caller's boundary check correctly permits only the complete bytes, so the
> extra load reads one byte past the supplied PER buffer. A crafted Q.931
> User-User IE reaches this with a 17-bit sequence extension bitmap starting
> at bit offset 7. An AddressSanitizer build of the decoder reports:
>
> heap-buffer-overflow in get_bitmap
> decode_seq
> decode_seq
> DecodeH323_UserInformation
> DecodeQ931
>
> The same condition also excludes a total of exactly 32 bits from the
> alignment shift, producing an incorrect bitmap for unaligned inputs.
>
> Read a trailing byte only when there is a partial-byte remainder. Include
> the 32-bit total in the alignment branch. This makes all start offsets
> and bitmap lengths from 1 through 32 agree with a bit-by-bit reference
> decoder.
>
> The same input reaches q931_help(), DecodeQ931(), and decode_seq() through
> an nftables Q.931 conntrack helper on current nf.git. The helper's static
> scratch buffer has tailroom, so in-kernel KASAN does not report this logical
> packet-boundary overread. A diagnostic check immediately before the load
> does observe bs->cur == bs->end. No crash, disclosure, or corruption has
> been demonstrated.
>
> Fixes: 5e35941d9901 ("[NETFILTER]: Add H.323 conntrack/NAT helper")
> Cc: stable@vger.kernel.org
> Signed-off-by: Sangho Lee <kudo3228@gmail.com>
> ---
> net/netfilter/nf_conntrack_h323_asn1.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/netfilter/nf_conntrack_h323_asn1.c b/net/netfilter/nf_conntrack_h323_asn1.c
> index 6830c9da3..482860d2c 100644
> --- a/net/netfilter/nf_conntrack_h323_asn1.c
> +++ b/net/netfilter/nf_conntrack_h323_asn1.c
> @@ -228,8 +228,9 @@ static unsigned int get_bitmap(struct bitstr *bs, unsigned int b)
> bytes--, shift -= 8)
> v |= (unsigned int)(*bs->cur++) << shift;
>
> - if (l < 32) {
> - v |= (unsigned int)(*bs->cur) << shift;
> + if (l <= 32) {
> + if (l & 7)
> + v |= (unsigned int)(*bs->cur) << shift;
> v <<= bs->bit;
> } else if (l > 32) {
This branch is now dead code after your update.
> v <<= bs->bit;
> --
> 2.43.0
prev parent reply other threads:[~2026-08-17 22:50 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 12:57 [PATCH net] netfilter: nf_conntrack_h323: fix get_bitmap() overread Sangho Lee
2026-08-17 22:50 ` Pablo Neira Ayuso [this message]
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=aoOQHtBE1GNDaPou@chamomile \
--to=pablo@netfilter.org \
--cc=fw@strlen.de \
--cc=kudo3228@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
--cc=stable@vger.kernel.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