On Tue, 2007-03-06 at 22:13 -0500, Alexander Viro wrote:
OK... Here's combined patch (with switch to
security_task_getsecid(), etc.)
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 3599558..f8875cb 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -729,6 +732,7 @@ static inline void audit_free_context(struct audit_context *context)
audit_free_names(context);
audit_free_aux(context);
kfree(context->filterkey);
+ kfree(context->obj_ctx);
Technically, this should be:
security_release_secctx(context->obj_ctx, context->ctxlen);
Although that does require keeping the length around, and the rest of
the audit code is already assuming it is just a string (unlike the
original user of these LSM hooks, the labeled IPSEC code).
@@ -739,28 +743,26 @@ static inline void audit_free_context(struct
audit_context *context)
void audit_log_task_context(struct audit_buffer *ab)
{
char *ctx = NULL;
- ssize_t len = 0;
+ unsigned len;
+ int error;
+ u32 sid;
- len = security_getprocattr(current, "current", NULL, 0);
- if (len < 0) {
- if (len != -EINVAL)
+ security_task_getsecid(current, &sid);
+ if (!sid)
+ return;
+
+ error = security_secid_to_secctx(sid, &ctx, &len);
+ if (error) {
+ if (error != -EINVAL)
goto error_path;
return;
}
- ctx = kmalloc(len, GFP_KERNEL);
- if (!ctx)
- goto error_path;
-
- len = security_getprocattr(current, "current", ctx, len);
- if (len < 0 )
- goto error_path;
-
audit_log_format(ab, " subj=%s", ctx);
+ kfree(ctx);
As above, technically should be:
security_release_secctx(ctx,len).
@@ -1195,6 +1207,9 @@ void audit_syscall_exit(int valid, long
return_code)
} else {
audit_free_names(context);
audit_free_aux(context);
+ kfree(context->obj_ctx);
And again.
Otherwise, looks fine.
--
Stephen Smalley
National Security Agency