13 Oct, 2012

3 commits

  • Keep a pointer to the audit_names "slot" in struct filename.

    Have all of the audit_inode callers pass a struct filename ponter to
    audit_inode instead of a string pointer. If the aname field is already
    populated, then we can skip walking the list altogether and just use it
    directly.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • Currently, if we call getname() on a userland string more than once,
    we'll get multiple copies of the string and multiple audit_names
    records.

    Add a function that will allow the audit_names code to satisfy getname
    requests using info from the audit_names list, avoiding a new allocation
    and audit_names records.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • getname() is intended to copy pathname strings from userspace into a
    kernel buffer. The result is just a string in kernel space. It would
    however be quite helpful to be able to attach some ancillary info to
    the string.

    For instance, we could attach some audit-related info to reduce the
    amount of audit-related processing needed. When auditing is enabled,
    we could also call getname() on the string more than once and not
    need to recopy it from userspace.

    This patchset converts the getname()/putname() interfaces to return
    a struct instead of a string. For now, the struct just tracks the
    string in kernel space and the original userland pointer for it.

    Later, we'll add other information to the struct as it becomes
    convenient.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     

12 Oct, 2012

8 commits

  • In order to accomodate retrying path-based syscalls, we need to add a
    new "type" argument to audit_inode_child. This will tell us whether
    we're looking for a child entry that represents a create or a delete.

    If we find a parent, don't automatically assume that we need to create a
    new entry. Instead, use the information we have to try to find an
    existing entry first. Update it if one is found and create a new one if
    not.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • In the cases where we already know the length of the parent, pass it as
    a parm so we don't need to recompute it. In the cases where we don't
    know the length, pass in AUDIT_NAME_FULL (-1) to indicate that it should
    be determined.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • All the callers set this to NULL now.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • Currently, this gets set mostly by happenstance when we call into
    audit_inode_child. While that might be a little more efficient, it seems
    wrong. If the syscall ends up failing before audit_inode_child ever gets
    called, then you'll have an audit_names record that shows the full path
    but has the parent inode info attached.

    Fix this by passing in a parent flag when we call audit_inode that gets
    set to the value of LOOKUP_PARENT. We can then fix up the pathname for
    the audit entry correctly from the get-go.

    While we're at it, clean up the no-op macro for audit_inode in the
    !CONFIG_AUDITSYSCALL case.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • For now, we just have two possibilities:

    UNKNOWN: for a new audit_names record that we don't know anything about yet
    NORMAL: for everything else

    In later patches, we'll add other types so we can distinguish and update
    records created under different circumstances.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • Most of the callers get called with an inode and dentry in the reverse
    order. The compiler then has to reshuffle the arg registers and/or
    stack in order to pass them on to audit_inode_child.

    Reverse those arguments for a micro-optimization.

    Reported-by: Eric Paris
    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • If name is NULL then the condition in the loop will never be true. Also,
    with this change, we can eliminate the check for n->name == NULL since
    the equivalence check will never be true if it is.

    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     
  • In some cases, we were passing in NULL even when we have a dentry.

    Reported-by: Eric Paris
    Signed-off-by: Jeff Layton
    Signed-off-by: Al Viro

    Jeff Layton
     

09 Oct, 2012

1 commit

  • Some security modules and oprofile still uses VM_EXECUTABLE for retrieving
    a task's executable file. After this patch they will use mm->exe_file
    directly. mm->exe_file is protected with mm->mmap_sem, so locking stays
    the same.

    Signed-off-by: Konstantin Khlebnikov
    Acked-by: Chris Metcalf [arch/tile]
    Acked-by: Tetsuo Handa [tomoyo]
    Cc: Alexander Viro
    Cc: Carsten Otte
    Cc: Cyrill Gorcunov
    Cc: Eric Paris
    Cc: H. Peter Anvin
    Cc: Hugh Dickins
    Cc: Ingo Molnar
    Acked-by: James Morris
    Cc: Jason Baron
    Cc: Kentaro Takeda
    Cc: Matt Helsley
    Cc: Nick Piggin
    Cc: Oleg Nesterov
    Cc: Peter Zijlstra
    Cc: Robert Richter
    Cc: Suresh Siddha
    Cc: Venkatesh Pallipadi
    Acked-by: Linus Torvalds
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Konstantin Khlebnikov
     

03 Oct, 2012

