PERFORCE change 85606 for review
Robert Watson
rwatson at FreeBSD.org
Thu Oct 20 18:00:42 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=85606
Change 85606 by rwatson at rwatson_zoo on 2005/10/20 18:00:05
Break out M_AUDIT kernel malloc type into a number of different
malloc types in order to better track memory use, and make it
easier to identify the source of memory leaks.
Affected files ...
.. //depot/projects/trustedbsd/audit3/sys/security/audit/audit_arg.c#8 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/audit_private.h#11 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/audit_syscalls.c#5 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/audit_trigger.c#6 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/kern_audit.c#49 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_audit.c#26 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_klib.c#16 edit
.. //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_token.c#11 edit
Differences ...
==== //depot/projects/trustedbsd/audit3/sys/security/audit/audit_arg.c#8 (text+ko) ====
@@ -474,7 +474,8 @@
return;
if (ar->k_ar.ar_arg_text == NULL)
- ar->k_ar.ar_arg_text = malloc(MAXPATHLEN, M_AUDIT, M_WAITOK);
+ ar->k_ar.ar_arg_text = malloc(MAXPATHLEN, M_AUDITTEXT,
+ M_WAITOK);
strncpy(ar->k_ar.ar_arg_text, text, MAXPATHLEN);
ARG_SET_VALID(ar, ARG_TEXT);
@@ -678,7 +679,7 @@
pathp = &ar->k_ar.ar_arg_upath2;
if (*pathp == NULL)
- *pathp = malloc(MAXPATHLEN, M_AUDIT, M_WAITOK);
+ *pathp = malloc(MAXPATHLEN, M_AUDITPATH, M_WAITOK);
canon_path(td, upath, *pathp);
==== //depot/projects/trustedbsd/audit3/sys/security/audit/audit_private.h#11 (text+ko) ====
@@ -38,7 +38,10 @@
#include <sys/ucred.h>
#ifdef MALLOC_DECLARE
-MALLOC_DECLARE(M_AUDIT);
+MALLOC_DECLARE(M_AUDITBSM);
+MALLOC_DECLARE(M_AUDITDATA);
+MALLOC_DECLARE(M_AUDITPATH);
+MALLOC_DECLARE(M_AUDITTEXT);
#endif
/*
==== //depot/projects/trustedbsd/audit3/sys/security/audit/audit_syscalls.c#5 (text+ko) ====
@@ -83,7 +83,7 @@
if (uap->length > MAX_AUDIT_RECORD_SIZE)
return (EINVAL);
- rec = malloc(uap->length, M_AUDIT, M_WAITOK);
+ rec = malloc(uap->length, M_AUDITDATA, M_WAITOK);
error = copyin(uap->record, rec, uap->length);
if (error)
@@ -111,7 +111,7 @@
/* audit_syscall_exit() will free the audit record on the thread
* even if we allocated it above.
*/
- free(rec, M_AUDIT);
+ free(rec, M_AUDITDATA);
return (error);
}
==== //depot/projects/trustedbsd/audit3/sys/security/audit/audit_trigger.c#6 (text+ko) ====
@@ -46,6 +46,7 @@
unsigned int trigger;
TAILQ_ENTRY(trigger_info) list;
};
+static MALLOC_DEFINE(M_AUDITTRIGGER, "audit_trigger", "Audit trigger events");
static struct cdev *audit_dev;
static int audit_isopen = 0;
static TAILQ_HEAD(, trigger_info) trigger_list;
@@ -79,7 +80,7 @@
while (!TAILQ_EMPTY(&trigger_list)) {
ti = TAILQ_FIRST(&trigger_list);
TAILQ_REMOVE(&trigger_list, ti, list);
- free(ti, M_AUDIT);
+ free(ti, M_AUDITTRIGGER);
}
mtx_unlock(&audit_trigger_mtx);
@@ -106,7 +107,7 @@
mtx_unlock(&audit_trigger_mtx);
if (!error) {
error = uiomove(ti, sizeof *ti, uio);
- free(ti, M_AUDIT);
+ free(ti, M_AUDITTRIGGER);
}
return (error);
}
@@ -131,7 +132,7 @@
/*
* XXXAUDIT: Use a condition variable instead of msleep/wakeup?
*/
- ti = malloc(sizeof *ti, M_AUDIT, M_WAITOK);
+ ti = malloc(sizeof *ti, M_AUDITTRIGGER, M_WAITOK);
mtx_lock(&audit_trigger_mtx);
ti->trigger = trigger;
TAILQ_INSERT_TAIL(&trigger_list, ti, list);
==== //depot/projects/trustedbsd/audit3/sys/security/audit/kern_audit.c#49 (text+ko) ====
@@ -68,7 +68,11 @@
#define AUDIT_PRINTF(X)
#endif
-MALLOC_DEFINE(M_AUDIT, "audit", "Audit event records");
+static MALLOC_DEFINE(M_AUDITPROC, "audit_proc", "Audit process storage");
+static MALLOC_DEFINE(M_AUDITREC, "audit_rec", "Audit event records");
+MALLOC_DEFINE(M_AUDITDATA, "audit_data", "Audit data storage");
+MALLOC_DEFINE(M_AUDITPATH, "audit_path", "Audit path storage");
+MALLOC_DEFINE(M_AUDITTEXT, "audit_text", "Audit text storage");
/*
* Audit control settings that are set/read by system calls and are
@@ -187,18 +191,18 @@
{
if (ar->k_ar.ar_arg_upath1 != NULL) {
- free(ar->k_ar.ar_arg_upath1, M_AUDIT);
+ free(ar->k_ar.ar_arg_upath1, M_AUDITPATH);
}
if (ar->k_ar.ar_arg_upath2 != NULL) {
- free(ar->k_ar.ar_arg_upath2, M_AUDIT);
+ free(ar->k_ar.ar_arg_upath2, M_AUDITPATH);
}
if (ar->k_ar.ar_arg_text != NULL) {
- free(ar->k_ar.ar_arg_text, M_AUDIT);
+ free(ar->k_ar.ar_arg_text, M_AUDITTEXT);
}
if (ar->k_udata != NULL) {
- free(ar->k_udata, M_AUDIT);
+ free(ar->k_udata, M_AUDITDATA);
}
- free(ar, M_AUDIT);
+ free(ar, M_AUDITREC);
}
/*
@@ -749,7 +753,7 @@
* calls in the kernel.
*/
- ar = malloc(sizeof(*ar), M_AUDIT, M_WAITOK);
+ ar = malloc(sizeof(*ar), M_AUDITREC, M_WAITOK);
if (ar == NULL)
return NULL;
@@ -997,7 +1001,7 @@
KASSERT(p->p_au == NULL, ("audit_proc_alloc: p->p_au != NULL (%d)",
p->p_pid));
- p->p_au = malloc(sizeof(*(p->p_au)), M_AUDIT, M_WAITOK);
+ p->p_au = malloc(sizeof(*(p->p_au)), M_AUDITPROC, M_WAITOK);
/* XXXAUDIT: Zero? Slab allocate? */
//printf("audit_proc_alloc: pid %d p_au %p\n", p->p_pid, p->p_au);
}
@@ -1065,6 +1069,6 @@
/*
* XXXAUDIT: Assert that external memory pointers are NULL?
*/
- free(p->p_au, M_AUDIT);
+ free(p->p_au, M_AUDITPROC);
p->p_au = NULL;
}
==== //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_audit.c#26 (text+ko) ====
@@ -43,6 +43,8 @@
#include <netinet/in.h>
#include <netinet/ip.h>
+MALLOC_DEFINE(M_AUDITBSM, "audit_bsm", "Audit BSM data");
+
/*
* Forward declares.
*/
@@ -73,9 +75,9 @@
{
struct au_record *rec;
- rec = malloc(sizeof(*rec), M_AUDIT, M_WAITOK);
- rec->data = malloc(MAX_AUDIT_RECORD_SIZE * sizeof(u_char), M_AUDIT,
- M_WAITOK | M_ZERO);
+ rec = malloc(sizeof(*rec), M_AUDITBSM, M_WAITOK);
+ rec->data = malloc(MAX_AUDIT_RECORD_SIZE * sizeof(u_char),
+ M_AUDITBSM, M_WAITOK | M_ZERO);
TAILQ_INIT(&rec->token_q);
rec->len = 0;
rec->used = 1;
@@ -147,13 +149,13 @@
/* Free the token list */
while ((tok = TAILQ_FIRST(&rec->token_q))) {
TAILQ_REMOVE(&rec->token_q, tok, tokens);
- free(tok->t_data, M_AUDIT);
- free(tok, M_AUDIT);
+ free(tok->t_data, M_AUDITBSM);
+ free(tok, M_AUDITBSM);
}
rec->used = 0;
rec->len = 0;
- free(tok, M_AUDIT);
+ free(tok, M_AUDITBSM);
}
/*
==== //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_klib.c#16 (text+ko) ====
@@ -54,6 +54,7 @@
LIST_HEAD(, evclass_elem) head;
};
+static MALLOC_DEFINE(M_AUDITEVCLASS, "audit_evclass", "Audit event class");
static struct mtx evclass_mtx;
static struct evclass_list evclass_hash[EVCLASSMAP_HASH_TABLE_SIZE];
@@ -97,7 +98,7 @@
* Pessimistically, always allocate storage before acquiring mutex.
* Free if there is already a mapping for this event.
*/
- evc_new = malloc(sizeof(*evc), M_AUDIT, M_WAITOK);
+ evc_new = malloc(sizeof(*evc), M_AUDITEVCLASS, M_WAITOK);
mtx_lock(&evclass_mtx);
evcl = &evclass_hash[event % EVCLASSMAP_HASH_TABLE_SIZE];
@@ -105,7 +106,7 @@
if (evc->event == event) {
evc->class = class;
mtx_unlock(&evclass_mtx);
- free(evc_new, M_AUDIT);
+ free(evc_new, M_AUDITEVCLASS);
return;
}
}
==== //depot/projects/trustedbsd/audit3/sys/security/audit/kern_bsm_token.c#11 (text+ko) ====
@@ -58,13 +58,13 @@
#include <security/audit/audit_private.h>
#define GET_TOKEN_AREA(t, dptr, length) do { \
- t = malloc(sizeof(token_t), M_AUDIT, M_WAITOK); \
+ t = malloc(sizeof(token_t), M_AUDITBSM, M_WAITOK); \
if (t != NULL) { \
t->len = length; \
t->t_data = malloc(length * sizeof(u_char), \
- M_AUDIT, M_WAITOK); \
+ M_AUDITBSM, M_WAITOK); \
if ((dptr = t->t_data) == NULL) { \
- free(t, M_AUDIT); \
+ free(t, M_AUDITBSM); \
t = NULL; \
} else \
memset(dptr, 0, length); \
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list