--- linux/kernel/pid.c.orig +++ linux/kernel/pid.c @@ -103,7 +103,7 @@ int alloc_pidmap(void) pidmap_t *map; pid = last_pid + 1; - if (pid >= pid_max) + if (unlikely(pid >= pid_max)) pid = RESERVED_PIDS; offset = pid & BITS_PER_PAGE_MASK; @@ -116,6 +116,10 @@ int alloc_pidmap(void) * slowpath and that fixes things up. */ return_pid: + if (unlikely(pid >= pid_max)) { + clear_bit(offset, map->page); + goto failure; + } atomic_dec(&map->nr_free); last_pid = pid; return pid;