From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: [PATCH 1/15] don't reallocate buffer in every audit_sockaddr() Date: Tue, 16 Dec 2008 23:49:27 -0800 Message-ID: <20081216234927.9cb8a077.akpm@linux-foundation.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Return-path: Received: from mx3.redhat.com (mx3.redhat.com [172.16.48.32]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id mBH7oC0a000811 for ; Wed, 17 Dec 2008 02:50:12 -0500 Received: from smtp1.linux-foundation.org (smtp1.linux-foundation.org [140.211.169.13]) by mx3.redhat.com (8.13.8/8.13.8) with ESMTP id mBH7o0oe008237 for ; Wed, 17 Dec 2008 02:50:01 -0500 In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-audit-bounces@redhat.com Errors-To: linux-audit-bounces@redhat.com To: Al Viro Cc: linux-audit@redhat.com, linux-kernel@vger.kernel.org List-Id: linux-audit@redhat.com On Wed, 17 Dec 2008 05:11:10 +0000 Al Viro wrote: > int audit_sockaddr(int len, void *a) > { > - struct audit_aux_data_sockaddr *ax; > struct audit_context *context = current->audit_context; > > if (likely(!context || context->dummy)) > return 0; > > - ax = kmalloc(sizeof(*ax) + len, GFP_KERNEL); > - if (!ax) > - return -ENOMEM; > - > - ax->len = len; > - memcpy(ax->a, a, len); > + if (!context->sockaddr) { > + void *p = kmalloc(sizeof(struct sockaddr_storage), GFP_KERNEL); argh, I really hate having to run all around the code verifying that the type passed to sizeof matches the type that we'll be storing there :( > + if (!p) > + return -ENOMEM; > + context->sockaddr = p; > + } > > - ax->d.type = AUDIT_SOCKADDR; > - ax->d.next = context->aux; > - context->aux = (void *)ax; > + context->sockaddr_len = len; > + memcpy(context->sockaddr, a, len); > return 0; > } stoopid question: can an audit_contect be shared between threads/processes? If so, is locking needed around the read/test/write of context->sockaddr and friends?