1 commit

  • Pull security subsystem updates from James Morris:
    "Highlights:

    - Integrity: add local fs integrity verification to detect offline
    attacks
    - Integrity: add digital signature verification
    - Simple stacking of Yama with other LSMs (per LSS discussions)
    - IBM vTPM support on ppc64
    - Add new driver for Infineon I2C TIS TPM
    - Smack: add rule revocation for subject labels"

    Fixed conflicts with the user namespace support in kernel/auditsc.c and
    security/integrity/ima/ima_policy.c.

    * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (39 commits)
    Documentation: Update git repository URL for Smack userland tools
    ima: change flags container data type
    Smack: setprocattr memory leak fix
    Smack: implement revoking all rules for a subject label
    Smack: remove task_wait() hook.
    ima: audit log hashes
    ima: generic IMA action flag handling
    ima: rename ima_must_appraise_or_measure
    audit: export audit_log_task_info
    tpm: fix tpm_acpi sparse warning on different address spaces
    samples/seccomp: fix 31 bit build on s390
    ima: digital signature verification support
    ima: add support for different security.ima data types
    ima: add ima_inode_setxattr/removexattr function and calls
    ima: add inode_post_setattr call
    ima: replace iint spinblock with rwlock/read_lock
    ima: allocating iint improvements
    ima: add appraise action keywords and default rules
    ima: integrity appraisal extension
    vfs: move ima_file_free before releasing the file
    ...

    Linus Torvalds
     

18 Sep, 2012

3 commits

  • - Explicitly format uids gids in audit messges in the initial user
    namespace. This is safe because auditd is restrected to be in
    the initial user namespace.

    - Convert audit_sig_uid into a kuid_t.

    - Enable building the audit code and user namespaces at the same time.

    The net result is that the audit subsystem now uses kuid_t and kgid_t whenever
    possible making it almost impossible to confuse a raw uid_t with a kuid_t
    preventing bugs.

    Cc: Al Viro
    Cc: Eric Paris
    Cc: Greg Kroah-Hartman
    Signed-off-by: Eric W. Biederman

    Eric W. Biederman
     
  • Always store audit loginuids in type kuid_t.

    Print loginuids by converting them into uids in the appropriate user
    namespace, and then printing the resulting uid.

    Modify audit_get_loginuid to return a kuid_t.

    Modify audit_set_loginuid to take a kuid_t.

    Modify /proc//loginuid on read to convert the loginuid into the
    user namespace of the opener of the file.

    Modify /proc//loginud on write to convert the loginuid
    rom the user namespace of the opener of the file.

    Cc: Al Viro
    Cc: Eric Paris
    Cc: Paul Moore ?
    Cc: David Miller
    Signed-off-by: Eric W. Biederman

    Eric W. Biederman
     
  • The audit filter code guarantees that uid are always compared with
    uids and gids are always compared with gids, as the comparason
    operations are type specific. Take advantage of this proper to define
    audit_uid_comparator and audit_gid_comparator which use the type safe
    comparasons from uidgid.h.

    Build on audit_uid_comparator and audit_gid_comparator and replace
    audit_compare_id with audit_compare_uid and audit_compare_gid. This
    is one of those odd cases where being type safe and duplicating code
    leads to simpler shorter and more concise code.

    Don't allow bitmask operations in uid and gid comparisons in
    audit_data_to_entry. Bitmask operations are already denined in
    audit_rule_to_entry.

    Convert constants in audit_rule_to_entry and audit_data_to_entry into
    kuids and kgids when appropriate.

    Convert the uid and gid field in struct audit_names to be of type
    kuid_t and kgid_t respectively, so that the new uid and gid comparators
    can be applied in a type safe manner.

    Cc: Al Viro
    Cc: Eric Paris
    Signed-off-by: "Eric W. Biederman"

    Eric W. Biederman
     

12 Sep, 2012

1 commit

  • At the suggestion of eparis@redhat.com, move this chunk of task
    logging from audit_log_exit to audit_log_task_info and export this
    function so it's usuable elsewhere in the kernel.

    This patch is against
    git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity#next-ima-appraisal

    Changelog v2:
    - add empty audit_log_task_info if CONFIG_AUDITSYSCALL isn't set.

    Changelog v1:
    - Initial post.

    Signed-off-by: Peter Moody
    Signed-off-by: Mimi Zohar

    Peter Moody
     

14 Apr, 2012

1 commit

  • This consolidates the seccomp filter error logging path and adds more
    details to the audit log.

    Signed-off-by: Will Drewry
    Signed-off-by: Kees Cook
    Acked-by: Eric Paris

    v18: make compat= permanent in the record
    v15: added a return code to the audit_seccomp path by wad@chromium.org
    (suggested by eparis@redhat.com)
    v*: original by keescook@chromium.org
    Signed-off-by: James Morris

    Kees Cook
     

