-----BEGIN PGP SIGNED MESSAGE----- # Patch for linux 2.2.12 to add volatile shared memory. # Antonomasia 03Jan2000 Freeware # cd /usr/src && patch -p0 < filename *** linux-2.2.12/arch/i386/kernel/entry.S~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/arch/i386/kernel/entry.S Mon Jan 3 21:16:07 2000 *************** *** 562,567 **** - --- 562,568 ---- .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */ .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ .long SYMBOL_NAME(sys_vfork) /* 190 */ + .long SYMBOL_NAME(sys_do_vshm) /* * NOTE!! This doesn't have to be exact - we just have *************** *** 569,574 **** * entries. Don't panic if you notice that this hasn't * been shrunk every time we add a new system call. */ ! .rept NR_syscalls-190 .long SYMBOL_NAME(sys_ni_syscall) .endr - --- 570,575 ---- * entries. Don't panic if you notice that this hasn't * been shrunk every time we add a new system call. */ ! .rept NR_syscalls-191 .long SYMBOL_NAME(sys_ni_syscall) .endr *** linux-2.2.12/arch/i386/kernel/process.c~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/arch/i386/kernel/process.c Mon Jan 3 21:15:26 2000 *************** *** 270,282 **** void machine_restart(char * __unused) { #if __SMP__ /* * turn off the IO-APIC, so we can do a clean reboot */ init_pic_mode(); #endif - - if(!reboot_thru_bios) { /* rebooting needs to touch the page at absolute addr 0 */ *((unsigned short *)__va(0x472)) = reboot_mode; - --- 270,282 ---- void machine_restart(char * __unused) { + sys_do_vshm(VSHM_DESTROY_ALL, NULL); #if __SMP__ /* * turn off the IO-APIC, so we can do a clean reboot */ init_pic_mode(); #endif if(!reboot_thru_bios) { /* rebooting needs to touch the page at absolute addr 0 */ *((unsigned short *)__va(0x472)) = reboot_mode; *** linux-2.2.12/include/asm/unistd.h~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/include/asm/unistd.h Mon Jan 3 21:15:26 2000 *************** *** 195,200 **** - --- 195,201 ---- #define __NR_getpmsg 188 /* some people actually want streams */ #define __NR_putpmsg 189 /* some people actually want streams */ #define __NR_vfork 190 + #define __NR_do_vshm 191 /* user-visible error numbers are in the range -1 - -122: see */ *** linux-2.2.12/include/linux/kernel.h~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/include/linux/kernel.h Mon Jan 3 21:15:26 2000 *************** *** 94,96 **** - --- 94,119 ---- }; #endif + + + /* for sys_vshm (volatile shared memory; ant notatla.demon.co.uk) */ + #ifndef VSHMSZ + + #define VSHMSZ 1024 + + #define VSHM_SET_LFSR 0 + #define VSHM_SET_DATA 1 + #define VSHM_GET_DATA 2 + #define VSHM_DESTROY_ALL 3 + #define VSHM_DESTROY 4 + + struct vshm + { + int euid; + unsigned char lfsr[VSHMSZ]; + unsigned char data[VSHMSZ]; + unsigned char pad[VSHMSZ]; + struct vshm *next; + }; + + #endif *** linux-2.2.12/kernel/Makefile~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/kernel/Makefile Mon Jan 3 21:15:26 2000 *************** *** 13,19 **** O_TARGET := kernel.o O_OBJS = sched.o dma.o fork.o exec_domain.o panic.o printk.o sys.o \ module.o exit.o itimer.o info.o time.o softirq.o resource.o \ ! sysctl.o acct.o capability.o OX_OBJS += signal.o - --- 13,19 ---- O_TARGET := kernel.o O_OBJS = sched.o dma.o fork.o exec_domain.o panic.o printk.o sys.o \ module.o exit.o itimer.o info.o time.o softirq.o resource.o \ ! sysctl.o acct.o capability.o vshm.o OX_OBJS += signal.o *** linux-2.2.12/kernel/sched.c~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/kernel/sched.c Mon Jan 3 21:15:25 2000 *************** *** 44,49 **** - --- 44,52 ---- * kernel variables */ + /* volatile shared memory (ant notatla.demon.co.uk) */ + struct vshm vshm_anchor; + unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */ long tick = (1000000 + HZ/2) / HZ; /* timer interrupt period */ *************** *** 305,310 **** - --- 308,314 ---- goto out_no_target; send_now: + target_cpu = target_tsk->processor; target_tsk->need_resched = 1; spin_unlock_irqrestore(&runqueue_lock, flags); *************** *** 459,464 **** - --- 463,470 ---- return; out: spin_unlock_irqrestore(&runqueue_lock, flags); + + } static void process_timeout(unsigned long __data) *************** *** 700,705 **** - --- 706,747 ---- goto scheduling_in_interrupt; release_kernel_lock(prev, this_cpu); + + /* VSHM like shared memory with flipping for volatile storage */ + { + static int vshm_sched_count=-1; + struct vshm *block; + unsigned char tmp; + int i; + + if (-1==vshm_sched_count) { + memset (&vshm_anchor, 0, sizeof (struct vshm)); + } + if (0==vshm_sched_count) { + for (block=&vshm_anchor; block ; block=block->next) { + /* flip bits (in data and pad to preserve XOR) */ + for(i=0;idata[i] ^=block->lfsr[i] ; + block->pad[i] ^=block->lfsr[i] ; + } + /* update LFSR */ + tmp=block->lfsr[17] ^ + block->lfsr[ 3] ^ + block->lfsr[ 0]; + memmove(block->lfsr+1, block->lfsr, VSHMSZ-1); + block->lfsr[0]=tmp; + /* + * printk(KERN_INFO "VSHM LFSR(%d): ", block->euid); + * for(i=0;i<18;i++) { + * printk("%02x", block->lfsr[i]); + * } + * printk("\n"); + */ + } + } + vshm_sched_count++; + vshm_sched_count &= 63; /* approx 2/3 second between flips */ + } /* Do "administrative" work here while we don't hold any locks */ if (bh_mask & bh_active) *** linux-2.2.12/kernel/sys.c~ Mon Jan 3 21:15:25 2000 - --- linux-2.2.12/kernel/sys.c Mon Jan 3 21:15:25 2000 *************** *** 170,175 **** - --- 170,176 ---- lock_kernel(); switch (cmd) { case LINUX_REBOOT_CMD_RESTART: + sys_do_vshm(VSHM_DESTROY_ALL, NULL); notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL); printk(KERN_EMERG "Restarting system.\n"); machine_restart(NULL); *************** *** 184,189 **** - --- 185,191 ---- break; case LINUX_REBOOT_CMD_HALT: + sys_do_vshm(VSHM_DESTROY_ALL, NULL); notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL); printk(KERN_EMERG "System halted.\n"); machine_halt(); *************** *** 191,196 **** - --- 193,199 ---- break; case LINUX_REBOOT_CMD_POWER_OFF: + sys_do_vshm(VSHM_DESTROY_ALL, NULL); notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL); printk(KERN_EMERG "Power down.\n"); machine_power_off(); *************** *** 204,209 **** - --- 207,213 ---- } buffer[sizeof(buffer) - 1] = '\0'; + sys_do_vshm(VSHM_DESTROY_ALL, NULL); notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer); printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer); machine_restart(buffer); *** linux-2.2.12/kernel/vshm.c~ Mon Jan 3 21:44:00 2000 - --- linux-2.2.12/kernel/vshm.c Mon Jan 3 20:57:45 2000 *************** *** 0 **** - --- 1,134 ---- + /* + * linux/kernel/vshm.c + * Copyright (C) 2000 Antonomasia + * + */ + + #include + #include + #include + #include + #include + #include + #include + #include + + /* #if defined(CONFIG_VSHM) */ + + extern struct vshm vshm_anchor; + + + struct vshm * + findblob (int euid) + { + struct vshm *kp = &vshm_anchor; + struct vshm *old=NULL; + struct vshm *new=NULL; + + while ((kp) && (euid >= kp->euid)) + { + if (euid == kp->euid) + return kp; + old=kp; + kp = kp->next; + } + + /* need to add a new block */ + new=kmalloc(sizeof (struct vshm) , GFP_KERNEL); + if (NULL==new) return NULL; + old->next=new; + new->next=kp; + new->euid=euid; + + return new; + } + + asmlinkage int sys_do_vshm (int op, unsigned char *k) + { + struct vshm *block; + int i, error; + + switch (op) { + case VSHM_SET_LFSR: + error=verify_area(VERIFY_READ,k,VSHMSZ); + if (0 != error) {return error;} + + block = findblob ((int) current->euid); + if (NULL == block) { return -1; } + if (copy_from_user(block->lfsr, k, VSHMSZ)) + return -1; + memset (block->pad, 0, VSHMSZ); + break; + + case VSHM_SET_DATA: + /* copy data from program to kernel */ + error=verify_area(VERIFY_READ,k,VSHMSZ); + if (0 != error) {return error;} + + block = findblob ((int) current->euid); + if (NULL == block) { return -1; } + if (copy_from_user(block->data, k, VSHMSZ)) + return -1; + memset (block->pad, 0, VSHMSZ); + if (VSHMSZ < 512) { + printk(KERN_ERR "VSHMSZ is set too small\n"); + return -1; + } + /* ensure nobody uses an all-zero register */ + for(i=0; i<18; i++) { + if ('\0'!=block->lfsr[i]) { + block->lfsr[i]= ((i+1) * 17) & 255; + } + } + break; + + case VSHM_GET_DATA: + /* copy data from kernel to program */ + error=verify_area(VERIFY_WRITE,k,VSHMSZ); + if (0 != error) return error; + + block = findblob ((int) current->euid); + if (NULL == block) { + return -1; + } + for (i = 0; i < VSHMSZ; i++) { + block->data[i]= block->data[i] ^ block->pad[i] ; + } + memset (block->pad, 0, VSHMSZ); + + if (copy_to_user(k, block->data, VSHMSZ)) + return -1; + break; + case VSHM_DESTROY_ALL: + /* destroy all vshm data (only root can do this) */ + if (suser ()) + { + for (block=&vshm_anchor; block ; block=block->next) { + memset (block->data, 0, VSHMSZ); + memset (block->pad, 0, VSHMSZ); + } + printk(KERN_NOTICE "all volatile SHM blocks wiped\n"); + return 0; + } + break; + case VSHM_DESTROY: + /* destroy a single user's data */ + block = findblob ((int) current->euid); + if (block) { + memset (block->data, 0, VSHMSZ); + memset (block->pad, 0, VSHMSZ); + } + /* + * data destruction does NOT unlink the data from the list + * instead we leave it in place to have further overwrites + */ + break; + default: + return -EINVAL; + break; + } + + return 0; + } + + /* #endif *//* CONFIG_VSHM */ And a small demo program to show usage.... #include #include #include #include #include int main() { char k[VSHMSZ]; char in[8]; int rc; _syscall2(int, do_vshm , int, i , char *, k ); memset(&k,0, sizeof(k)); while (0==0) { printf("choice (0=seed, 1=store, 2=retrieve, 3=wipe all, 4=wipe, q=quit): "); fgets(in,sizeof(in)-1,stdin); if ('1'==in[0]) strcpy(k,"original string...abcdef"); if ('q'==in[0]) exit(0); rc=do_vshm( (int) (in[0]-'0') , k); if (rc) printf("RC=%d\n", rc); printf("k=:%s:\n",k); strcpy(k,"=0123456789abcdef="); } exit(0); } -----BEGIN PGP SIGNATURE----- Version: 2.6.3i Charset: noconv iQCVAgUBOHErUErZ5ZQH9XIxAQG7aQP/R95/YRY98l6r+qIjItBiCiyC/axQ3DlB /KG8bcZUvuydh3O50Ew5o2LWeVJjMH4MuvLT8MOz4W3R5DICZCBneyerWP37VIwb FlucKUopZcHOBNN7dU0YBHumXifOpLp/lUJmdBmNn7qyX/EOclp2TXvRiqamKyjp q/y4eoB+4Vc= =5XyJ -----END PGP SIGNATURE-----