linux-audit.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: Eric Paris <eparis@redhat.com>
Cc: Thomas Graf <tgraf@suug.ch>,
	linux-audit@redhat.com, viro@zeniv.linux.org.uk
Subject: Re: [PATCH] audit: fix size of netlink messages
Date: Fri, 07 Jun 2013 18:24:02 +0200	[thread overview]
Message-ID: <51B20922.7070909@6wind.com> (raw)
In-Reply-To: <1370619781.3184.25.camel@localhost>

Put Thomas in CC.

Le 07/06/2013 17:43, Eric Paris a écrit :
> On Fri, 2013-06-07 at 17:25 +0200, Nicolas Dichtel wrote:
>
> NAK.
>
> I tried this once before and as I recal userspace actually expected the
> stoopidity of being unaligned and broke   :-(
On which userspace tools do you think?

For example, in the libnl, the function which tries to get the next netlink 
message expects this alignment:

struct nlmsghdr *nlmsg_next(struct nlmsghdr *nlh, int *remaining)
{
         int totlen = NLMSG_ALIGN(nlh->nlmsg_len);

         *remaining -= totlen;

         return (struct nlmsghdr *) ((unsigned char *) nlh + totlen);
}

http://www.infradead.org/~tgr/libnl/doc/core.html#_message_parsing_amp_construction

>
>> Netlink messages must be aligned on NLMSG_ALIGNTO (4 bytes), thus we need to
>> update the skb length before sending it to userspace.
>>
>> This patch adds the needed padding to be compliant with this requirement.
>>
>> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>> ---
>>   kernel/audit.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/kernel/audit.c b/kernel/audit.c
>> index 21c7fa6..31d213a 100644
>> --- a/kernel/audit.c
>> +++ b/kernel/audit.c
>> @@ -1669,6 +1669,17 @@ void audit_log_end(struct audit_buffer *ab)
>>   		struct nlmsghdr *nlh = nlmsg_hdr(ab->skb);
>>   		nlh->nlmsg_len = ab->skb->len - NLMSG_HDRLEN;
>>
>> +		if (NLMSG_ALIGN(ab->skb->len) != ab->skb->len) {
Here, I think it's better to use nlmsg_padlen().

>> +			unsigned int pad = NLMSG_ALIGN(ab->skb->len) -
>> +					   ab->skb->len;
>> +
>> +			if (skb_tailroom(ab->skb) >= pad)
>> +				skb_put(ab->skb, pad);
>> +			else if (pskb_expand_head(ab->skb, 0, pad,
>> +						  GFP_KERNEL) < 0)
>> +				audit_log_lost("out of memory in audit_log_end");
>> +		}
>> +
>>   		if (audit_pid) {
>>   			skb_queue_tail(&audit_skb_queue, ab->skb);
>>   			wake_up_interruptible(&kauditd_wait);
>
>

--
Linux-audit mailing list
Linux-audit@redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit

  reply	other threads:[~2013-06-07 16:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-07 15:25 [PATCH] audit: fix size of netlink messages Nicolas Dichtel
2013-06-07 15:43 ` Eric Paris
2013-06-07 16:24   ` Nicolas Dichtel [this message]
     [not found]     ` <20130609132934.GA10805@casper.infradead.org>
2013-06-10  8:50       ` Nicolas Dichtel

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=51B20922.7070909@6wind.com \
    --to=nicolas.dichtel@6wind.com \
    --cc=eparis@redhat.com \
    --cc=linux-audit@redhat.com \
    --cc=tgraf@suug.ch \
    --cc=viro@zeniv.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).