syscall_get_* functions are required to be implemented on all
architectures in order to extend the generic ptrace API with
PTRACE_GET_SYSCALL_INFO request.

This adds all 5 syscall_get_* functions on xtensa as documented
in asm-generic/syscall.h: syscall_get_nr, syscall_get_arguments,
syscall_get_error, syscall_get_return_value, and syscall_get_arch.

Cc: Max Filippov <jcmvb...@gmail.com>
Cc: Oleg Nesterov <o...@redhat.com>
Cc: Andy Lutomirski <l...@kernel.org>
Cc: Elvira Khabirova <lineprin...@altlinux.org>
Cc: Eugene Syromyatnikov <e...@redhat.com>
Cc: Chris Zankel <ch...@zankel.net>
Cc: Paul Moore <p...@paul-moore.com>
Cc: Eric Paris <epa...@redhat.com>
Cc: linux-xte...@linux-xtensa.org
Cc: linux-audit@redhat.com
Signed-off-by: Dmitry V. Levin <l...@altlinux.org>
---

Notes:
    v6: there is a tracehook support in xtensa tree where all syscall_get_*
        functions are implemented already, no need to pay attention at this 
patch
    v5: added syscall_get_nr, syscall_get_arguments, syscall_get_error,
        and syscall_get_return_value
    v2: added Acked-by
    v1: added syscall_get_arch

 arch/xtensa/include/asm/syscall.h | 65 +++++++++++++++++++++++++++++++
 include/uapi/linux/audit.h        |  1 +
 2 files changed, 66 insertions(+)

diff --git a/arch/xtensa/include/asm/syscall.h 
b/arch/xtensa/include/asm/syscall.h
index 3673ff1f1bc5..40c6de062ac8 100644
--- a/arch/xtensa/include/asm/syscall.h
+++ b/arch/xtensa/include/asm/syscall.h
@@ -8,6 +8,71 @@
  * Copyright (C) 2001 - 2007 Tensilica Inc.
  */
 
+#include <linux/err.h>
+#include <uapi/linux/audit.h>
+#include <asm/ptrace.h>
+#include <asm-generic/syscall.h>
+
+static inline int
+syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
+{
+       return regs->syscall;
+}
+
+static inline void
+__syscall_get_arguments(struct task_struct *task, struct pt_regs *regs,
+                       unsigned int i, unsigned int n, unsigned long *args)
+{
+       switch (i) {
+       case 0:
+               if (!n--)
+                       break;
+               *args++ = regs->areg[6];
+               /* fall through */
+       case 1:
+               if (!n--)
+                       break;
+               *args++ = regs->areg[3];
+               /* fall through */
+       case 2:
+               if (!n--)
+                       break;
+               *args++ = regs->areg[4];
+               /* fall through */
+       case 3:
+               if (!n--)
+                       break;
+               *args++ = regs->areg[5];
+               /* fall through */
+       case 4:
+               if (!n--)
+                       break;
+               *args++ = regs->areg[8];
+               /* fall through */
+       case 5:
+               if (!n--)
+                       break;
+               *args++ = regs->areg[9];
+       }
+}
+
+static inline long
+syscall_get_error(struct task_struct *task, struct pt_regs *regs)
+{
+       return IS_ERR_VALUE(regs->areg[2]) ? regs->areg[2] : 0;
+
+static inline long
+syscall_get_return_value(struct task_struct *task, struct pt_regs *regs)
+{
+       return regs->areg[2];
+}
+
+static inline int
+syscall_get_arch(void)
+{
+       return AUDIT_ARCH_XTENSA;
+}
+
 struct pt_regs;
 asmlinkage long xtensa_ptrace(long, long, long, long);
 asmlinkage long xtensa_sigreturn(struct pt_regs*);
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index 1e9808f3a240..bcc0619b046f 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -425,6 +425,7 @@ enum {
 #define AUDIT_ARCH_TILEGX32    (EM_TILEGX|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_TILEPRO     (EM_TILEPRO|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_X86_64      (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_XTENSA      (EM_XTENSA)
 
 #define AUDIT_PERM_EXEC                1
 #define AUDIT_PERM_WRITE       2
-- 
ldv

--
Linux-audit mailing list
Linux-audit@redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit

Reply via email to