Commit 5ef30ee5 authored by Eric Paris's avatar Eric Paris Committed by Al Viro

audit: make filetype matching consistent with other filters

Every other filter that matches part of the inodes list collected by audit
will match against any of the inodes on that list.  The filetype matching
however had a strange way of doing things.  It allowed userspace to
indicated if it should match on the first of the second name collected by
the kernel.  Name collection ordering seems like a kernel internal and
making userspace rules get that right just seems like a bad idea.  As it
turns out the userspace audit writers had no idea it was doing this and
thus never overloaded the value field.  The kernel always checked the first
name collected which for the tested rules was always correct.

This patch just makes the filetype matching like the major, minor, inode,
and LSM rules in that it will match against any of the names collected.  It
also changes the rule validation to reject the old unused rule types.

Noone knew it was there.  Noone used it.  Why keep around the extra code?
Signed-off-by: default avatarEric Paris <eparis@redhat.com>
parent 9fc5c3e3
...@@ -385,7 +385,7 @@ static struct audit_entry *audit_rule_to_entry(struct audit_rule *rule) ...@@ -385,7 +385,7 @@ static struct audit_entry *audit_rule_to_entry(struct audit_rule *rule)
goto exit_free; goto exit_free;
break; break;
case AUDIT_FILETYPE: case AUDIT_FILETYPE:
if ((f->val & ~S_IFMT) > S_IFMT) if (f->val & ~S_IFMT)
goto exit_free; goto exit_free;
break; break;
case AUDIT_INODE: case AUDIT_INODE:
...@@ -536,7 +536,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data, ...@@ -536,7 +536,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
goto exit_free; goto exit_free;
break; break;
case AUDIT_FILETYPE: case AUDIT_FILETYPE:
if ((f->val & ~S_IFMT) > S_IFMT) if (f->val & ~S_IFMT)
goto exit_free; goto exit_free;
break; break;
default: default:
......
...@@ -305,21 +305,20 @@ static int audit_match_perm(struct audit_context *ctx, int mask) ...@@ -305,21 +305,20 @@ static int audit_match_perm(struct audit_context *ctx, int mask)
} }
} }
static int audit_match_filetype(struct audit_context *ctx, int which) static int audit_match_filetype(struct audit_context *ctx, int val)
{ {
unsigned index = which & ~S_IFMT; int index;
umode_t mode = which & S_IFMT; umode_t mode = (umode_t)val;
if (unlikely(!ctx)) if (unlikely(!ctx))
return 0; return 0;
if (index >= ctx->name_count) for (index = 0; index < ctx->name_count; index++) {
return 0; if ((ctx->names[index].ino != -1) &&
if (ctx->names[index].ino == -1) ((ctx->names[index].mode & S_IFMT) == mode))
return 0; return 1;
if ((ctx->names[index].mode ^ mode) & S_IFMT) }
return 0; return 0;
return 1;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment