diff -udr linux-vanilla/drivers/char/random.c linux-2.2.19/drivers/char/random.c --- linux-vanilla/drivers/char/random.c Wed Jun 7 23:26:42 2000 +++ linux-2.2.19/drivers/char/random.c Wed Apr 4 12:15:11 2001 @@ -260,7 +260,7 @@ #undef BENCHMARK_NOINT #define ROTATE_PARANOIA -#define POOLWORDS 128 /* Power of 2 - note that this is 32-bit words */ +#define POOLWORDS 2048 /* Power of 2 - note that this is 32-bit words */ #define POOLBITS (POOLWORDS*32) /* * The pool is stirred with a primitive polynomial of degree POOLWORDS diff -udr linux-vanilla/include/linux/sched.h linux-2.2.19/include/linux/sched.h --- linux-vanilla/include/linux/sched.h Tue Apr 3 14:40:54 2001 +++ linux-2.2.19/include/linux/sched.h Wed Apr 4 15:21:27 2001 @@ -65,6 +65,10 @@ extern int nr_running, nr_tasks; extern int last_pid; +#define NREMEMBER_PIDS 64 /* number of pids to remember to prevent to-soon-re-use */ +extern pid_t last_pids[NREMEMBER_PIDS]; +extern int cur_nremember_pids; /* number of pids in above array */ + #include #include #include diff -udr linux-vanilla/kernel/exit.c linux-2.2.19/kernel/exit.c --- linux-vanilla/kernel/exit.c Tue Apr 3 13:16:19 2001 +++ linux-2.2.19/kernel/exit.c Wed Apr 4 13:37:09 2001 @@ -13,6 +13,7 @@ #ifdef CONFIG_BSD_PROCESS_ACCT #include #endif +#include #include #include @@ -378,14 +379,23 @@ if (in_interrupt()) printk("Aiee, killing interrupt handler\n"); - if (!tsk->pid) - panic("Attempted to kill the idle task!"); + if (tsk->pid <= 1) { + if (tsk->pid) + panic("Attempted to kill init!"); + else + panic("Attempted to kill the idle task!"); + } tsk->flags |= PF_EXITING; start_bh_atomic(); del_timer(&tsk->real_timer); end_bh_atomic(); lock_kernel(); + + /* add this pid to the list of recently used pids */ + last_pids[cur_nremember_pids++] = tsk -> pid; + cur_nremember_pids %= NREMEMBER_PIDS; + fake_volatile: #ifdef CONFIG_BSD_PROCESS_ACCT acct_process(code); diff -udr linux-vanilla/kernel/fork.c linux-2.2.19/kernel/fork.c --- linux-vanilla/kernel/fork.c Tue Apr 3 13:16:19 2001 +++ linux-2.2.19/kernel/fork.c Wed Apr 4 15:02:24 2001 @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -185,47 +186,64 @@ /* Protects next_safe and last_pid. */ spinlock_t lastpid_lock = SPIN_LOCK_UNLOCKED; +/* array of pids to remember to prevent to-soon-re-use */ +pid_t last_pids[NREMEMBER_PIDS]; /* no need to initialize; in bss section which is 0x00'ed anyway */ +int cur_nremember_pids; /* number of pids in above array */ + static int get_pid(unsigned long flags) { - static int next_safe = PID_MAX; struct task_struct *p; + int pid, loop; + static char first_pid=1; if (flags & CLONE_PID) return current->pid; spin_lock(&lastpid_lock); - if((++last_pid) & 0xffff8000) { - last_pid = 300; /* Skip daemons etc. */ - goto inside; + + /* generate a PID number */ +loop: + if (first_pid) { /* first pid; must be '1' -> init=1 */ + first_pid=0; + pid = 1; } - if(last_pid >= next_safe) { -inside: - next_safe = PID_MAX; - read_lock(&tasklist_lock); - repeat: - for_each_task(p) { - if(p->pid == last_pid || - p->pgrp == last_pid || - p->session == last_pid) { - if(++last_pid >= next_safe) { - if(last_pid & 0xffff8000) - last_pid = 300; - next_safe = PID_MAX; - } - goto repeat; - } - if(p->pid > last_pid && next_safe > p->pid) - next_safe = p->pid; - if(p->pgrp > last_pid && next_safe > p->pgrp) - next_safe = p->pgrp; - if(p->session > last_pid && next_safe > p->session) - next_safe = p->session; + else { + do { + get_random_bytes(&pid, sizeof(pid)); + pid &= 32767; + } while (pid<2); + } + + /* see if this pid was used recently */ + for(loop=0; loop abort and try again */ + if (p -> pid == pid || + p -> pgrp == pid || + p -> session == pid) { + read_unlock(&tasklist_lock); + /* I've always learned: "thy shall not use goto" + * but, well, this one makes all code so much + * shorter + */ + goto loop; + } + } + + read_unlock(&tasklist_lock); + spin_unlock(&lastpid_lock); - return last_pid; + return pid; } static inline int dup_mmap(struct mm_struct * mm) diff -udr linux-vanilla/net/core/utils.c linux-2.2.19/net/core/utils.c --- linux-vanilla/net/core/utils.c Sun Mar 1 23:40:40 1998 +++ linux-2.2.19/net/core/utils.c Wed Apr 4 12:16:17 2001 @@ -20,20 +20,22 @@ #include #include #include - -static unsigned long net_rand_seed = 152L; +#include unsigned long net_random(void) { - net_rand_seed=net_rand_seed*69069L+1; - return net_rand_seed^jiffies; + unsigned long dummy; + + get_random_bytes(&dummy, sizeof(dummy)); + + return dummy; } void net_srandom(unsigned long entropy) { - net_rand_seed ^= entropy; - net_random(); + add_mouse_randomness((__u32)entropy); } + int net_msg_cost = 5*HZ; int net_msg_burst = 10*5*HZ;