2 * vi:set cin noet sw=4 tw=70:
3 * Copyright 2004, International Business Machines Corporation and others.
6 * This software has been released under the terms of the IBM Public
7 * License. For details, see the LICENSE file in the top-level source
8 * directory or online at http://www.openafs.org/dl/license10.html
10 * Portions of this code borrowed from arla under the following terms:
11 * Copyright (c) 2003-2004 Kungliga Tekniska Högskolan
12 * (Royal Institute of Technology, Stockholm, Sweden).
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
26 * 3. Neither the name of the Institute nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
30 * Alternatively, this software may be distributed under the terms of the
31 * GNU General Public License ("GPL").
33 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46 /* Code to find the Linux syscall table */
48 #if defined(EXPORTED_INIT_MM)
49 #ifdef OSI_PROBE_STANDALONE
50 #define OSI_PROBE_DEBUG
52 #ifndef OSI_PROBE_STANDALONE
53 #include <afsconfig.h>
54 #include "afs/param.h"
56 #ifdef AFS_LINUX24_ENV
57 #include <linux/module.h> /* early to avoid printf->printk mapping */
58 #ifndef OSI_PROBE_STANDALONE
59 #include "afs/sysincludes.h"
60 #include "afsincludes.h"
62 #include <linux/version.h>
63 #include <linux/sched.h>
64 #ifdef CONFIG_H_EXISTS
65 #include <linux/config.h>
67 #include <linux/linkage.h>
68 #include <linux/init.h>
69 #include <linux/unistd.h>
71 #ifdef AFS_LINUX26_ENV
72 #include <scsi/scsi.h> /* for scsi_command_size */
75 #if defined(AFS_PPC64_LINUX26_ENV)
76 #include <asm/abs_addr.h>
79 #ifdef AFS_AMD64_LINUX20_ENV
80 #include <asm/ia32_unistd.h>
83 /* number of syscalls */
84 /* NB: on MIPS we care about the 4xxx range */
86 #define NR_syscalls 222
89 /* lower bound of valid kernel text pointers */
90 #ifdef AFS_IA64_LINUX20_ENV
91 #define ktxt_lower_bound (((unsigned long)&kernel_thread ) & 0xfff00000L)
92 #elif defined(AFS_PPC64_LINUX20_ENV)
93 #define ktxt_lower_bound (KERNELBASE)
95 #define ktxt_lower_bound (((unsigned long)&kernel_thread ) & ~0xfffffL)
98 /* On SPARC64 and S390X, sys_call_table contains 32-bit entries
99 * even though pointers are 64 bit quantities.
101 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390X_LINUX24_ENV)
102 #define SYSCALLTYPE unsigned int
103 #define PROBETYPE int
105 #define SYSCALLTYPE void *
106 #define PROBETYPE long
109 #if defined(AFS_S390X_LINUX20_ENV) && !defined(AFS_S390X_LINUX26_ENV)
110 #define _SS(x) ((x) << 1)
111 #define _SX(x) ((x) &~ 1)
117 /* Older Linux doesn't have __user. The sys_read prototype needs it. */
122 /* Allow the user to specify sys_call_table addresses */
123 static unsigned long sys_call_table_addr[4] = { 0,0,0,0 };
124 #if defined(module_param_array) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
125 module_param_array(sys_call_table_addr, long, NULL, 0);
127 MODULE_PARM(sys_call_table_addr, "1-4l");
129 MODULE_PARM_DESC(sys_call_table_addr, "Location of system call tables");
131 /* If this is set, we are more careful about avoiding duplicate matches */
132 static int probe_carefully = 1;
133 #if defined(module_param) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
134 module_param(probe_carefully, int, 0);
136 MODULE_PARM(probe_carefully, "i");
138 MODULE_PARM_DESC(probe_carefully, "Probe for system call tables carefully");
140 static int probe_ignore_syscalls[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
141 #if defined(module_param_array) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
142 module_param_array(probe_ignore_syscalls, int, NULL, 0);
144 MODULE_PARM(probe_ignore_syscalls, "1-8i");
146 MODULE_PARM_DESC(probe_ignore_syscalls, "Syscalls to ignore in table checks");
148 #ifdef OSI_PROBE_DEBUG
151 * 0x0001 - General debugging
152 * 0x0002 - detail - try
153 * 0x0004 - detail - try_harder
154 * 0x0008 - detail - check_table
155 * 0x0010 - detail - check_harder
156 * 0x0020 - detail - check_harder/zapped
157 * 0x0040 - automatically ignore setgroups and afs_syscall
158 * 0x0080 - detail - check_table_readable
160 static int probe_debug = 0x41;
161 #if defined(module_param) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
162 module_param(probe_debug, int, 0);
164 MODULE_PARM(probe_debug, "i");
166 MODULE_PARM_DESC(probe_debug, "Debugging level");
168 static unsigned long probe_debug_addr[4] = { 0,0,0,0 };
169 #if defined(module_param_array) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
170 module_param_array(probe_debug_addr, long, NULL, 0);
172 MODULE_PARM(probe_debug_addr, "1-4l");
174 MODULE_PARM_DESC(probe_debug_addr, "Debug range starting locations");
176 static unsigned long probe_debug_range = 0;
177 #if defined(module_param) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
178 module_param(probe_debug_range, long, 0);
180 MODULE_PARM(probe_debug_range, "l");
182 MODULE_PARM_DESC(probe_debug_range, "Debug range length");
184 static unsigned long probe_debug_tag = 0;
185 #if defined(module_param) && LINUX_VERSION_CODE > KERNEL_VERSION(2,6,9)
186 module_param(probe_debug_tag, long, 0);
188 MODULE_PARM(probe_debug_tag, "l");
190 MODULE_PARM_DESC(probe_debug_tag, "Debugging output start tag");
194 /* Weak references are our friends. They are supported by the in-kernel
195 * linker in Linux 2.6 and by all versions of modutils back to 2.2pre1.
196 * A weak reference not satisified by the kernel will have value zero.
198 * Unfortunately, weak references to functions don't work right on
199 * IA64; specifically, if you actually try to make a call through
200 * such a reference, and the symbol doesn't exist in the kernel, then
201 * the module relocation code will oops. A workaround for this is
202 * probably possible, but the use of kallsyms_* is of limited value,
203 * so I'm not bothing with the effort for now.
204 * -- jhutz, 10-Feb-2005
206 #ifdef OSI_PROBE_KALLSYMS
207 extern int kallsyms_symbol_to_address(char *name, unsigned long *token,
209 unsigned long *mod_start,
210 unsigned long *mod_end,
212 unsigned long *sec_start,
213 unsigned long *sec_end,
215 unsigned long *sym_start,
216 unsigned long *sym_end
217 ) __attribute__((weak));
219 extern int kallsyms_address_to_symbol(unsigned long address,
221 unsigned long *mod_start,
222 unsigned long *mod_end,
224 unsigned long *sec_start,
225 unsigned long *sec_end,
227 unsigned long *sym_start,
228 unsigned long *sym_end
229 ) __attribute__((weak));
232 extern SYSCALLTYPE sys_call_table[] __attribute__((weak));
233 extern SYSCALLTYPE ia32_sys_call_table[] __attribute__((weak));
234 extern SYSCALLTYPE sys_call_table32[] __attribute__((weak));
235 extern SYSCALLTYPE sys_call_table_emu[] __attribute__((weak));
237 extern asmlinkage ssize_t sys_read(unsigned int fd, char __user * buf, size_t count) __attribute__((weak));
238 extern asmlinkage long sys_close(unsigned int) __attribute__((weak));
239 #if defined(EXPORTED_SYS_CHDIR)
240 extern asmlinkage long sys_chdir(const char *) __attribute__((weak));
242 extern asmlinkage ssize_t sys_write(unsigned int, const char *, size_t) __attribute__((weak));
243 #ifdef AFS_LINUX26_ENV
244 extern asmlinkage long sys_wait4(pid_t, int *, int, struct rusage *) __attribute__((weak));
246 extern asmlinkage long sys_wait4(pid_t, unsigned int *, int, struct rusage *) __attribute__((weak));
248 extern asmlinkage long sys_exit (int) __attribute__((weak));
249 #if defined(EXPORTED_SYS_OPEN)
250 extern asmlinkage long sys_open (const char *, int, int) __attribute__((weak));
252 extern asmlinkage long sys_ioctl(unsigned int, unsigned int, unsigned long) __attribute__((weak));
255 /* Structures used to control probing. We put all the details of which
256 * symbols we're interested in, what syscall functions to look for, etc
257 * into tables, so we can then have a single copy of the functions that
258 * actually do the work.
271 char *symbol; /* symbol name */
272 char *desc; /* description for messages */
273 int offset; /* first syscall number in table */
275 void *weak_answer; /* weak symbol ref */
276 void *parm_answer; /* module parameter answer */
277 void *debug_answer; /* module parameter answer */
278 unsigned long given_answer; /* compiled-in answer, if any */
280 tryctl *trylist; /* array of combinations to try */
282 unsigned long try_sect_sym; /* symbol in section to try scanning */
283 unsigned long try_base; /* default base address for scan */
284 unsigned long try_base_mask; /* base address bits to force to zero */
285 unsigned long try_length; /* default length for scan */
287 unsigned long alt_try_sect_sym; /* symbol in section to try scanning */
288 unsigned long alt_try_base; /* default base address for scan */
289 unsigned long alt_try_base_mask; /* base address bits to force to zero */
290 unsigned long alt_try_length; /* default length for scan */
292 int n_zapped_syscalls; /* number of unimplemented system calls */
293 int *zapped_syscalls; /* list of unimplemented system calls */
295 int n_unique_syscalls; /* number of unique system calls */
296 int *unique_syscalls; /* list of unimplemented system calls */
298 int verifyNR; /* syscall number to verify match */
299 void *verify_fn; /* syscall pointer to verify match */
301 int debug_ignore_NR[4]; /* syscalls to ignore for debugging */
304 #if defined(AFS_I386_LINUX26_ENV) || defined(AFS_AMD64_LINUX26_ENV)
305 static int check_access(unsigned long, int);
306 static int check_table_readable(probectl *, PROBETYPE *);
310 /********** Probing Configuration: sys_call_table **********/
312 /* syscall pairs/triplets to probe */
313 /* On PPC64 and SPARC64, we need to omit the ones that might match both tables */
314 static tryctl main_try[] = {
315 #if !defined(AFS_PPC64_LINUX20_ENV) && !defined(AFS_SPARC64_LINUX20_ENV)
316 #if defined(EXPORTED_SYS_CHDIR)
317 { "scan: close+chdir+write", __NR_close, &sys_close, __NR_chdir, &sys_chdir, __NR_write, &sys_write },
320 { "scan: close+wait4", __NR_close, &sys_close, __NR_wait4, &sys_wait4, -1, 0 },
321 #if !defined(AFS_PPC64_LINUX20_ENV) && !defined(AFS_SPARC64_LINUX20_ENV)
322 #if defined(EXPORTED_SYS_CHDIR)
323 { "scan: close+chdir", __NR_close, &sys_close, __NR_chdir, &sys_chdir, -1, 0 },
326 { "scan: close+ioctl", __NR_close, &sys_close, __NR_ioctl, &sys_ioctl, -1, 0 },
327 #if defined(EXPORTED_SYS_OPEN)
328 { "scan: exit+open", __NR_exit, &sys_exit, __NR_open, &sys_open, -1, 0 },
333 /* zapped syscalls for try_harder */
334 /* this list is based on the table in 'zapped_syscalls' */
336 static int main_zapped_syscalls[] = {
338 * SPARC-Linux uses syscall number mappings chosen to be compatible
339 * with SunOS. So, it doesn't have any of the traditional calls or
340 * the new STREAMS ones. However, there are a number of syscalls
341 * which are SunOS-specific (not implemented on Linux), i386-specific
342 * (not implemented on SPARC-Linux), or implemented only on one of
343 * sparc32 or sparc64. Of course, there are no __NR macros for most
346 * Note that the calls we list here are implemented by sys_nis_syscall,
347 * not by sys_ni_syscall. That means we have to exclude all of the
348 * other entries, or we might get a sys_ni_syscall into the list and
349 * the test would no longer work.
351 #if defined(AFS_SPARC64_LINUX20_ENV)
352 /* mmap2, fstat64, getmsg, putmsg, modify_ldt */
353 56, 63, 151, 152, 218,
354 #elif defined(AFS_SPARC_LINUX20_ENV)
355 /* memory_ordering, getmsg, putmsg, unimplemented, modify_ldt */
356 52, 151, 152, 164, 218,
357 #else /* !AFS_SPARC_LINUX20_ENV */
360 * These 7 syscalls are present in the syscall table on most "older"
361 * platforms that use the traditional syscall number mappings. They
362 * are not implemented on any platform.
386 * On s390 and arm (but not arm26), the seven traditional unimplemented
387 * system calls are indeed present and unimplemented. However, the
388 * corresponding __NR macros are not defined, so the tests above fail.
389 * Instead, we just have to know the numbers for these.
391 #if defined(AFS_S390_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
392 /* break, stty, gtty, ftime, prof, lock, mpx */
393 17, 31, 32, 35, 44, 53, 56,
397 * Sadly, some newer platforms like IA64, amd64, and PA-RISC don't have
398 * the traditional numbers, so the list above are not helpful. They
399 * do have entries for getpmsg/putpmsg, which are always unimplemented.
409 * The module-loading mechanism changed in Linux 2.6, and insmod's
410 * loss is our gain: three new unimplemented system calls!
412 #if defined(AFS_LINUX26_ENV)
416 #ifdef __NR_query_module
419 #ifdef __NR_get_kernel_syms
420 __NR_get_kernel_syms,
422 #endif /* AFS_LINUX26_ENV */
425 * On IA64, the old module-loading calls are indeed present and
426 * unimplemented, but the __NR macros are not defined. Again,
427 * we simply have to know their numbers.
429 #ifdef AFS_IA64_LINUX26_ENV
430 /* create_module, query_module, get_kernel_sysms */
434 /* And the same deal for arm (not arm26), if we ever support that. */
436 /* create_module, query_module, get_kernel_sysms */
441 * Alpha-Linux uses syscall number mappings chosen to be compatible
442 * with OSF/1. So, it doesn't have any of the traditional calls or
443 * the new STREAMS ones, but it does have several OSF/1-specific
444 * syscalls which are not implemented on Linux. These don't exist on
445 * any other platform.
447 #ifdef __NR_osf_syscall
450 #ifdef __NR_osf_profil
453 #ifdef __NR_osf_reboot
456 #ifdef __NR_osf_kmodcall
459 #ifdef __NR_osf_old_vtrace
464 * On PPC64, we need a couple more entries to distinguish the two
465 * tables, since the system call numbers are the same and the sets of
466 * unimplemented calls are very similar.
467 * mmap2 and fstat64 are implemented only for 32-bit calls
469 #ifdef AFS_PPC64_LINUX20_ENV
470 /* _mmap2, _fstat64 */
472 #endif /* AFS_PPC64_LINUX20_ENV */
474 /* Similarly for S390X, with lcown16 and fstat64 */
475 #ifdef AFS_S390X_LINUX20_ENV
476 /* lchown16, fstat64 */
479 #endif /* !AFS_SPARC_LINUX20_ENV */
483 /* unique syscalls for try_harder */
484 static int main_unique_syscalls[] = {
485 #if defined(AFS_SPARC64_LINUX24_ENV) || defined(AFS_SPARC_LINUX24_ENV)
487 * On SPARC, we need some additional unique calls to make sure
488 * we don't match the SunOS-compatibility table.
490 __NR_sgetmask, __NR_ssetmask,
492 __NR_exit, __NR_mount, __NR_read, __NR_write,
493 __NR_open, __NR_close, __NR_unlink
496 /* probe control structure */
497 static probectl main_probe = {
498 /* symbol name and description */
502 /* syscall number of first entry in table */
503 #ifdef AFS_IA64_LINUX20_ENV
509 sys_call_table, /* weak symbol ref */
510 0, 0, /* module parameter answers */
511 #ifdef AFS_LINUX_sys_call_table
512 AFS_LINUX_sys_call_table, /* compiled-in answer, if any */
517 main_try, /* array of combinations to try */
519 /* symbol in section to try scanning */
520 #if defined(AFS_SPARC64_LINUX20_ENV) || defined(AFS_S390_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
521 (unsigned long)&sys_close,
522 #elif defined(AFS_AMD64_LINUX26_ENV)
523 /* On this platform, it's in a different section! */
524 (unsigned long)&generic_ro_fops,
525 #elif defined(AFS_AMD64_LINUX20_ENV)
526 /* On this platform, it's in a different section! */
527 (unsigned long)&tasklist_lock,
529 (unsigned long)&init_mm,
532 /* default base address for scan */
533 /* base address bits to force to zero */
534 /* default length for scan */
535 #if defined(AFS_SPARC64_LINUX20_ENV)
536 (unsigned long)(&sys_close),
539 #elif defined(AFS_S390_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
540 /* bleah; this is so suboptimal */
541 (unsigned long)(&sys_close),
544 #elif defined(AFS_IA64_LINUX20_ENV)
545 (unsigned long)(&init_mm),
548 #elif defined(AFS_AMD64_LINUX26_ENV)
549 (unsigned long)(&generic_ro_fops) - 0x30000,
552 #elif defined(AFS_AMD64_LINUX20_ENV)
553 (unsigned long)(&tasklist_lock) - 0x30000,
556 #elif defined(AFS_PPC64_LINUX26_ENV)
557 (unsigned long)(&do_signal),
560 #elif defined(AFS_PPC_LINUX20_ENV) || defined(AFS_PPC_LINUX20_ENV)
561 (unsigned long)&init_mm,
565 (unsigned long)&init_mm,
570 #ifdef AFS_LINUX26_ENV
571 (unsigned long)scsi_command_size,
572 (unsigned long)scsi_command_size - 0x10000,
579 /* number and list of unimplemented system calls */
580 ((sizeof(main_zapped_syscalls)/sizeof(main_zapped_syscalls[0])) - 1),
581 main_zapped_syscalls,
583 /* number and list of unique system calls */
584 (sizeof(main_unique_syscalls)/sizeof(main_unique_syscalls[0])),
585 main_unique_syscalls,
587 /* syscall number and pointer to verify match */
588 __NR_close, &sys_close,
590 /* syscalls to ignore for debugging */
592 #if defined(AFS_ALPHA_LINUX20_ENV)
594 #elif defined(AFS_AMD64_LINUX20_ENV)
596 #elif defined(AFS_IA64_LINUX20_ENV)
598 #elif defined(AFS_SPARC_LINUX20_ENV) || defined(AFS_SPARC64_LINUX20_ENV)
604 #ifdef __NR_setgroups32
614 /********** Probing Configuration: amd64 ia32_sys_call_table **********/
615 #if defined(AFS_AMD64_LINUX20_ENV)
617 /* syscall pairs/triplets to probe */
618 static tryctl ia32_try[] = {
619 #if defined(EXPORTED_SYS_CHDIR)
620 { "scan: close+chdir+write", __NR_ia32_close, &sys_close, __NR_ia32_chdir, &sys_chdir, __NR_ia32_write, &sys_write },
621 { "scan: close+chdir", __NR_ia32_close, &sys_close, __NR_ia32_chdir, &sys_chdir, -1, 0 },
626 /* zapped syscalls for try_harder */
627 static int ia32_zapped_syscalls[] = {
628 __NR_ia32_break, __NR_ia32_stty, __NR_ia32_gtty, __NR_ia32_ftime,
629 __NR_ia32_prof, __NR_ia32_lock, __NR_ia32_mpx,
633 /* unique syscalls for try_harder */
634 static int ia32_unique_syscalls[] = {
635 __NR_ia32_exit, __NR_ia32_mount, __NR_ia32_read, __NR_ia32_write,
636 __NR_ia32_open, __NR_ia32_close, __NR_ia32_unlink
639 /* probe control structure */
640 static probectl ia32_probe = {
641 /* symbol name and description */
642 "ia32_sys_call_table",
643 "32-bit system call table",
645 /* syscall number of first entry in table */
648 ia32_sys_call_table, /* weak symbol ref */
649 0, 0, /* module parameter answers */
650 #ifdef AFS_LINUX_ia32_sys_call_table
651 AFS_LINUX_ia32_sys_call_table,/* compiled-in answer, if any */
656 ia32_try, /* array of combinations to try */
658 /* symbol in section to try scanning */
659 (unsigned long)&init_mm,
661 /* default base address for scan */
662 /* base address bits to force to zero */
663 /* default length for scan */
664 (unsigned long)&init_mm,
666 (0x180000 / sizeof(unsigned long *)),
668 #ifdef AFS_LINUX26_ENV
669 (unsigned long)scsi_command_size,
670 (unsigned long)scsi_command_size - 0x10000,
678 /* number and list of unimplemented system calls */
679 ((sizeof(ia32_zapped_syscalls)/sizeof(ia32_zapped_syscalls[0])) - 1),
680 ia32_zapped_syscalls,
682 /* number and list of unique system calls */
683 (sizeof(ia32_unique_syscalls)/sizeof(ia32_unique_syscalls[0])),
684 ia32_unique_syscalls,
686 /* syscall number and pointer to verify match */
687 __NR_ia32_close, &sys_close,
689 /* syscalls to ignore for debugging */
693 __NR_ia32_setgroups32,
698 static probectl *probe_list[] = {
699 &main_probe, &ia32_probe
703 /********** Probing Configuration: IA64 **********/
704 #elif defined(AFS_IA64_LINUX20_ENV)
710 /* no 32-bit support on IA64 for now */
711 static probectl *probe_list[] = {
716 /********** Probing Configuration: ppc64, sparc64 sys_call_table32 **********/
717 #elif defined(AFS_PPC64_LINUX20_ENV) || defined(AFS_SPARC64_LINUX20_ENV)
724 * syscall pairs/triplets to probe
725 * This has to be empty, because anything that would work will
726 * also match the main table, and that's no good.
728 static tryctl sct32_try[] = {
732 /* zapped syscalls for try_harder */
733 static int sct32_zapped_syscalls[] = {
734 #ifdef AFS_PPC64_LINUX20_ENV
735 /* These should be sufficient */
736 __NR_break, __NR_stty, __NR_gtty, __NR_ftime,
737 __NR_prof, __NR_lock, __NR_mpx,
739 #ifdef AFS_SPARC64_LINUX20_ENV
740 /* memory_ordering, getmsg, putmsg, unimplemented, modify_ldt */
741 52, 151, 152, 164, 218,
746 /* unique syscalls for try_harder */
747 /* mmap2 and fstat64 are implemented only for 32-bit calls */
748 static int sct32_unique_syscalls[] = {
749 #ifdef AFS_PPC64_LINUX20_ENV
750 /* _mmap2, _fstat64 */
753 #ifdef AFS_SPARC64_LINUX24_ENV
755 * On SPARC, we need some additional unique calls to make sure
756 * we don't match the SunOS-compatibility table.
758 __NR_sgetmask, __NR_ssetmask,
760 __NR_exit, __NR_mount, __NR_read, __NR_write,
761 __NR_open, __NR_close, __NR_unlink
764 /* probe control structure */
765 static probectl sct32_probe = {
766 /* symbol name and description */
768 "32-bit system call table",
770 /* syscall number of first entry in table */
773 sys_call_table32, /* weak symbol ref */
774 0, 0, /* module parameter answers */
775 #ifdef AFS_LINUX_sys_call_table32
776 AFS_LINUX_sys_call_table32, /* compiled-in answer, if any */
781 sct32_try, /* array of combinations to try */
783 /* symbol in section to try scanning */
784 #if defined(AFS_SPARC64_LINUX20_ENV)
785 (unsigned long)&sys_close,
787 (unsigned long)&init_mm,
790 /* default base address for scan */
791 /* base address bits to force to zero */
792 /* default length for scan */
793 #if defined(AFS_SPARC64_LINUX20_ENV)
794 (unsigned long)(&sys_close),
797 #elif defined(AFS_PPC64_LINUX26_ENV)
798 (unsigned long)(&do_signal),
802 (unsigned long)&init_mm,
807 #ifdef AFS_LINUX26_ENV
808 (unsigned long)scsi_command_size,
809 (unsigned long)scsi_command_size - 0x10000,
816 /* number and list of unimplemented system calls */
817 ((sizeof(sct32_zapped_syscalls)/sizeof(sct32_zapped_syscalls[0])) - 1),
818 sct32_zapped_syscalls,
820 /* number and list of unique system calls */
821 (sizeof(sct32_unique_syscalls)/sizeof(sct32_unique_syscalls[0])),
822 sct32_unique_syscalls,
824 /* syscall number and pointer to verify match */
825 __NR_close, &sys_close,
827 /* syscalls to ignore for debugging */
829 #if defined(AFS_SPARC64_LINUX20_ENV)
840 static probectl *probe_list[] = {
841 &main_probe, &sct32_probe
845 /********** Probing Configuration: s390x sys_call_table_emu **********/
846 /* We only actually need to do this on s390x_linux26 and later.
847 * On earlier versions, the two tables were interleaved and so
848 * have related base addresses.
850 #elif defined(AFS_S390X_LINUX26_ENV)
852 /* syscall pairs/triplets to probe */
853 /* nothing worthwhile is exported, so this is empty */
854 static tryctl emu_try[] = {
858 /* zapped syscalls for try_harder */
859 static int emu_zapped_syscalls[] = {
860 /* break, stty, gtty, ftime, prof, lock, mpx */
861 17, 31, 32, 35, 44, 53, 56,
865 /* unique syscalls for try_harder */
866 static int emu_unique_syscalls[] = {
867 /* lchown16, fstat64 */
869 __NR_exit, __NR_mount, __NR_read, __NR_write,
870 __NR_open, __NR_close, __NR_unlink
873 /* probe control structure */
874 static probectl emu_probe = {
875 /* symbol name and description */
876 "sys_call_table_emu",
877 "32-bit system call table",
879 /* syscall number of first entry in table */
882 sys_call_table_emu, /* weak symbol ref */
883 0, 0, /* module parameter answers */
884 #ifdef AFS_LINUX_sys_call_table_emu
885 AFS_LINUX_sys_call_table_emu, /* compiled-in answer, if any */
890 emu_try, /* array of combinations to try */
892 /* symbol in section to try scanning */
893 (unsigned long)&sys_close,
895 /* default base address for scan */
896 /* base address bits to force to zero */
897 /* default length for scan */
898 (unsigned long)&sys_close,
902 #ifdef AFS_LINUX26_ENV
903 (unsigned long)scsi_command_size,
904 (unsigned long)scsi_command_size - 0x10000,
911 /* number and list of unimplemented system calls */
912 ((sizeof(emu_zapped_syscalls)/sizeof(emu_zapped_syscalls[0])) - 1),
915 /* number and list of unique system calls */
916 (sizeof(emu_unique_syscalls)/sizeof(emu_unique_syscalls[0])),
919 /* syscall number and pointer to verify match */
920 __NR_close, &sys_close,
922 /* syscalls to ignore for debugging */
931 static probectl *probe_list[] = {
932 &main_probe, &emu_probe
936 /********** End of Probing Configuration **********/
938 #else /* no per-platform probe control, so use the default list */
939 static probectl *probe_list[] = {
944 #define N_PROBE_LIST (sizeof(probe_list) / sizeof(*probe_list))
945 #define DEBUG_IN_RANGE(P,x) (!probe_debug_range || \
946 (P->debug_answer && \
947 (unsigned long)(x) >= (unsigned long)P->debug_answer && \
948 (unsigned long)(x) < (unsigned long)P->debug_answer + probe_debug_range))
952 static int check_table(probectl *P, PROBETYPE *ptr)
957 #if defined(AFS_I386_LINUX26_ENV) || defined(AFS_AMD64_LINUX26_ENV)
958 i = check_table_readable(P, ptr);
959 if (i >= 0) return i;
962 for (x = ptr, i = 0; i < _SS(NR_syscalls); i++, x++) {
963 #ifdef OSI_PROBE_DEBUG
964 if (probe_debug & 0x0040) {
965 for (j = 0; j < 4; j++) {
966 if (_SS(P->debug_ignore_NR[j]) == _SX(i + P->offset)) break;
971 for (j = 0; j < 8; j++) {
972 if (_SS(probe_ignore_syscalls[j]) == _SX(i) + P->offset) break;
975 if (*x <= ktxt_lower_bound) {
976 #ifdef OSI_PROBE_DEBUG
977 if ((probe_debug & 0x0008) && DEBUG_IN_RANGE(P,ptr))
978 printk("<7>check 0x%lx -> %d [0x%lx]\n",
979 (unsigned long)ptr, i, (unsigned long)*x);
984 #ifdef OSI_PROBE_DEBUG
985 if ((probe_debug & 0x0008) && DEBUG_IN_RANGE(P,ptr))
986 printk("<7>check 0x%lx -> ok\n", (unsigned long)ptr);
991 static void *try(probectl *P, tryctl *T, PROBETYPE *aptr,
992 unsigned long datalen)
994 #ifdef OSI_PROBE_KALLSYMS
995 char *mod_name, *sec_name, *sym_name;
996 unsigned long mod_start, mod_end;
997 unsigned long sec_start, sec_end;
998 unsigned long sym_start, sym_end;
1000 unsigned long offset, ip1, ip2, ip3;
1004 #if defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
1005 ip1 = T->fn1 ? (unsigned long)((struct fptr *)T->fn1)->ip : 0;
1006 ip2 = T->fn2 ? (unsigned long)((struct fptr *)T->fn2)->ip : 0;
1007 ip3 = T->fn3 ? (unsigned long)((struct fptr *)T->fn3)->ip : 0;
1009 ip1 = (unsigned long)T->fn1;
1010 ip2 = (unsigned long)T->fn2;
1011 ip3 = (unsigned long)T->fn3;
1014 #ifdef OSI_PROBE_DEBUG
1015 if (probe_debug & 0x0001)
1016 printk("<7>osi_probe: %s %s (%d->0x%lx, %d->0x%lx, %d->0x%lx)\n",
1017 P->symbol, T->name, T->NR1, ip1, T->NR2, ip2, T->NR3, ip3);
1020 if (!ip1 || !ip2 || (T->NR3 >= 0 && !ip3))
1023 for (offset = 0; offset < datalen; offset++, aptr++) {
1024 #if defined(AFS_PPC64_LINUX20_ENV)
1025 ptr = (PROBETYPE*)(*aptr);
1026 if ((unsigned long)ptr <= KERNELBASE) {
1032 if ((unsigned long)ptr < init_mm.start_code ||
1033 #if defined(AFS_AMD64_LINUX20_ENV)
1034 (unsigned long)ptr > init_mm.brk)
1036 (unsigned long)ptr > init_mm.end_data)
1039 /* printk("address 0x%lx (from 0x%lx %d) is out of range in check_table. wtf?\n", (unsigned long)x, (unsigned long)ptr, i);*/
1043 ret = check_table(P, ptr);
1045 /* return value is number of entries to skip */
1051 #ifdef OSI_PROBE_DEBUG
1052 if ((probe_debug & 0x0002) && DEBUG_IN_RANGE(P,ptr))
1053 printk("<7>try 0x%lx\n", (unsigned long)ptr);
1055 if (ptr[_SS(T->NR1 - P->offset)] != ip1) continue;
1056 if (ptr[_SS(T->NR2 - P->offset)] != ip2) continue;
1057 if (ip3 && ptr[_SS(T->NR3 - P->offset)] != ip3) continue;
1059 #ifdef OSI_PROBE_DEBUG
1060 if (probe_debug & 0x0002)
1061 printk("<7>try found 0x%lx\n", (unsigned long)ptr);
1063 #ifdef OSI_PROBE_KALLSYMS
1064 if (kallsyms_address_to_symbol) {
1065 ret = kallsyms_address_to_symbol((unsigned long)ptr,
1066 &mod_name, &mod_start, &mod_end,
1067 &sec_name, &sec_start, &sec_end,
1068 &sym_name, &sym_start, &sym_end);
1069 if (!ret || strcmp(sym_name, P->symbol)) continue;
1072 /* XXX should we make sure there is only one match? */
1079 static int check_harder(probectl *P, PROBETYPE *p)
1084 #if defined(AFS_I386_LINUX26_ENV) || defined(AFS_AMD64_LINUX26_ENV)
1085 i = check_table_readable(P, p);
1086 if (i >= 0) return 0;
1089 /* Check zapped syscalls */
1090 for (i = 1; i < P->n_zapped_syscalls; i++) {
1091 if (p[_SS(P->zapped_syscalls[i])] != p[_SS(P->zapped_syscalls[0])]) {
1092 #ifdef OSI_PROBE_DEBUG
1093 if ((probe_debug & 0x0020) && DEBUG_IN_RANGE(P,p))
1094 printk("<7>check_harder 0x%lx zapped failed i=%d\n", (unsigned long)p, i);
1100 /* Check unique syscalls */
1101 for (i = 0; i < P->n_unique_syscalls; i++) {
1102 for (s = 0; s < NR_syscalls; s++) {
1103 if (p[_SS(s)] == p[_SS(P->unique_syscalls[i])]
1104 && s != P->unique_syscalls[i]) {
1105 #ifdef OSI_PROBE_DEBUG
1106 if ((probe_debug & 0x0010) && DEBUG_IN_RANGE(P,p))
1107 printk("<7>check_harder 0x%lx unique failed i=%d s=%d\n", (unsigned long)p, i, s);
1114 #if defined(AFS_IA64_LINUX20_ENV) || defined(AFS_PPC64_LINUX20_ENV)
1115 ip1 = P->verify_fn ? (unsigned long)((struct fptr *)(P->verify_fn))->ip : 0;
1117 ip1 = (unsigned long)(P->verify_fn);
1120 if (ip1 && p[_SS(P->verifyNR - P->offset)] != ip1) {
1121 #ifdef OSI_PROBE_DEBUG
1122 if ((probe_debug & 0x0010) && DEBUG_IN_RANGE(P,p))
1123 printk("<7>check_harder 0x%lx verify failed\n", (unsigned long)p);
1128 #ifdef OSI_PROBE_DEBUG
1129 if ((probe_debug & 0x0010) && DEBUG_IN_RANGE(P,p))
1130 printk("<7>check_harder 0x%lx success!\n", (unsigned long)p);
1135 static void *try_harder(probectl *P, PROBETYPE *ptr, unsigned long datalen)
1137 #ifdef OSI_PROBE_KALLSYMS
1138 char *mod_name, *sec_name, *sym_name;
1139 unsigned long mod_start, mod_end;
1140 unsigned long sec_start, sec_end;
1141 unsigned long sym_start, sym_end;
1143 unsigned long offset;
1147 #ifdef OSI_PROBE_DEBUG
1148 if (probe_debug & 0x0001)
1149 printk("<7>osi_probe: %s try_harder\n", P->symbol);
1151 for (offset = 0; offset < datalen; offset++, ptr++) {
1152 if ((unsigned long)ptr < init_mm.start_code ||
1153 #if defined(AFS_AMD64_LINUX20_ENV)
1154 (unsigned long)ptr > init_mm.brk)
1156 (unsigned long)ptr > init_mm.end_data)
1159 /* printk("address 0x%lx (from 0x%lx %d) is out of range in check_table. wtf?\n", (unsigned long)x, (unsigned long)ptr, i);*/
1162 ret = check_table(P, ptr);
1164 /* return value is number of entries to skip */
1170 #ifdef OSI_PROBE_DEBUG
1171 if ((probe_debug & 0x0004) && DEBUG_IN_RANGE(P,ptr))
1172 printk("<7>try_harder 0x%lx\n", (unsigned long)ptr);
1174 if (!check_harder(P, ptr))
1177 #ifdef OSI_PROBE_DEBUG
1178 if (probe_debug & 0x0004)
1179 printk("<7>try_harder found 0x%lx\n", (unsigned long)ptr);
1182 #ifdef OSI_PROBE_KALLSYMS
1183 if (kallsyms_address_to_symbol) {
1184 ret = kallsyms_address_to_symbol((unsigned long)ptr,
1185 &mod_name, &mod_start, &mod_end,
1186 &sec_name, &sec_start, &sec_end,
1187 &sym_name, &sym_start, &sym_end);
1188 if (!ret || strcmp(sym_name, P->symbol)) continue;
1193 #ifdef OSI_PROBE_DEBUG
1194 if (probe_debug & 0x0005)
1195 printk("<7>%s: try_harder found multiple matches!\n", P->symbol);
1200 match = (void *)ptr;
1201 if (!probe_carefully)
1208 #ifdef OSI_PROBE_DEBUG
1209 #define check_result(x,m) do { \
1210 if (probe_debug & 0x0001) { \
1211 printk("<7>osi_probe: %s = 0x%016lx %s\n", P->symbol, (unsigned long)(x), (m)); \
1215 final_answer = (void *)(x); \
1219 #define check_result(x,m) do { \
1222 return (void *)(x); \
1226 static void *scan_for_syscall_table(probectl *P, PROBETYPE *B, unsigned long L)
1230 #if defined(AFS_S390_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
1233 #ifdef OSI_PROBE_DEBUG
1234 void *final_answer = 0;
1236 #ifdef OSI_PROBE_DEBUG
1237 if (probe_debug & 0x0007)
1238 printk("<7>osi_probe: %s base=0x%lx, len=0x%lx\n",
1239 P->symbol, (unsigned long)B, L);
1240 if (probe_debug & 0x0009) {
1241 printk("<7>osi_probe: %s ktxt_lower_bound=0x%lx\n",
1242 P->symbol, ktxt_lower_bound);
1243 printk("<7>osi_probe: %s NR_syscalls=%d\n",
1244 P->symbol, NR_syscalls);
1248 for (T = P->trylist; T->name; T++) {
1249 answer = try(P, T, B, L);
1250 #if defined(AFS_S390_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
1251 answer2 = try(P, T, (PROBETYPE *)(2 + (void *)B), L);
1252 #ifdef OSI_PROBE_DEBUG
1253 if (probe_debug & 0x0003) {
1254 printk("<7>osi_probe: %s = 0x%016lx %s (even)\n",
1255 P->symbol, (unsigned long)(answer), T->name);
1256 printk("<7>osi_probe: %s = 0x%016lx %s (odd)\n",
1257 P->symbol, (unsigned long)(answer2), T->name);
1260 if (answer && answer2) answer = 0;
1261 else if (answer2) answer = answer2;
1267 /* XXX more checks here */
1269 answer = try_harder(P, B, L);
1270 #if defined(AFS_S390_LINUX20_ENV) || defined(AFS_S390X_LINUX20_ENV)
1271 answer2 = try_harder(P, (PROBETYPE *)(2 + (void *)B), L);
1272 #ifdef OSI_PROBE_DEBUG
1273 if (probe_debug & 0x0005) {
1274 printk("<7>osi_probe: %s = 0x%016lx pattern scan (even)\n",
1275 P->symbol, (unsigned long)(answer));
1276 printk("<7>osi_probe: %s = 0x%016lx pattern scan (odd)\n",
1277 P->symbol, (unsigned long)(answer2));
1280 if (answer && answer2) answer = 0;
1281 else if (answer2) answer = answer2;
1286 static void *do_find_syscall_table(probectl *P, char **method)
1288 #ifdef OSI_PROBE_KALLSYMS
1289 char *mod_name, *sec_name, *sym_name;
1290 unsigned long mod_start, mod_end;
1291 unsigned long sec_start, sec_end;
1292 unsigned long sym_start, sym_end;
1293 unsigned long token;
1299 #ifdef OSI_PROBE_DEBUG
1300 void *final_answer = 0;
1303 *method = "not found";
1305 /* if it's exported, there's nothing to do */
1306 check_result(P->weak_answer, "exported");
1308 /* ask the kernel to do the name lookup, if it's willing */
1309 #ifdef OSI_PROBE_KALLSYMS
1310 if (kallsyms_symbol_to_address) {
1314 ret = kallsyms_symbol_to_address(P->symbol, &token,
1315 &mod_name, &mod_start, &mod_end,
1316 &sec_name, &sec_start, &sec_end,
1317 &sym_name, &sym_start, &sym_end);
1318 if (ret && !strcmp(mod_name, "kernel") && sym_start)
1322 check_result(sym_start, "kallsyms_symbol_to_address");
1326 /* Maybe a little birdie told us */
1327 check_result(P->parm_answer, "module parameter");
1328 check_result(P->given_answer, "compiled-in");
1330 /* OK, so we have to scan. */
1331 B = (PROBETYPE *)((P->try_base) & ~(P->try_base_mask));
1333 /* Now, see if the kernel will tell us something better than the default */
1334 #ifdef OSI_PROBE_KALLSYMS
1335 if (kallsyms_address_to_symbol) {
1336 ret = kallsyms_address_to_symbol(P->try_sect_sym,
1337 &mod_name, &mod_start, &mod_end,
1338 &sec_name, &sec_start, &sec_end,
1339 &sym_name, &sym_start, &sym_end);
1341 B = (PROBETYPE *)sec_start;
1342 L = (sec_end - sec_start) / sizeof(unsigned long);
1347 answer = scan_for_syscall_table(P, B, L);
1348 check_result(answer, "pattern scan");
1349 B = (PROBETYPE *)((P->alt_try_base) & ~(P->alt_try_base_mask));
1350 L = P->alt_try_length;
1351 /* Now, see if the kernel will tell us something better than the default */
1352 #ifdef OSI_PROBE_KALLSYMS
1353 if (kallsyms_address_to_symbol && P->alt_try_sect_sym) {
1354 ret = kallsyms_address_to_symbol(P->alt_try_sect_sym,
1355 &mod_name, &mod_start, &mod_end,
1356 &sec_name, &sec_start, &sec_end,
1357 &sym_name, &sym_start, &sym_end);
1359 B = (PROBETYPE *)sec_start;
1360 L = (sec_end - sec_start) / sizeof(unsigned long);
1365 answer = scan_for_syscall_table(P, B, L);
1366 check_result(answer, "pattern scan");
1368 #ifdef OSI_PROBE_DEBUG
1369 return final_answer;
1375 #if defined(AFS_I386_LINUX26_ENV) || defined(AFS_AMD64_LINUX26_ENV)
1376 static int check_access(unsigned long address, int mode)
1378 pgd_t *pgd = pgd_offset_k(address);
1388 pud = pud_offset(pgd, address);
1391 pmd = pmd_offset(pud, address);
1393 pmd = pmd_offset(pgd, address);
1397 if (pmd_large(*pmd))
1400 pte = pte_offset_kernel(pmd, address);
1401 if (pte_none(*pte) || !pte_present(*pte))
1403 if (mode && !pte_write(*pte))
1408 static int check_table_readable(probectl *P, PROBETYPE *ptr)
1410 PROBETYPE *next_page;
1413 while (i < _SS(NR_syscalls)) {
1414 next_page = (PROBETYPE *)PAGE_ALIGN((unsigned long)(ptr+1));
1415 delta = next_page - ptr;
1416 if (!check_access((unsigned long)ptr, 0)) {
1417 #ifdef OSI_PROBE_DEBUG
1418 if (probe_debug & 0x0080)
1419 printk("<7>osi_probe: %s 0x%016lx not readable; delta=0x%lx\n",
1420 P->symbol, (unsigned long)ptr, delta);
1431 void *osi_find_syscall_table(int which)
1437 if (which < 0 || which >= N_PROBE_LIST) {
1438 printk("error - afs_find_syscall_table called with invalid index!\n");
1441 P = probe_list[which];
1443 P->parm_answer = (void *)sys_call_table_addr[which];
1444 #ifdef OSI_PROBE_DEBUG
1445 P->debug_answer = (void *)probe_debug_addr[which];
1448 answer = do_find_syscall_table(P, &method);
1450 printk("Warning: failed to find address of %s\n", P->desc);
1451 printk("System call hooks will not be installed; proceeding anyway\n");
1454 printk("Found %s at 0x%lx (%s)\n", P->desc, (unsigned long)answer, method);
1455 #if defined(AFS_I386_LINUX26_ENV) || defined(AFS_AMD64_LINUX26_ENV)
1456 if (!check_access((unsigned long)answer, 1)) {
1457 printk("Address 0x%lx is not writable.\n", (unsigned long)answer);
1458 printk("System call hooks will not be installed; proceeding anyway\n");
1466 #ifdef OSI_PROBE_STANDALONE
1467 int __init osi_probe_init(void)
1471 if (!probe_debug_tag) probe_debug_tag = jiffies;
1472 printk("*** osi_probe %ld debug = 0x%04x ***\n",
1473 probe_debug_tag, probe_debug);
1474 for (i = 0; i < N_PROBE_LIST; i++)
1475 (void)osi_find_syscall_table(i);
1479 void osi_probe_exit(void) { }
1481 module_init(osi_probe_init);
1482 module_exit(osi_probe_exit);
1486 void *osi_find_syscall_table(int which)
1490 #endif /* EXPORTED_INIT_MM */