From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Paris Subject: Re: [PATCH] audit: fix size of netlink messages Date: Fri, 07 Jun 2013 11:43:01 -0400 Message-ID: <1370619781.3184.25.camel@localhost> References: <1370618731-29326-1-git-send-email-nicolas.dichtel@6wind.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1370618731-29326-1-git-send-email-nicolas.dichtel@6wind.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: Nicolas Dichtel Cc: linux-audit@redhat.com, viro@zeniv.linux.org.uk List-Id: linux-audit@redhat.com 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 :-( > 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 > --- > 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) { > + 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);