PERFORCE change 45192 for review
Robert Watson
rwatson at FreeBSD.org
Mon Jan 12 06:08:08 GMT 2004
http://perforce.freebsd.org/chv.cgi?CH=45192
Change 45192 by rwatson at rwatson_paprika on 2004/01/11 22:08:07
Create a MALLOC_DECLARE() for M_AUDIT in kern_audit.h so M_AUDIT
can be used in additional .c files.
Remove kmem/mutex stubs from bsm_audit.c, bsm_token.c and use
FreeBSD mutex and malloc/free functions. Much logical
simplification.
Affected files ...
.. //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_audit.c#6 edit
.. //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_token.c#5 edit
.. //depot/projects/trustedbsd/audit2/sys/security/audit/kern_audit.h#5 edit
Differences ...
==== //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_audit.c#6 (text+ko) ====
@@ -30,6 +30,7 @@
#include <sys/fcntl.h>
#include <sys/ipc.h>
#include <sys/lock.h>
+#include <sys/malloc.h>
#include <sys/mutex.h>
#include <sys/socket.h>
#include <sys/systm.h>
@@ -43,14 +44,6 @@
#include <security/audit/kern_audit.h>
#include <security/audit/bsm_klib.h>
-/* XXXDARWIN */
-typedef struct mutex mutex_t;
-#define kmem_alloc(map, ptrref, size)
-#define kmem_free(map, ptr, size)
-#define mutex_alloc(x) (NULL)
-#define mutex_lock(x)
-#define mutex_unlock(x)
-
/* The number of BSM records allocated. */
static int bsm_rec_count = 0;
@@ -65,7 +58,7 @@
/*
* Lock for serializing access to the list of audit records.
*/
-static mutex_t *bsm_audit_mutex;
+static struct mtx bsm_audit_mutex;
/*
* Initialize the BSM auditing subsystem.
@@ -75,7 +68,7 @@
{
printf("BSM auditing present\n");
LIST_INIT(&bsm_free_q);
- bsm_audit_mutex = mutex_alloc(ETAP_NO_TRACE);
+ mtx_init(&bsm_audit_mutex, "bsm_audit_mutex", NULL, MTX_DEF);
}
/*
@@ -94,38 +87,31 @@
/*
* Find an unused record, remove it from the free list, mark as used
*/
- mutex_lock(bsm_audit_mutex);
+ mtx_lock(&bsm_audit_mutex);
if (!LIST_EMPTY(&bsm_free_q)) {
rec = LIST_FIRST(&bsm_free_q);
LIST_REMOVE(rec, au_rec_q);
}
- mutex_unlock(bsm_audit_mutex);
+ mtx_unlock(&bsm_audit_mutex);
if (rec == NULL) {
- mutex_lock(bsm_audit_mutex);
+ mtx_lock(&bsm_audit_mutex);
if (bsm_rec_count >= MAX_AUDIT_RECORDS) {
/* XXX We need to increase size of MAX_AUDIT_RECORDS */
- mutex_unlock(bsm_audit_mutex);
+ mtx_unlock(&bsm_audit_mutex);
return NULL;
}
- mutex_unlock(bsm_audit_mutex);
+ mtx_unlock(&bsm_audit_mutex);
/*
* Create a new BSM kernel record.
*/
- kmem_alloc(kernel_map, &rec, sizeof(*rec));
- if(rec == NULL) {
- return NULL;
- }
- kmem_alloc(kernel_map, &rec->data,
- MAX_AUDIT_RECORD_SIZE * sizeof(u_char));
- if((rec->data) == NULL) {
- kmem_free(kernel_map, rec, sizeof(*rec));
- return NULL;
- }
- mutex_lock(bsm_audit_mutex);
+ rec = malloc(sizeof(*rec), M_AUDIT, M_WAITOK);
+ rec->data = malloc(MAX_AUDIT_RECORD_SIZE * sizeof(u_char),
+ M_AUDIT, M_WAITOK);
+ mtx_lock(&bsm_audit_mutex);
bsm_rec_count++;
- mutex_unlock(bsm_audit_mutex);
+ mtx_unlock(&bsm_audit_mutex);
}
memset(rec->data, 0, MAX_AUDIT_RECORD_SIZE);
@@ -205,19 +191,19 @@
/* Free the token list */
while ((tok = TAILQ_FIRST(&rec->token_q))) {
TAILQ_REMOVE(&rec->token_q, tok, tokens);
- kmem_free(kernel_map, tok->t_data, tok->len);
- kmem_free(kernel_map, tok, sizeof(struct au_token));
+ free(tok->t_data, M_AUDIT);
+ free(tok, M_AUDIT);
}
rec->used = 0;
rec->len = 0;
- mutex_lock(bsm_audit_mutex);
+ mtx_lock(&bsm_audit_mutex);
/* Add the record to the freelist */
LIST_INSERT_HEAD(&bsm_free_q, rec, au_rec_q);
- mutex_unlock(bsm_audit_mutex);
+ mtx_unlock(&bsm_audit_mutex);
}
==== //depot/projects/trustedbsd/audit2/sys/security/audit/bsm_token.c#5 (text+ko) ====
@@ -28,37 +28,26 @@
#include <sys/bsm_token.h>
#include <sys/ipc.h>
#include <sys/libkern.h>
+#include <sys/malloc.h>
#include <sys/socket.h>
-#include <sys/un.h>
+#include <sys/ucred.h>
+#include <sys/un.h>
#include <sys/vnode.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
-#define kmem_alloc(map, ptrref, size)
-#define kmem_free(map, ptr, size)
+#include <security/audit/kern_audit.h>
-#define GET_TOKEN_AREA(tok, dptr, length) \
- do {\
- kmem_alloc(kernel_map, &tok, sizeof(*tok)); \
- if(tok != NULL)\
- {\
- tok->len = length;\
- kmem_alloc(kernel_map, &tok->t_data, \
- length * sizeof(u_char));\
- if((dptr = tok->t_data) == NULL)\
- {\
- kmem_free(kernel_map, tok, sizeof(*tok));\
- tok = NULL;\
- }\
- else\
- {\
- memset(dptr, 0, length);\
- }\
- }\
- }while(0)
-
+#define GET_TOKEN_AREA(tok, dptr, length) \
+ do { \
+ tok = malloc(sizeof(*tok), M_AUDIT, M_WAITOK); \
+ tok->len = length; \
+ dptr = tok->t_data = malloc(length * sizeof(u_char), \
+ M_AUDIT, M_WAITOK); \
+ memset(tok->t_data, 0, length); \
+ } while (0)
/*
==== //depot/projects/trustedbsd/audit2/sys/security/audit/kern_audit.h#5 (text+ko) ====
@@ -85,6 +85,10 @@
#define ARG_NONE 0x0000000000000000ULL
#define ARG_ALL 0xFFFFFFFFFFFFFFFFULL
+#ifdef MALLOC_DECLARE
+MALLOC_DECLARE(M_AUDIT);
+#endif
+
struct vnode_au_info {
mode_t vn_mode;
uid_t vn_uid;
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