Skip to content

Commit 7183abc

Browse files
cschauflerpcmoore
authored andcommitted
audit: maintain an lsm_prop in audit_context
Replace the secid value stored in struct audit_context with a struct lsm_prop. Change the code that uses this value to accommodate the change. security_audit_rule_match() expects a lsm_prop, so existing scaffolding can be removed. A call to security_secid_to_secctx() is changed to security_lsmprop_to_secctx(). The call to security_ipc_getsecid() is scaffolded. A new function lsmprop_is_set() is introduced to identify whether an lsm_prop contains a non-zero value. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> [PM: subject line tweak, fix lsmprop_is_set() typo] Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 6f2f724 commit 7183abc

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

include/linux/security.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,19 @@ static inline const char *kernel_load_data_id_str(enum kernel_load_data_id id)
291291

292292
#ifdef CONFIG_SECURITY
293293

294+
/**
295+
* lsmprop_is_set - report if there is a value in the lsm_prop
296+
* @prop: Pointer to the exported LSM data
297+
*
298+
* Returns true if there is a value set, false otherwise
299+
*/
300+
static inline bool lsmprop_is_set(struct lsm_prop *prop)
301+
{
302+
const struct lsm_prop empty = {};
303+
304+
return !!memcmp(prop, &empty, sizeof(*prop));
305+
}
306+
294307
int call_blocking_lsm_notifier(enum lsm_event event, void *data);
295308
int register_blocking_lsm_notifier(struct notifier_block *nb);
296309
int unregister_blocking_lsm_notifier(struct notifier_block *nb);
@@ -552,6 +565,17 @@ int security_bdev_setintegrity(struct block_device *bdev,
552565
size_t size);
553566
#else /* CONFIG_SECURITY */
554567

568+
/**
569+
* lsmprop_is_set - report if there is a value in the lsm_prop
570+
* @prop: Pointer to the exported LSM data
571+
*
572+
* Returns true if there is a value set, false otherwise
573+
*/
574+
static inline bool lsmprop_is_set(struct lsm_prop *prop)
575+
{
576+
return false;
577+
}
578+
555579
static inline int call_blocking_lsm_notifier(enum lsm_event event, void *data)
556580
{
557581
return 0;

kernel/audit.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <linux/fs.h>
1313
#include <linux/audit.h>
14+
#include <linux/security.h>
1415
#include <linux/skbuff.h>
1516
#include <uapi/linux/mqueue.h>
1617
#include <linux/tty.h>
@@ -160,7 +161,7 @@ struct audit_context {
160161
kuid_t uid;
161162
kgid_t gid;
162163
umode_t mode;
163-
u32 osid;
164+
struct lsm_prop oprop;
164165
int has_perm;
165166
uid_t perm_uid;
166167
gid_t perm_gid;

kernel/auditsc.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,7 @@ static int audit_filter_rules(struct task_struct *tsk,
724724
/* Find ipc objects that match */
725725
if (!ctx || ctx->type != AUDIT_IPC)
726726
break;
727-
/* scaffolding */
728-
prop.scaffold.secid = ctx->ipc.osid;
729-
if (security_audit_rule_match(&prop,
727+
if (security_audit_rule_match(&ctx->ipc.oprop,
730728
f->type, f->op,
731729
f->lsm_rule))
732730
++result;
@@ -1394,19 +1392,17 @@ static void show_special(struct audit_context *context, int *call_panic)
13941392
audit_log_format(ab, " a%d=%lx", i,
13951393
context->socketcall.args[i]);
13961394
break; }
1397-
case AUDIT_IPC: {
1398-
u32 osid = context->ipc.osid;
1399-
1395+
case AUDIT_IPC:
14001396
audit_log_format(ab, "ouid=%u ogid=%u mode=%#ho",
14011397
from_kuid(&init_user_ns, context->ipc.uid),
14021398
from_kgid(&init_user_ns, context->ipc.gid),
14031399
context->ipc.mode);
1404-
if (osid) {
1400+
if (lsmprop_is_set(&context->ipc.oprop)) {
14051401
char *ctx = NULL;
14061402
u32 len;
14071403

1408-
if (security_secid_to_secctx(osid, &ctx, &len)) {
1409-
audit_log_format(ab, " osid=%u", osid);
1404+
if (security_lsmprop_to_secctx(&context->ipc.oprop,
1405+
&ctx, &len)) {
14101406
*call_panic = 1;
14111407
} else {
14121408
audit_log_format(ab, " obj=%s", ctx);
@@ -1426,7 +1422,7 @@ static void show_special(struct audit_context *context, int *call_panic)
14261422
context->ipc.perm_gid,
14271423
context->ipc.perm_mode);
14281424
}
1429-
break; }
1425+
break;
14301426
case AUDIT_MQ_OPEN:
14311427
audit_log_format(ab,
14321428
"oflag=0x%x mode=%#ho mq_flags=0x%lx mq_maxmsg=%ld "
@@ -2642,7 +2638,8 @@ void __audit_ipc_obj(struct kern_ipc_perm *ipcp)
26422638
context->ipc.gid = ipcp->gid;
26432639
context->ipc.mode = ipcp->mode;
26442640
context->ipc.has_perm = 0;
2645-
security_ipc_getsecid(ipcp, &context->ipc.osid);
2641+
/* scaffolding */
2642+
security_ipc_getsecid(ipcp, &context->ipc.oprop.scaffold.secid);
26462643
context->type = AUDIT_IPC;
26472644
}
26482645

0 commit comments

Comments
 (0)