All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Stosse <florian.stosse@harvester.fr>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH libmnl 0/5] libmnl: fix memory safety issues found by static analysis
Date: Fri, 13 Nov 2026 12:47:23 +0100	[thread overview]
Message-ID: <avb4y4AJsR6LUqgz@chamomile> (raw)
In-Reply-To: <20261106191841.1645-1-florian.stosse@harvester.fr>

On Fri, Nov 06, 2026 at 08:18:35PM +0100, Florian Stosse wrote:
> Hi,
> 
> This series fixes five bugs found while analysing libmnl with Frama-C
> (Eva, WP and E-ACSL-instrumented fuzzing). Each one was then confirmed
> on current master with a small standalone program under ASan/UBSan.
> 
> None of them can be triggered by netlink data received from the kernel
> through the usual parsing path. They all need a caller that uses the
> API in a less common, but valid or near-valid, way, so I am sending
> them as ordinary fixes.
> 
> Patch 1 is the most relevant one. When the message that overflowed a
> batch is larger than the messages already in it, mnl_nlmsg_batch_reset()
> memcpy()s it onto an overlapping range and then reads nlmsg_len back
> from the overwritten location. With limit = 100, a 20-byte message
> followed by a 92-byte one leaves mnl_nlmsg_batch_size() returning
> 0x97969594 on glibc/x86-64, and the next mnl_nlmsg_batch_next() uses
> b->buf + 0x97969594.
> 
> Patches 2 and 3 fix out-of-bounds accesses on unusual input:
> - The *_check() builders compare the unaligned nlmsg_len against
>   buflen while the attribute is written at MNL_ALIGN(nlmsg_len), so
>   they can write up to 3 bytes past the buffer.
> - mnl_attr_get_payload_len() wraps for nla_len < 4, which makes
>   mnl_attr_parse_nested() read past the end of the nest.
> 
> Patches 4 and 5 are minor:
> - mnl_nlmsg_fprintf() can read up to 3 bytes past an unaligned message.
> - mnl_cb_error() can compute -INT_MIN.
> 
> I can send the reproducers if they are useful.

I'm planning to apply 1-3.

Patch 4 and 5, it would be good to display in some way that unaligned
bytes has been ignored while printing. As for the -INT_MIN case, it is
probably safe to remove the workaround in userspace, IIRC this was
helping with a very old kernel where netlink was reported a negative
errno value in the error message, it can possibly be removed and the
need for this ugly corner case will not be needed anymore.

I am looking into adding

#ifdef __GNUC__
#define unlikely(x) __builtin_expect(!!(x), 0)
#define likely(x)   __builtin_expect(!!(x), 1)
#endif

so this can be used in patch 3 in the check there.

      parent reply	other threads:[~2026-11-13 11:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 19:18 [PATCH libmnl 0/5] libmnl: fix memory safety issues found by static analysis Florian Stosse
2026-11-06 19:18 ` [PATCH libmnl 1/5] nlmsg: fix overlapping copy in mnl_nlmsg_batch_reset() Florian Stosse
2026-11-10  0:51   ` Pablo Neira Ayuso
2026-11-06 19:18 ` [PATCH libmnl 2/5] attr: account for alignment padding in the *_check() builders Florian Stosse
2026-11-06 19:18 ` [PATCH libmnl 3/5] attr: do not wrap mnl_attr_get_payload_len() for nla_len < 4 Florian Stosse
2026-11-06 19:18 ` [PATCH libmnl 4/5] nlmsg: do not read past nlmsg_len in mnl_nlmsg_fprintf() Florian Stosse
2026-11-13 10:46   ` Pablo Neira Ayuso
2026-11-06 19:18 ` [PATCH libmnl 5/5] callback: avoid signed overflow on INT_MIN error code Florian Stosse
2026-11-13 11:05   ` Pablo Neira Ayuso
2026-11-13 11:47 ` 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=avb4y4AJsR6LUqgz@chamomile \
    --to=pablo@netfilter.org \
    --cc=florian.stosse@harvester.fr \
    --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.