LINUX 5.3.0: Check for 'recurse' arg in keyring_search
[openafs.git] / src / afs / LINUX / osi_syscall.c
index 75cb922..921a7a8 100644 (file)
 #include <afsconfig.h>
 #include "afs/param.h"
 
-RCSID
-    ("$Header$");
+#ifdef LINUX_KEYRING_SUPPORT
+/* The syscall probing stuff is unnecessary (and is never called) if we have
+ * keyrings support; we rely on keyrings instead of group ids to track PAGs.
+ * So if we have keyrings, just stub out the syscall functions to do nothing. */
+int
+osi_syscall_init(void)
+{
+    return 0;
+}
+void
+osi_syscall_clean(void)
+{
+    return;
+}
+
+#else /* LINUX_KEYRING_SUPPORT */
 
-#ifdef AFS_LINUX24_ENV
 #include <linux/module.h> /* early to avoid printf->printk mapping */
-#endif
 #include "afs/sysincludes.h"
 #include "afsincludes.h"
-#include "h/unistd.h"          /* For syscall numbers. */
-#include "h/mm.h"
+#include <linux/unistd.h>              /* For syscall numbers. */
+#include <linux/mm.h>
 
 #ifdef AFS_AMD64_LINUX20_ENV
 #include <asm/ia32_unistd.h>
@@ -31,10 +43,8 @@ RCSID
 
 #include <linux/proc_fs.h>
 #include <linux/slab.h>
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
 #include <linux/init.h>
 #include <linux/sched.h>
-#endif
 
 #ifndef NR_syscalls
 #define NR_syscalls 222
@@ -54,9 +64,25 @@ RCSID
 #define SYSCALL2POINTER (void *)
 #endif
 
-#if defined(AFS_S390X_LINUX24_ENV) && !defined(AFS_LINUX26_ENV)
-#define _S(x) ((x)<<1)
-#elif defined(AFS_IA64_LINUX20_ENV)
+#if defined(AFS_S390X_LINUX24_ENV) 
+#define INSERT_SYSCALL(SLOT, TMPPAGE, FUNC) \
+       if (SYSCALL2POINTER FUNC > 0x7fffffff) { \
+           TMPPAGE = kmalloc ( PAGE_SIZE, GFP_DMA|GFP_KERNEL );        \
+           if (SYSCALL2POINTER TMPPAGE > 0x7fffffff) { \
+               printf("Cannot allocate page for FUNC syscall jump vector\n"); \
+               return EINVAL; \
+           } \
+           memcpy(TMPPAGE, syscall_jump_code, sizeof(syscall_jump_code)); \
+           *(void **)(TMPPAGE + 0x0c) = &FUNC; \
+           afs_sys_call_table[_S(SLOT)] = POINTER2SYSCALL TMPPAGE; \
+       } else \
+           afs_sys_call_table[_S(SLOT)] = POINTER2SYSCALL FUNC;
+#else
+#define INSERT_SYSCALL(SLOT, TMPPAGE, FUNC) \
+    afs_sys_call_table[_S(SLOT)] = POINTER2SYSCALL FUNC;
+#endif 
+
+#if defined(AFS_IA64_LINUX20_ENV)
 #define _S(x) ((x)-1024)
 #else
 #define _S(x) x
@@ -70,31 +96,41 @@ afs_syscall(long syscall, long parm1, long parm2, long parm3, long parm4);
 static SYSCALLTYPE *afs_sys_call_table;
 static SYSCALLTYPE afs_ni_syscall = 0;
 
-extern long afs_xsetgroups();
-asmlinkage long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist);
-
-#ifdef AFS_LINUX24_ENV
-extern int afs_xsetgroups32();
-asmlinkage int (*sys_setgroups32p) (int gidsetsize,
-                                   __kernel_gid32_t * grouplist);
+#ifdef AFS_S390X_LINUX24_ENV
+static void *afs_sys_setgroups_page = 0;
+#if defined(__NR_setgroups32)
+static void *afs_sys_setgroups32_page = 0;
 #endif
+static void *afs_syscall_page = 0;
+
+/* Because of how the syscall table is handled, we need to ensure our 
+   syscalls are within the first 2gb of address space. This means we need
+   self-modifying code we can inject to call our handlers if the module 
+   is loaded high. If keyrings had advanced as fast as false protection
+   this would be unnecessary. */
 
-#if !defined(AFS_LINUX24_ENV)
-asmlinkage int (*sys_settimeofdayp) (struct timeval * tv, struct timezone * tz);
+uint32_t syscall_jump_code[] = {
+  0xe3d0f030, 0x00240dd0, 0xa7f40006, 0xffffffff, 0xffffffff, 0xe310d004, 
+  0x0004e3d0, 0xf0300004, 0x07f10000, 
+};
 #endif
 
