Skip to content

Commit 9ec5209

Browse files
Cedric Le GoaterLinus Torvalds
authored andcommitted
[PATCH] replace cad_pid by a struct pid
There are a few places in the kernel where the init task is signaled. The ctrl+alt+del sequence is one them. It kills a task, usually init, using a cached pid (cad_pid). This patch replaces the pid_t by a struct pid to avoid pid wrap around problem. The struct pid is initialized at boot time in init() and can be modified through systctl with /proc/sys/kernel/cad_pid [ I haven't found any distro using it ? ] It also introduces a small helper routine kill_cad_pid() which is used where it seemed ok to use cad_pid instead of pid 1. [akpm@osdl.org: cleanups, build fix] Signed-off-by: Cedric Le Goater <clg@fr.ibm.com> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Paul Mackerras <paulus@samba.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 1a657f7 commit 9ec5209

File tree

11 files changed

+48
-16
lines changed

11 files changed

+48
-16
lines changed

arch/mips/sgi-ip22/ip22-reset.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ static inline void power_button(void)
123123
if (machine_state & MACHINE_PANICED)
124124
return;
125125

126-
if ((machine_state & MACHINE_SHUTTING_DOWN) || kill_proc(1,SIGINT,1)) {
126+
if ((machine_state & MACHINE_SHUTTING_DOWN) ||
127+
kill_cad_pid(SIGINT, 1)) {
127128
/* No init process or button pressed twice. */
128129
sgi_machine_power_off();
129130
}

arch/mips/sgi-ip32/ip32-reset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static inline void ip32_power_button(void)
120120
if (has_panicked)
121121
return;
122122

123-
if (shuting_down || kill_proc(1, SIGINT, 1)) {
123+
if (shuting_down || kill_cad_pid(SIGINT, 1)) {
124124
/* No init process or button pressed twice. */
125125
ip32_machine_power_off();
126126
}

arch/powerpc/platforms/iseries/mf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static int dma_and_signal_ce_msg(char *ce_msg,
357357
*/
358358
static int shutdown(void)
359359
{
360-
int rc = kill_proc(1, SIGINT, 1);
360+
int rc = kill_cad_pid(SIGINT, 1);
361361

362362
if (rc) {
363363
printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "

drivers/char/nwbutton.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,8 @@ static void button_consume_callbacks (int bpcount)
127127
static void button_sequence_finished (unsigned long parameters)
128128
{
129129
#ifdef CONFIG_NWBUTTON_REBOOT /* Reboot using button is enabled */
130-
if (button_press_count == reboot_count) {
131-
kill_proc (1, SIGINT, 1); /* Ask init to reboot us */
132-
}
130+
if (button_press_count == reboot_count)
131+
kill_cad_pid(SIGINT, 1); /* Ask init to reboot us */
133132
#endif /* CONFIG_NWBUTTON_REBOOT */
134133
button_consume_callbacks (button_press_count);
135134
bcount = sprintf (button_output_buffer, "%d\n", button_press_count);

drivers/char/snsc_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ scdrv_dispatch_event(char *event, int len)
220220
" Sending SIGPWR to init...\n");
221221

222222
/* give a SIGPWR signal to init proc */
223-
kill_proc(1, SIGPWR, 0);
223+
kill_cad_pid(SIGPWR, 0);
224224
} else {
225225
/* print to system log */
226226
printk("%s|$(0x%x)%s\n", severity, esp_code, desc);

drivers/parisc/power.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@
8484

8585
static void deferred_poweroff(void *dummy)
8686
{
87-
extern int cad_pid; /* from kernel/sys.c */
88-
if (kill_proc(cad_pid, SIGINT, 1)) {
87+
if (kill_cad_pid(SIGINT, 1)) {
8988
/* just in case killing init process failed */
9089
machine_power_off();
9190
}

drivers/s390/s390mach.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ s390_handle_mcck(void)
208208
*/
209209
__ctl_clear_bit(14, 24); /* Disable WARNING MCH */
210210
if (xchg(&mchchk_wng_posted, 1) == 0)
211-
kill_proc(1, SIGPWR, 1);
211+
kill_cad_pid(SIGPWR, 1);
212212
}
213213
#endif
214214

include/linux/sched.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,8 @@ static inline int is_init(struct task_struct *tsk)
10651065
return tsk->pid == 1;
10661066
}
10671067

1068+
extern struct pid *cad_pid;
1069+
10681070
extern void free_task(struct task_struct *tsk);
10691071
#define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0)
10701072

@@ -1292,6 +1294,11 @@ extern int send_group_sigqueue(int, struct sigqueue *, struct task_struct *);
12921294
extern int do_sigaction(int, struct k_sigaction *, struct k_sigaction *);
12931295
extern int do_sigaltstack(const stack_t __user *, stack_t __user *, unsigned long);
12941296

1297+
static inline int kill_cad_pid(int sig, int priv)
1298+
{
1299+
return kill_pid(cad_pid, sig, priv);
1300+
}
1301+
12951302
/* These can be the second arg to send_sig_info/send_group_sig_info. */
12961303
#define SEND_SIG_NOINFO ((struct siginfo *) 0)
12971304
#define SEND_SIG_PRIV ((struct siginfo *) 1)

init/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ static int init(void * unused)
721721
*/
722722
child_reaper = current;
723723

724+
cad_pid = task_pid(current);
725+
724726
smp_prepare_cpus(max_cpus);
725727

726728
do_pre_smp_initcalls();

kernel/sys.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ EXPORT_SYMBOL(fs_overflowgid);
9292
*/
9393

9494
int C_A_D = 1;
95-
int cad_pid = 1;
95+
struct pid *cad_pid;
96+
EXPORT_SYMBOL(cad_pid);
9697

9798
/*
9899
* Notifier list for kernel code which wants to be called
@@ -773,10 +774,9 @@ void ctrl_alt_del(void)
773774
if (C_A_D)
774775
schedule_work(&cad_work);
775776
else
776-
kill_proc(cad_pid, SIGINT, 1);
777+
kill_cad_pid(SIGINT, 1);
777778
}
778779

779-
780780
/*
781781
* Unprivileged users may change the real gid to the effective gid
782782
* or vice versa. (BSD-style)

0 commit comments

Comments
 (0)