24 Jan, 2012

1 commit

  • Fix new kernel-doc warnings in auditsc.c:

    Warning(kernel/auditsc.c:1875): No description found for parameter 'success'
    Warning(kernel/auditsc.c:1875): No description found for parameter 'return_code'
    Warning(kernel/auditsc.c:1875): Excess function parameter 'pt_regs' description in '__audit_syscall_exit'

    Signed-off-by: Randy Dunlap
    Cc: Al Viro
    Cc: Eric Paris
    Signed-off-by: Linus Torvalds

    Randy Dunlap
     

18 Jan, 2012

21 commits

  • audit_log_d_path() injects an additional space before the prefix,
    which serves no purpose and doesn't mix well with other audit_log*()
    functions that do not sneak extra characters into the log.

    Signed-off-by: Kees Cook
    Signed-off-by: Eric Paris

    Kees Cook
     
  • In the loop, a size_t "len" is used to hold the return value of
    audit_log_single_execve_arg(), which returns -1 on error. In that
    case the error handling (len
    Signed-off-by: Eric Paris

    Xi Wang
     
  • This allows audit to specify rules in which we compare two fields of a
    process. Such as is the running process uid != to the running process
    euid?

    Signed-off-by: Peter Moody
    Signed-off-by: Eric Paris

    Peter Moody
     
  • This completes the matrix of interfield comparisons between uid/gid
    information for the current task and the uid/gid information for inodes.
    aka I can audit based on differences between the euid of the process and
    the uid of fs objects.

    Signed-off-by: Peter Moody
    Signed-off-by: Eric Paris

    Peter Moody
     
  • Allow audit rules to compare the gid of the running task to the gid of the
    inode in question.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Rather than code the same loop over and over implement a helper function which
    uses some pointer magic to make it generic enough to be used numerous places
    as we implement more audit interfield comparisons

    Signed-off-by: Eric Paris

    Eric Paris
     
  • We wish to be able to audit when a uid=500 task accesses a file which is
    uid=0. Or vice versa. This patch introduces a new audit filter type
    AUDIT_FIELD_COMPARE which takes as an 'enum' which indicates which fields
    should be compared. At this point we only define the task->uid vs
    inode->uid, but other comparisons can be added.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Just a code cleanup really. We don't need to make a function call just for
    it to return on error. This also makes the VFS function even easier to follow
    and removes a conditional on a hot path.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • At the moment we allow tasks to set their loginuid if they have
    CAP_AUDIT_CONTROL. In reality we want tasks to set the loginuid when they
    log in and it be impossible to ever reset. We had to make it mutable even
    after it was once set (with the CAP) because on update and admin might have
    to restart sshd. Now sshd would get his loginuid and the next user which
    logged in using ssh would not be able to set his loginuid.

    Systemd has changed how userspace works and allowed us to make the kernel
    work the way it should. With systemd users (even admins) are not supposed
    to restart services directly. The system will restart the service for
    them. Thus since systemd is going to loginuid==-1, sshd would get -1, and
    sshd would be allowed to set a new loginuid without special permissions.

    If an admin in this system were to manually start an sshd he is inserting
    himself into the system chain of trust and thus, logically, it's his
    loginuid that should be used! Since we have old systems I make this a
    Kconfig option.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The function always deals with current. Don't expose an option
    pretending one can use it for something. You can't.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Much like the ability to filter audit on the uid of an inode collected, we
    should be able to filter on the gid of the inode.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Allow syscall exit filter matching based on the uid of the owner of an
    inode used in a syscall. aka:

    auditctl -a always,exit -S open -F obj_uid=0 -F perm=wa

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Audit entry,always rules are not allowed and are automatically changed in
    exit,always rules in userspace. The kernel refuses to load such rules.

    Thus a task in the middle of a syscall (and thus in audit_finish_fork())
    can only be in one of two states: AUDIT_BUILD_CONTEXT or AUDIT_DISABLED.
    Since the current task cannot be in AUDIT_RECORD_CONTEXT we aren't every
    going to actually use the code in audit_finish_fork() since it will
    return without doing anything. Thus drop the code.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • make the conditional a static inline instead of doing it in generic code.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • A number of audit hooks make function calls before they determine that
    auxilary records do not need to be collected. Do those checks as static
    inlines since the most common case is going to be that records are not
    needed and we can skip the function call overhead.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The audit code makes heavy use of likely() and unlikely() macros, but they
    don't always make sense. Drop any that seem questionable and let the
    computer do it's thing.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • Every arch calls:

    if (unlikely(current->audit_context))
    audit_syscall_entry()

    which requires knowledge about audit (the existance of audit_context) in
    the arch code. Just do it all in static inline in audit.h so that arch's
    can remain blissfully ignorant.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The audit system previously expected arches calling to audit_syscall_exit to
    supply as arguments if the syscall was a success and what the return code was.
    Audit also provides a helper AUDITSC_RESULT which was supposed to simplify things
    by converting from negative retcodes to an audit internal magic value stating
    success or failure. This helper was wrong and could indicate that a valid
    pointer returned to userspace was a failed syscall. The fix is to fix the
    layering foolishness. We now pass audit_syscall_exit a struct pt_reg and it
    in turns calls back into arch code to collect the return value and to
    determine if the syscall was a success or failure. We also define a generic
    is_syscall_success() macro which determines success/failure based on if the
    value is < -MAX_ERRNO. This works for arches like x86 which do not use a
    separate mechanism to indicate syscall failure.

    We make both the is_syscall_success() and regs_return_value() static inlines
    instead of macros. The reason is because the audit function must take a void*
    for the regs. (uml calls theirs struct uml_pt_regs instead of just struct
    pt_regs so audit_syscall_exit can't take a struct pt_regs). Since the audit
    function takes a void* we need to use static inlines to cast it back to the
    arch correct structure to dereference it.

    The other major change is that on some arches, like ia64, MIPS and ppc, we
    change regs_return_value() to give us the negative value on syscall failure.
    THE only other user of this macro, kretprobe_example.c, won't notice and it
    makes the value signed consistently for the audit functions across all archs.

    In arch/sh/kernel/ptrace_64.c I see that we were using regs[9] in the old
    audit code as the return value. But the ptrace_64.h code defined the macro
    regs_return_value() as regs[3]. I have no idea which one is correct, but this
    patch now uses the regs_return_value() function, so it now uses regs[3].

    For powerpc we previously used regs->result but now use the
    regs_return_value() function which uses regs->gprs[3]. regs->gprs[3] is
    always positive so the regs_return_value(), much like ia64 makes it negative
    before calling the audit code when appropriate.

    Signed-off-by: Eric Paris
    Acked-by: H. Peter Anvin [for x86 portion]
    Acked-by: Tony Luck [for ia64]
    Acked-by: Richard Weinberger [for uml]
    Acked-by: David S. Miller [for sparc]
    Acked-by: Ralf Baechle [for mips]
    Acked-by: Benjamin Herrenschmidt [for ppc]

    Eric Paris
     
  • The audit system likes to collect information about processes that end
    abnormally (SIGSEGV) as this may me useful intrusion detection information.
    This patch adds audit support to collect information when seccomp forces a
    task to exit because of misbehavior in a similar way.

    Signed-off-by: Eric Paris

    Eric Paris
     
  • The audit system has the ability to filter on the major and minor number of
    the device containing the inode being operated upon. Lets say that
    /dev/sda1 has major,minor 8,1 and that we mount /dev/sda1 on /boot. Now lets
    say we add a watch with a filter on 8,1. If we proceed to open an inode
    inside /boot, such as /vboot/vmlinuz, we will match the major,minor filter.

    Lets instead assume that one were to use a tool like debugfs and were to
    open /dev/sda1 directly and to modify it's contents. We might hope that
    this would also be logged, but it isn't. The rules will check the
    major,minor of the device containing /dev/sda1. In other words the rule
    would match on the major/minor of the tmpfs mounted at /dev.

    I believe these rules should trigger on either device. The man page is
    devoid of useful information about the intended semantics. It only seems
    logical that if you want to know everything that happened on a major,minor
    that would include things that happened to the device itself...

    Signed-off-by: Eric Paris

    Eric Paris
     
  • This patch does 2 things. First it reduces the number of audit_names
    allocated in every audit context from 20 to 5. 5 should be enough for all
    'normal' syscalls (rename being the worst). Some syscalls can still touch
    more the 5 inodes such as mount. When rpc filesystem is mounted it will
    create inodes and those can exceed 5. To handle that problem this patch will
    dynamically allocate audit_names if it needs more than 5. This should
    decrease the typicall memory usage while still supporting all the possible
    kernel operations.

    Signed-off-by: Eric Paris

    Eric Paris