diff options
| author | <dwmw2@shinybook.infradead.org> | 2005-04-29 11:08:28 -0400 |
|---|---|---|
| committer | <dwmw2@shinybook.infradead.org> | 2005-04-29 11:08:28 -0400 |
| commit | 2fd6f58ba6efc82ea2c9c2630f7ff5ed9eeaf34a (patch) | |
| tree | 87cf236a78ad242ae01f1b71c289131e6d1c0662 | |
| parent | ea3834d9fb348fb1144ad3affea22df933eaf62e (diff) | |
[AUDIT] Don't allow ptrace to fool auditing, log arch of audited syscalls.
We were calling ptrace_notify() after auditing the syscall and arguments,
but the debugger could have _changed_ them before the syscall was actually
invoked. Reorder the calls to fix that.
While we're touching ever call to audit_syscall_entry(), we also make it
take an extra argument: the architecture of the syscall which was made,
because some architectures allow more than one type of syscall.
Also add an explicit success/failure flag to audit_syscall_exit(), for
the benefit of architectures which return that in a condition register
rather than only returning a single register.
Change type of syscall return value to 'long' not 'int'.
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
| -rw-r--r-- | arch/i386/kernel/ptrace.c | 19 | ||||
| -rw-r--r-- | arch/ia64/kernel/ptrace.c | 21 | ||||
| -rw-r--r-- | arch/mips/kernel/ptrace.c | 38 | ||||
| -rw-r--r-- | arch/ppc64/kernel/ptrace.c | 15 | ||||
| -rw-r--r-- | arch/s390/kernel/ptrace.c | 21 | ||||
| -rw-r--r-- | arch/x86_64/kernel/ptrace.c | 13 | ||||
| -rw-r--r-- | include/linux/audit.h | 48 | ||||
| -rw-r--r-- | kernel/auditsc.c | 22 |
8 files changed, 139 insertions, 58 deletions
diff --git a/arch/i386/kernel/ptrace.c b/arch/i386/kernel/ptrace.c index b2f17640ce..5606ec7a5c 100644 --- a/arch/i386/kernel/ptrace.c +++ b/arch/i386/kernel/ptrace.c | |||
| @@ -682,24 +682,18 @@ void do_syscall_trace(struct pt_regs *regs, int entryexit) | |||
| 682 | /* do the secure computing check first */ | 682 | /* do the secure computing check first */ |
| 683 | secure_computing(regs->orig_eax); | 683 | secure_computing(regs->orig_eax); |
| 684 | 684 | ||
| 685 | if (unlikely(current->audit_context)) { | 685 | if (unlikely(current->audit_context) && entryexit) |
| 686 | if (!entryexit) | 686 | audit_syscall_exit(current, AUDITSC_RESULT(regs->eax), regs->eax); |
| 687 | audit_syscall_entry(current, regs->orig_eax, | ||
| 688 | regs->ebx, regs->ecx, | ||
| 689 | regs->edx, regs->esi); | ||
| 690 | else | ||
| 691 | audit_syscall_exit(current, regs->eax); | ||
| 692 | } | ||
| 693 | 687 | ||
| 694 | if (!(current->ptrace & PT_PTRACED)) | 688 | if (!(current->ptrace & PT_PTRACED)) |
| 695 | return; | 689 | goto out; |
| 696 | 690 | ||
| 697 | /* Fake a debug trap */ | 691 | /* Fake a debug trap */ |
| 698 | if (test_thread_flag(TIF_SINGLESTEP)) | 692 | if (test_thread_flag(TIF_SINGLESTEP)) |
| 699 | send_sigtrap(current, regs, 0); | 693 | send_sigtrap(current, regs, 0); |
| 700 | 694 | ||
| 701 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) | 695 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
| 702 | return; | 696 | goto out; |
| 703 | 697 | ||
| 704 | /* the 0x80 provides a way for the tracing parent to distinguish | 698 | /* the 0x80 provides a way for the tracing parent to distinguish |
| 705 | between a syscall stop and SIGTRAP delivery */ | 699 | between a syscall stop and SIGTRAP delivery */ |
| @@ -714,4 +708,9 @@ void do_syscall_trace(struct pt_regs *regs, int entryexit) | |||
| 714 | send_sig(current->exit_code, current, 1); | 708 | send_sig(current->exit_code, current, 1); |
| 715 | current->exit_code = 0; | 709 | current->exit_code = 0; |
| 716 | } | 710 | } |
| 711 | out: | ||
| 712 | if (unlikely(current->audit_context) && !entryexit) | ||
| 713 | audit_syscall_entry(current, AUDIT_ARCH_I386, regs->orig_eax, | ||
| 714 | regs->ebx, regs->ecx, regs->edx, regs->esi); | ||
| 715 | |||
| 717 | } | 716 | } |
diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c index 55789fcd72..8dde0b16d4 100644 --- a/arch/ia64/kernel/ptrace.c +++ b/arch/ia64/kernel/ptrace.c | |||
| @@ -1595,20 +1595,25 @@ syscall_trace_enter (long arg0, long arg1, long arg2, long arg3, | |||
| 1595 | long arg4, long arg5, long arg6, long arg7, | 1595 | long arg4, long arg5, long arg6, long arg7, |
| 1596 | struct pt_regs regs) | 1596 | struct pt_regs regs) |
| 1597 | { | 1597 | { |
| 1598 | long syscall; | 1598 | if (test_thread_flag(TIF_SYSCALL_TRACE) |
| 1599 | && (current->ptrace & PT_PTRACED)) | ||
| 1600 | syscall_trace(); | ||
| 1599 | 1601 | ||
| 1600 | if (unlikely(current->audit_context)) { | 1602 | if (unlikely(current->audit_context)) { |
| 1601 | if (IS_IA32_PROCESS(®s)) | 1603 | long syscall; |
| 1604 | int arch; | ||
| 1605 | |||
| 1606 | if (IS_IA32_PROCESS(®s)) { | ||
| 1602 | syscall = regs.r1; | 1607 | syscall = regs.r1; |
| 1603 | else | 1608 | arch = AUDIT_ARCH_I386; |
| 1609 | } else { | ||
| 1604 | syscall = regs.r15; | 1610 | syscall = regs.r15; |
| 1611 | arch = AUDIT_ARCH_IA64; | ||
| 1612 | } | ||
| 1605 | 1613 | ||
| 1606 | audit_syscall_entry(current, syscall, arg0, arg1, arg2, arg3); | 1614 | audit_syscall_entry(current, arch, syscall, arg0, arg1, arg2, arg3); |
| 1607 | } | 1615 | } |
| 1608 | 1616 | ||
| 1609 | if (test_thread_flag(TIF_SYSCALL_TRACE) | ||
| 1610 | && (current->ptrace & PT_PTRACED)) | ||
| 1611 | syscall_trace(); | ||
| 1612 | } | 1617 | } |
| 1613 | 1618 | ||
| 1614 | /* "asmlinkage" so the input arguments are preserved... */ | 1619 | /* "asmlinkage" so the input arguments are preserved... */ |
| @@ -1619,7 +1624,7 @@ syscall_trace_leave (long arg0, long arg1, long arg2, long arg3, | |||
| 1619 | struct pt_regs regs) | 1624 | struct pt_regs regs) |
| 1620 | { | 1625 | { |
| 1621 | if (unlikely(current->audit_context)) | 1626 | if (unlikely(current->audit_context)) |
| 1622 | audit_syscall_exit(current, regs.r8); | 1627 | audit_syscall_exit(current, AUDITSC_RESULT(regs.r10), regs.r8); |
| 1623 | 1628 | ||
| 1624 | if (test_thread_flag(TIF_SYSCALL_TRACE) | 1629 | if (test_thread_flag(TIF_SYSCALL_TRACE) |
| 1625 | && (current->ptrace & PT_PTRACED)) | 1630 | && (current->ptrace & PT_PTRACED)) |
diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c index 92f2c39afe..eaf7be9d0b 100644 --- a/arch/mips/kernel/ptrace.c +++ b/arch/mips/kernel/ptrace.c | |||
| @@ -300,25 +300,38 @@ out: | |||
| 300 | return ret; | 300 | return ret; |
| 301 | } | 301 | } |
| 302 | 302 | ||
| 303 | static inline int audit_arch() | ||
| 304 | { | ||
| 305 | #ifdef CONFIG_CPU_LITTLE_ENDIAN | ||
| 306 | #ifdef CONFIG_MIPS64 | ||
| 307 | if (!(current->thread.mflags & MF_32BIT_REGS)) | ||
| 308 | return AUDIT_ARCH_MIPSEL64; | ||
| 309 | #endif /* MIPS64 */ | ||
| 310 | return AUDIT_ARCH_MIPSEL; | ||
| 311 | |||
| 312 | #else /* big endian... */ | ||
| 313 | #ifdef CONFIG_MIPS64 | ||
| 314 | if (!(current->thread.mflags & MF_32BIT_REGS)) | ||
| 315 | return AUDIT_ARCH_MIPS64; | ||
| 316 | #endif /* MIPS64 */ | ||
| 317 | return AUDIT_ARCH_MIPS; | ||
| 318 | |||
| 319 | #endif /* endian */ | ||
| 320 | } | ||
| 321 | |||
| 303 | /* | 322 | /* |
| 304 | * Notification of system call entry/exit | 323 | * Notification of system call entry/exit |
| 305 | * - triggered by current->work.syscall_trace | 324 | * - triggered by current->work.syscall_trace |
| 306 | */ | 325 | */ |
| 307 | asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit) | 326 | asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit) |
| 308 | { | 327 | { |
| 309 | if (unlikely(current->audit_context)) { | 328 | if (unlikely(current->audit_context) && entryexit) |
| 310 | if (!entryexit) | 329 | audit_syscall_exit(current, AUDITSC_RESULT(regs->regs[2]), regs->regs[2]); |
| 311 | audit_syscall_entry(current, regs->regs[2], | ||
| 312 | regs->regs[4], regs->regs[5], | ||
| 313 | regs->regs[6], regs->regs[7]); | ||
| 314 | else | ||
| 315 | audit_syscall_exit(current, regs->regs[2]); | ||
| 316 | } | ||
| 317 | 330 | ||
| 318 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) | 331 | if (!test_thread_flag(TIF_SYSCALL_TRACE)) |
| 319 | return; | 332 | goto out; |
| 320 | if (!(current->ptrace & PT_PTRACED)) | 333 | if (!(current->ptrace & PT_PTRACED)) |
| 321 | return; | 334 | goto out; |
| 322 | 335 | ||
| 323 | /* The 0x80 provides a way for the tracing parent to distinguish | 336 | /* The 0x80 provides a way for the tracing parent to distinguish |
| 324 | between a syscall stop and SIGTRAP delivery */ | 337 | between a syscall stop and SIGTRAP delivery */ |
| @@ -334,4 +347,9 @@ asmlinkage void do_syscall_trace(struct pt_regs *regs, int entryexit) | |||
| 334 | send_sig(current->exit_code, current, 1); | 347 | send_sig(current->exit_code, current, 1); |
| 335 | current->exit_code = 0; | 348 | current->exit_code = 0; |
| 336 | } | 349 | } |
| 350 | out: | ||
| 351 | if (unlikely(current->audit_context) && !entryexit) | ||
| 352 | audit_syscall_entry(current, audit_arch(), regs->regs[2], | ||
| 353 | regs->regs[4], regs->regs[5], | ||
| 354 | regs->regs[6], regs->regs[7]); | ||
| 337 | } | 355 | } |
diff --git a/arch/ppc64/kernel/ptrace.c b/arch/ppc64/kernel/ptrace.c index 354a287c67..3c76333ec3 100644 --- a/arch/ppc64/kernel/ptrace.c +++ b/arch/ppc64/kernel/ptrace.c | |||
| @@ -304,14 +304,17 @@ static void do_syscall_trace(void) | |||
| 304 | 304 | ||
| 305 | void do_syscall_trace_enter(struct pt_regs *regs) | 305 | void do_syscall_trace_enter(struct pt_regs *regs) |
| 306 | { | 306 | { |
| 307 | if (test_thread_flag(TIF_SYSCALL_TRACE) | ||
| 308 | && (current->ptrace & PT_PTRACED)) | ||
| 309 | do_syscall_trace(); | ||
| 310 | |||
| 307 | if (unlikely(current->audit_context)) | 311 | if (unlikely(current->audit_context)) |
| 308 | audit_syscall_entry(current, regs->gpr[0], | 312 | audit_syscall_entry(current, |
| 313 | test_thread_flag(TIF_32BIT)?AUDIT_ARCH_PPC:AUDIT_ARCH_PPC64, | ||
| 314 | regs->gpr[0], | ||
| 309 | regs->gpr[3], regs->gpr[4], | 315 | regs->gpr[3], regs->gpr[4], |
| 310 | regs->gpr[5], regs->gpr[6]); | 316 | regs->gpr[5], regs->gpr[6]); |
| 311 | 317 | ||
| 312 | if (test_thread_flag(TIF_SYSCALL_TRACE) | ||
| 313 | && (current->ptrace & PT_PTRACED)) | ||
| 314 | do_syscall_trace(); | ||
| 315 | } | 318 | } |
| 316 | 319 | ||
| 317 | void do_syscall_trace_leave(struct pt_regs *regs) | 320 | void do_syscall_trace_leave(struct pt_regs *regs) |
| @@ -319,7 +322,9 @@ void do_syscall_trace_leave(struct pt_regs *regs) | |||
| 319 | secure_computing(regs->gpr[0]); | 322 | secure_computing(regs->gpr[0]); |
| 320 | 323 | ||
| 321 | if (unlikely(current->audit_context)) | 324 | <|
