mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Moore <paul@paul-moore.com>
To: Bradley Morgan <include@grrlz.net>
Cc: Eric Paris <eparis@redhat.com>,
	Ricardo Robaina <rrobaina@redhat.com>,
	audit@vger.kernel.org, linux-kernel@vger.kernel.org,
	include@grrlz.net
Subject: Re: [PATCH] audit: move the nlmsg_len fixup from __audit_log_end() to  send time
Date: Mon, 24 Aug 2026 20:08:46 -0400	[thread overview]
Message-ID: <552658f244965a3dca8081f0020155e8@paul-moore.com> (raw)
In-Reply-To: <20260814010153.14488-1-include@grrlz.net>

On Aug 13, 2026 Bradley Morgan <include@grrlz.net> wrote:
> 
> Right now the auditd breakage (nlmsg_len gets set to the payload
> length instead of the full message length) is applied when the record
> is queued, in __audit_log_end(). That is why
> kauditd_send_multicast_skb() has to deep copy every record and then
> undo the length on the copy, just so the multicast group still sees a
> standard netlink message.
> 
> So flip it: finalize the header with the standard full length at
> queue time, and apply the auditd length at send time in
> kauditd_send_queue(), right before the unicast. Records stay standard
> netlink messages the whole time they sit in the queues, and the
> multicast copy stops needing its own fixup. The copy itself stays,
> because the rewrite still lands in the data region the listeners
> already hold.
> 
> auditd sees the same bytes as before: the fixup is computed from
> skb->len and that does not change between queueing and sending, so
> records that come back around through the retry and hold queues get
> the same value again. Reply and rule list skbs are built with
> nlmsg_put() and go out on their own paths, none of that is touched.
> 
> This came out of reviewing Ricardo's "use copied skb length" patch,
> where I suggested moving the fixup as the more interesting cleanup.
> 
> Reviewed-by: Ricardo Robaina <rrobaina@redhat.com>
> Tested-by: Ricardo Robaina <rrobaina@redhat.com>
> Signed-off-by: Bradley Morgan <include@grrlz.net>
> Link: https://lore.kernel.org/r/20260810125726.775689-2-rrobaina@redhat.com
> ---
>  kernel/audit.c | 30 +++++++++++++-----------------
>  1 file changed, 13 insertions(+), 17 deletions(-)
> 
> diff --git a/kernel/audit.c b/kernel/audit.c
> index 9412af9144bc..bcfed6e3678e 100644
> --- a/kernel/audit.c
> +++ b/kernel/audit.c
> @@ -802,6 +802,12 @@ static int kauditd_send_queue(struct sock *sk, u32 portid,
>  		if (skb_hook)
>  			(*skb_hook)(skb);
>  
> +		/*
> +		 * auditd wants nlmsg_len to be the payload length, not the
> +		 * full length, so break it here at send time.
> +		 */
> +		nlmsg_hdr(skb)->nlmsg_len = skb->len - NLMSG_HDRLEN;

One of the reasons we set the length in __audit_log_end() is so that we
only do it once, plus the multicast fixup.  In this patch we still set the
length in __audit_log_end() as well as potentially multiple times in
kauditd_send_queue().  This patch does drop the multicast fixup, but it
isn't as clean a solution conceptually as the current code in my opinion.

Ultimately, in this patch we still have at least two length calculations
with the potential for additional unnecessary calculations/assignments if
we need to loop through kauditd_send_queue() multiple times.  The existing
code is capped at two calculations/assignments.  I appreciate the time
you've put into this, but I think the existing code is the better option
at this point in time.

>  		/* can we send to anyone via unicast? */
>  		if (!sk) {
>  			if (err_hook)

--
paul-moore.com

  parent reply	other threads:[~2026-08-25  0:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-14  1:01 Bradley Morgan
2026-08-20 15:14 ` Bradley Morgan
2026-08-20 15:57   ` Ricardo Robaina
2026-08-20 16:38     ` Bradley Morgan
2026-08-25  1:28       ` Paul Moore
2026-08-25  0:08 ` Paul Moore [this message]
2026-08-25  0:15   ` Bradley Morgan

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=552658f244965a3dca8081f0020155e8@paul-moore.com \
    --to=paul@paul-moore.com \
    --cc=audit@vger.kernel.org \
    --cc=eparis@redhat.com \
    --cc=include@grrlz.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rrobaina@redhat.com \
    /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

all inboxes | Powered by JetHome®