+extern asmlinkage long afs_xsetgroups(int gidsetsize, gid_t * grouplist);
+asmlinkage long (*sys_setgroupsp) (int gidsetsize, gid_t * grouplist);
+
+extern asmlinkage long afs_xsetgroups32(int gidsetsize, gid_t * grouplist);
+asmlinkage int (*sys_setgroups32p) (int gidsetsize,
+                                   __kernel_gid32_t * grouplist);
 
 /***** AMD64 *****/
 #ifdef AFS_AMD64_LINUX20_ENV
 static SYSCALLTYPE *afs_ia32_sys_call_table;
 static SYSCALLTYPE ia32_ni_syscall = 0;
 
-extern int afs32_xsetgroups();
+extern asmlinkage long afs32_xsetgroups(int gidsetsize, u16 * grouplist);
 asmlinkage long (*sys32_setgroupsp) (int gidsetsize, u16 * grouplist);
-#ifdef AFS_LINUX24_ENV
-extern int afs32_xsetgroups32();
+extern asmlinkage long afs32_xsetgroups32(int gidsetsize, gid_t * grouplist);
 asmlinkage long (*sys32_setgroups32p) (int gidsetsize, gid_t * grouplist);
-#endif /* __NR_ia32_setgroups32 */
 #endif /* AFS_AMD64_LINUX20_ENV */
 
 
@@ -105,56 +141,40 @@ static SYSCALLTYPE afs_ni_syscall32 = 0;
 static SYSCALLTYPE old_sys_setgroupsp = 0;
 static SYSCALLTYPE old_sys32_setgroupsp = 0;
 
-extern int afs32_xsetgroups();
+asmlinkage long afs32_xsetgroups(int gidsetsize, gid_t *grouplist);
 asmlinkage long (*sys32_setgroupsp)(int gidsetsize, gid_t *grouplist);
 
 asmlinkage long sys_close(unsigned int fd);
-static void sys_setgroups_stub() 
+static void sys_setgroups_stub(void)
        __attribute__ ((pure,const,no_instrument_function));
-static void sys_setgroups_stub() 
+static void sys_setgroups_stub(void)
 { 
        printf("*** error! sys_setgroups_stub called\n");
 }
 
-static void sys32_setgroups_stub() 
+static void sys32_setgroups_stub(void)
        __attribute__ ((pure,const,no_instrument_function));
-static void sys32_setgroups_stub() 
+static void sys32_setgroups_stub(void)
 { 
        printf("*** error! sys32_setgroups_stub called\n");
 }
 
-#endif /* AFS_AMD64_LINUX20_ENV */
+#endif /* AFS_PPC64_LINUX26_ENV */
 
 
 /***** SPARC64 *****/
-#ifdef AFS_SPARC64_LINUX20_ENV
 #ifdef AFS_SPARC64_LINUX26_ENV
 static SYSCALLTYPE *afs_sys_call_table32;
-#else
-extern SYSCALLTYPE *afs_sys_call_table32;
-#endif
 static SYSCALLTYPE afs_ni_syscall32 = 0;
 
-extern int afs32_xsetgroups();
-#ifdef AFS_SPARC64_LINUX26_ENV
+extern asmlinkage long afs32_xsetgroups(int gidsetsize, u16 * grouplist);
 asmlinkage int (*sys32_setgroupsp) (int gidsetsize,
                                    __kernel_gid32_t * grouplist);
-#else
-asmlinkage int (*sys32_setgroupsp) (int gidsetsize,
-                                   __kernel_gid_t32 * grouplist);
-#endif
-#ifdef AFS_LINUX24_ENV
 /* This number is not exported for some bizarre reason. */
 #define __NR_setgroups32      82
-extern int afs32_xsetgroups32();
-#ifdef AFS_SPARC64_LINUX26_ENV
+extern asmlinkage long afs32_xsetgroups32(int gidsetsize, gid_t * grouplist);
 asmlinkage int (*sys32_setgroups32p) (int gidsetsize,
                                      __kernel_gid32_t * grouplist);
