diff -urN linux-2.4.23/arch/i386/config.in linux-2423HRDKRL/arch/i386/config.in --- linux-2.4.23/arch/i386/config.in 2003-11-28 13:26:19.000000000 -0500 +++ linux-2423HRDKRL/arch/i386/config.in 2004-03-16 11:54:10.000000000 -0500 @@ -487,3 +487,8 @@ source crypto/Config.in source lib/Config.in + +bool 'Hardened Kernels For Linux Servers' CONFIG_HRDKRL +if [ "$CONFIG_HRDKRL" != "n" ]; then +source hrdkrl/Config.in +fi diff -urN linux-2.4.23/arch/i386/kernel/entry.S linux-2423HRDKRL/arch/i386/kernel/entry.S --- linux-2.4.23/arch/i386/kernel/entry.S 2003-06-13 10:51:29.000000000 -0400 +++ linux-2423HRDKRL/arch/i386/kernel/entry.S 2004-03-18 10:26:11.000000000 -0500 @@ -413,14 +413,42 @@ .long SYMBOL_NAME(sys_close) .long SYMBOL_NAME(sys_waitpid) .long SYMBOL_NAME(sys_creat) + +# if !defined(CONFIG_HRDKRL_NO_LINK) .long SYMBOL_NAME(sys_link) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_UNLINK) .long SYMBOL_NAME(sys_unlink) /* 10 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_execve) .long SYMBOL_NAME(sys_chdir) .long SYMBOL_NAME(sys_time) +# if !defined(CONFIG_HRDKRL_NO_MKNOD) .long SYMBOL_NAME(sys_mknod) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_CHMOD) .long SYMBOL_NAME(sys_chmod) /* 15 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_LCHOWN) .long SYMBOL_NAME(sys_lchown16) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_ni_syscall) /* old break syscall holder */ .long SYMBOL_NAME(sys_stat) .long SYMBOL_NAME(sys_lseek) @@ -429,25 +457,79 @@ .long SYMBOL_NAME(sys_oldumount) .long SYMBOL_NAME(sys_setuid16) .long SYMBOL_NAME(sys_getuid16) + +# if !defined(CONFIG_HRDKRL_NO_STIME) .long SYMBOL_NAME(sys_stime) /* 25 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_PTRACE) .long SYMBOL_NAME(sys_ptrace) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_alarm) .long SYMBOL_NAME(sys_fstat) .long SYMBOL_NAME(sys_pause) + +# if !defined(CONFIG_HRDKRL_NO_UTIME) .long SYMBOL_NAME(sys_utime) /* 30 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_ni_syscall) /* old stty syscall holder */ .long SYMBOL_NAME(sys_ni_syscall) /* old gtty syscall holder */ .long SYMBOL_NAME(sys_access) - .long SYMBOL_NAME(sys_nice) + +# if !defined(CONFIG_HRDKRL_NO_NICE) + .long SYMBOL_NAME(sys_nice) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_ni_syscall) /* 35 */ /* old ftime syscall holder */ +# if !defined(CONFIG_HRDKRL_NO_SYNC) .long SYMBOL_NAME(sys_sync) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_kill) + +# if !defined(CONFIG_HRDKRL_NO_RENAME) .long SYMBOL_NAME(sys_rename) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_MKDIR) .long SYMBOL_NAME(sys_mkdir) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_RMDIR) .long SYMBOL_NAME(sys_rmdir) /* 40 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_dup) .long SYMBOL_NAME(sys_pipe) + +# if !defined(CONFIG_HRDKRL_NO_TIMES) .long SYMBOL_NAME(sys_times) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_ni_syscall) /* old prof syscall holder */ .long SYMBOL_NAME(sys_brk) /* 45 */ .long SYMBOL_NAME(sys_setgid16) @@ -455,7 +537,12 @@ .long SYMBOL_NAME(sys_signal) .long SYMBOL_NAME(sys_geteuid16) .long SYMBOL_NAME(sys_getegid16) /* 50 */ +# if !defined(CONFIG_HRDKRL_NO_ACCT) .long SYMBOL_NAME(sys_acct) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_umount) /* recycled never used phys() */ .long SYMBOL_NAME(sys_ni_syscall) /* old lock syscall holder */ .long SYMBOL_NAME(sys_ioctl) @@ -465,8 +552,20 @@ .long SYMBOL_NAME(sys_ni_syscall) /* old ulimit syscall holder */ .long SYMBOL_NAME(sys_olduname) .long SYMBOL_NAME(sys_umask) /* 60 */ + +# if !defined(CONFIG_HRDKRL_NO_CHROOT) .long SYMBOL_NAME(sys_chroot) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_USTAT) .long SYMBOL_NAME(sys_ustat) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_dup2) .long SYMBOL_NAME(sys_getppid) .long SYMBOL_NAME(sys_getpgrp) /* 65 */ @@ -474,8 +573,17 @@ .long SYMBOL_NAME(sys_sigaction) .long SYMBOL_NAME(sys_sgetmask) .long SYMBOL_NAME(sys_ssetmask) +# if !defined(CONFIG_HRDKRL_NO_SETREUID) .long SYMBOL_NAME(sys_setreuid16) /* 70 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif +# if !defined(CONFIG_HRDKRL_NO_SETREGID) .long SYMBOL_NAME(sys_setregid16) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_sigsuspend) .long SYMBOL_NAME(sys_sigpending) .long SYMBOL_NAME(sys_sethostname) @@ -485,98 +593,391 @@ .long SYMBOL_NAME(sys_gettimeofday) .long SYMBOL_NAME(sys_settimeofday) .long SYMBOL_NAME(sys_getgroups16) /* 80 */ + +# if !defined(CONFIG_HRDKRL_NO_SETGROUPS) .long SYMBOL_NAME(sys_setgroups16) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SELECT) .long SYMBOL_NAME(old_select) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_symlink) .long SYMBOL_NAME(sys_lstat) +# if !defined(CONFIG_HRDKRL_NO_READLINK) .long SYMBOL_NAME(sys_readlink) /* 85 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_USELIB) .long SYMBOL_NAME(sys_uselib) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_swapon) .long SYMBOL_NAME(sys_reboot) .long SYMBOL_NAME(old_readdir) .long SYMBOL_NAME(old_mmap) /* 90 */ .long SYMBOL_NAME(sys_munmap) +# if !defined(CONFIG_HRDKRL_NO_TRUNCATE) .long SYMBOL_NAME(sys_truncate) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FTRUNCATE) .long SYMBOL_NAME(sys_ftruncate) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_FCHMOD) .long SYMBOL_NAME(sys_fchmod) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FCHOWN) .long SYMBOL_NAME(sys_fchown16) /* 95 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + + +# if !defined(CONFIG_HRDKRL_NO_GETPRIORITY) .long SYMBOL_NAME(sys_getpriority) - .long SYMBOL_NAME(sys_setpriority) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_SETPRIORITY) + .long SYMBOL_NAME(sys_setpriority) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_ni_syscall) /* old profil syscall holder */ + +# if !defined(CONFIG_HRDKRL_NO_STATFS) .long SYMBOL_NAME(sys_statfs) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FSTATFS) .long SYMBOL_NAME(sys_fstatfs) /* 100 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_IOPERM) .long SYMBOL_NAME(sys_ioperm) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_socketcall) +# if !defined(CONFIG_HRDKRL_NO_SYSLOG) .long SYMBOL_NAME(sys_syslog) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_setitimer) .long SYMBOL_NAME(sys_getitimer) /* 105 */ .long SYMBOL_NAME(sys_newstat) .long SYMBOL_NAME(sys_newlstat) .long SYMBOL_NAME(sys_newfstat) .long SYMBOL_NAME(sys_uname) + +# if !defined(CONFIG_HRDKRL_NO_IOPL) .long SYMBOL_NAME(sys_iopl) /* 110 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_VHANGUP) .long SYMBOL_NAME(sys_vhangup) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_ni_syscall) /* old "idle" system call */ +# if !defined(CONFIG_HRDKRL_NO_VM86) .long SYMBOL_NAME(sys_vm86old) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif .long SYMBOL_NAME(sys_wait4) .long SYMBOL_NAME(sys_swapoff) /* 115 */ + +# if !defined(CONFIG_HRDKRL_NO_SYSINFO) .long SYMBOL_NAME(sys_sysinfo) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_ipc) + +# if !defined(CONFIG_HRDKRL_NO_FSYNC) .long SYMBOL_NAME(sys_fsync) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_sigreturn) .long SYMBOL_NAME(sys_clone) /* 120 */ .long SYMBOL_NAME(sys_setdomainname) .long SYMBOL_NAME(sys_newuname) .long SYMBOL_NAME(sys_modify_ldt) + +# if !defined(CONFIG_HRDKRL_NO_ADJTIMEX) .long SYMBOL_NAME(sys_adjtimex) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_mprotect) /* 125 */ .long SYMBOL_NAME(sys_sigprocmask) +# if !defined(CONFIG_HRDKRL_NO_CREATE_MODULE) .long SYMBOL_NAME(sys_create_module) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_INIT_MODULE) .long SYMBOL_NAME(sys_init_module) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_DELETE_MODULE) .long SYMBOL_NAME(sys_delete_module) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_GET_KERNEL_SYMS) .long SYMBOL_NAME(sys_get_kernel_syms) /* 130 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_quotactl) .long SYMBOL_NAME(sys_getpgid) .long SYMBOL_NAME(sys_fchdir) + +# if !defined(CONFIG_HRDKRL_NO_BDFLUSH) .long SYMBOL_NAME(sys_bdflush) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SYSFS) .long SYMBOL_NAME(sys_sysfs) /* 135 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_PERSONALITY) .long SYMBOL_NAME(sys_personality) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_ni_syscall) /* for afs_syscall */ +# if !defined(CONFIG_HRDKRL_NO_SETFSUID) .long SYMBOL_NAME(sys_setfsuid16) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SETFSGID) .long SYMBOL_NAME(sys_setfsgid16) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_llseek) /* 140 */ .long SYMBOL_NAME(sys_getdents) +# if !defined(CONFIG_HRDKRL_NO_SELECT) .long SYMBOL_NAME(sys_select) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_flock) + +# if !defined(CONFIG_HRDKRL_NO_MSYNC) .long SYMBOL_NAME(sys_msync) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_READV) .long SYMBOL_NAME(sys_readv) /* 145 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_WRITEV) .long SYMBOL_NAME(sys_writev) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_getsid) +# if !defined(CONFIG_HRDKRL_NO_FDATASYNC) .long SYMBOL_NAME(sys_fdatasync) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_sysctl) +# if !defined(CONFIG_HRDKRL_NO_MLOCK) .long SYMBOL_NAME(sys_mlock) /* 150 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_MUNLOCK) .long SYMBOL_NAME(sys_munlock) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_MLOCKALL) .long SYMBOL_NAME(sys_mlockall) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_MUNLOCKALL) .long SYMBOL_NAME(sys_munlockall) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_SETPARAM) .long SYMBOL_NAME(sys_sched_setparam) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_GETPARAM) .long SYMBOL_NAME(sys_sched_getparam) /* 155 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_SETSCHEDULER) .long SYMBOL_NAME(sys_sched_setscheduler) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_GETSCHEDULER) .long SYMBOL_NAME(sys_sched_getscheduler) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_YIELD) .long SYMBOL_NAME(sys_sched_yield) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_GET_PRIORITY_MAX) .long SYMBOL_NAME(sys_sched_get_priority_max) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_GET_PRIORITY_MIN) .long SYMBOL_NAME(sys_sched_get_priority_min) /* 160 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SCHED_RR_GET_INTERVAL) .long SYMBOL_NAME(sys_sched_rr_get_interval) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_nanosleep) + +# if !defined(CONFIG_HRDKRL_NO_MREMAP) .long SYMBOL_NAME(sys_mremap) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SETRESUID) .long SYMBOL_NAME(sys_setresuid16) - .long SYMBOL_NAME(sys_getresuid16) /* 165 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_getresuid16) /* 165 */ +# if !defined(CONFIG_HRDKRL_NO_VM86) .long SYMBOL_NAME(sys_vm86) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_QUERY_MODULE) .long SYMBOL_NAME(sys_query_module) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_POLL) .long SYMBOL_NAME(sys_poll) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_NFSSERVCTL) .long SYMBOL_NAME(sys_nfsservctl) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SETRESGID) .long SYMBOL_NAME(sys_setresgid16) /* 170 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_getresgid16) + +# if !defined(CONFIG_HRDKRL_NO_PRCTL) .long SYMBOL_NAME(sys_prctl) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_rt_sigreturn) .long SYMBOL_NAME(sys_rt_sigaction) .long SYMBOL_NAME(sys_rt_sigprocmask) /* 175 */ @@ -584,66 +985,261 @@ .long SYMBOL_NAME(sys_rt_sigtimedwait) .long SYMBOL_NAME(sys_rt_sigqueueinfo) .long SYMBOL_NAME(sys_rt_sigsuspend) +# if !defined(CONFIG_HRDKRL_NO_PREAD) .long SYMBOL_NAME(sys_pread) /* 180 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_PWRITE) .long SYMBOL_NAME(sys_pwrite) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_CHOWN) .long SYMBOL_NAME(sys_chown16) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_getcwd) .long SYMBOL_NAME(sys_capget) .long SYMBOL_NAME(sys_capset) /* 185 */ .long SYMBOL_NAME(sys_sigaltstack) +# if !defined(CONFIG_HRDKRL_NO_SENDFILE) .long SYMBOL_NAME(sys_sendfile) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */ .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ +# if !defined(CONFIG_HRDKRL_NO_VFORK) .long SYMBOL_NAME(sys_vfork) /* 190 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_getrlimit) .long SYMBOL_NAME(sys_mmap2) +# if !defined(CONFIG_HRDKRL_NO_TRUNCATE) .long SYMBOL_NAME(sys_truncate64) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FTRUNCATE) .long SYMBOL_NAME(sys_ftruncate64) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_stat64) /* 195 */ .long SYMBOL_NAME(sys_lstat64) .long SYMBOL_NAME(sys_fstat64) + +# if !defined(CONFIG_HRDKRL_NO_LCHOWN) .long SYMBOL_NAME(sys_lchown) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_getuid) .long SYMBOL_NAME(sys_getgid) /* 200 */ .long SYMBOL_NAME(sys_geteuid) .long SYMBOL_NAME(sys_getegid) +# if !defined(CONFIG_HRDKRL_NO_SETREUID) .long SYMBOL_NAME(sys_setreuid) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif +# if !defined(CONFIG_HRDKRL_NO_SETREGID) .long SYMBOL_NAME(sys_setregid) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_getgroups) /* 205 */ + +# if !defined(CONFIG_HRDKRL_NO_SETGROUPS) .long SYMBOL_NAME(sys_setgroups) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + + +# if !defined(CONFIG_HRDKRL_NO_FCHOWN) .long SYMBOL_NAME(sys_fchown) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SETRESUID) .long SYMBOL_NAME(sys_setresuid) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_getresuid) +# if !defined(CONFIG_HRDKRL_NO_SETRESGID) .long SYMBOL_NAME(sys_setresgid) /* 210 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_getresgid) + +# if !defined(CONFIG_HRDKRL_NO_CHOWN) .long SYMBOL_NAME(sys_chown) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_setuid) .long SYMBOL_NAME(sys_setgid) + +# if !defined(CONFIG_HRDKRL_NO_SETFSUID) .long SYMBOL_NAME(sys_setfsuid) /* 215 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + +# if !defined(CONFIG_HRDKRL_NO_SETFSGID) .long SYMBOL_NAME(sys_setfsgid) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + + +# if !defined(CONFIG_HRDKRL_NO_PIVOT_ROOT) .long SYMBOL_NAME(sys_pivot_root) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_MINCORE) .long SYMBOL_NAME(sys_mincore) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_MADVISE) .long SYMBOL_NAME(sys_madvise) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + .long SYMBOL_NAME(sys_getdents64) /* 220 */ .long SYMBOL_NAME(sys_fcntl64) .long SYMBOL_NAME(sys_ni_syscall) /* reserved for TUX */ .long SYMBOL_NAME(sys_ni_syscall) /* Reserved for Security */ + +# if !defined(CONFIG_HRDKRL_NO_GETTID) .long SYMBOL_NAME(sys_gettid) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_READAHEAD) .long SYMBOL_NAME(sys_readahead) /* 225 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SETXATTR) .long SYMBOL_NAME(sys_setxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_LSETXATTR) .long SYMBOL_NAME(sys_lsetxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FSETXATTR) .long SYMBOL_NAME(sys_fsetxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_GETXATTR) .long SYMBOL_NAME(sys_getxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_LGETXATTR) .long SYMBOL_NAME(sys_lgetxattr) /* 230 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FGETXATTR) .long SYMBOL_NAME(sys_fgetxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_LISTXATTR) .long SYMBOL_NAME(sys_listxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_LLISTXATTR) .long SYMBOL_NAME(sys_llistxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FLISTXATTR) .long SYMBOL_NAME(sys_flistxattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_REMOVEXATTR) .long SYMBOL_NAME(sys_removexattr) /* 235 */ +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_LREMOVEXATTR) .long SYMBOL_NAME(sys_lremovexattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_FREMOVEXATTR) .long SYMBOL_NAME(sys_fremovexattr) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_TKILL) .long SYMBOL_NAME(sys_tkill) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + +# if !defined(CONFIG_HRDKRL_NO_SENDFILE) .long SYMBOL_NAME(sys_sendfile64) +# else + .long SYMBOL_NAME(freeze_syscall) +# endif + + .long SYMBOL_NAME(sys_ni_syscall) /* 240 reserved for futex */ .long SYMBOL_NAME(sys_ni_syscall) /* reserved for sched_setaffinity */ .long SYMBOL_NAME(sys_ni_syscall) /* reserved for sched_getaffinity */ @@ -663,6 +1259,47 @@ .long SYMBOL_NAME(sys_ni_syscall) /* sys_epoll_wait */ .long SYMBOL_NAME(sys_ni_syscall) /* sys_remap_file_pages */ .long SYMBOL_NAME(sys_ni_syscall) /* sys_set_tid_address */ +# if defined(CONFIG_HRDKRL_FREEZE_NETWORK) + .long SYMBOL_NAME(sys_freeze_network_configuration) /* freeze network configuration syscall no. 259*/ +# else + .long SYMBOL_NAME(sys_ni_syscall) +# endif + +# if defined(CONFIG_HRDKRL_SYSCALL_ELIM_RTIME) + .long SYMBOL_NAME(sys_freeze_syscall) /* freeze the system call syscall no. 260*/ +# else + .long SYMBOL_NAME(sys_ni_syscall) +# endif + +#if defined(CONFIG_HRDKRL_KLOGGER_SYSCALL) + .long SYMBOL_NAME(sys_kernellogger) /* system call to start klogger no. 261*/ +#else + .long SYMBOL_NAME(sys_ni_syscall) +#endif + +#if defined(CONFIG_HRDKRL_KIC_SYSCALL) + .long SYMBOL_NAME(sys_kic) /* system call to start KIC no. 262*/ +#else + .long SYMBOL_NAME(sys_ni_syscall) +#endif + +#if defined(CONFIG_HRDKRL_TPM_SYSCALL) + .long SYMBOL_NAME(sys_tpm) /* system call to start TPM no. 263*/ +#else + .long SYMBOL_NAME(sys_ni_syscall) +#endif + +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE_SYSCALL) + .long SYMBOL_NAME(sys_ftp_protection) /* system call to start FTP no overwrite protection no. 264*/ +#else + .long SYMBOL_NAME(sys_ni_syscall) +#endif + +#if defined(CONFIG_HRDKRL_CAP_ELIM_RTIME) + .long SYMBOL_NAME(sys_freeze_cap) /* system call freeze capabilities no. 265*/ +#else + .long SYMBOL_NAME(sys_ni_syscall) +#endif .rept NR_syscalls-(.-sys_call_table)/4 .long SYMBOL_NAME(sys_ni_syscall) diff -urN linux-2.4.23/Documentation/Configure.help linux-2423HRDKRL/Documentation/Configure.help --- linux-2.4.23/Documentation/Configure.help 2003-11-28 13:26:19.000000000 -0500 +++ linux-2423HRDKRL/Documentation/Configure.help 2004-05-26 19:05:03.000000000 -0400 @@ -14411,7 +14411,7 @@ CFI Flash device mapping on the Flaga Digital Module CONFIG_MTD_CFI_FLAGADM - Mapping for the Flaga digital module. If you don´t have one, ignore + Mapping for the Flaga digital module. If you don´t have one, ignore this setting. Momenco Ocelot boot flash device @@ -23954,7 +23954,7 @@ HERMES_PRO: Hermes-Pro ISDN/LAN router with integrated 8 x hub - Manufacturer: Multidata Gesellschaft für Datentechnik und Informatik + Manufacturer: Multidata Gesellschaft für Datentechnik und Informatik Date of Release: 2000 (?) End of life: - @@ -25537,7 +25537,7 @@ Tulsa CONFIG_SA1100_PFS168 - The Radisys Corp. PFS-168 (aka Tulsa) is an Intel® StrongArm® SA-1110 based + The Radisys Corp. PFS-168 (aka Tulsa) is an Intel® StrongArm® SA-1110 based computer which includes the SA-1111 Microprocessor Companion Chip and other custom I/O designed to add connectivity and multimedia features for vending and business machine applications. Say Y here if you require support for @@ -28848,3 +28848,246 @@ # adaptive-fill:nil # fill-column:70 # End: + +# Help for HRDKRL +Chroot Jail Restrictions +CONFIG_HRDKRL_CHROOT + If you say Y here, you will be able to choose options that will make + breaking out of a chrooted jail much more difficult. + +Deny access to UNIX sockets out of chroot +CONFIG_HRDKRL_CHROOT_DENY_UNIX_SOCKET + If you say Y here, processes inside a chroot will not be able to + connect to abstract UNIX domain sockets that were bound outside of a + chroot. + +Deny shmat() out of chroot +CONFIG_HRDKRL_CHROOT_SHMAT + If you say Y here, processes inside a chroot will not be able to attach + to shared memory segments that were created outside of the chroot jail. + +Deny double chroot +CONFIG_HRDKRL_CHROOT_DOUBLE + If you say Y here, processes inside a chroot will not be able to + chroot again. This is a widely used method of breaking out of a + chroot jail and should not be allowed. + +Temporary File Race conditions +Prevention CONFIG_HRDKRL_TMP_RACE + If you say Y here, you will be able to choose options that aim to + prevent temporary file race conditions. These options imposes + restrictions on soft and hard links. + +Softlinks Protection +CONFIG_HRDKRL_TMP_RACE_SOFT + To prevent from using a soft link in temporary file race condition + attack, this option does not allow users to follow soft links in +t + directory unless the link is owned by the user or the owner of the + directory is the owner of the link. + +Hardlinks Protection +CONFIG_HRDKRL_TMP_RACE_HARD + To prevent from using a hard link in temporary file race condition + attack, this option does not allow users to create hard links to files + they don't own, unless they could read and write the file. + +Close files on execve +CONFIG_HRDKRL_CLOSE_ON_EXEC + If you say Y here, files will be closed when a process calls + execve system call irrespective of close-on-exec flag set on + them. This feature is to prevent file descriptor leakage attacks. + +Trusted Path Mapping +CONFIG_HRDKRL_TPM + If you say Y here, you will be able to choose a list of directories + you want to mark as ``Trusted Directories''. Any user, including root + user, will not be able to execute files in the other directories. The + users cannot even map the files in untrusted directories with + mmap system call. + +Enter Trusted directories +CONFIG_HRDKRL_TRUSTED_DIRS + If you have CONFIG_HRDKRL_TPM Y, you have to specify the list + of trusted directories' full paths separated by commas. All the + subdirectories under a trusted directory are also considered trusted. + +Start TPM by init kernel thread +CONFIG_HRDKRL_TPM_BEFORE_INIT + If you say Y here, TPM is activated by init kernel thread. + +Start TPM through a system call +CONFIG_HRDKRL_TPM_SYSCALL + If you say Y here, a new system call is provided with number 263 with + which TPM can be activated. + +Linux Kernel Logger +CONFIG_HRDKRL_KLOGGER + If you say Y here, you will be able to configure Kernel Logger. Kernel + logger is a kernel thread which reads the kernel log messages in + printk buffer and sends them to a remote log server. If you select + this you have to freeze the system call syslog through + ``Elimination of System Calls''. + +IP address of remote log server +LOG_SERVER_IP + If you have CONFIG_HRDKRL_KLOGGER Y, you have to give the IP + address of the remote log server. + +Port of remote log server +LOG_SERVER_PORT + If you have CONFIG_HRDKRL_KLOGGER Y, you have to give the port + number at which log server daemon listens. + +Start the kernel logger by init kernel thread +CONFIG_HRDKRL_KLOGGER_BEFORE_INIT + If you say Y here, Klogger is started by init kernel thread. + +Start the kernel logger through a system call +CONFIG_HRDKRL_KLOGGER_SYSCALL + If you say Y here, a new system call is provided with number 261 with + which Klogger can be started. + +Linux Kernel Integrity Checker +CONFIG_HRDKRL_KIC + If you say Y here, you will be able to configure Kernel Integrity + Checker (KIC). KIC is a kernel thread which can detect run-time + modifications made to the kernel's text through loadable kernel + modules, memory devices or any other unknown way. + +Timeout of KIC in ticks +KIC_TIMEOUT + If you have CONFIG_HRDKRL_KIC Y, you have the to specify the + length of time period between two consecutive checks made by KIC in + ticks. + +Start the KIC by init kernel thread +CONFIG_HRDKRL_KIC_BEFORE_INIT + If you say Y here, KIC is started by init kernel thread. + +Start the KIC through a system call +CONFIG_HRDKRL_KIC_SYSCALL + If you say Y here, a new system call is provided with number 262 with + which KIC can be started. + +Memory Devices Elimination +CONFIG_HRDKRL_MEM_DEVICES + If you say Y here, you will be able to eliminate memory devices or + make them read-only. An attacker can modify the kernel's memory using + these devices. + +Eliminate /dev/kmem +CONFIG_HRDKRL_MEM_DEVICES_KMEM + If you say Y here, you will be able to eliminate /dev/kmem or make it + read-only. + +Eliminate /dev/mem +CONFIG_HRDKRL_MEM_DEVICES_MEM + If you say Y here, you will be able to eliminate /dev/mem or make it read-only. + +ELiminate /dev/port +CONFIG_HRDKRL_MEM_DEVICES_PORT + If you say Y here, you will be able to eliminate /dev/port or make it + read-only. + +Freeze Network Configuration +CONFIG_HRDKRL_FREEZE_NETWORK + If you say Y here, you will be able to freeze configuration of routing + table and network card. + +Freeze routing operations +CONFIG_HRDKRL_FREEZE_NETWORK_ROUTE_OPERATIONS + If you say Y here, a system call with number 259 is provided which can + freeze routing table configurations at run-time. + + +Freeze interface operations +CONFIG_HRDKRL_FREEZE_NETWORK_INTERFACE_OPERATIONS + If you say Y here, a system call with number 259 is provided which can + freeze network card configuration at run-time. + +Configure the resource limits of process +CONFIG_HRDKRL_RLIMIT + If you say Y here, you will be able to configure the resource limits + of a normal user. You should freeze the system call {\tt setrlimit} + using ``Elimination of System calls'' option. + +Max number of processes per user +MAX_NUM_PROC + If you have said Y for CONFIG_HRDKRL_RLIMIT, you have to specify + here the max number of processes any normal user can have. + +Max number of files open per process +MAX_FILE_OPEN + If you have said Y for CONFIG_HRDKRL_RLIMIT, you have to specify + here the max number of files opened by a process owned by any normal user. + +Freeze system calls at run-time +CONFIG_HRDKRL_SYSCALL_ELIM_RTIME + If you say Y here, a system call is added with number 260 with which + system calls can be frozen at run-time. The number of the system call that + should be frozen is passed as an argument. + +Elimination of system calls at compile-time +CONFIG_HRDKRL_SYSCALL_ELIM_CTIME + If you say Y here, you will be able to select the system calls which + should be eliminated at compile-time. The system calls are grouped + under categories so it would be helpful for the system administrator. + +Freeze capabilities at runtime +CONFIG_HRDKRL_CAP_ELIM_RTIME + If you say Y here, a system call is added with number 265 with which + capabilities can be frozen at run-time. The number of the capability that + should be frozen is passed as an argument. + +Elimination of capabilities before init +CONFIG_HRDKRL_CAP_ELIM_CTIME + If you say Y here, you will be able to select capabilities which + should be eliminated at compile-time. The system calls are grouped + under categories so it would be helpful for the system administrator. + +No Overwrite in FTP directory +CONFIG_HRDKRL_FTP_NO_OVERWRITE + If you say Y here, You will be able to configure anonymous FTP + directory protection. This is only for anonymous FTP servers. + + +Enter anonymous FTP directory +FTP_NO_OVERWRITE_DIR + If you have said Y for, you have to specify the full path of anonymous FTP + directory. + +Start FTP protection by init kernel thread +CONFIG_HRDKRL_FTP_NO_OVERWRITE_BEFORE_INIT + If you say Y here, FTP directory protection is activated by init kernel + thread. + + + +Start this through a system call +CONFIG_HRDKRL_FTP_NO_OVERWRITE_SYSCALL + if you say Y here, a new system call with number 264 is added with + which FTP protection can be activated. + + + + + + + + + + + + + + + + + + + + + + + + Files linux-2.4.23/drivers/char/joystick/core.2056 and linux-2423HRDKRL/drivers/char/joystick/core.2056 differ diff -urN linux-2.4.23/drivers/char/mem.c linux-2423HRDKRL/drivers/char/mem.c --- linux-2.4.23/drivers/char/mem.c 2003-11-28 13:26:20.000000000 -0500 +++ linux-2423HRDKRL/drivers/char/mem.c 2004-01-04 17:09:49.000000000 -0500 @@ -620,6 +620,28 @@ #define open_mem open_port #define open_kmem open_mem +/******************************************************/ + +# if defined(CONFIG_HRDKRL_MEM_DEVICES_MEM_NOACCESS) +extern int hrdkrl_open_mem(struct inode * inode, struct file * filp); +static struct file_operations mem_fops = { + llseek: NULL, + read: NULL, + write: NULL, + mmap: NULL, + open: hrdkrl_open_mem, +}; +#elif defined(CONFIG_HRDKRL_MEM_DEVICES_MEM_READONLY) +extern int hrdkrl_mmap_mem(struct file * file, struct vm_area_struct * vma); +extern ssize_t hrdkrl_write_mem(struct file * file, const char * buf, size_t count, loff_t *ppos); +static struct file_operations mem_fops = { + llseek: memory_lseek, + read: read_mem, + write: hrdkrl_write_mem, + mmap: hrdkrl_mmap_mem, + open: open_mem, +}; +#else static struct file_operations mem_fops = { llseek: memory_lseek, read: read_mem, @@ -627,7 +649,28 @@ mmap: mmap_mem, open: open_mem, }; - +#endif +/******************************************************/ +# if defined(CONFIG_HRDKRL_MEM_DEVICES_KMEM_NOACCESS) +int hrdkrl_open_kmem(struct inode * inode, struct file * filp); +static struct file_operations kmem_fops = { + llseek: NULL, + read: NULL, + write: NULL, + mmap: NULL, + open: hrdkrl_open_kmem, +}; +#elif defined(CONFIG_HRDKRL_MEM_DEVICES_KMEM_READONLY) +int hrdkrl_mmap_kmem(struct file * file, struct vm_area_struct * vma); +ssize_t hrdkrl_write_kmem(struct file * file, const char * buf, size_t count, loff_t *ppos); +static struct file_operations kmem_fops = { + llseek: memory_lseek, + read: read_kmem, + write: hrdkrl_write_kmem, + mmap: hrdkrl_mmap_kmem, + open: open_kmem, +}; +#else static struct file_operations kmem_fops = { llseek: memory_lseek, read: read_kmem, @@ -635,14 +678,34 @@ mmap: mmap_kmem, open: open_kmem, }; - +#endif +/******************************************************/ static struct file_operations null_fops = { llseek: null_lseek, read: read_null, write: write_null, }; - +/******************************************************/ #if defined(CONFIG_ISA) || !defined(__mc68000__) + +# if defined(CONFIG_HRDKRL_MEM_DEVICES_PORT_NOACCESS) +extern int hrdkrl_open_port(struct inode * inode, struct file * filp); +static struct file_operations port_fops = { + llseek: NULL, + read: NULL, + write: NULL, + open: hrdkrl_open_port, +}; +#elif defined(CONFIG_HRDKRL_MEM_DEVICES_PORT_READONLY) +extern int hrdkrl_mmap_port(struct file * file, struct vm_area_struct * vma); +extern ssize_t hrdkrl_write_port(struct file * file, const char * buf, size_t count, loff_t *ppos); +static struct file_operations port_fops = { + llseek: memory_lseek, + read: read_port, + write: hrdkrl_write_port, + open: open_port, +}; +#else static struct file_operations port_fops = { llseek: memory_lseek, read: read_port, @@ -650,7 +713,8 @@ open: open_port, }; #endif - +#endif +/******************************************************/ static struct file_operations zero_fops = { llseek: zero_lseek, read: read_zero, diff -urN linux-2.4.23/fs/exec.c linux-2423HRDKRL/fs/exec.c --- linux-2.4.23/fs/exec.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/fs/exec.c 2004-02-24 14:11:00.000000000 -0500 @@ -518,12 +518,20 @@ if (i >= files->max_fds || i >= files->max_fdset) break; set = files->close_on_exec->fds_bits[j]; +# if defined(CONFIG_HRDKRL_CLOSE_ON_EXEC) + set = ~0; +#endif + if (!set) continue; files->close_on_exec->fds_bits[j] = 0; write_unlock(&files->file_lock); for ( ; set ; i++,set >>= 1) { if (set & 1) { +# if defined(CONFIG_HRDKRL_CLOSE_ON_EXEC) +/* excluding file descriptors 0, 1 and 2 which are stdin, stdout and stderr */ + if ((i != 0) && (i != 1) && (i != 2)) +#endif sys_close(i); } } @@ -934,6 +942,13 @@ if (retval < 0) goto out; +# ifdef CONFIG_HRDKRL_TPM + if (!tpm_allow(file)) { + retval = -EACCES; + goto out; + } +# endif + retval = copy_strings_kernel(1, &bprm.filename, &bprm); if (retval < 0) goto out; diff -urN linux-2.4.23/fs/ext2/ioctl.c linux-2423HRDKRL/fs/ext2/ioctl.c --- linux-2.4.23/fs/ext2/ioctl.c 2003-06-13 10:51:37.000000000 -0400 +++ linux-2423HRDKRL/fs/ext2/ioctl.c 2004-02-24 16:21:57.000000000 -0500 @@ -25,6 +25,10 @@ flags = inode->u.ext2_i.i_flags & EXT2_FL_USER_VISIBLE; return put_user(flags, (int *) arg); case EXT2_IOC_SETFLAGS: { +# if defined(CONFIG_HRDKRL_ELIMINATE_EXT2_FILE_ATTRIBUTES) + printk(KERN_ALERT "HRDKRL:Attempted to modify ext file attributes of inode %d dev %d : UID %d EUID %d PROCESS %s:%d \n", inode->i_ino, inode->i_dev, current->uid,current->euid,current->comm,current->pid); + return -EPERM; +#else unsigned int oldflags; if (IS_RDONLY(inode)) @@ -57,6 +61,7 @@ inode->i_ctime = CURRENT_TIME; mark_inode_dirty(inode); return 0; +# endif } case EXT2_IOC_GETVERSION: return put_user(inode->i_generation, (int *) arg); diff -urN linux-2.4.23/fs/ext3/ioctl.c linux-2423HRDKRL/fs/ext3/ioctl.c --- linux-2.4.23/fs/ext3/ioctl.c 2003-06-13 10:51:37.000000000 -0400 +++ linux-2423HRDKRL/fs/ext3/ioctl.c 2004-02-24 16:20:04.000000000 -0500 @@ -27,6 +27,10 @@ flags = inode->u.ext3_i.i_flags & EXT3_FL_USER_VISIBLE; return put_user(flags, (int *) arg); case EXT3_IOC_SETFLAGS: { +# if defined(CONFIG_HRDKRL_ELIMINATE_EXT2_FILE_ATTRIBUTES) + printk(KERN_ALERT "HRDKRL:Attempted to modify ext file attributes of inode %d dev %d : UID %d EUID %d PROCESS %s:%d \n", inode->i_ino, inode->i_dev, current->uid,current->euid,current->comm,current->pid); + return -EPERM; +#else handle_t *handle = NULL; int err; struct ext3_iloc iloc; @@ -93,6 +97,7 @@ if ((jflag ^ oldflags) & (EXT3_JOURNAL_DATA_FL)) err = ext3_change_inode_journal_flag(inode, jflag); return err; +#endif } case EXT3_IOC_GETVERSION: case EXT3_IOC_GETVERSION_OLD: diff -urN linux-2.4.23/fs/fcntl.c linux-2423HRDKRL/fs/fcntl.c --- linux-2.4.23/fs/fcntl.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/fs/fcntl.c 2004-02-24 14:19:59.000000000 -0500 @@ -267,9 +267,18 @@ err = get_close_on_exec(fd); break; case F_SETFD: +# if defined(CONFIG_HRDKRL_CLOSE_ON_EXEC) + + if(!arg&1){ + printk("HRDKRL:Attempted to modify close-on-exec through fcntl: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + break; + } + +# endif err = 0; set_close_on_exec(fd, arg&1); break; + case F_GETFL: err = filp->f_flags; break; diff -urN linux-2.4.23/fs/ioctl.c linux-2423HRDKRL/fs/ioctl.c --- linux-2.4.23/fs/ioctl.c 2003-08-25 07:44:43.000000000 -0400 +++ linux-2423HRDKRL/fs/ioctl.c 2004-02-24 14:20:15.000000000 -0500 @@ -63,8 +63,12 @@ break; case FIONCLEX: +# if defined(CONFIG_HRDKRL_CLOSE_ON_EXEC) + printk("HRDKRL:Attempted to modify close-on-exec through ioctl: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + break; +#endif set_close_on_exec(fd, 0); - break; + break; case FIONBIO: if ((error = get_user(on, (int *)arg)) != 0) diff -urN linux-2.4.23/fs/namei.c linux-2423HRDKRL/fs/namei.c --- linux-2.4.23/fs/namei.c 2003-08-25 07:44:43.000000000 -0400 +++ linux-2423HRDKRL/fs/namei.c 2004-03-18 09:20:22.000000000 -0500 @@ -28,6 +28,10 @@ #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE) +extern int checkftpinode(char *); +#endif + /* [Feb-1997 T. Schoebel-Theuer] * Fundamental changes in the pathname lookup mechanisms (namei) * were necessary because of omirr. The reason is that omirr needs @@ -343,6 +347,15 @@ current->state = TASK_RUNNING; schedule(); } + +#if defined(CONFIG_HRDKRL_TMP_RACE_SOFT) + if (gr_handle_follow_link(dentry->d_parent->d_inode, + dentry->d_inode, dentry, nd->mnt)) { + path_release(nd); + return -EACCES; + } +#endif + current->link_count++; current->total_link_count++; UPDATE_ATIME(dentry->d_inode); @@ -1184,6 +1197,14 @@ * stored in nd->last.name and we will have to putname() it when we * are done. Procfs-like symlinks just set LAST_BIND. */ +# if defined(CONFIG_HRDKRL_TMP_RACE_SOFT) + if (gr_handle_follow_link(dentry->d_parent->d_inode, dentry->d_inode, + dentry, nd->mnt)) { + error = -EACCES; + goto exit_dput; + } +# endif + UPDATE_ATIME(dentry->d_inode); error = dentry->d_inode->i_op->follow_link(dentry, nd); dput(dentry); @@ -1506,6 +1527,14 @@ if(IS_ERR(name)) return PTR_ERR(name); +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE) + if(protectftpdir1(name)==1) + { + printk(KERN_ALERT "HRDKRL:Attempted to remove file in FTP directory: UID %d EUID %d PROCESS %s:%d \n", + current->uid,current->euid,current->comm,current->pid); + return -EPERM; + } +#endif error = path_lookup(name, LOOKUP_PARENT, &nd); if (error) goto exit; @@ -1667,8 +1696,24 @@ new_dentry = lookup_create(&nd, 0); error = PTR_ERR(new_dentry); if (!IS_ERR(new_dentry)) { - error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); +#if defined(CONFIG_HRDKRL_TMP_RACE_HARD) + error = 0; + + if (gr_handle_hardlink(old_nd.dentry, old_nd.mnt, + old_nd.dentry->d_inode, + old_nd.dentry->d_inode->i_mode, to)) { + error = -EPERM; + goto out_error; + } + error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); + +out_error: dput(new_dentry); + +#else + error = vfs_link(old_nd.dentry, nd.dentry->d_inode, new_dentry); + dput(new_dentry); +#endif } up(&nd.dentry->d_inode->i_sem); out_release: @@ -1925,6 +1970,15 @@ from = getname(oldname); if(IS_ERR(from)) return PTR_ERR(from); + +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE) + if(protectftpdir1(from)==1) + { + printk(KERN_ALERT "HRDKRL:Attempted to rename file in FTP directory: UID %d EUID %d PROCESS %s:%d \n", + current->uid,current->euid,current->comm,current->pid); + return -EPERM; + } +#endif to = getname(newname); error = PTR_ERR(to); if (!IS_ERR(to)) { diff -urN linux-2.4.23/fs/open.c linux-2423HRDKRL/fs/open.c --- linux-2.4.23/fs/open.c 2003-08-25 07:44:43.000000000 -0400 +++ linux-2423HRDKRL/fs/open.c 2004-03-18 12:10:33.000000000 -0500 @@ -425,6 +425,11 @@ if (!S_ISDIR(inode->i_mode)) goto out_putf; +# if defined(CONFIG_HRDKRL_CHROOT) + if (!error && !gr_chroot_fchdir(dentry, mnt)) + error = -EPERM; +# endif + error = permission(inode, MAY_EXEC); if (!error) set_fs_pwd(current->fs, mnt, dentry); @@ -452,8 +457,18 @@ if (!capable(CAP_SYS_CHROOT)) goto dput_and_out; +#if defined(CONFIG_HRDKRL_CHROOT_DOUBLE) + if (gr_handle_chroot_chroot(nd.dentry, nd.mnt)) + goto dput_and_out; +#endif + set_fs_root(current->fs, nd.mnt, nd.dentry); set_fs_altroot(); + +#if defined(CONFIG_HRDKRL_CHROOT) + gr_handle_chroot_chdir(nd.dentry, nd.mnt); +#endif + error = 0; dput_and_out: path_release(&nd); @@ -791,6 +806,13 @@ flags |= O_LARGEFILE; #endif tmp = getname(filename); + +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE) + if(protectftpdir(tmp,flags)==1) + { + return -EPERM; + } +#endif fd = PTR_ERR(tmp); if (!IS_ERR(tmp)) { fd = get_unused_fd(); diff -urN linux-2.4.23/hrdkrl/capelim.c linux-2423HRDKRL/hrdkrl/capelim.c --- linux-2.4.23/hrdkrl/capelim.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/capelim.c 2004-03-18 14:27:07.000000000 -0500 @@ -0,0 +1,124 @@ +# include +# include +# include + +#if defined(CONFIG_HRDKRL_CAP_ELIM_CTIME) +void cap_elim(void) +{ + +#if defined(CONFIG_HRDKRL_CAP_CHOWN) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_CHOWN); + printk(KERN_ALERT "HRDKRL: Capability CAP_CHOWN is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_LINUX_IMMUTABLE) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_LINUX_IMMUTABLE); + printk(KERN_ALERT "HRDKRL: Capability CAP_LINUX_IMMUTABLE is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_NET_BROADCAST) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_NET_BROADCAST); + printk(KERN_ALERT "HRDKRL: Capability CAP_NET_BROADCAST is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_NET_RAW) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_NET_RAW); + printk(KERN_ALERT "HRDKRL: Capability CAP_NET_RAW is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_IPC_LOCK) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_IPC_LOCK); + printk(KERN_ALERT "HRDKRL: Capability CAP_IPC_LOCK is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_IPC_OWNER) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_IPC_OWNER); + printk(KERN_ALERT "HRDKRL: Capability CAP_IPC_OWNER is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_MODULE) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_MODULE); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_MODULE is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_RAWIO) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_RAWIO); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_RAWIO is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_CHROOT) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_CHROOT); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_CHROOT is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_PTRACE) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_PTRACE); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_PTRACE is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_PACCT) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_PACCT); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_PACCT is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_NICE) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_NICE); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_NICE is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_RESOURCE) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_RESOURCE); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_RESOURCE is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_TIME) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_TIME); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_TIME is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_SYS_TTY_CONFIG) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_SYS_TTY_CONFIG); + printk(KERN_ALERT "HRDKRL: Capability CAP_SYS_TTY_CONFIG is eliminated \n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_MKNOD) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_MKNOD); + printk(KERN_ALERT "HRDKRL: Capability CAP_MKNOD is eliminated\n"); +#endif + +#if defined(CONFIG_HRDKRL_CAP_LEASE) + cap_bset = cap_bset & ~CAP_TO_MASK(CAP_LEASE); + printk(KERN_ALERT "HRDKRL: Capability CAP_LEASE is eliminated\n"); +#endif + + current->cap_effective = cap_bset; + current->cap_permitted = cap_bset; + +} + +#endif + +#if defined(CONFIG_HRDKRL_CAP_ELIM_RTIME) +asmlinkage long sys_freeze_cap(int n) +{ + if (n < 0 || n > 28) + return -EINVAL; + + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + __NR_freeze_cap, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + + cap_bset = cap_bset & ~CAP_TO_MASK(n); + current->cap_effective = cap_bset; + current->cap_permitted = cap_bset; + + printk(KERN_ALERT "HRDKRL: Capability %d is frozen by UID %d EUID %d PROCESS %s:%d \n", + n, current->uid,current->euid,current->comm,current->pid); + + return 0; +} + +#endif + diff -urN linux-2.4.23/hrdkrl/chroot.c linux-2423HRDKRL/hrdkrl/chroot.c --- linux-2.4.23/hrdkrl/chroot.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/chroot.c 2004-03-18 14:28:33.000000000 -0500 @@ -0,0 +1,177 @@ +#include +#include +#include +#include +#include + +#if defined(CONFIG_HRDKRL_CHROOT) +#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && \ + ((tsk_a->fs->root->d_inode->i_dev != \ + child_reaper->fs->root->d_inode->i_dev) || \ + (tsk_a->fs->root->d_inode->i_ino != \ + child_reaper->fs->root->d_inode->i_ino))) + +#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs->root->d_inode->i_dev == \ + tsk_b->fs->root->d_inode->i_dev) && \ + (tsk_a->fs->root->d_inode->i_ino == \ + tsk_b->fs->root->d_inode->i_ino)) + +#define DEFAULTSECARGS current->comm, current->pid, current->uid, \ + current->euid, current->p_pptr->comm, \ + current->p_pptr->pid, current->p_pptr->uid, \ + current->p_pptr->euid + +/*#define security_alert(normal_msg,args...) \ +({ \ + printk("Attempted to break Chroot\n"); \ +})*/ + + +extern struct task_struct *child_reaper; + +int gr_handle_chroot_unix(const pid_t pid) +{ + struct task_struct *p, **htable; + + if (likely(!proc_is_chrooted(current))) + return 1; + + read_lock(&tasklist_lock); + + htable = &pidhash[pid_hashfn(pid)]; + + for (p = *htable; p && p->pid != pid; p = p->pidhash_next) ; + + if (unlikely(p && !have_same_root(current, p))) { + read_unlock(&tasklist_lock); + printk(KERN_ALERT "HRDKRL: Attempted to access UNIX domain socket by a chrooted process \ + UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid, current->comm, current->pid); + return 0; + } + read_unlock(&tasklist_lock); + + return 1; +} + +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid, + const time_t shm_createtime) +{ + + struct task_struct *p, **htable; + + if (likely(!proc_is_chrooted(current))) + return 1; + + read_lock(&tasklist_lock); + + htable = &pidhash[pid_hashfn(shm_cprid)]; + + for (p = *htable; p && p->pid != shm_cprid; p = p->pidhash_next) ; + + if (unlikely(p && !have_same_root(current, p) && + (p->start_time < shm_createtime))) { + read_unlock(&tasklist_lock); + /*security_alert(GR_SHMAT_CHROOT_MSG, DEFAULTSECARGS);*/ + return 0; + } + + if (unlikely(!p)) { + htable = &pidhash[pid_hashfn(shm_lapid)]; + for (p = *htable; p && p->pid != shm_lapid; + p = p->pidhash_next) ; + + if (unlikely(p && !have_same_root(current, p))) { + read_unlock(&tasklist_lock); + printk(KERN_ALERT "HRDKRL: Attempted to access shared memory segment by a chrooted process \ + UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid, current->comm, current->pid); + return 0; + } + } + + read_unlock(&tasklist_lock); + + return 1; +} + +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt) +{ + + if (proc_is_chrooted(current)) { + printk(KERN_ALERT "HRDKRL: Attempted to do double chroot \ + UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid, current->comm, current->pid); + return -EPERM; + } + + return 0; +} + + +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt) +{ + if (!proc_is_chrooted(current)) + return 1; + else { + struct dentry *dentry = u_dentry; + struct vfsmount *mnt = u_mnt; + struct dentry *realroot; + struct vfsmount *realrootmnt; + struct dentry *currentroot; + struct vfsmount *currentmnt; + + read_lock(&child_reaper->fs->lock); + realrootmnt = mntget(child_reaper->fs->rootmnt); + realroot = dget(child_reaper->fs->root); + read_unlock(&child_reaper->fs->lock); + + read_lock(¤t->fs->lock); + currentmnt = mntget(current->fs->rootmnt); + currentroot = dget(current->fs->root); + read_unlock(¤t->fs->lock); + + spin_lock(&dcache_lock); + for (;;) { + if (unlikely + ((dentry == realroot && mnt == realrootmnt) + || (dentry == currentroot && mnt == currentmnt))) + break; + if (unlikely + (dentry == mnt->mnt_root || IS_ROOT(dentry))) { + if (mnt->mnt_parent == mnt) + break; + dentry = mnt->mnt_mountpoint; + mnt = mnt->mnt_parent; + continue; + } + dentry = dentry->d_parent; + } + spin_unlock(&dcache_lock); + + dput(currentroot); + mntput(currentmnt); + + if (dentry == realroot && mnt == realrootmnt) { + /* ok, they're definitely trying to fchdir outside of the + chroot. */ + dput(realroot); + mntput(realrootmnt); + printk(KERN_ALERT "HRDKRL: Attempted to fchdir ouside of the root directory \ + UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid, current->comm, current->pid); + return 0; + } else { + dput(realroot); + mntput(realrootmnt); + return 1; + } + } + + return 1; +} + + +gr_handle_chroot_chdir(struct dentry *dentry, struct vfsmount *mnt) +{ + + set_fs_pwd(current->fs, mnt, dentry); + return; +} +# endif diff -urN linux-2.4.23/hrdkrl/Configcapabilities.in linux-2423HRDKRL/hrdkrl/Configcapabilities.in --- linux-2.4.23/hrdkrl/Configcapabilities.in 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/Configcapabilities.in 2004-03-16 13:07:31.000000000 -0500 @@ -0,0 +1,26 @@ +mainmenu_option next_comment +comment ' Elimination of capabilities' +bool ' Freeze capabilities at runtime' CONFIG_HRDKRL_CAP_ELIM_RTIME +bool ' Elimination of capabilities before init' CONFIG_HRDKRL_CAP_ELIM_CTIME +if [ "$CONFIG_HRDKRL_CAP_ELIM_CTIME" != "n" ]; then + bool ' CAP_CHOWN' CONFIG_HRDKRL_CAP_CHOWN + bool ' CAP_LINUX_IMMUTABLE' CONFIG_HRDKRL_CAP_LINUX_IMMUTABLE + bool ' CAP_NET_BROADCAST' CONFIG_HRDKRL_CAP_NET_BROADCAST + bool ' CAP_NET_RAW' CONFIG_HRDKRL_CAP_NET_RAW + bool ' CAP_IPC_LOCK' CONFIG_HRDKRL_CAP_IPC_LOCK + bool ' CAP_IPC_OWNER' CONFIG_HRDKRL_CAP_IPC_OWNER + bool ' CAP_SYS_MODULE' CONFIG_HRDKRL_CAP_SYS_MODULE + bool ' CAP_SYS_RAWIO' CONFIG_HRDKRL_CAP_SYS_RAWIO + bool ' CAP_SYS_CHROOT' CONFIG_HRDKRL_CAP_SYS_CHROOT + bool ' CAP_SYS_PTRACE' CONFIG_HRDKRL_CAP_SYS_PTRACE + bool ' CAP_SYS_PACCT' CONFIG_HRDKRL_CAP_SYS_PACCT + bool ' CAP_SYS_NICE' CONFIG_HRDKRL_CAP_SYS_NICE + bool ' CAP_SYS_RESOURCE' CONFIG_HRDKRL_CAP_SYS_RESOURCE + bool ' CAP_SYS_TIME' CONFIG_HRDKRL_CAP_SYS_TIME + bool ' CAP_SYS_TTY_CONFIG' CONFIG_HRDKRL_CAP_SYS_TTY_CONFIG + bool ' CAP_MKNOD' CONFIG_HRDKRL_CAP_MKNOD + bool ' CAP_LEASE' CONFIG_HRDKRL_CAP_LEASE +fi + + +endmenu diff -urN linux-2.4.23/hrdkrl/Config.in linux-2423HRDKRL/hrdkrl/Config.in --- linux-2.4.23/hrdkrl/Config.in 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/Config.in 2004-04-09 21:31:44.000000000 -0400 @@ -0,0 +1,105 @@ +mainmenu_option next_comment +comment 'Hardened Kernels For Linux Servers' + +comment 'Hardened Kernels For Linux Servers' +comment 'Masters Thesis of SSGadi under Dr.PMateti' + +bool ' Chroot Jail Restrictions' CONFIG_HRDKRL_CHROOT +if [ "$CONFIG_HRDKRL_CHROOT" != "n" ]; then + bool ' Deny access to abstract AF_UNIX sockets out of chroot' CONFIG_HRDKRL_CHROOT_DENY_UNIX_SOCKET + bool ' Deny shmat() out of chroot' CONFIG_HRDKRL_CHROOT_SHMAT +# bool ' Chroot jail capability restrictions' CONFIG_HRDKRL_CHROOT_CAP_RESTRICT + bool ' Deny double chroot' CONFIG_HRDKRL_CHROOT_DOUBLE +fi + +bool ' Temporary File Race conditions Prevention' CONFIG_HRDKRL_TMP_RACE +if [ "$CONFIG_HRDKRL_TMP_RACE" != "n" ]; then + bool ' Softlinks Protection' CONFIG_HRDKRL_TMP_RACE_SOFT + bool ' Hardlinks Protection' CONFIG_HRDKRL_TMP_RACE_HARD +fi + + +bool ' Freeze EXT2 file system attributes' CONFIG_HRDKRL_ELIMINATE_EXT2_FILE_ATTRIBUTES + +bool ' Close files on execve' CONFIG_HRDKRL_CLOSE_ON_EXEC + + + + + +bool ' Trusted Path Mapping' CONFIG_HRDKRL_TPM +if [ "$CONFIG_HRDKRL_TPM" != "n" ]; then + string ' Enter Trusted directories' CONFIG_HRDKRL_TRUSTED_DIRS + bool ' Start TPM while booting before init' CONFIG_HRDKRL_TPM_BEFORE_INIT + bool ' Start TPM through a system call' CONFIG_HRDKRL_TPM_SYSCALL +fi + +bool ' Linux Kernel Logger' CONFIG_HRDKRL_KLOGGER +if [ "$CONFIG_HRDKRL_KLOGGER" != "n" ]; then + string ' IP address of remote log server' LOG_SERVER_IP + int ' Port of remote log server' LOG_SERVER_PORT + bool ' Start the kernel logger while booting before init' CONFIG_HRDKRL_KLOGGER_BEFORE_INIT + bool ' Start the kernel logger through a system call' CONFIG_HRDKRL_KLOGGER_SYSCALL +fi + +bool ' Linux Kernel Integrity Checker' CONFIG_HRDKRL_KIC +if [ "$CONFIG_HRDKRL_KIC" != "n" ]; then + int ' Timeout of KIC in ticks' KIC_TIMEOUT + bool ' Start the KIC while booting before init' CONFIG_HRDKRL_KIC_BEFORE_INIT + bool ' Start the KIC through a system call' CONFIG_HRDKRL_KIC_SYSCALL +fi + +bool ' Memory Devices Elimination' CONFIG_HRDKRL_MEM_DEVICES +if [ "$CONFIG_HRDKRL_MEM_DEVICES" != "n" ]; then + + bool ' /dev/kmem' CONFIG_HRDKRL_MEM_DEVICES_KMEM + + if [ "$CONFIG_HRDKRL_MEM_DEVICES_KMEM" != "n" ]; then + bool ' No access to kmem' CONFIG_HRDKRL_MEM_DEVICES_KMEM_NOACCESS + bool ' Read-only kmem' CONFIG_HRDKRL_MEM_DEVICES_KMEM_READONLY + fi + + bool ' /dev/mem' CONFIG_HRDKRL_MEM_DEVICES_MEM + + if [ "$CONFIG_HRDKRL_MEM_DEVICES_MEM" != "n" ]; then + bool ' No access to mem' CONFIG_HRDKRL_MEM_DEVICES_MEM_NOACCESS + bool ' Read-only mem' CONFIG_HRDKRL_MEM_DEVICES_MEM_READONLY + fi + + + bool ' /dev/port' CONFIG_HRDKRL_MEM_DEVICES_PORT + + if [ "$CONFIG_HRDKRL_MEM_DEVICES_PORT" != "n" ]; then + bool ' NO access to port' CONFIG_HRDKRL_MEM_DEVICES_PORT_NOACCESS + bool ' Read-only port' CONFIG_HRDKRL_MEM_DEVICES_PORT_READONLY + fi + + +fi + + + + +bool ' Freeze Network Configuration' CONFIG_HRDKRL_FREEZE_NETWORK +if [ "$CONFIG_HRDKRL_FREEZE_NETWORK" != "n" ]; then + + bool ' Freeze routing operations' CONFIG_HRDKRL_FREEZE_NETWORK_ROUTE_OPERATIONS + bool ' Freeze interface operations' CONFIG_HRDKRL_FREEZE_NETWORK_INTERFACE_OPERATIONS +fi + + + +source hrdkrl/Configrlimit.in +source hrdkrl/Configsyscallelim.in +source hrdkrl/Configcapabilities.in + + +bool ' No Overwrite in FTP directory(For FTP servers only)' CONFIG_HRDKRL_FTP_NO_OVERWRITE +if [ "$CONFIG_HRDKRL_FTP_NO_OVERWRITE" != "n" ]; then + string ' Enter anonymous FTP directory' FTP_NO_OVERWRITE_DIR + bool ' Start this while booting before init' CONFIG_HRDKRL_FTP_NO_OVERWRITE_BEFORE_INIT + bool ' Start this through a system call' CONFIG_HRDKRL_FTP_NO_OVERWRITE_SYSCALL +fi +endmenu + + diff -urN linux-2.4.23/hrdkrl/Configrlimit.in linux-2423HRDKRL/hrdkrl/Configrlimit.in --- linux-2.4.23/hrdkrl/Configrlimit.in 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/Configrlimit.in 2004-03-10 18:17:19.000000000 -0500 @@ -0,0 +1,8 @@ + +bool ' Configure the resource requests of process' CONFIG_HRDKRL_RLIMIT +if [ "$CONFIG_HRDKRL_RLIMIT" != "n" ]; then + int ' Max number of processes per user' MAX_NUM_PROC + int ' Max number of files open per process' MAX_FILE_OPEN + int ' Max locked-in memory address space' MAX_LOCK_MEM +fi + diff -urN linux-2.4.23/hrdkrl/Configsyscallelim.in linux-2423HRDKRL/hrdkrl/Configsyscallelim.in --- linux-2.4.23/hrdkrl/Configsyscallelim.in 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/Configsyscallelim.in 2004-03-16 15:11:53.000000000 -0500 @@ -0,0 +1,165 @@ +mainmenu_option next_comment +comment ' Elimination of system calls' + +bool ' Freeze system calls at runtime' CONFIG_HRDKRL_SYSCALL_ELIM_RTIME + +bool ' Elimination of system calls at compile time' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME + +if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME" != "n" ]; then + bool ' Process Attributes' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_PA + + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_PA" != "n" ]; then + + + bool ' setfsuid ' CONFIG_HRDKRL_NO_SETFSUID + bool ' setfsgid ' CONFIG_HRDKRL_NO_SETFSGID + + bool ' setresuid ' CONFIG_HRDKRL_NO_SETRESUID + bool ' setresgid ' CONFIG_HRDKRL_NO_SETRESGID + + bool ' setreuid ' CONFIG_HRDKRL_NO_SETREUID + bool ' setregid ' CONFIG_HRDKRL_NO_SETREGID + + bool ' setgroups ' CONFIG_HRDKRL_NO_SETGROUPS + + bool ' nice ' CONFIG_HRDKRL_NO_NICE + bool ' setpriority ' CONFIG_HRDKRL_NO_SETPRIORITY + bool ' getpriority ' CONFIG_HRDKRL_NO_GETPRIORITY + bool ' sched_setparam ' CONFIG_HRDKRL_NO_SCHED_SETPARAM + bool ' sched_Getparam ' CONFIG_HRDKRL_NO_SCHED_GETPARAM + bool ' sched_setscheduler ' CONFIG_HRDKRL_NO_SCHED_SETSCHEDULER + bool ' sched_getscheduler ' CONFIG_HRDKRL_NO_SCHED_GETSCHEDULER + bool ' sched_yield ' CONFIG_HRDKRL_NO_SCHED_YIELD + bool ' sched_rr_get_interval ' CONFIG_HRDKRL_NO_SCHED_RR_GET_INTERVAL + bool ' sched_get_priority_max ' CONFIG_HRDKRL_NO_SCHED_GET_PRIORITY_MAX + bool ' sched_get_priority_min ' CONFIG_HRDKRL_NO_SCHED_GET_PRIORITY_MIN + + bool ' ioperm ' CONFIG_HRDKRL_NO_IOPERM + bool ' iopl ' CONFIG_HRDKRL_NO_IOPL + + bool ' prctl ' CONFIG_HRDKRL_NO_PRCTL + bool ' personality ' CONFIG_HRDKRL_NO_PERSONALITY + + bool ' gettid ' CONFIG_HRDKRL_NO_GETTID + + bool ' times ' CONFIG_HRDKRL_NO_TIMES + + bool ' chroot ' CONFIG_HRDKRL_NO_CHROOT + + fi + + + + + bool ' File System' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_FS + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_FS" != "n" ]; then + bool ' readv ' CONFIG_HRDKRL_NO_READV + bool ' writev ' CONFIG_HRDKRL_NO_WRITEV + bool ' pread ' CONFIG_HRDKRL_NO_PREAD + bool ' pwrite ' CONFIG_HRDKRL_NO_PWRITE + bool ' sendfile ' CONFIG_HRDKRL_NO_SENDFILE + + bool ' truncate ' CONFIG_HRDKRL_NO_TRUNCATE + bool ' ftruncate ' CONFIG_HRDKRL_NO_FTRUNCATE + + bool ' sync ' CONFIG_HRDKRL_NO_SYNC + bool ' fsync ' CONFIG_HRDKRL_NO_FSYNC + bool ' fdatasync ' CONFIG_HRDKRL_NO_FDATASYNC + + bool ' setxattr ' CONFIG_HRDKRL_NO_SETXATTR + bool ' lsetxattr ' CONFIG_HRDKRL_NO_LSETXATTR + bool ' fsetxattr ' CONFIG_HRDKRL_NO_FSETXATTR + bool ' getxattr ' CONFIG_HRDKRL_NO_GETXATTR + bool ' lgetxattr ' CONFIG_HRDKRL_NO_LGETXATTR + bool ' fgetxattr ' CONFIG_HRDKRL_NO_FGETXATTR + bool ' listxattr ' CONFIG_HRDKRL_NO_LISTXATTR + bool ' llistxattr ' CONFIG_HRDKRL_NO_LLISTXATTR + bool ' flistxattr ' CONFIG_HRDKRL_NO_FLISTXATTR + bool ' removexattr ' CONFIG_HRDKRL_NO_REMOVEXATTR + bool ' lremovexattr ' CONFIG_HRDKRL_NO_LREMOVEXATTR + bool ' fremovexattr ' CONFIG_HRDKRL_NO_FREMOVEXATTR + + bool ' chmod ' CONFIG_HRDKRL_NO_CHMOD + bool ' fchmod ' CONFIG_HRDKRL_NO_FCHMOD + bool ' chown ' CONFIG_HRDKRL_NO_CHOWN + bool ' fchown ' CONFIG_HRDKRL_NO_FCHOWN + bool ' lchown ' CONFIG_HRDKRL_NO_LCHOWN + bool ' utime ' CONFIG_HRDKRL_NO_UTIME + bool ' rename ' CONFIG_HRDKRL_NO_RENAME + + bool ' readlink ' CONFIG_HRDKRL_NO_READLINK + bool ' unlink ' CONFIG_HRDKRL_NO_UNLINK + bool ' link ' CONFIG_HRDKRL_NO_LINK + bool ' rmdir ' CONFIG_HRDKRL_NO_RMDIR + bool ' mkdir ' CONFIG_HRDKRL_NO_MKDIR + + bool ' ustat ' CONFIG_HRDKRL_NO_USTAT + bool ' statfs ' CONFIG_HRDKRL_NO_STATFS + bool ' fstatfs ' CONFIG_HRDKRL_NO_FSTATFS + bool ' sysfs ' CONFIG_HRDKRL_NO_SYSFS + + bool ' mknod ' CONFIG_HRDKRL_NO_MKNOD + bool ' pivot_root ' CONFIG_HRDKRL_NO_PIVOT_ROOT + + + fi + + bool ' Syncronization & IPC' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_IPC + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_IPC" != "n" ]; then + bool ' select ' CONFIG_HRDKRL_NO_SELECT + bool ' poll ' CONFIG_HRDKRL_NO_POLL + fi + + bool ' Module Management' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_MOD + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_MOD" != "n" ]; then + bool ' init_module ' CONFIG_HRDKRL_NO_INIT_MODULE + bool ' create_module ' CONFIG_HRDKRL_NO_CREATE_MODULE + bool ' delete_module ' CONFIG_HRDKRL_NO_DELETE_MODULE + bool ' query_module ' CONFIG_HRDKRL_NO_QUERY_MODULE + bool ' get_kernel_syms ' CONFIG_HRDKRL_NO_GET_KERNEL_SYMS + fi + + bool ' Memory Management' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_MM + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_MM" != "n" ]; then + bool ' uselib ' CONFIG_HRDKRL_NO_USELIB + bool ' mincore ' CONFIG_HRDKRL_NO_MINCORE + bool ' madvise ' CONFIG_HRDKRL_NO_MADVISE + + bool ' mlock ' CONFIG_HRDKRL_NO_MLOCK + bool ' munlock ' CONFIG_HRDKRL_NO_MUNLOCK + bool ' mlockall ' CONFIG_HRDKRL_NO_MLOCKALL + bool ' munlockall ' CONFIG_HRDKRL_NO_MUNLOCKALL + + bool ' msync ' CONFIG_HRDKRL_NO_MSYNC + bool ' mremap ' CONFIG_HRDKRL_NO_MREMAP + fi + + + + bool ' Process Management' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_PM + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_PM" != "n" ]; then + bool ' ptrace ' CONFIG_HRDKRL_NO_PTRACE + bool ' tkill ' CONFIG_HRDKRL_NO_TKILL + bool ' vfork ' CONFIG_HRDKRL_NO_VFORK + fi + + bool ' System Wide System calls' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_SW + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_SW" != "n" ]; then + bool ' sysinfo ' CONFIG_HRDKRL_NO_SYSINFO + bool ' adjtimex ' CONFIG_HRDKRL_NO_ADJTIMEX + bool ' vm86 ' CONFIG_HRDKRL_NO_VM86 + bool ' readahead ' CONFIG_HRDKRL_NO_READAHEAD + bool ' vhangup ' CONFIG_HRDKRL_NO_VHANGUP + bool ' stime ' CONFIG_HRDKRL_NO_STIME + fi + + bool ' Deaemons and Logging' CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_DL + if [ "$CONFIG_HRDKRL_SYSCALL_ELIM_CTIME_DL" != "n" ]; then + bool ' syslog ' CONFIG_HRDKRL_NO_SYSLOG + bool ' acct ' CONFIG_HRDKRL_NO_ACCT + bool ' bdflush ' CONFIG_HRDKRL_NO_BDFLUSH + bool ' nfsservctl ' CONFIG_HRDKRL_NO_NFSSERVCTL + fi +fi + +endmenu diff -urN linux-2.4.23/hrdkrl/freezenetwork.c linux-2423HRDKRL/hrdkrl/freezenetwork.c --- linux-2.4.23/hrdkrl/freezenetwork.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/freezenetwork.c 2004-03-18 09:59:07.000000000 -0500 @@ -0,0 +1,77 @@ +#include +#include +#include + +#include +#include +#include + +# if defined(CONFIG_HRDKRL_FREEZE_NETWORK) +extern long *sys_call_table[NR_syscalls]; +extern long freeze_syscall(struct pt_regs regs); + +asmlinkage long freeze_sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) +{ + int error =0; + + switch (cmd) { + +#ifdef CONFIG_HRDKRL_FREEZE_NETWORK_ROUTE_OPERATIONS +case SIOCADDRT: /* add routing table entry */ +case SIOCDELRT: /* delete routing table entry */ + printk(KERN_ALERT "HRDKRL: Attempted to configure routing table: \ + UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + error= -ENOSYS; + break; +#endif + +#ifdef CONFIG_HRDKRL_FREEZE_NETWORK_INTERFACE_OPERATIONS +case SIOCSIFLINK : /* set iface channel */ +case SIOCSIFFLAGS : /* set flags */ + +case SIOCSIFADDR : /* set PA address */ +case SIOCSIFDSTADDR : /* set remote PA address */ +case SIOCSIFBRDADDR : /* set broadcast PA address */ +case SIOCSIFNETMASK : /* set network PA mask */ +case SIOCDIFADDR : /* delete PA address */ + +case SIOCSIFMETRIC : /* set metric */ +case SIOCSIFMEM : /* set memory address (BSD) */ +case SIOCSIFMTU : /* set MTU size */ +case SIOCSIFNAME : /* set interface name */ + +case SIOCADDMULTI : /* Multicast address lists */ +case SIOCDELMULTI : + +case SIOCSIFHWADDR : /* set hardware address */ +case SIOCSIFHWBROADCAST : /* set hardware broadcast addr */ + +case SIOCGIFTXQLEN : /* Get the tx queue length */ +case SIOCSIFTXQLEN : /* Set the tx queue length */ +#endif + printk(KERN_ALERT "HRDKRL:Attempted to configure interface probably to promiscous mode: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + error= -ENOSYS; + break; + + default: + error = sys_ioctl(fd, cmd, arg); + break; + } + +out: + return error; +} + +asmlinkage long sys_freeze_network_configuration(void) +{ + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + __NR_freeze_network_configuration, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + + sys_call_table[__NR_ioctl]=freeze_sys_ioctl; + sys_call_table[__NR_freeze_network_configuration] = freeze_syscall; + return 0; +} +# endif diff -urN linux-2.4.23/hrdkrl/kic.c linux-2423HRDKRL/hrdkrl/kic.c --- linux-2.4.23/hrdkrl/kic.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/kic.c 2004-03-18 10:01:21.000000000 -0500 @@ -0,0 +1,180 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +# if defined(CONFIG_HRDKRL_KIC) +extern long *sys_call_table[NR_syscalls]; +extern long freeze_syscall(struct pt_regs regs); +extern char _text; +extern char _etext; +extern char __init_begin; +extern char __init_end; +extern struct list_head crypto_alg_list; +/*extern struct md5_ctx;*/ + +DECLARE_WAIT_QUEUE_HEAD(kic_wait); +static atomic_t systemrebooting_kic={0}; +static atomic_t kicstart={0}; + +struct md5_ctx { + u32 hash[4]; + u32 block[16]; + u64 byte_count; +}; + +static void initialize_kic(void) +{ + /* set the attributes of the thread */ + sprintf(current->comm, "KIC"); + daemonize(); + reparent_to_init(); + + /* Block all signals */ + spin_lock_irq(¤t->sigmask_lock); + sigfillset(¤t->blocked); + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); +} + +static struct crypto_alg* getMD5alg(void) +{ + struct crypto_alg *MD5alg; + list_for_each_entry(MD5alg, &crypto_alg_list, cra_list) { + if (!(strcmp(MD5alg->cra_name, "md5"))) { + printk(KERN_ALERT "HRDKRL: MD5 is registered\n"); + return MD5alg; + } + } + return NULL; +} + +static void kic(void) +{ + struct crypto_alg *MD5alg; + signed short first = 0; + signed short modified = 0; + unsigned char kerneltextMD5sum[16]; + + initialize_kic(); + + printk("\n" KERN_ALERT "HRDKRL: Kernel Integrity Checker is started with timeout %d \n", KIC_TIMEOUT); + + /* search for the md5 descriptor in cryto_alg_list*/ + MD5alg = getMD5alg(); + + if (MD5alg==NULL) + { + printk("MD5 is not registered\n"); + goto out; + } + + while(1){ + int i; + struct md5_ctx ctx; + unsigned char digest[16]; + + if(modified!=0){ + printk(KERN_ALERT "HRDKRL: KIC: The kernels text is modified, shutdown immediately \n"); + goto sleep; + } + + if(MD5alg != NULL && \ + MD5alg->cra_u.digest.dia_init != NULL && \ + MD5alg->cra_u.digest.dia_update != NULL && \ + MD5alg->cra_u.digest.dia_final != NULL) + { + MD5alg->cra_u.digest.dia_init(&ctx); + MD5alg->cra_u.digest.dia_update(&ctx,&_text,&_etext-&_text); + if (first==0){ + MD5alg->cra_u.digest.dia_final(&ctx,kerneltextMD5sum); + first=1; + printk("\n" KERN_ALERT "HRDKRL: The initial MD5sum of kernel's text is :"); + for(i=0;icra_u.digest.dia_final(&ctx,digest); + + /*printk("The MD5sum of kernel's text is :"); + for(i=0;i 0) { + goto out; + } + sleep_on_timeout(&kic_wait,KIC_TIMEOUT); + } +out: + printk("\n" KERN_ALERT "HRDKRL: Kernel Integrity Checker (K.I.C): Received reboot message and exiting \n"); +} + +void kic_init() +{ + if (atomic_read(&kicstart)>0) + { + printk(KERN_ALERT "HRDKRL: Attempted to start multiple KICs by : UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return; + } + kernel_thread(kic, NULL,NULL); + atomic_inc(&kicstart); +} + +#if defined(CONFIG_HRDKRL_KIC_SYSCALL) +asmlinkage long sys_kic(void) +{ + int err; + + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + __NR_kic, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + + if (atomic_read(&kicstart)>0) + { + printk(KERN_ALERT "HRDKRL: Attempted to start multiple KICs by : UID %d EUID %d PROCESS %s:%d \n", + current->uid,current->euid,current->comm,current->pid); + err=-1; + goto freeze; + } + kernel_thread(kic, NULL, NULL); + atomic_inc(&kicstart); + err = 0; + +freeze: + sys_call_table[__NR_kic]=freeze_syscall; + return err; +} + +#endif + +void notifykic(void) +{ + atomic_inc(&systemrebooting_kic); + wake_up_all(&kic_wait); + set_current_state(TASK_UNINTERRUPTIBLE); + schedule_timeout(1000); + current->state = TASK_RUNNING; +} + +#endif diff -urN linux-2.4.23/hrdkrl/klogger.c linux-2423HRDKRL/hrdkrl/klogger.c --- linux-2.4.23/hrdkrl/klogger.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/klogger.c 2004-03-18 11:47:17.000000000 -0500 @@ -0,0 +1,61 @@ + +#include +#include +#include +#include + +#include +#include +#include + +#if defined(CONFIG_HRDKRL_KLOGGER) + +extern void kernellogger(void); +extern long *sys_call_table[NR_syscalls]; +extern long freeze_syscall(struct pt_regs regs); + +static atomic_t kloggerstart={0}; + +void klogger_init() +{ + if (atomic_read(&kloggerstart)>0) + { + printk(KERN_ALERT "%d HRDKRL: Attempted to start multiple kloggers by : UID %d EUID %d PROCESS %s:%d \n", + klogtime(), current->uid,current->euid,current->comm,current->pid); + return; + } + kernel_thread(kernellogger, NULL,NULL); + atomic_inc(&kloggerstart); +} + + +#if defined(CONFIG_HRDKRL_KLOGGER_SYSCALL) + +asmlinkage int sys_kernellogger(void) +{ + int err; + + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "%d HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + klogtime(),__NR_klogger, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + if (atomic_read(&kloggerstart)>0) + { + printk(KERN_ALERT "%d HRDKRL: Attempted to start multiple kloggers by : UID %d EUID %d PROCESS %s:%d \n", + klogtime(), current->uid,current->euid,current->comm,current->pid); + err = -1; + goto freeze; + } + err = 0; + atomic_inc(&kloggerstart); + kernel_thread(kernellogger, NULL, NULL); + +freeze: + sys_call_table[__NR_klogger]=freeze_syscall; + return err; +} + +#endif +#endif + diff -urN linux-2.4.23/hrdkrl/kmem.c linux-2423HRDKRL/hrdkrl/kmem.c --- linux-2.4.23/hrdkrl/kmem.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/kmem.c 2004-03-16 15:50:16.000000000 -0500 @@ -0,0 +1,65 @@ +#include +#include +#include + +#if defined(CONFIG_HRDKRL_MEM_DEVICES_MEM) +int hrdkrl_mmap_mem(struct file * file, struct vm_area_struct * vma) +{ + printk(KERN_ALERT "HRDKRL:Attempted to mmap /dev/mem: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return -EPERM; +} + +int hrdkrl_open_mem(struct inode * inode, struct file * filp) +{ + printk(KERN_ALERT "HRDKRL:Attempted to open /dev/mem: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return -EPERM; +} + +ssize_t hrdkrl_write_mem(struct file * file, const char * buf, size_t count, loff_t *ppos) +{ + printk(KERN_ALERT "HRDKRL:Attempted to write to /dev/mem: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return 0; +} +#endif +/*******************************************************************/ +#if defined(CONFIG_HRDKRL_MEM_DEVICES_KMEM) +int hrdkrl_mmap_kmem(struct file * file, struct vm_area_struct * vma) +{ + printk(KERN_ALERT "HRDKRL:Attempted to mmap /dev/kmem: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return -EPERM; +} + +int hrdkrl_open_kmem(struct inode * inode, struct file * filp) +{ + printk(KERN_ALERT "HRDKRL:Attempted to open /dev/kmem: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return -EPERM; +} + +ssize_t hrdkrl_write_kmem(struct file * file, const char * buf, size_t count, loff_t *ppos) +{ + printk(KERN_ALERT "HRDKRL:Attempted to write to /dev/kmem: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return 0; +} +#endif +/*******************************************************************/ +#if defined(CONFIG_HRDKRL_MEM_DEVICES_PORT) +int hrdkrl_mmap_port(struct file * file, struct vm_area_struct * vma) +{ + printk(KERN_ALERT "HRDKRL:Attempted to mmap /dev/port: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + + return -EAGAIN; +} + +int hrdkrl_open_port(struct inode * inode, struct file * filp) +{ + printk(KERN_ALERT "HRDKRL:Attempted to open /dev/port: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + + return -EPERM; +} + +ssize_t hrdkrl_write_port(struct file * file, const char * buf, size_t count, loff_t *ppos) +{ + printk(KERN_ALERT "HRDKRL:Attempted to write to /dev/port: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return 0; +} +#endif diff -urN linux-2.4.23/hrdkrl/logtime.c linux-2423HRDKRL/hrdkrl/logtime.c --- linux-2.4.23/hrdkrl/logtime.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/logtime.c 2004-03-16 11:59:47.000000000 -0500 @@ -0,0 +1,12 @@ + +#include + +extern void do_gettimeofday(struct timeval *); +long klogtime(void) +{ + struct timeval now; + int i; + do_gettimeofday(&now); + i = now.tv_sec; + return i; +} diff -urN linux-2.4.23/hrdkrl/Makefile linux-2423HRDKRL/hrdkrl/Makefile --- linux-2.4.23/hrdkrl/Makefile 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/Makefile 2004-03-18 12:06:09.000000000 -0500 @@ -0,0 +1,13 @@ +# +# Makefile +# + + +O_TARGET := hrdkrl.o + +# export-objs = +ifeq ($(CONFIG_HRDKRL),y) +obj-y = logtime.o freezenetwork.o syscallelim.o tpm.o race.o capelim.o chroot.o kmem.o klogger.o kic.o Nooverwrite.o rlimit.o +endif + +include $(TOPDIR)/Rules.make diff -urN linux-2.4.23/hrdkrl/Nooverwrite.c linux-2423HRDKRL/hrdkrl/Nooverwrite.c --- linux-2.4.23/hrdkrl/Nooverwrite.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/Nooverwrite.c 2004-03-18 12:10:38.000000000 -0500 @@ -0,0 +1,147 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef CONFIG_HRDKRL_FTP_NO_OVERWRITE +extern long freeze_syscall(struct pt_regs regs); +extern long *sys_call_table[NR_syscalls]; + +static int noowftpdirstart=0; +static char ftpdirname[4095]=FTP_NO_OVERWRITE_DIR; +static unsigned long ftpdirinodenum=NULL; +static kdev_t ftpdirdevnum=NULL; + +int lookup_ftpdir(void) +{ + struct nameidata nd; + int error; + noowftpdirstart = 1; + if(ftpdirinodenum==NULL || ftpdirdevnum == NULL){ + error = path_lookup(ftpdirname, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); + if (error) + { + printk("HRDKRL: FTP dir %s lookup failed \n", ftpdirname); + return 0; + } + ftpdirinodenum=nd.dentry->d_inode->i_ino; + ftpdirdevnum=nd.dentry->d_inode->i_dev; + path_release(&nd); + } + printk(KERN_ALERT "HRDKRL: FTP dir %s lookup successful, inodenum:%d, devnum:%d \n", + ftpdirname,ftpdirinodenum,ftpdirdevnum); + + return 1; +} + +int checkftpinode(char *filename) +{ + struct dentry *dentry2; + struct nameidata nd2; + int dirinode, dirdev; + int error; + + error = path_lookup(filename, LOOKUP_FOLLOW|LOOKUP_POSITIVE, &nd2); + if (error) + { + error = 0; + return error; + } + dentry2=nd2.dentry; + error=0; + while(dentry2) { + if ((dentry2->d_inode)!=NULL) { + if((ftpdirinodenum == dentry2->d_inode->i_ino) && + (ftpdirdevnum == dentry2->d_inode->i_dev)){ + error =1 ; goto exit;} + } + if (dentry2==dentry2->d_parent) { + error= 0; goto exit; + } + dentry2 = dentry2->d_parent; + } + +exit: + path_release(&nd2); + return error; +} + +int protectftpdir1(char *filename) +{ + int error=1; + if((ftpdirinodenum==NULL) || (ftpdirdevnum == NULL)){ + if(noowftpdirstart==1) + printk(KERN_ALERT "HRDKRD: No overwrite FTP protection failed to lookup ftp directory \n"); + error = 0; + goto exit; + } + + if(checkftpinode(filename)==0){ + error=0; goto exit;} +exit: + return error; + +} + + +int protectftpdir(char *filename,int flags) +{ + int error; + if((ftpdirinodenum==NULL) || (ftpdirdevnum == NULL)){ + if(noowftpdirstart==1) + printk(KERN_ALERT "HRDKRD: No overwrite FTP protection failed to lookup ftp directory \n"); + return 0; + } + + if(checkftpinode(filename)==0){ + error=0; goto exit;} + +ok: + if (((flags&O_WRONLY) == O_WRONLY) || ((flags&O_RDWR) == O_RDWR)) + if ( !( ((flags&O_CREAT) == O_CREAT) && ((flags&O_EXCL) == O_EXCL) ) ) + { + printk(KERN_ALERT "HRDKRL:Attempted to overwrite file in FTP directory: UID %d EUID %d PROCESS %s:%d \n", + current->uid,current->euid,current->comm,current->pid); + error = 1; + } + else{ + error = 0; + } + +exit: + return error; + +} + +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE_SYSCALL) +asmlinkage long sys_ftp_protection(void) +{ + int err; + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + __NR_no_overwrite_ftp, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + if(lookup_ftpdir()) + err = 0; + else + err = -1; + + sys_call_table[__NR_no_overwrite_ftp]=freeze_syscall; + return err; +} +#endif + +#endif + diff -urN linux-2.4.23/hrdkrl/race.c linux-2423HRDKRL/hrdkrl/race.c --- linux-2.4.23/hrdkrl/race.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/race.c 2004-03-16 15:52:25.000000000 -0500 @@ -0,0 +1,45 @@ +#include +#include + +#if defined(CONFIG_HRDKRL_TMP_RACE) +int gr_handle_follow_link(const struct inode *parent, + const struct inode *inode, + const struct dentry *dentry, const struct vfsmount *mnt) +{ + + if (S_ISLNK(inode->i_mode) && + (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) && + (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) { + printk(KERN_ALERT "HRDKRL:Attempted to follow softlink: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + + return 0; +} + +int gr_handle_hardlink(const struct dentry *dentry, + const struct vfsmount *mnt, + struct inode *inode, const int mode, const char *to) +{ + if ( current->fsuid != inode->i_uid && + + ( !S_ISREG(mode) || + (mode & S_ISUID) || + ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) || + (permission(inode, MAY_READ | MAY_WRITE)) + ) + ) + { + printk(KERN_ALERT "HRDKRL:Attempted to create hardlink: UID %d EUID %d PROCESS %s:%d \n",current->uid,current->euid,current->comm,current->pid); + return -EPERM; + } + + return 0; +} +#endif + + + + + + diff -urN linux-2.4.23/hrdkrl/rlimit.c linux-2423HRDKRL/hrdkrl/rlimit.c --- linux-2.4.23/hrdkrl/rlimit.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/rlimit.c 2004-05-26 19:00:16.000000000 -0400 @@ -0,0 +1,29 @@ +# include +# include +# include + +# if defined(CONFIG_HRDKRL_RLIMIT) +void setrlimit(struct task_struct *task) +{ + + if(task->rlim[RLIMIT_NPROC].rlim_cur > MAX_NUM_PROC) + task->rlim[RLIMIT_NPROC].rlim_cur = MAX_NUM_PROC; + + if(task->rlim[RLIMIT_NPROC].rlim_max > MAX_NUM_PROC) + task->rlim[RLIMIT_NPROC].rlim_max = MAX_NUM_PROC; + + if(task->rlim[RLIMIT_NOFILE].rlim_cur > MAX_FILE_OPEN) + task->rlim[RLIMIT_NOFILE].rlim_cur = MAX_FILE_OPEN; + + if(task->rlim[RLIMIT_NOFILE].rlim_max > MAX_FILE_OPEN) + task->rlim[RLIMIT_NOFILE].rlim_max = MAX_FILE_OPEN; + + if(task->rlim[RLIMIT_MEMLOCK].rlim_cur > MAX_LOCK_MEM) + task->rlim[RLIMIT_MEMLOCK].rlim_cur = MAX_LOCK_MEM; + + if(task->rlim[RLIMIT_MEMLOCK].rlim_max > MAX_LOCK_MEM) + task->rlim[RLIMIT_MEMLOCK].rlim_max = MAX_LOCK_MEM; + +} + +# endif diff -urN linux-2.4.23/hrdkrl/syscallelim.c linux-2423HRDKRL/hrdkrl/syscallelim.c --- linux-2.4.23/hrdkrl/syscallelim.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/syscallelim.c 2004-03-18 14:26:47.000000000 -0500 @@ -0,0 +1,37 @@ + +#include +#include +#include +#include +#include + +extern long *sys_call_table[NR_syscalls]; + + + +asmlinkage long freeze_syscall(struct pt_regs regs) +{ + printk(KERN_ALERT "HRDKRL:Attempted to invoke frozen system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + regs.eax, current->uid,current->euid,current->comm,current->pid); + return -ENOSYS; +} + +# if defined(CONFIG_HRDKRL_SYSCALL_ELIM_RTIME) +asmlinkage long sys_freeze_syscall(int n) +{ + if (n < 0 || n > NR_syscalls) + return -EINVAL; + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + __NR_freeze_syscall, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + + sys_call_table[n] = freeze_syscall; + printk(KERN_ALERT " HRDKRL: System call no %d is frozen by UID %d EUID %d PROCESS %s:%d \n", + n, current->uid,current->euid,current->comm,current->pid); + + return 0; +} +#endif + diff -urN linux-2.4.23/hrdkrl/tpm.c linux-2423HRDKRL/hrdkrl/tpm.c --- linux-2.4.23/hrdkrl/tpm.c 1969-12-31 19:00:00.000000000 -0500 +++ linux-2423HRDKRL/hrdkrl/tpm.c 2004-03-19 09:40:34.000000000 -0500 @@ -0,0 +1,163 @@ +# include +# include +# include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#ifdef CONFIG_HRDKRL_TPM +extern long freeze_syscall(struct pt_regs regs); +extern long *sys_call_table[NR_syscalls]; + +struct tpmdir_struct +{ + unsigned long inum; + kdev_t devnum; + struct tpmdir_struct *next; +}; + +static struct tpmdir_struct* tpmdirs=NULL; +static char dirnames[] = CONFIG_HRDKRL_TRUSTED_DIRS; +static int tpmstart=0; + +static int is_tpm(struct dentry*); + +int tpm_allow(const struct file *file) +{ + + if (!file) + return 1; + struct inode *inode = file->f_dentry->d_parent->d_inode; + + /*if ((inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) || + (inode->i_mode & S_IWOTH))))) */ + if(is_tpm(file->f_dentry)){ + return 1; + } + + printk(KERN_ALERT "HRDKRL:Attempted to break TPM: UID %d EUID %d PROCESS %s:%d Inode num: %d, Device num: %d \n", current->uid, current->euid,current->comm,current->pid,file->f_dentry->d_inode->i_ino, file->f_dentry->d_inode->i_dev); + return 0; +} + + + +int build_tpmdirs(void) +{ + int error = 1; + struct tpmdir_struct *tmp; + tpmstart = 1; + + if (tpmdirs==NULL){ + struct nameidata nd; + char *name; + printk("\n HRDKRL: TPM: Trusted Path Directories are %s\n",dirnames); + name=strtok(dirnames,","); + tpmdirs = kmalloc(sizeof(struct tpmdir_struct),GFP_KERNEL); + tmp = tpmdirs; + + printk("HRDKRL: TPM: Trusted Path Directories are "); + for(;;) + { + printk("%s ",name); + + error = path_lookup(name, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd); + if (error) + { + printk("\n HRDKRL: (TPM) path_lookup of Trusted Path directory %s failed \n",name); + /* release the memory TBD */ + tpmdirs=NULL; + error = 0; + goto exit; + } + + tmp->inum=nd.dentry->d_inode->i_ino; + tmp->devnum=nd.dentry->d_inode->i_dev; + path_release(&nd); + + name=strtok(NULL,","); + if(!name) + break; + + tmp->next = kmalloc(sizeof(struct tpmdir_struct),GFP_KERNEL); + tmp = tmp->next; + + } + printk("\n"); + } + +exit: +return error; + +} + + +static int is_tpm(struct dentry * den) +{ + int error=0; + struct tpmdir_struct *tmp; + struct dentry *d; + + if (tpmdirs==NULL){ + error = 1; + if(tpmstart==1) + printk(KERN_ALERT "HRDKRD: TPM failed to lookup trusted path directories \n"); + + goto exit; + } + + tmp = tpmdirs; + while(tmp) + { + d = den; + while(d) { + if ((d->d_inode)!=NULL) { + if((tmp->inum == d->d_inode->i_ino) && + (tmp->devnum == d->d_inode->i_dev)) + { error =1; goto exit;} + } + if (d==d->d_parent) { + break; + } + d = d->d_parent; + } + tmp=tmp->next; + } + + +exit: +return error; + +} +#if defined(CONFIG_HRDKRL_TPM_SYSCALL) +asmlinkage long sys_tpm(void) +{ + int err; + if (!capable(CAP_SYS_ADMIN)){ + printk(KERN_ALERT "HRDKRL:Attempted to invoke HRDKRL system call: syscall no %d UID %d EUID %d PROCESS %s:%d \n", + __NR_tpm, current->uid,current->euid,current->comm,current->pid); + return -EACCES; + } + if(build_tpmdirs()) + err = 0; + else + err = -1; + + sys_call_table[__NR_tpm]=freeze_syscall; + return err; +} +#endif + +#endif diff -urN linux-2.4.23/include/asm-i386/unistd.h linux-2423HRDKRL/include/asm-i386/unistd.h --- linux-2.4.23/include/asm-i386/unistd.h 2002-11-28 18:53:15.000000000 -0500 +++ linux-2423HRDKRL/include/asm-i386/unistd.h 2004-04-03 16:42:40.000000000 -0500 @@ -258,6 +258,34 @@ #define __NR_free_hugepages 251 #define __NR_exit_group 252 +# if defined(CONFIG_HRDKRL_FREEZE_NETWORK) +#define __NR_freeze_network_configuration 259 +# endif + +# if defined(CONFIG_HRDKRL_SYSCALL_ELIM_RTIME) +#define __NR_freeze_syscall 260 +# endif + +#if defined(CONFIG_HRDKRL_KLOGGER_SYSCALL) +#define __NR_klogger 261 +#endif + +#if defined(CONFIG_HRDKRL_KIC_SYSCALL) +#define __NR_kic 262 +#endif + +#if defined(CONFIG_HRDKRL_TPM_SYSCALL) +#define __NR_tpm 263 +#endif + +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE_SYSCALL) +#define __NR_no_overwrite_ftp 264 +#endif + +#if defined(CONFIG_HRDKRL_CAP_ELIM_RTIME) +#define __NR_freeze_cap 265 +#endif + /* user-visible error numbers are in the range -1 - -124: see */ #define __syscall_return(type, res) \ diff -urN linux-2.4.23/include/linux/kernel.h linux-2423HRDKRL/include/linux/kernel.h --- linux-2.4.23/include/linux/kernel.h 2002-11-28 18:53:15.000000000 -0500 +++ linux-2423HRDKRL/include/linux/kernel.h 2004-03-16 10:58:55.000000000 -0500 @@ -30,7 +30,7 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define KERN_EMERG "<0>" /* system is unusable */ -#define KERN_ALERT "<1>" /* action must be taken immediately */ +#define KERN_ALERT "<1>" /* action must be taken immediately */ #define KERN_CRIT "<2>" /* critical conditions */ #define KERN_ERR "<3>" /* error conditions */ #define KERN_WARNING "<4>" /* warning conditions */ diff -urN linux-2.4.23/init/main.c linux-2423HRDKRL/init/main.c --- linux-2.4.23/init/main.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/init/main.c 2004-02-01 16:38:06.000000000 -0500 @@ -591,6 +591,25 @@ * The Bourne shell can be used instead of init if we are * trying to recover a really broken machine. */ +# if defined(CONFIG_HRDKRL_KLOGGER_BEFORE_INIT) + klogger_init(); +# endif + +# if defined(CONFIG_HRDKRL_KIC_BEFORE_INIT) + kic_init(); +#endif + +#if defined(CONFIG_HRDKRL_CAP_ELIM_CTIME) + cap_elim(); +#endif + +#if defined(CONFIG_HRDKRL_TPM_BEFORE_INIT) + build_tpmdirs(); +#endif + +#if defined(CONFIG_HRDKRL_FTP_NO_OVERWRITE_BEFORE_INIT) + lookup_ftpdir(); +#endif if (execute_command) run_init_process(execute_command); diff -urN linux-2.4.23/ipc/shm.c linux-2423HRDKRL/ipc/shm.c --- linux-2.4.23/ipc/shm.c 2002-08-02 20:39:46.000000000 -0400 +++ linux-2423HRDKRL/ipc/shm.c 2004-01-04 16:33:08.000000000 -0500 @@ -38,6 +38,10 @@ time_t shm_ctim; pid_t shm_cprid; pid_t shm_lprid; +#if defined(CONFIG_HRDKRL_CHROOT_SHMAT) + time_t shm_createtime; + pid_t shm_lapid; +#endif }; #define shm_flags shm_perm.mode @@ -209,6 +213,9 @@ shp->shm_lprid = 0; shp->shm_atim = shp->shm_dtim = 0; shp->shm_ctim = CURRENT_TIME; +#if defined(CONFIG_HRDKRL_CHROOT_SHMAT) + shp->shm_createtime = CURRENT_TIME; +#endif shp->shm_segsz = size; shp->shm_nattch = 0; shp->id = shm_buildid(id,shp->shm_perm.seq); @@ -622,11 +629,23 @@ shm_unlock(shmid); return -EACCES; } + +# if defined(CONFIG_HRDKRL_CHROOT_SHMAT) + if (!gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) { + shm_unlock(shmid); + return -EACCES; + } +# endif + file = shp->shm_file; size = file->f_dentry->d_inode->i_size; shp->shm_nattch++; - shm_unlock(shmid); + +#if defined(CONFIG_HRDKRL_CHROOT_SHMAT) + shp->shm_lapid = current->pid; +#endif + shm_unlock(shmid); down_write(¤t->mm->mmap_sem); if (addr && !(shmflg & SHM_REMAP)) { user_addr = ERR_PTR(-EINVAL); diff -urN linux-2.4.23/kernel/fork.c linux-2423HRDKRL/kernel/fork.c --- linux-2.4.23/kernel/fork.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/kernel/fork.c 2004-02-09 17:13:22.000000000 -0500 @@ -806,6 +806,11 @@ SET_LINKS(p); hash_pid(p); nr_threads++; +# if defined(CONFIG_HRDKRL_RLIMIT) + /* if process is created through fork(), not through clone(), or vfork() */ + if(clone_flags == SIGCHLD) + setrlimit(p); +# endif write_unlock_irq(&tasklist_lock); if (p->ptrace & PT_PTRACED) diff -urN linux-2.4.23/kernel/printk.c linux-2423HRDKRL/kernel/printk.c --- linux-2.4.23/kernel/printk.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/kernel/printk.c 2004-03-17 11:16:32.000000000 -0500 @@ -24,9 +24,11 @@ #include #include #include -#include /* For in_interrupt() */ +#include /* For in_interrupt() */ #include - +# if defined(CONFIG_HRDKRL_KLOGGER) +#include +# endif #include #if !defined(CONFIG_LOG_BUF_SHIFT) || (CONFIG_LOG_BUF_SHIFT == 0) @@ -36,10 +38,10 @@ #define LOG_BUF_LEN (131072) #elif defined(CONFIG_SMP) #define LOG_BUF_LEN (32768) -#else -#define LOG_BUF_LEN (16384) /* This must be a power of two */ +#else +#define LOG_BUF_LEN (16384) /* This must be a power of two */ #endif -#else /* CONFIG_LOG_BUF_SHIFT */ +#else /* CONFIG_LOG_BUF_SHIFT */ #define LOG_BUF_LEN (1 << CONFIG_LOG_BUF_SHIFT) #endif @@ -50,19 +52,19 @@ #endif /* printk's without a loglevel use this.. */ -#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */ +#define DEFAULT_MESSAGE_LOGLEVEL 4 /* KERN_WARNING */ /* We show everything that is MORE important than this.. */ -#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */ -#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */ +#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */ +#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */ DECLARE_WAIT_QUEUE_HEAD(log_wait); int console_printk[4] = { - DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */ - DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */ - MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */ - DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ + DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */ + DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */ + MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */ + DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */ }; int oops_in_progress; @@ -89,10 +91,10 @@ * The indices into log_buf are not constrained to LOG_BUF_LEN - they * must be masked before subscripting */ -static unsigned long log_start; /* Index into log_buf: next char to be read by syslog() */ -static unsigned long con_start; /* Index into log_buf: next char to be sent to consoles */ -static unsigned long log_end; /* Index into log_buf: most-recently-written-char + 1 */ -static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */ +static unsigned long log_start; /* Index into log_buf: next char to be read by syslog() */ +static unsigned long con_start; /* Index into log_buf: next char to be sent to consoles */ +static unsigned long log_end; /* Index into log_buf: most-recently-written-char + 1 */ +static unsigned long logged_chars; /* Number of chars produced since last read+clear operation */ struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES]; static int preferred_console = -1; @@ -105,52 +107,52 @@ */ static int __init console_setup(char *str) { - struct console_cmdline *c; - char name[sizeof(c->name)]; - char *s, *options; - int i, idx; - - /* - * Decode str into name, index, options. - */ - if (str[0] >= '0' && str[0] <= '9') { - strcpy(name, "ttyS"); - strncpy(name + 4, str, sizeof(name) - 5); - } else - strncpy(name, str, sizeof(name) - 1); - name[sizeof(name) - 1] = 0; - if ((options = strchr(str, ',')) != NULL) - *(options++) = 0; + struct console_cmdline *c; + char name[sizeof(c->name)]; + char *s, *options; + int i, idx; + + /* + * Decode str into name, index, options. + */ + if (str[0] >= '0' && str[0] <= '9') { + strcpy(name, "ttyS"); + strncpy(name + 4, str, sizeof(name) - 5); + } else + strncpy(name, str, sizeof(name) - 1); + name[sizeof(name) - 1] = 0; + if ((options = strchr(str, ',')) != NULL) + *(options++) = 0; #ifdef __sparc__ - if (!strcmp(str, "ttya")) - strcpy(name, "ttyS0"); - if (!strcmp(str, "ttyb")) - strcpy(name, "ttyS1"); + if (!strcmp(str, "ttya")) + strcpy(name, "ttyS0"); + if (!strcmp(str, "ttyb")) + strcpy(name, "ttyS1"); #endif - for(s = name; *s; s++) - if (*s >= '0' && *s <= '9') - break; - idx = simple_strtoul(s, NULL, 10); - *s = 0; - - /* - * See if this tty is not yet registered, and - * if we have a slot free. - */ - for(i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++) - if (strcmp(console_cmdline[i].name, name) == 0 && - console_cmdline[i].index == idx) { - preferred_console = i; - return 1; - } - if (i == MAX_CMDLINECONSOLES) - return 1; - preferred_console = i; - c = &console_cmdline[i]; - memcpy(c->name, name, sizeof(c->name)); - c->options = options; - c->index = idx; - return 1; + for (s = name; *s; s++) + if (*s >= '0' && *s <= '9') + break; + idx = simple_strtoul(s, NULL, 10); + *s = 0; + + /* + * See if this tty is not yet registered, and + * if we have a slot free. + */ + for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++) + if (strcmp(console_cmdline[i].name, name) == 0 && + console_cmdline[i].index == idx) { + preferred_console = i; + return 1; + } + if (i == MAX_CMDLINECONSOLES) + return 1; + preferred_console = i; + c = &console_cmdline[i]; + memcpy(c->name, name, sizeof(c->name)); + c->options = options; + c->index = idx; + return 1; } __setup("console=", console_setup); @@ -169,138 +171,138 @@ * 8 -- Set level of messages printed to console * 9 -- Return number of unread characters in the log buffer */ -int do_syslog(int type, char * buf, int len) -{ - unsigned long i, j, limit, count; - int do_clear = 0; - char c; - int error = 0; - - switch (type) { - case 0: /* Close log */ - break; - case 1: /* Open log */ - break; - case 2: /* Read from log */ - error = -EINVAL; - if (!buf || len < 0) - goto out; - error = 0; - if (!len) - goto out; - error = verify_area(VERIFY_WRITE,buf,len); - if (error) - goto out; - error = wait_event_interruptible(log_wait, (log_start - log_end)); - if (error) - goto out; - i = 0; - spin_lock_irq(&logbuf_lock); - while ((log_start != log_end) && i < len) { - c = LOG_BUF(log_start); - log_start++; - spin_unlock_irq(&logbuf_lock); - __put_user(c,buf); - buf++; - i++; - spin_lock_irq(&logbuf_lock); - } - spin_unlock_irq(&logbuf_lock); - error = i; - break; - case 4: /* Read/clear last kernel messages */ - do_clear = 1; - /* FALL THRU */ - case 3: /* Read last kernel messages */ - error = -EINVAL; - if (!buf || len < 0) - goto out; - error = 0; - if (!len) - goto out; - error = verify_area(VERIFY_WRITE,buf,len); - if (error) - goto out; - count = len; - if (count > LOG_BUF_LEN) - count = LOG_BUF_LEN; - spin_lock_irq(&logbuf_lock); - if (count > logged_chars) - count = logged_chars; - if (do_clear) - logged_chars = 0; - limit = log_end; - /* - * __put_user() could sleep, and while we sleep - * printk() could overwrite the messages - * we try to copy to user space. Therefore - * the messages are copied in reverse. - */ - for(i=0;i < count;i++) { - j = limit-1-i; - if (j+LOG_BUF_LEN < log_end) - break; - c = LOG_BUF(j); - spin_unlock_irq(&logbuf_lock); - __put_user(c,&buf[count-1-i]); - spin_lock_irq(&logbuf_lock); - } - spin_unlock_irq(&logbuf_lock); - error = i; - if(i != count) { - int offset = count-error; - /* buffer overflow during copy, correct user buffer. */ - for(i=0;i 8) - goto out; - if (len < minimum_console_loglevel) - len = minimum_console_loglevel; - spin_lock_irq(&logbuf_lock); - console_loglevel = len; - spin_unlock_irq(&logbuf_lock); - error = 0; - break; - case 9: /* Number of chars in the log buffer */ - spin_lock_irq(&logbuf_lock); - error = log_end - log_start; - spin_unlock_irq(&logbuf_lock); - break; - default: - error = -EINVAL; - break; - } -out: - return error; -} - -asmlinkage long sys_syslog(int type, char * buf, int len) +int do_syslog(int type, char *buf, int len) { - if ((type != 3) && !capable(CAP_SYS_ADMIN)) - return -EPERM; - return do_syslog(type, buf, len); + unsigned long i, j, limit, count; + int do_clear = 0; + char c; + int error = 0; + + switch (type) { + case 0: /* Close log */ + break; + case 1: /* Open log */ + break; + case 2: /* Read from log */ + error = -EINVAL; + if (!buf || len < 0) + goto out; + error = 0; + if (!len) + goto out; + error = verify_area(VERIFY_WRITE, buf, len); + if (error) + goto out; + error = wait_event_interruptible(log_wait, (log_start - log_end)); + if (error) + goto out; + i = 0; + spin_lock_irq(&logbuf_lock); + while ((log_start != log_end) && i < len) { + c = LOG_BUF(log_start); + log_start++; + spin_unlock_irq(&logbuf_lock); + __put_user(c, buf); + buf++; + i++; + spin_lock_irq(&logbuf_lock); + } + spin_unlock_irq(&logbuf_lock); + error = i; + break; + case 4: /* Read/clear last kernel messages */ + do_clear = 1; + /* FALL THRU */ + case 3: /* Read last kernel messages */ + error = -EINVAL; + if (!buf || len < 0) + goto out; + error = 0; + if (!len) + goto out; + error = verify_area(VERIFY_WRITE, buf, len); + if (error) + goto out; + count = len; + if (count > LOG_BUF_LEN) + count = LOG_BUF_LEN; + spin_lock_irq(&logbuf_lock); + if (count > logged_chars) + count = logged_chars; + if (do_clear) + logged_chars = 0; + limit = log_end; + /* + * __put_user() could sleep, and while we sleep + * printk() could overwrite the messages + * we try to copy to user space. Therefore + * the messages are copied in reverse. + */ + for (i = 0; i < count; i++) { + j = limit - 1 - i; + if (j + LOG_BUF_LEN < log_end) + break; + c = LOG_BUF(j); + spin_unlock_irq(&logbuf_lock); + __put_user(c, &buf[count - 1 - i]); + spin_lock_irq(&logbuf_lock); + } + spin_unlock_irq(&logbuf_lock); + error = i; + if (i != count) { + int offset = count - error; + /* buffer overflow during copy, correct user buffer. */ + for (i = 0; i < error; i++) { + __get_user(c, &buf[i + offset]); + __put_user(c, &buf[i]); + } + } + + break; + case 5: /* Clear ring buffer */ + spin_lock_irq(&logbuf_lock); + logged_chars = 0; + spin_unlock_irq(&logbuf_lock); + break; + case 6: /* Disable logging to console */ + spin_lock_irq(&logbuf_lock); + console_loglevel = minimum_console_loglevel; + spin_unlock_irq(&logbuf_lock); + break; + case 7: /* Enable logging to console */ + spin_lock_irq(&logbuf_lock); + console_loglevel = default_console_loglevel; + spin_unlock_irq(&logbuf_lock); + break; + case 8: /* Set level of messages printed to console */ + error = -EINVAL; + if (len < 1 || len > 8) + goto out; + if (len < minimum_console_loglevel) + len = minimum_console_loglevel; + spin_lock_irq(&logbuf_lock); + console_loglevel = len; + spin_unlock_irq(&logbuf_lock); + error = 0; + break; + case 9: /* Number of chars in the log buffer */ + spin_lock_irq(&logbuf_lock); + error = log_end - log_start; + spin_unlock_irq(&logbuf_lock); + break; + default: + error = -EINVAL; + break; + } + out: + return error; +} + +asmlinkage long sys_syslog(int type, char *buf, int len) +{ + if ((type != 3) && !capable(CAP_SYS_ADMIN)) + return -EPERM; + return do_syslog(type, buf, len); } /* @@ -308,28 +310,30 @@ */ static void __call_console_drivers(unsigned long start, unsigned long end) { - struct console *con; + struct console *con; - for (con = console_drivers; con; con = con->next) { - if ((con->flags & CON_ENABLED) && con->write) - con->write(con, &LOG_BUF(start), end - start); - } + for (con = console_drivers; con; con = con->next) { + if ((con->flags & CON_ENABLED) && con->write) + con->write(con, &LOG_BUF(start), end - start); + } } /* * Write out chars from start to end - 1 inclusive */ -static void _call_console_drivers(unsigned long start, unsigned long end, int msg_log_level) +static void _call_console_drivers(unsigned long start, unsigned long end, + int msg_log_level) { - if (msg_log_level < console_loglevel && console_drivers && start != end) { - if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) { - /* wrapped write */ - __call_console_drivers(start & LOG_BUF_MASK, LOG_BUF_LEN); - __call_console_drivers(0, end & LOG_BUF_MASK); - } else { - __call_console_drivers(start, end); - } - } + if (msg_log_level < console_loglevel && console_drivers + && start != end) { + if ((start & LOG_BUF_MASK) > (end & LOG_BUF_MASK)) { + /* wrapped write */ + __call_console_drivers(start & LOG_BUF_MASK, LOG_BUF_LEN); + __call_console_drivers(0, end & LOG_BUF_MASK); + } else { + __call_console_drivers(start, end); + } + } } /* @@ -339,60 +343,59 @@ */ static void call_console_drivers(unsigned long start, unsigned long end) { - unsigned long cur_index, start_print; - static int msg_level = -1; + unsigned long cur_index, start_print; + static int msg_level = -1; - if (((long)(start - end)) > 0) - BUG(); + if (((long) (start - end)) > 0) + BUG(); - cur_index = start; - start_print = start; - while (cur_index != end) { - if ( msg_level < 0 && - ((end - cur_index) > 2) && - LOG_BUF(cur_index + 0) == '<' && - LOG_BUF(cur_index + 1) >= '0' && - LOG_BUF(cur_index + 1) <= '7' && - LOG_BUF(cur_index + 2) == '>') - { - msg_level = LOG_BUF(cur_index + 1) - '0'; - cur_index += 3; - start_print = cur_index; - } - while (cur_index != end) { - char c = LOG_BUF(cur_index); - cur_index++; - - if (c == '\n') { - if (msg_level < 0) { - /* - * printk() has already given us loglevel tags in - * the buffer. This code is here in case the - * log buffer has wrapped right round and scribbled - * on those tags - */ - msg_level = default_message_loglevel; - } - _call_console_drivers(start_print, cur_index, msg_level); - msg_level = -1; - start_print = cur_index; - break; - } - } - } - _call_console_drivers(start_print, end, msg_level); + cur_index = start; + start_print = start; + while (cur_index != end) { + if (msg_level < 0 && + ((end - cur_index) > 2) && + LOG_BUF(cur_index + 0) == '<' && + LOG_BUF(cur_index + 1) >= '0' && + LOG_BUF(cur_index + 1) <= '7' && + LOG_BUF(cur_index + 2) == '>') { + msg_level = LOG_BUF(cur_index + 1) - '0'; + cur_index += 3; + start_print = cur_index; + } + while (cur_index != end) { + char c = LOG_BUF(cur_index); + cur_index++; + + if (c == '\n') { + if (msg_level < 0) { + /* + * printk() has already given us loglevel tags in + * the buffer. This code is here in case the + * log buffer has wrapped right round and scribbled + * on those tags + */ + msg_level = default_message_loglevel; + } + _call_console_drivers(start_print, cur_index, msg_level); + msg_level = -1; + start_print = cur_index; + break; + } + } + } + _call_console_drivers(start_print, end, msg_level); } static void emit_log_char(char c) { - LOG_BUF(log_end) = c; - log_end++; - if (log_end - log_start > LOG_BUF_LEN) - log_start = log_end - LOG_BUF_LEN; - if (log_end - con_start > LOG_BUF_LEN) - con_start = log_end - LOG_BUF_LEN; - if (logged_chars < LOG_BUF_LEN) - logged_chars++; + LOG_BUF(log_end) = c; + log_end++; + if (log_end - log_start > LOG_BUF_LEN) + log_start = log_end - LOG_BUF_LEN; + if (log_end - con_start > LOG_BUF_LEN) + con_start = log_end - LOG_BUF_LEN; + if (logged_chars < LOG_BUF_LEN) + logged_chars++; } /* @@ -410,73 +413,74 @@ */ asmlinkage int printk(const char *fmt, ...) { - va_list args; - unsigned long flags; - int printed_len; - char *p; - static char printk_buf[1024]; - static int log_level_unknown = 1; - - if (oops_in_progress) { - /* If a crash is occurring, make sure we can't deadlock */ - spin_lock_init(&logbuf_lock); - /* And make sure that we print immediately */ - init_MUTEX(&console_sem); - } - - /* This stops the holder of console_sem just where we want him */ - spin_lock_irqsave(&logbuf_lock, flags); - - /* Emit the output into the temporary buffer */ - va_start(args, fmt); - printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args); - va_end(args); - - /* - * Copy the output into log_buf. If the caller didn't provide - * appropriate log level tags, we insert them here - */ - for (p = printk_buf; *p; p++) { - if (log_level_unknown) { - if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>') { - emit_log_char('<'); - emit_log_char(default_message_loglevel + '0'); - emit_log_char('>'); - } - log_level_unknown = 0; - } - emit_log_char(*p); - if (*p == '\n') - log_level_unknown = 1; - } - - if (!arch_consoles_callable()) { - /* - * On some architectures, the consoles are not usable - * on secondary CPUs early in the boot process. - */ - spin_unlock_irqrestore(&logbuf_lock, flags); - goto out; - } - if (!down_trylock(&console_sem)) { - /* - * We own the drivers. We can drop the spinlock and let - * release_console_sem() print the text - */ - spin_unlock_irqrestore(&logbuf_lock, flags); - console_may_schedule = 0; - release_console_sem(); - } else { - /* - * Someone else owns the drivers. We drop the spinlock, which - * allows the semaphore holder to proceed and to call the - * console drivers with the output which we just produced. - */ - spin_unlock_irqrestore(&logbuf_lock, flags); - } -out: - return printed_len; + va_list args; + unsigned long flags; + int printed_len; + char *p; + static char printk_buf[1024]; + static int log_level_unknown = 1; + + if (oops_in_progress) { + /* If a crash is occurring, make sure we can't deadlock */ + spin_lock_init(&logbuf_lock); + /* And make sure that we print immediately */ + init_MUTEX(&console_sem); + } + + /* This stops the holder of console_sem just where we want him */ + spin_lock_irqsave(&logbuf_lock, flags); + + /* Emit the output into the temporary buffer */ + va_start(args, fmt); + printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args); + va_end(args); + + /* + * Copy the output into log_buf. If the caller didn't provide + * appropriate log level tags, we insert them here + */ + for (p = printk_buf; *p; p++) { + if (log_level_unknown) { + if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>') { + emit_log_char('<'); + emit_log_char(default_message_loglevel + '0'); + emit_log_char('>'); + } + log_level_unknown = 0; + } + emit_log_char(*p); + if (*p == '\n') + log_level_unknown = 1; + } + + if (!arch_consoles_callable()) { + /* + * On some architectures, the consoles are not usable + * on secondary CPUs early in the boot process. + */ + spin_unlock_irqrestore(&logbuf_lock, flags); + goto out; + } + if (!down_trylock(&console_sem)) { + /* + * We own the drivers. We can drop the spinlock and let + * release_console_sem() print the text + */ + spin_unlock_irqrestore(&logbuf_lock, flags); + console_may_schedule = 0; + release_console_sem(); + } else { + /* + * Someone else owns the drivers. We drop the spinlock, which + * allows the semaphore holder to proceed and to call the + * console drivers with the output which we just produced. + */ + spin_unlock_irqrestore(&logbuf_lock, flags); + } + out: + return printed_len; } + EXPORT_SYMBOL(printk); /** @@ -489,11 +493,12 @@ */ void acquire_console_sem(void) { - if (in_interrupt()) - BUG(); - down(&console_sem); - console_may_schedule = 1; + if (in_interrupt()) + BUG(); + down(&console_sem); + console_may_schedule = 1; } + EXPORT_SYMBOL(acquire_console_sem); /** @@ -512,26 +517,30 @@ */ void release_console_sem(void) { - unsigned long flags; - unsigned long _con_start, _log_end; - unsigned long must_wake_klogd = 0; - - for ( ; ; ) { - spin_lock_irqsave(&logbuf_lock, flags); - must_wake_klogd |= log_start - log_end; - if (con_start == log_end) - break; /* Nothing to print */ - _con_start = con_start; - _log_end = log_end; - con_start = log_end; /* Flush */ - spin_unlock_irqrestore(&logbuf_lock, flags); - call_console_drivers(_con_start, _log_end); - } - console_may_schedule = 0; - up(&console_sem); - spin_unlock_irqrestore(&logbuf_lock, flags); - if (must_wake_klogd && !oops_in_progress) - wake_up_interruptible(&log_wait); + unsigned long flags; + unsigned long _con_start, _log_end; + unsigned long must_wake_klogd = 0; + + for (;;) { + spin_lock_irqsave(&logbuf_lock, flags); + must_wake_klogd |= log_start - log_end; + if (con_start == log_end) + break; /* Nothing to print */ + _con_start = con_start; + _log_end = log_end; + con_start = log_end; /* Flush */ + spin_unlock_irqrestore(&logbuf_lock, flags); + call_console_drivers(_con_start, _log_end); + } + console_may_schedule = 0; + up(&console_sem); + spin_unlock_irqrestore(&logbuf_lock, flags); + if (must_wake_klogd && !oops_in_progress) +#if defined(CONFIG_HRDKRL_KLOGGER) + wake_up_all(&log_wait); +#else + wake_up_interruptible(&log_wait); +#endif } /** console_conditional_schedule - yield the CPU if required @@ -544,35 +553,37 @@ */ void console_conditional_schedule(void) { - if (console_may_schedule && current->need_resched) { - set_current_state(TASK_RUNNING); - schedule(); - } + if (console_may_schedule && current->need_resched) { + set_current_state(TASK_RUNNING); + schedule(); + } } void console_print(const char *s) { - printk(KERN_EMERG "%s", s); + printk(KERN_EMERG "%s", s); } + EXPORT_SYMBOL(console_print); void console_unblank(void) { - struct console *c; + struct console *c; - /* - * Try to get the console semaphore. If someone else owns it - * we have to return without unblanking because console_unblank - * may be called in interrupt context. - */ - if (down_trylock(&console_sem) != 0) - return; - console_may_schedule = 0; - for (c = console_drivers; c != NULL; c = c->next) - if ((c->flags & CON_ENABLED) && c->unblank) - c->unblank(); - release_console_sem(); + /* + * Try to get the console semaphore. If someone else owns it + * we have to return without unblanking because console_unblank + * may be called in interrupt context. + */ + if (down_trylock(&console_sem) != 0) + return; + console_may_schedule = 0; + for (c = console_drivers; c != NULL; c = c->next) + if ((c->flags & CON_ENABLED) && c->unblank) + c->unblank(); + release_console_sem(); } + EXPORT_SYMBOL(console_unblank); /* @@ -581,108 +592,109 @@ * print any messages that were printed by the kernel before the * console driver was initialized. */ -void register_console(struct console * console) +void register_console(struct console *console) { - int i; - unsigned long flags; + int i; + unsigned long flags; - /* - * See if we want to use this console driver. If we - * didn't select a console we take the first one - * that registers here. - */ - if (preferred_console < 0) { - if (console->index < 0) - console->index = 0; - if (console->setup == NULL || - console->setup(console, NULL) == 0) { - console->flags |= CON_ENABLED | CON_CONSDEV; - preferred_console = 0; - } - } - - /* - * See if this console matches one we selected on - * the command line. - */ - for(i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++) { - if (strcmp(console_cmdline[i].name, console->name) != 0) - continue; - if (console->index >= 0 && - console->index != console_cmdline[i].index) - continue; - if (console->index < 0) - console->index = console_cmdline[i].index; - if (console->setup && - console->setup(console, console_cmdline[i].options) != 0) - break; - console->flags |= CON_ENABLED; - console->index = console_cmdline[i].index; - if (i == preferred_console) - console->flags |= CON_CONSDEV; - break; - } - - if (!(console->flags & CON_ENABLED)) - return; - - /* - * Put this console in the list - keep the - * preferred driver at the head of the list. - */ - acquire_console_sem(); - if ((console->flags & CON_CONSDEV) || console_drivers == NULL) { - console->next = console_drivers; - console_drivers = console; - } else { - console->next = console_drivers->next; - console_drivers->next = console; - } - if (console->flags & CON_PRINTBUFFER) { - /* - * release_console_sem() will print out the buffered messages for us. - */ - spin_lock_irqsave(&logbuf_lock, flags); - con_start = log_start; - spin_unlock_irqrestore(&logbuf_lock, flags); - } - release_console_sem(); + /* + * See if we want to use this console driver. If we + * didn't select a console we take the first one + * that registers here. + */ + if (preferred_console < 0) { + if (console->index < 0) + console->index = 0; + if (console->setup == NULL || console->setup(console, NULL) == 0) { + console->flags |= CON_ENABLED | CON_CONSDEV; + preferred_console = 0; + } + } + + /* + * See if this console matches one we selected on + * the command line. + */ + for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++) { + if (strcmp(console_cmdline[i].name, console->name) != 0) + continue; + if (console->index >= 0 && + console->index != console_cmdline[i].index) + continue; + if (console->index < 0) + console->index = console_cmdline[i].index; + if (console->setup && + console->setup(console, console_cmdline[i].options) != 0) + break; + console->flags |= CON_ENABLED; + console->index = console_cmdline[i].index; + if (i == preferred_console) + console->flags |= CON_CONSDEV; + break; + } + + if (!(console->flags & CON_ENABLED)) + return; + + /* + * Put this console in the list - keep the + * preferred driver at the head of the list. + */ + acquire_console_sem(); + if ((console->flags & CON_CONSDEV) || console_drivers == NULL) { + console->next = console_drivers; + console_drivers = console; + } else { + console->next = console_drivers->next; + console_drivers->next = console; + } + if (console->flags & CON_PRINTBUFFER) { + /* + * release_console_sem() will print out the buffered messages for us. + */ + spin_lock_irqsave(&logbuf_lock, flags); + con_start = log_start; + spin_unlock_irqrestore(&logbuf_lock, flags); + } + release_console_sem(); } + EXPORT_SYMBOL(register_console); -int unregister_console(struct console * console) +int unregister_console(struct console *console) { - struct console *a,*b; - int res = 1; + struct console *a, *b; + int res = 1; + + acquire_console_sem(); + if (console_drivers == console) { + console_drivers = console->next; + res = 0; + } else { + for (a = console_drivers->next, b = console_drivers; + a; b = a, a = b->next) { + if (a == console) { + b->next = a->next; + res = 0; + break; + } + } + } + + /* If last console is removed, we re-enable picking the first + * one that gets registered. Without that, pmac early boot console + * would prevent fbcon from taking over. + */ + if (console_drivers == NULL) + preferred_console = -1; - acquire_console_sem(); - if (console_drivers == console) { - console_drivers=console->next; - res = 0; - } else { - for (a=console_drivers->next, b=console_drivers ; - a; b=a, a=b->next) { - if (a == console) { - b->next = a->next; - res = 0; - break; - } - } - } - - /* If last console is removed, we re-enable picking the first - * one that gets registered. Without that, pmac early boot console - * would prevent fbcon from taking over. - */ - if (console_drivers == NULL) - preferred_console = -1; - - release_console_sem(); - return res; + release_console_sem(); + return res; } + EXPORT_SYMBOL(unregister_console); - + /** * tty_write_message - write a message to a certain tty, not just the console. * @@ -692,7 +704,194 @@ */ void tty_write_message(struct tty_struct *tty, char *msg) { - if (tty && tty->driver.write) - tty->driver.write(tty, 0, msg, strlen(msg)); - return; + if (tty && tty->driver.write) + tty->driver.write(tty, 0, msg, strlen(msg)); + return; +} + +# if defined(CONFIG_HRDKRL_KLOGGER) + +static void writelogstoconsole() +{ + unsigned long flags; + spin_lock_irqsave(&logbuf_lock, flags); + if (log_start - log_end) { + if (!down_trylock(&console_sem)) { + console_may_schedule = 0; +/* __call_console_drivers(log_start, log_end);*/ + call_console_drivers(log_start, log_end); + up(&console_sem); + } + } + spin_unlock_irqrestore(&logbuf_lock, flags); + +} + + +extern long mysys_socket(int family, int type, int protocol); +extern long mysys_connect(int fd, struct sockaddr *uservaddr, int addrlen); +extern int mysock_create(int family, int type, int protocol, + struct socket *sock); +static atomic_t systemrebooting = { 0 }; +static char tempbuf[LOG_BUF_LEN]; + + +static void initialize_klogger(void) +{ + /* set the attributes of the thread */ + sprintf(current->comm, "KLOGGER"); + daemonize(); + reparent_to_init(); + + /* Block all signals */ + spin_lock_irq(¤t->sigmask_lock); + sigfillset(¤t->blocked); + recalc_sigpending(current); + spin_unlock_irq(¤t->sigmask_lock); +} + + +static void preparesockaddr(struct sockaddr_in *sin) +{ + + char servip[4]; + servip[0] = simple_strtol(strtok(LOG_SERVER_IP, "."), NULL, 10); + servip[1] = simple_strtol(strtok(NULL, "."), NULL, 10); + servip[2] = simple_strtol(strtok(NULL, "."), NULL, 10); + servip[3] = simple_strtol(strtok(NULL, "."), NULL, 10); + sin->sin_family = AF_INET; + sin->sin_addr.s_addr = *((unsigned int *) servip); + sin->sin_port = htons((unsigned short) LOG_SERVER_PORT); +} + +void kernellogger(void) +{ + struct socket *sock; + struct sockaddr_in sin; + int error, sockfd; + mm_segment_t oldfs; + char c; + int logbufcount, numofbytes, start; + /* char servip[4]; = { 192, 168, 17, 211 }; */ +/* int servport = LOG_SERVER_PORT; Port at which Log server daemon is listening */ + + + initialize_klogger(); + + /* Prepare sin for connection */ + preparesockaddr(&sin); + +/* sin.sin_family = AF_INET; + sin.sin_addr.s_addr = *((unsigned int *) servip); + sin.sin_port = htons((unsigned short) servport);*/ + + /* say hello to logserver (also this make prink buffer nonempty) */ + printk(KERN_ALERT "HRDKRL: Kernel Logger is started \n"); + + while (1) { + /* Create the socket and get socket file descriptor */ + sockfd = mysys_socket(PF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + printk(KERN_ALERT "HRDKRL: KLogger: Socket creation failed, error: %d\n", + sockfd); + break; + } + /* Connect to log server */ + error = + mysys_connect(sockfd, (struct sockaddr *) &sin, sizeof(sin)); + if (error < 0) { + /* if connection fails, the log server may be down or the system is rebooting. + Check if the system is + rebooting. If rebooting write log messages to console and exit. If not + rebooting, yield the CPU to other runnable processes. */ + + sys_close(sockfd); + if (atomic_read(&systemrebooting) > 0) { + printk(KERN_ALERT "HRDKRL: KLogger: Received reboot message, exiting \n"); + writelogstoconsole(); + goto out; + } else { + yield(); + continue; + } + + } + + /* get the socket descriptor from file descriptor */ + sock = sockfd_lookup(sockfd, &error); + wait: + wait_event(log_wait, + ((log_start - log_end) || atomic_read(&systemrebooting))); + + if (atomic_read(&systemrebooting) > 0) { + printk(KERN_ALERT "HRDKRL: KLogger: Received reboot message, exiting \n"); + writelogstoconsole(); + goto out; + } + + if (sock->file->f_op && ((sock->file->f_op->write) != NULL)) { + logbufcount = 0; + spin_lock_irq(&logbuf_lock); + start = log_start; + /* copy the contents of the log buffer into tempbuf */ + while ((log_start != log_end)) { + tempbuf[logbufcount] = LOG_BUF(log_start); + c = LOG_BUF(log_start); + log_start++; + logbufcount++; + } + spin_unlock_irq(&logbuf_lock); + + /* Write the log messgaes to socket */ + oldfs = get_fs(); + set_fs(KERNEL_DS); + numofbytes = + sock->file->f_op->write(sock->file, tempbuf, logbufcount, + &sock->file->f_pos); + set_fs(oldfs); + + if (numofbytes < 0) { + /* if writing to socket fails, the log server may be down or the system is + rebooting. First reset + log_start to previous position. Check if the system is rebooting. If + rebooting write log mesages to console and exit. If not rebooting, yield + the processor to other runnable processes. */ + spin_lock_irq(&logbuf_lock); + log_start = start; + spin_unlock_irq(&logbuf_lock); + sys_close(sockfd); + if (atomic_read(&systemrebooting) > 0) { + printk(KERN_ALERT "HRDKRL: KLogger: Received reboot message, exiting \n"); + writelogstoconsole(); + goto out; + } else { + yield(); + continue; + } + } + + goto wait; + } else { + printk + (KERN_ALERT "HRDKRL: KLogger: Write operation of socket is not present, exiting\n"); + break; + } + + sys_close(sockfd); + } +out: + /*printk(KERN_ALERT "HRDKRL: KLogger: Received reboot message, exiting \n");*/ + return; } + +void notifyklogger() +{ + atomic_inc(&systemrebooting); + wake_up_all(&log_wait); + set_current_state(TASK_UNINTERRUPTIBLE); + schedule_timeout(2500); + current->state = TASK_RUNNING; +} + +# endif + diff -urN linux-2.4.23/kernel/sys.c linux-2423HRDKRL/kernel/sys.c --- linux-2.4.23/kernel/sys.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/kernel/sys.c 2004-01-08 12:35:29.000000000 -0500 @@ -286,6 +286,14 @@ * * reboot doesn't sync: do that yourself before calling this. */ +# if defined(CONFIG_HRDKRL_KIC) +extern void notifykic(void); +# endif + +# if defined(CONFIG_HRDKRL_KLOGGER) +extern void notifyklogger(void); +# endif + asmlinkage long sys_reboot(int magic1, int magic2, unsigned int cmd, void * arg) { char buffer[256]; @@ -303,6 +311,12 @@ lock_kernel(); switch (cmd) { case LINUX_REBOOT_CMD_RESTART: +# if defined(CONFIG_HRDKRL_KIC) + notifykic(); +# endif +# if defined(CONFIG_HRDKRL_KLOGGER) + notifyklogger(); +# endif notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL); printk(KERN_EMERG "Restarting system.\n"); machine_restart(NULL); @@ -317,6 +331,12 @@ break; case LINUX_REBOOT_CMD_HALT: +# if defined(CONFIG_HRDKRL_KIC) + notifykic(); +# endif +# if defined(CONFIG_HRDKRL_KLOGGER) + notifyklogger(); +# endif notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL); printk(KERN_EMERG "System halted.\n"); machine_halt(); @@ -324,6 +344,12 @@ break; case LINUX_REBOOT_CMD_POWER_OFF: +# if defined(CONFIG_HRDKRL_KIC) + notifykic(); +# endif +# if defined(CONFIG_HRDKRL_KLOGGER) + notifyklogger(); +# endif notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL); printk(KERN_EMERG "Power down.\n"); machine_power_off(); @@ -331,6 +357,12 @@ break; case LINUX_REBOOT_CMD_RESTART2: +# if defined(CONFIG_HRDKRL_KIC) + notifykic(); +# endif +# if defined(CONFIG_HRDKRL_KLOGGER) + notifyklogger(); +# endif if (strncpy_from_user(&buffer[0], (char *)arg, sizeof(buffer) - 1) < 0) { unlock_kernel(); return -EFAULT; @@ -778,7 +810,7 @@ } /* - * Samma på svenska.. + * Samma pÃ¥ svenska.. */ asmlinkage long sys_setfsgid(gid_t gid) { diff -urN linux-2.4.23/Makefile linux-2423HRDKRL/Makefile --- linux-2.4.23/Makefile 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/Makefile 2004-03-18 12:10:25.000000000 -0500 @@ -1,7 +1,7 @@ VERSION = 2 PATCHLEVEL = 4 SUBLEVEL = 23 -EXTRAVERSION = +EXTRAVERSION =HRDKRL KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) @@ -126,9 +126,9 @@ CORE_FILES =kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o NETWORKS =net/network.o - +HRDKRL =hrdkrl/hrdkrl.o LIBS =$(TOPDIR)/lib/lib.a -SUBDIRS =kernel drivers mm fs net ipc lib crypto +SUBDIRS =kernel drivers mm fs net ipc lib crypto hrdkrl DRIVERS-n := DRIVERS-y := @@ -271,7 +271,7 @@ export CPPFLAGS CFLAGS CFLAGS_KERNEL AFLAGS AFLAGS_KERNEL -export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS +export NETWORKS DRIVERS LIBS HEAD LDFLAGS LINKFLAGS MAKEBOOT ASFLAGS HRDKRL .S.s: $(CPP) $(AFLAGS) $(AFLAGS_KERNEL) -traditional -o $*.s $< @@ -290,6 +290,7 @@ $(CORE_FILES) \ $(DRIVERS) \ $(NETWORKS) \ + $(HRDKRL) \ $(LIBS) \ --end-group \ -o vmlinux diff -urN linux-2.4.23/mm/mmap.c linux-2423HRDKRL/mm/mmap.c --- linux-2.4.23/mm/mmap.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/mm/mmap.c 2003-12-29 20:00:11.000000000 -0500 @@ -479,7 +479,10 @@ break; } } - +# ifdef CONFIG_HRDKRL_TPM + if (!tpm_allow(file)) + return -EACCES; +# endif /* Clear old maps */ munmap_back: vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent); diff -urN linux-2.4.23/mm/mprotect.c linux-2423HRDKRL/mm/mprotect.c --- linux-2.4.23/mm/mprotect.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/mm/mprotect.c 2003-12-29 20:02:21.000000000 -0500 @@ -287,7 +287,13 @@ error = -ENOMEM; if (!vma || vma->vm_start > start) goto out; - +# ifdef CONFIG_HRDKRL_TPM + if (!tpm_allow(vma->vm_file)) + { + error = -EACCES; + goto out; + } +# endif for (nstart = start ; ; ) { unsigned int newflags; int last = 0; diff -urN linux-2.4.23/net/socket.c linux-2423HRDKRL/net/socket.c --- linux-2.4.23/net/socket.c 2003-11-28 13:26:21.000000000 -0500 +++ linux-2423HRDKRL/net/socket.c 2004-01-05 19:59:58.000000000 -0500 @@ -1754,3 +1754,70 @@ len = 0; return len; } + +# if defined(CONFIG_HRDKRL_KLOGGER) +int mysock_create(int family, int type, int protocol, struct socket *sock) + { + int retval; + /*struct socket *sock;*/ + + retval = sock_create(family, type, protocol, &sock); + if (retval < 0) + goto out; + + retval = sock_map_fd(sock); + if (retval < 0) + goto out_release; + + out: + /* It may be already another descriptor 8) Not kernel problem. */ + return retval; + + out_release: + sock_release(sock); + return retval; + } + +long mysys_socket(int family, int type, int protocol) +{ + int retval; + struct socket *sock; + + retval = sock_create(family, type, protocol, &sock); + if (retval < 0) + goto out; + + retval = sock_map_fd(sock); + if (retval < 0) + goto out_release; + +out: + /* It may be already another descriptor 8) Not kernel problem. */ + return retval; + +out_release: + sock_release(sock); + return retval; +} + +long mysys_connect(int fd, struct sockaddr *uservaddr, int addrlen) +{ + struct socket *sock; + char address[MAX_SOCK_ADDR]; + int err; + + sock = sockfd_lookup(fd, &err); + if (!sock) + goto out; +/* err = move_addr_to_kernel(uservaddr, addrlen, address); + if (err < 0) + goto out_put;*/ + err = sock->ops->connect(sock, (struct sockaddr *) uservaddr, addrlen, + sock->file->f_flags); +out_put: + sockfd_put(sock); +out: + return err; +} + +# endif diff -urN linux-2.4.23/net/unix/af_unix.c linux-2423HRDKRL/net/unix/af_unix.c --- linux-2.4.23/net/unix/af_unix.c 2002-11-28 18:53:16.000000000 -0500 +++ linux-2423HRDKRL/net/unix/af_unix.c 2004-01-04 16:36:30.000000000 -0500 @@ -622,6 +622,16 @@ if (u) { struct dentry *dentry; dentry = u->protinfo.af_unix.dentry; + +# if defined(CONFIG_HRDKRL_CHROOT_DENY_UNIX_SOCKET) + if (!gr_handle_chroot_unix(u->peercred.pid)) { + err = -EPERM; + sock_put(u); + goto fail; + } +# endif + + if (dentry) UPDATE_ATIME(dentry->d_inode); } else @@ -740,6 +750,11 @@ goto out_unlock; } + +# if defined(CONFIG_HRDKRL_CHROOT_DENY_UNIX_SOCKET) + sk->peercred.pid = current->pid; +# endif + list = &unix_socket_table[addr->hash]; } else { list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];