Skip to content

Commit 8b67dca

Browse files
author
Al Viro
committed
[PATCH] new predicate - AUDIT_FILETYPE
Argument is S_IF... | <index>, where index is normally 0 or 1. Triggers if chosen element of ctx->names[] is present and the mode of object in question matches the upper bits of argument. I.e. for things like "is the argument of that chmod a directory", etc. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent 4a761b8 commit 8b67dca

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

include/linux/audit.h

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
#define AUDIT_WATCH 105
210210
#define AUDIT_PERM 106
211211
#define AUDIT_DIR 107
212+
#define AUDIT_FILETYPE 108
212213

213214
#define AUDIT_ARG0 200
214215
#define AUDIT_ARG1 (AUDIT_ARG0+1)

kernel/auditfilter.c

+8
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,10 @@ static struct audit_entry *audit_rule_to_entry(struct audit_rule *rule)
478478
if (f->val & ~15)
479479
goto exit_free;
480480
break;
481+
case AUDIT_FILETYPE:
482+
if ((f->val & ~S_IFMT) > S_IFMT)
483+
goto exit_free;
484+
break;
481485
case AUDIT_INODE:
482486
err = audit_to_inode(&entry->rule, f);
483487
if (err)
@@ -649,6 +653,10 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
649653
if (f->val & ~15)
650654
goto exit_free;
651655
break;
656+
case AUDIT_FILETYPE:
657+
if ((f->val & ~S_IFMT) > S_IFMT)
658+
goto exit_free;
659+
break;
652660
default:
653661
goto exit_free;
654662
}

kernel/auditsc.c

+16
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,19 @@ static int audit_match_perm(struct audit_context *ctx, int mask)
280280
}
281281
}
282282

283+
static int audit_match_filetype(struct audit_context *ctx, int which)
284+
{
285+
unsigned index = which & ~S_IFMT;
286+
mode_t mode = which & S_IFMT;
287+
if (index >= ctx->name_count)
288+
return 0;
289+
if (ctx->names[index].ino == -1)
290+
return 0;
291+
if ((ctx->names[index].mode ^ mode) & S_IFMT)
292+
return 0;
293+
return 1;
294+
}
295+
283296
/*
284297
* We keep a linked list of fixed-sized (31 pointer) arrays of audit_chunk *;
285298
* ->first_trees points to its beginning, ->trees - to the current end of data.
@@ -589,6 +602,9 @@ static int audit_filter_rules(struct task_struct *tsk,
589602
case AUDIT_PERM:
590603
result = audit_match_perm(ctx, f->val);
591604
break;
605+
case AUDIT_FILETYPE:
606+
result = audit_match_filetype(ctx, f->val);
607+
break;
592608
}
593609

594610
if (!result)

0 commit comments

Comments
 (0)