-#else
-asmlinkage int (*sys32_setgroups32p) (int gidsetsize,
-                                     __kernel_gid_t32 * grouplist);
-#endif
-#endif
 
 asmlinkage int
 afs_syscall32(long syscall, long parm1, long parm2, long parm3, long parm4,
@@ -389,10 +409,6 @@ int osi_syscall_init(void)
     afs_sys_call_table = osi_find_syscall_table(0);
     if (afs_sys_call_table) {
 
-#if !defined(AFS_LINUX24_ENV)
-       /* XXX no sys_settimeofday on IA64? */
-#endif
-
        /* check we aren't already loaded */
        /* XXX this can't be right */
        if (SYSCALL2POINTER afs_sys_call_table[_S(__NR_afs_syscall)]
@@ -461,18 +477,14 @@ int osi_syscall_init(void)
 
         flush_cache((void *)afs_sys_call_table, 2*NR_syscalls*sizeof(void*));
 
-       sys_setgroupsp = sys_setgroups_stub;
-       sys32_setgroupsp = sys32_setgroups_stub;
+       sys_setgroupsp = POINTER2SYSCALL sys_setgroups_stub;
+       sys32_setgroupsp = POINTER2SYSCALL sys32_setgroups_stub;
     }
 /***** COMMON (except IA64 or PPC64) *****/
 #else /* !AFS_IA64_LINUX20_ENV */
 
     afs_sys_call_table = osi_find_syscall_table(0);
     if (afs_sys_call_table) {
-#if !defined(AFS_LINUX24_ENV)
-       sys_settimeofdayp =
-           SYSCALL2POINTER afs_sys_call_table[_S(__NR_settimeofday)];
-#endif /* AFS_LINUX24_ENV */
 
        /* check we aren't already loaded */
        if (SYSCALL2POINTER afs_sys_call_table[_S(__NR_afs_syscall)]
@@ -483,16 +495,17 @@ int osi_syscall_init(void)
 
        /* setup AFS entry point */
        afs_ni_syscall = afs_sys_call_table[_S(__NR_afs_syscall)];
-       afs_sys_call_table[_S(__NR_afs_syscall)] = POINTER2SYSCALL afs_syscall;
+
+       INSERT_SYSCALL(__NR_afs_syscall, afs_syscall_page, afs_syscall)
 
        /* setup setgroups */
        sys_setgroupsp = SYSCALL2POINTER afs_sys_call_table[_S(__NR_setgroups)];
-       afs_sys_call_table[_S(__NR_setgroups)] = POINTER2SYSCALL afs_xsetgroups;
+       INSERT_SYSCALL(__NR_setgroups, afs_sys_setgroups_page, afs_xsetgroups)
 
 #if defined(__NR_setgroups32)
        /* setup setgroups32 */
        sys_setgroups32p = SYSCALL2POINTER afs_sys_call_table[__NR_setgroups32];
-       afs_sys_call_table[__NR_setgroups32] = POINTER2SYSCALL afs_xsetgroups32;
+       INSERT_SYSCALL(__NR_setgroups32, afs_sys_setgroups32_page, afs_xsetgroups32)
 #endif
     }
 #endif /* !AFS_IA64_LINUX20_ENV */
@@ -513,13 +526,11 @@ int osi_syscall_init(void)
        afs_ia32_sys_call_table[__NR_ia32_setgroups] =
            POINTER2SYSCALL afs32_xsetgroups;
 
-#if AFS_LINUX24_ENV
        /* setup setgroups32 for IA32 */
        sys32_setgroups32p =
            SYSCALL2POINTER afs_ia32_sys_call_table[__NR_ia32_setgroups32];
        afs_ia32_sys_call_table[__NR_ia32_setgroups32] =
            POINTER2SYSCALL afs32_xsetgroups32;
-#endif /* __NR_ia32_setgroups32 */
     }
 #endif /* AFS_AMD64_LINUX20_ENV */
 
@@ -536,13 +547,11 @@ int osi_syscall_init(void)
        sys32_setgroupsp = SYSCALL2POINTER afs_sys_call_table32[__NR_setgroups];
        afs_sys_call_table32[__NR_setgroups] = POINTER2SYSCALL afs32_xsetgroups;
 
-#ifdef AFS_LINUX24_ENV
        /* setup setgroups32 for 32-bit SPARC */
        sys32_setgroups32p =
            SYSCALL2POINTER afs_sys_call_table32[__NR_setgroups32];
        afs_sys_call_table32[__NR_setgroups32] =
            POINTER2SYSCALL afs32_xsetgroups32;
-#endif
     }
 #endif /* AFS_SPARC64_LINUX20_ENV */
     return 0;
@@ -580,6 +589,16 @@ void osi_syscall_clean(void)
        /* put back setgroups32 */
        afs_sys_call_table[__NR_setgroups32] = POINTER2SYSCALL sys_setgroups32p;
 #endif
+#if defined(AFS_S390X_LINUX24_ENV)
+#if defined(__NR_setgroups32) && !defined(AFS_IA64_LINUX20_ENV)
+       if (afs_sys_setgroups32_page)
+           kfree(afs_sys_setgroups32_page);
+#endif
+       if (afs_sys_setgroups_page)
+           kfree(afs_sys_setgroups_page);
+       if (afs_syscall_page)
+           kfree(afs_syscall_page);
+#endif
     }
 
 
@@ -600,11 +619,9 @@ void osi_syscall_clean(void)
        afs_ia32_sys_call_table[__NR_ia32_setgroups] =
            POINTER2SYSCALL sys32_setgroupsp;
 
-#ifdef AFS_LINUX24_ENV
        /* put back setgroups32 for IA32 */
        afs_ia32_sys_call_table[__NR_ia32_setgroups32] =
            POINTER2SYSCALL sys32_setgroups32p;
-#endif
     }
 #endif
 
@@ -619,11 +636,11 @@ void osi_syscall_clean(void)
        afs_sys_call_table32[__NR_setgroups] =
            POINTER2SYSCALL sys32_setgroupsp;
 
-#ifdef AFS_LINUX24_ENV
        /* put back setgroups32 for IA32 */
        afs_sys_call_table32[__NR_setgroups32] =
            POINTER2SYSCALL sys32_setgroups32p;
-#endif
     }
 #endif
 }
+
+#endif /* !LINUX_KEYRING_SUPPORT */