From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Ilia Kashintsev <ilia.kashintsev@gmail.com>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: Global buffer overflow in parse_ip6_mask()
Date: Sat, 20 Dec 2025 22:11:22 +0100 [thread overview]
Message-ID: <aUcQ-lW5FWeVH90G@chamomile> (raw)
In-Reply-To: <CAF6ebR70NXKv54uEE=kGC2O9tg5K+LoB5gZCm7tKJJaJRGLZcg@mail.gmail.com>
On Thu, Dec 18, 2025 at 04:15:05PM +0300, Ilia Kashintsev wrote:
[...]
> 2) Build the example:
>
> clang -g -O0 -fsanitize=address -o reproduction reproduction.c
> libebtc_la-useful_functions.o ./.libs/libebtc.a
>
> reproduction.c:
Hm, a custom file that uses this static library?
Maybe you describe how to crash this using ebtables userspace tool?
This is not even a shared library system wide available?
More comments below.
> #include <stdio.h>
> #include <unistd.h>
>
> #include <arpa/inet.h>
> #include <netinet/in.h>
>
> #if defined(__linux__)
> # include <netinet/ether.h>
> #else
> # include <net/ethernet.h>
> # include <arpa/inet.h>
> # include <netinet/ether.h>
> #endif
>
> void ebt_parse_ip6_address(char *address, struct in6_addr *addr,
> struct in6_addr *msk);
>
> int main(void) {
> unsigned char buf[256];
> ssize_t len;
>
> len = read(STDIN_FILENO, buf, sizeof(buf));
> if (len <= 0) {
> if (len == 0) {
> return 0;
> } else {
> perror("read");
> return 1;
> }
> }
>
> if (len < sizeof(buf)) {
> buf[len] = '\0';
> } else {
> buf[sizeof(buf) - 1] = '\0';
> }
>
> struct in6_addr addr = {0};
> struct in6_addr msk = {0};
>
> ebt_parse_ip6_address((char *)buf, &addr, &msk);
>
> return 0;
> }
>
>
> 3) Launch the example with the provided inputs:
>
> ./reproduction < input1.txt
> ./reproduction < input2.txt
>
> To generate input1.txt and input2.txt copy the corresponding text into
> bs64_1.txt and bs64_2.txt and then run:
>
> base64 -d bs64_1.txt > input1.txt
> base64 -d bs64_2.txt > input2.txt
>
> bs64_1.txt:
> WTEvLzESES8vMTI4AAAAWQAAAAExEhIfAIAADgBk/wB/8Q4mLwAAAAAAAAEAMTIxDg4=
>
> bs64_2.txt:
> WWxsN4BvUTYg2GxsLzgADg==
Maybe next time just post a patch to fix this silly bug... this tool
can only be run with root priviledges.
> Suggested fix:
>
> It is proposed to handle 2 cases separately, keeping current behaviour
> when bits % 8 != 0 and avoiding it when bits % 8 == 0. Nevertheless, i
> can't be sure this fix is totally correct.
>
> diff --git a/useful_functions.c b/useful_functions.c
As said, post a patch that applies via git-format-patch for review.
Thanks.
> index 133ae2f..a8dfcbc 100644
> --- a/useful_functions.c
> +++ b/useful_functions.c
> @@ -364,8 +364,12 @@ static struct in6_addr *parse_ip6_mask(char *mask)
> if (bits != 0) {
> char *p = (char *)&maskaddr;
> memset(p, 0xff, bits / 8);
> - memset(p + (bits / 8) + 1, 0, (128 - bits) / 8);
> - p[bits / 8] = 0xff << (8 - (bits & 7));
> + if (bits & 7) {
> + memset(p + (bits / 8) + 1, 0, (128 - bits) / 8);
> + p[bits / 8] = 0xff << (8 - (bits & 7));
> + } else {
> + memset(p + (bits / 8), 0, (128 - bits) / 8);
> + }
> return &maskaddr;
> }
>
prev parent reply other threads:[~2025-12-20 21:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-18 13:15 Global buffer overflow in parse_ip6_mask() Ilia Kashintsev
2025-12-18 14:44 ` Phil Sutter
2026-02-11 13:08 ` Florian Westphal
2026-02-11 19:43 ` Phil Sutter
2025-12-20 21:11 ` 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=aUcQ-lW5FWeVH90G@chamomile \
--to=pablo@netfilter.org \
--cc=ilia.kashintsev@gmail.com \
--cc=netfilter-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.