From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Florian Stosse <florian.stosse@harvester.fr>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH libmnl 4/5] nlmsg: do not read past nlmsg_len in mnl_nlmsg_fprintf()
Date: Fri, 13 Nov 2026 11:46:22 +0100 [thread overview]
Message-ID: <avbqfgxdWkiPX0z2@chamomile> (raw)
In-Reply-To: <20261106191841.1645-5-florian.stosse@harvester.fr>
On Fri, Nov 06, 2026 at 08:18:39PM +0100, Florian Stosse wrote:
> mnl_nlmsg_fprintf_payload() prints the message in 4-byte words while
> i < nlmsg_len. mnl_nlmsg_ok() does not require nlmsg_len to be a
> multiple of 4, so for an unaligned length the last word reads up to 3
> bytes past the end of the message, and past the buffer when it ends
> there.
This function is used for debugging, I think it can be confusing if it
skips them.
It should at least print that it is leaving bytes behind while
printing.
> Only print complete words within nlmsg_len.
>
> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
> Signed-off-by: Florian Stosse <florian.stosse@harvester.fr>
> ---
> src/nlmsg.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/nlmsg.c b/src/nlmsg.c
> index f8eed79..e38f806 100644
> --- a/src/nlmsg.c
> +++ b/src/nlmsg.c
> @@ -302,7 +302,7 @@ static void mnl_nlmsg_fprintf_payload(FILE *fd, const struct nlmsghdr *nlh,
> if (fdnum != -1)
> colorize = isatty(fdnum);
>
> - for (i=sizeof(struct nlmsghdr); i<nlh->nlmsg_len; i+=4) {
> + for (i=sizeof(struct nlmsghdr); i + 4 <= nlh->nlmsg_len; i+=4) {
> char *b = (char *) nlh;
> struct nlattr *attr = (struct nlattr *) (b+i);
>
> --
> 2.56.0.windows.4
>
next prev parent reply other threads:[~2026-11-13 10:46 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 [this message]
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 ` [PATCH libmnl 0/5] libmnl: fix memory safety issues found by static analysis Pablo Neira Ayuso
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=avbqfgxdWkiPX0z2@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.