diff options
author | Paul Moore <pmoore@redhat.com> | 2014-12-22 12:27:39 -0500 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2014-12-22 12:27:39 -0500 |
commit | 4a92843601ad0f5067f441d2f0dca55bbe18c076 (patch) | |
tree | c4c2aeed2e5c7c0e6512f91059fd504fe8dcbfe1 /kernel/auditsc.c | |
parent | 54dc77d974a50147d6639dac6f59cb2c29207161 (diff) |
audit: correctly record file names with different path name types
There is a problem with the audit system when multiple audit records
are created for the same path, each with a different path name type.
The root cause of the problem is in __audit_inode() when an exact
match (both the path name and path name type) is not found for a
path name record; the existing code creates a new path name record,
but it never sets the path name in this record, leaving it NULL.
This patch corrects this problem by assigning the path name to these
newly created records.
There are many ways to reproduce this problem, but one of the
easiest is the following (assuming auditd is running):
# mkdir /root/tmp/test
# touch /root/tmp/test/567
# auditctl -a always,exit -F dir=/root/tmp/test
# touch /root/tmp/test/567
Afterwards, or while the commands above are running, check the audit
log and pay special attention to the PATH records. A faulty kernel
will display something like the following for the file creation:
type=SYSCALL msg=audit(1416957442.025:93): arch=c000003e syscall=2
success=yes exit=3 ... comm="touch" exe="/usr/bin/touch"
type=CWD msg=audit(1416957442.025:93): cwd="/root/tmp"
type=PATH msg=audit(1416957442.025:93): item=0 name="test/"
inode=401409 ... nametype=PARENT
type=PATH msg=audit(1416957442.025:93): item=1 name=(null)
inode=393804 ... nametype=NORMAL
type=PATH msg=audit(1416957442.025:93): item=2 name=(null)
inode=393804 ... nametype=NORMAL
While a patched kernel will show the following:
type=SYSCALL msg=audit(1416955786.566:89): arch=c000003e syscall=2
success=yes exit=3 ... comm="touch" exe="/usr/bin/touch"
type=CWD msg=audit(1416955786.566:89): cwd="/root/tmp"
type=PATH msg=audit(1416955786.566:89): item=0 name="test/"
inode=401409 ... nametype=PARENT
type=PATH msg=audit(1416955786.566:89): item=1 name="test/567"
inode=393804 ... nametype=NORMAL
This issue was brought up by a number of people, but special credit
should go to hujianyang@huawei.com for reporting the problem along
with an explanation of the problem and a patch. While the original
patch did have some problems (see the archive link below), it did
demonstrate the problem and helped kickstart the fix presented here.
* https://lkml.org/lkml/2014/9/5/66
Reported-by: hujianyang <hujianyang@huawei.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Acked-by: Richard Guy Briggs <rgb@redhat.com>
Diffstat (limited to 'kernel/auditsc.c')
-rw-r--r-- | kernel/auditsc.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/kernel/auditsc.c b/kernel/auditsc.c index 89335723fb2a..287b3d381174 100644 --- a/kernel/auditsc.c +++ b/kernel/auditsc.c | |||
@@ -1877,12 +1877,18 @@ void __audit_inode(struct filename *name, const struct dentry *dentry, | |||
1877 | } | 1877 | } |
1878 | 1878 | ||
1879 | out_alloc: | 1879 | out_alloc: |
1880 | /* unable to find the name from a previous getname(). Allocate a new | 1880 | /* unable to find an entry with both a matching name and type */ |
1881 | * anonymous entry. | 1881 | n = audit_alloc_name(context, AUDIT_TYPE_UNKNOWN); |
1882 | */ | ||
1883 | n = audit_alloc_name(context, AUDIT_TYPE_NORMAL); | ||
1884 | if (!n) | 1882 | if (!n) |
1885 | return; | 1883 | return; |
1884 | if (name) | ||
1885 | /* since name is not NULL we know there is already a matching | ||
1886 | * name record, see audit_getname(), so there must be a type | ||
1887 | * mismatch; reuse the string path since the original name | ||
1888 | * record will keep the string valid until we free it in | ||
1889 | * audit_free_names() */ | ||
1890 | n->name = name; | ||
1891 | |||
1886 | out: | 1892 | out: |
1887 | if (parent) { | 1893 | if (parent) { |
1888 | n->name_len = n->name ? parent_len(n->name->name) : AUDIT_NAME_FULL; | 1894 | n->name_len = n->name ? parent_len(n->name->name) : AUDIT_NAME_FULL; |