From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linda Knippers Subject: Re: [PATCH] Audit of POSIX Message Queue Syscalls v.2 Date: Wed, 24 May 2006 17:23:03 -0400 Message-ID: <4474CEB7.10901@hp.com> References: <20060517014055.GA16852@us.ibm.com> <20060524210955.GA27747@us.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k4OLN2LE029618 for ; Wed, 24 May 2006 17:23:02 -0400 Received: from atlrel6.hp.com (atlrel6.hp.com [156.153.255.205]) by mx1.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id k4OLN2HO000546 for ; Wed, 24 May 2006 17:23:02 -0400 In-Reply-To: <20060524210955.GA27747@us.ibm.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: "George C. Wilson" Cc: linux-audit@redhat.com List-Id: linux-audit@redhat.com Hi George, > > memory leak from above allocation. > These do not appear to be leaks. They always get freed in > do_syscall_trace_leave(), both when the syscalls return -EFAULT and > when audit is disabled. I verified this with printk's. With the > check for audit enabled, they no longer get allocated needlessly. > Unless a syscall can bypass do_syscall_trace_leave(), these look > like they don't leak. I think you do have some memory leaks. For example: > +int audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr) > +{ > + struct audit_aux_data_mq_open *ax; > + struct audit_context *context = current->audit_context; > + > + if (!audit_enabled) > + return 0; > + > + if (likely(!context)) > + return 0; > + > + ax = kmalloc(sizeof(*ax), GFP_ATOMIC); > + if (!ax) > + return -ENOMEM; > + > + if (u_attr != NULL) { > + if (copy_from_user(&ax->attr, u_attr, sizeof(ax->attr))) > + return -EFAULT; If this return is taken, the memory allocated above will not be freed at syscall exit time because the assignment of context->aux was not made. ax needs to be freed before returning from the error paths. > + } else > + memset(&ax->attr, 0, sizeof(ax->attr)); > + > + ax->oflag = oflag; > + ax->mode = mode; > + > + ax->d.type = AUDIT_MQ_OPEN; > + ax->d.next = context->aux; > + context->aux = (void *)ax; > + return 0; > +} There are similar cases in other functions. -- ljk