* [PATCH] Configurable Magic Sysrq
@ 2004-10-29 9:39 Jan Kara
2004-10-29 9:46 ` Andrew Morton
2004-10-31 18:52 ` Pavel Machek
0 siblings, 2 replies; 20+ messages in thread
From: Jan Kara @ 2004-10-29 9:39 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm
[-- Attachment #1: Type: text/plain, Size: 542 bytes --]
Hello,
I know about a few people who would like to use some functionality of
the Magic Sysrq but don't want to enable all the functions it provides.
So I wrote a patch which should allow them to do so. It allows to
configure available functions of Sysrq via /proc/sys/kernel/sysrq (the
interface is backward compatible). If you think it's useful then use it :)
Andrew, do you think it can go into mainline or it's just an overdesign?
Thanks in advance for comments, bugreports
Honza
--
Jan Kara <jack@suse.cz>
SuSE CR Labs
[-- Attachment #2: enable-sysrq.diff --]
[-- Type: text/plain, Size: 5649 bytes --]
Enable configuration of sysrq functions via /proc/sys/kernel/sysrq.
Signed-off-by: Jan Kara <jack@suse.cz>
diff -ru linux-2.6.9/Documentation/sysrq.txt linux-2.6.9-sysrq/Documentation/sysrq.txt
--- linux-2.6.9/Documentation/sysrq.txt 2004-10-18 23:54:08.000000000 +0200
+++ linux-2.6.9-sysrq/Documentation/sysrq.txt 2004-10-22 18:58:07.924933784 +0200
@@ -10,13 +10,27 @@
* How do I enable the magic SysRq key?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You need to say "yes" to 'Magic SysRq key (CONFIG_MAGIC_SYSRQ)' when
-configuring the kernel. When running on a kernel with SysRq compiled in, it
-may be DISABLED at run-time using following command:
+configuring the kernel. When running a kernel with SysRq compiled in,
+/proc/sys/kernel/sysrq controls the functions allowed to be invoked via
+the SysRq key. By default the file contains 1 which means that every
+possible SysRq request is allowed (in older versions SysRq was disabled
+by default, and you were required to specifically enable it at run-time
+but this is not the case any more). Here is the list of possible values
+in /proc/sys/kernel/sysrq:
+ 0 - disable sysrq completely
+ 1 - enable all functions of sysrq
+ >1 - bitmask of allowed sysrq functions (see below for detailed function
+ description):
+ 2 - enable control of console logging level
+ 4 - enable control of keyboard (SAK, unraw)
+ 8 - enable debugging dumps of processes etc.
+ 16 - enable sync command
+ 32 - enable remount read-only
+ 64 - enable signalling of processes (term, kill)
+ 128 - allow reboot
- echo "0" > /proc/sys/kernel/sysrq
-
-Note that previous versions disabled sysrq by default, and you were required
-to specifically enable it at run-time. That is not the case any longer.
+You can set the value in the file by the following command:
+ echo "number" >/proc/sys/kernel/sysrq
* How do I use the magic SysRq key?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff -ru linux-2.6.9/drivers/char/sysrq.c linux-2.6.9-sysrq/drivers/char/sysrq.c
--- linux-2.6.9/drivers/char/sysrq.c 2004-10-18 23:55:06.000000000 +0200
+++ linux-2.6.9-sysrq/drivers/char/sysrq.c 2004-10-22 14:47:25.000000000 +0200
@@ -38,6 +38,15 @@
extern void reset_vc(unsigned int);
+/* 0x0001 is reserved for enable everything */
+#define SYSRQ_ENABLE_LOG 0x0002
+#define SYSRQ_ENABLE_KEYBOARD 0x0004
+#define SYSRQ_ENABLE_DUMP 0x0008
+#define SYSRQ_ENABLE_SYNC 0x0010
+#define SYSRQ_ENABLE_REMOUNT 0x0020
+#define SYSRQ_ENABLE_SIGNAL 0x0040
+#define SYSRQ_ENABLE_BOOT 0x0080
+
/* Whether we react on sysrq keys or just ignore them */
int sysrq_enabled = 1;
@@ -58,6 +67,7 @@
.handler = sysrq_handle_loglevel,
.help_msg = "loglevel0-8",
.action_msg = "Changing Loglevel",
+ .enable_mask = SYSRQ_ENABLE_LOG,
};
@@ -74,6 +84,7 @@
.handler = sysrq_handle_SAK,
.help_msg = "saK",
.action_msg = "SAK",
+ .enable_mask = SYSRQ_ENABLE_KEYBOARD,
};
#endif
@@ -91,6 +102,7 @@
.handler = sysrq_handle_unraw,
.help_msg = "unRaw",
.action_msg = "Keyboard mode set to XLATE",
+ .enable_mask = SYSRQ_ENABLE_KEYBOARD,
};
#endif /* CONFIG_VT */
@@ -105,6 +117,7 @@
.handler = sysrq_handle_reboot,
.help_msg = "reBoot",
.action_msg = "Resetting",
+ .enable_mask = SYSRQ_ENABLE_BOOT,
};
static void sysrq_handle_sync(int key, struct pt_regs *pt_regs,
@@ -117,6 +130,7 @@
.handler = sysrq_handle_sync,
.help_msg = "Sync",
.action_msg = "Emergency Sync",
+ .enable_mask = SYSRQ_ENABLE_SYNC,
};
static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs,
@@ -129,6 +143,7 @@
.handler = sysrq_handle_mountro,
.help_msg = "Unmount",
.action_msg = "Emergency Remount R/O",
+ .enable_mask = SYSRQ_ENABLE_REMOUNT,
};
/* END SYNC SYSRQ HANDLERS BLOCK */
@@ -146,6 +161,7 @@
.handler = sysrq_handle_showregs,
.help_msg = "showPc",
.action_msg = "Show Regs",
+ .enable_mask = SYSRQ_ENABLE_DUMP,
};
@@ -158,6 +174,7 @@
.handler = sysrq_handle_showstate,
.help_msg = "showTasks",
.action_msg = "Show State",
+ .enable_mask = SYSRQ_ENABLE_DUMP,
};
@@ -170,6 +187,7 @@
.handler = sysrq_handle_showmem,
.help_msg = "showMem",
.action_msg = "Show Memory",
+ .enable_mask = SYSRQ_ENABLE_DUMP,
};
/* SHOW SYSRQ HANDLERS BLOCK */
@@ -200,6 +218,7 @@
.handler = sysrq_handle_term,
.help_msg = "tErm",
.action_msg = "Terminate All Tasks",
+ .enable_mask = SYSRQ_ENABLE_SIGNAL,
};
static void sysrq_handle_kill(int key, struct pt_regs *pt_regs,
@@ -212,6 +231,7 @@
.handler = sysrq_handle_kill,
.help_msg = "kIll",
.action_msg = "Kill All Tasks",
+ .enable_mask = SYSRQ_ENABLE_SIGNAL,
};
/* END SIGNAL SYSRQ HANDLERS BLOCK */
@@ -331,9 +351,13 @@
op_p = __sysrq_get_key_op(key);
if (op_p) {
- printk ("%s\n", op_p->action_msg);
- console_loglevel = orig_log_level;
- op_p->handler(key, pt_regs, tty);
+ if (sysrq_enabled == 1 || sysrq_enabled & op_p->enable_mask) {
+ printk ("%s\n", op_p->action_msg);
+ console_loglevel = orig_log_level;
+ op_p->handler(key, pt_regs, tty);
+ }
+ else
+ printk("This sysrq operation is disabled.\n");
} else {
printk("HELP : ");
/* Only print the help msg once per handler */
diff -ru linux-2.6.9/include/linux/sysrq.h linux-2.6.9-sysrq/include/linux/sysrq.h
--- linux-2.6.9/include/linux/sysrq.h 2004-10-18 23:53:06.000000000 +0200
+++ linux-2.6.9-sysrq/include/linux/sysrq.h 2004-10-22 14:47:25.000000000 +0200
@@ -20,6 +20,7 @@
void (*handler)(int, struct pt_regs *, struct tty_struct *);
char *help_msg;
char *action_msg;
+ int enable_mask;
};
#ifdef CONFIG_MAGIC_SYSRQ
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 9:39 [PATCH] Configurable Magic Sysrq Jan Kara @ 2004-10-29 9:46 ` Andrew Morton 2004-10-29 10:17 ` Jan Kara 2004-10-29 11:34 ` Måns Rullgård 2004-10-31 18:52 ` Pavel Machek 1 sibling, 2 replies; 20+ messages in thread From: Andrew Morton @ 2004-10-29 9:46 UTC (permalink / raw) To: Jan Kara; +Cc: linux-kernel Jan Kara <jack@suse.cz> wrote: > > I know about a few people who would like to use some functionality of > the Magic Sysrq but don't want to enable all the functions it provides. That's a new one. Can you tell us more about why people want to do such a thing? > So I wrote a patch which should allow them to do so. It allows to > configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > interface is backward compatible). If you think it's useful then use it :) > Andrew, do you think it can go into mainline or it's just an overdesign? Patch looks reasonable - we just need to decide whether the requirement warrants its inclusion. There have been a few changes in the sysrq code since 2.6.9 and there are more changes queued up in -mm. The patch applies OK, but it'll need checking and redoing. There's a new `sysrq-f' command in the pipeline which causes a manual oom-killer call. ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 9:46 ` Andrew Morton @ 2004-10-29 10:17 ` Jan Kara 2004-10-29 10:24 ` Andrew Morton 2004-10-31 18:59 ` Pavel Machek 2004-10-29 11:34 ` Måns Rullgård 1 sibling, 2 replies; 20+ messages in thread From: Jan Kara @ 2004-10-29 10:17 UTC (permalink / raw) To: Andrew Morton; +Cc: linux-kernel > Jan Kara <jack@suse.cz> wrote: > > > > I know about a few people who would like to use some functionality of > > the Magic Sysrq but don't want to enable all the functions it provides. > > That's a new one. Can you tell us more about why people want to do such a > thing? For example in a computer lab at the university the admin don't want to allow users to Umount/Kill (mainly to make it harder for users to screw up the computer) but wants to allow SAK/Unraw. Another (actually not so legitimate ;) example is that in e.g. SUSE kernels sysrq is turned off by default (some people are afraid that it could be a security issue) so most users have it turned off and hence when the computer deadlocks, there's no debugging output. When you could allow only debugging outputs then the fear about security would be much smaller. So in general it's mainly to make life a bit easier to admins/developpers... > > So I wrote a patch which should allow them to do so. It allows to > > configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > > interface is backward compatible). If you think it's useful then use it :) > > Andrew, do you think it can go into mainline or it's just an overdesign? > > Patch looks reasonable - we just need to decide whether the requirement > warrants its inclusion. > > There have been a few changes in the sysrq code since 2.6.9 and there are > more changes queued up in -mm. The patch applies OK, but it'll need > checking and redoing. There's a new `sysrq-f' command in the pipeline > which causes a manual oom-killer call. OK, I'll rediff it againts latest -mm if we agree that inclusion would be useful. Honza -- Jan Kara <jack@suse.cz> SuSE CR Labs ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 10:17 ` Jan Kara @ 2004-10-29 10:24 ` Andrew Morton 2004-10-29 20:09 ` Dave Jones 2004-10-31 18:59 ` Pavel Machek 1 sibling, 1 reply; 20+ messages in thread From: Andrew Morton @ 2004-10-29 10:24 UTC (permalink / raw) To: Jan Kara; +Cc: linux-kernel Jan Kara <jack@suse.cz> wrote: > > > Jan Kara <jack@suse.cz> wrote: > > > > > > I know about a few people who would like to use some functionality of > > > the Magic Sysrq but don't want to enable all the functions it provides. > > > > That's a new one. Can you tell us more about why people want to do such a > > thing? > For example in a computer lab at the university the admin don't want > to allow users to Umount/Kill (mainly to make it harder for users to > screw up the computer) but wants to allow SAK/Unraw. > Another (actually not so legitimate ;) example is that in e.g. SUSE > kernels sysrq is turned off by default (some people are afraid that it > could be a security issue) so most users have it turned off and hence > when the computer deadlocks, there's no debugging output. OK, fair enough. I'll merge the patch if you talk suse into enabling sysrq-T and sysrq-P and sysrq-M by default ;) ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 10:24 ` Andrew Morton @ 2004-10-29 20:09 ` Dave Jones 2004-10-30 6:45 ` Olaf Hering 2004-11-01 9:29 ` Jan Kara 0 siblings, 2 replies; 20+ messages in thread From: Dave Jones @ 2004-10-29 20:09 UTC (permalink / raw) To: Andrew Morton; +Cc: Jan Kara, linux-kernel On Fri, Oct 29, 2004 at 03:24:20AM -0700, Andrew Morton wrote: > OK, fair enough. I'll merge the patch if you talk suse into enabling > sysrq-T and sysrq-P and sysrq-M by default ;) you already have those available if /proc/sys/kernel/sysrq is 0. alt-scrolllock / ctrl-scrolllock / shift-scrolllock. Dave ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 20:09 ` Dave Jones @ 2004-10-30 6:45 ` Olaf Hering 2004-11-01 9:29 ` Jan Kara 1 sibling, 0 replies; 20+ messages in thread From: Olaf Hering @ 2004-10-30 6:45 UTC (permalink / raw) To: Dave Jones, Andrew Morton, Jan Kara, linux-kernel On Fri, Oct 29, Dave Jones wrote: > On Fri, Oct 29, 2004 at 03:24:20AM -0700, Andrew Morton wrote: > > OK, fair enough. I'll merge the patch if you talk suse into enabling > > sysrq-T and sysrq-P and sysrq-M by default ;) > > you already have those available if /proc/sys/kernel/sysrq is 0. > > alt-scrolllock / ctrl-scrolllock / shift-scrolllock. How do I trigger that via serial/hvc? -- USB is for mice, FireWire is for men! sUse lINUX ag, nÜRNBERG ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 20:09 ` Dave Jones 2004-10-30 6:45 ` Olaf Hering @ 2004-11-01 9:29 ` Jan Kara 1 sibling, 0 replies; 20+ messages in thread From: Jan Kara @ 2004-11-01 9:29 UTC (permalink / raw) To: Dave Jones, Andrew Morton, linux-kernel > On Fri, Oct 29, 2004 at 03:24:20AM -0700, Andrew Morton wrote: > > OK, fair enough. I'll merge the patch if you talk suse into enabling > > sysrq-T and sysrq-P and sysrq-M by default ;) > > you already have those available if /proc/sys/kernel/sysrq is 0. > > alt-scrolllock / ctrl-scrolllock / shift-scrolllock. I admit I didn't know that but I also just found out that there's no scrolllock on my notebook keyboard... But anyway thanks for info. Honza -- Jan Kara <jack@suse.cz> SuSE CR Labs ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 10:17 ` Jan Kara 2004-10-29 10:24 ` Andrew Morton @ 2004-10-31 18:59 ` Pavel Machek 1 sibling, 0 replies; 20+ messages in thread From: Pavel Machek @ 2004-10-31 18:59 UTC (permalink / raw) To: Jan Kara; +Cc: Andrew Morton, linux-kernel Hi! > > > I know about a few people who would like to use some functionality of > > > the Magic Sysrq but don't want to enable all the functions it provides. > > > > That's a new one. Can you tell us more about why people want to do such a > > thing? > For example in a computer lab at the university the admin don't want > to allow users to Umount/Kill (mainly to make it harder for users to > screw up the computer) but wants to allow SAK/Unraw. In that particular computer lab, admin is *****, and paranoid one, too. He's more worried about security that functionality, and then you find suid bash in /tmp and learn that root password is name of the laboratory, with first character uppercased. Heh. BTW interesting things can be done with sak alone. (It is bye-bye vlock -a, right?). Changing console log-level and info-prints could lead to user seeing some info he's not allowed to see [perhaps part of some password are in the registers because they are now memcopied?], but I agree allowing that is probably okay. Pavel -- People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl! ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 9:46 ` Andrew Morton 2004-10-29 10:17 ` Jan Kara @ 2004-10-29 11:34 ` Måns Rullgård 2004-10-29 13:35 ` Jan Kara 1 sibling, 1 reply; 20+ messages in thread From: Måns Rullgård @ 2004-10-29 11:34 UTC (permalink / raw) To: linux-kernel; +Cc: Andrew Morton, Jan Kara Andrew Morton <akpm@osdl.org> writes: > Jan Kara <jack@suse.cz> wrote: >> >> I know about a few people who would like to use some functionality of >> the Magic Sysrq but don't want to enable all the functions it provides. > > That's a new one. Can you tell us more about why people want to do such a > thing? > >> So I wrote a patch which should allow them to do so. It allows to >> configure available functions of Sysrq via /proc/sys/kernel/sysrq (the >> interface is backward compatible). If you think it's useful then use it :) >> Andrew, do you think it can go into mainline or it's just an overdesign? > > Patch looks reasonable - we just need to decide whether the requirement > warrants its inclusion. > > There have been a few changes in the sysrq code since 2.6.9 and there are > more changes queued up in -mm. The patch applies OK, but it'll need > checking and redoing. There's a new `sysrq-f' command in the pipeline > which causes a manual oom-killer call. See also the patch I just posted to lkml. I also thought of an improved way of selecting keys to enable. Instead of an arbitrary bitmask, would it be possible to simply list the keys you want to enable, such as "echo sku > /proc/sys/kernel/sysrq"? -- Måns Rullgård mru@inprovide.com ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 11:34 ` Måns Rullgård @ 2004-10-29 13:35 ` Jan Kara 2004-10-29 13:44 ` Måns Rullgård 2004-10-29 14:33 ` Jan Engelhardt 0 siblings, 2 replies; 20+ messages in thread From: Jan Kara @ 2004-10-29 13:35 UTC (permalink / raw) To: M?ns Rullg?rd; +Cc: linux-kernel, Andrew Morton [-- Attachment #1: Type: text/plain, Size: 1834 bytes --] > Andrew Morton <akpm@osdl.org> writes: > > > Jan Kara <jack@suse.cz> wrote: > >> > >> I know about a few people who would like to use some functionality of > >> the Magic Sysrq but don't want to enable all the functions it provides. > > > > That's a new one. Can you tell us more about why people want to do such a > > thing? > > > >> So I wrote a patch which should allow them to do so. It allows to > >> configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > >> interface is backward compatible). If you think it's useful then use it :) > >> Andrew, do you think it can go into mainline or it's just an overdesign? > > > > Patch looks reasonable - we just need to decide whether the requirement > > warrants its inclusion. > > > > There have been a few changes in the sysrq code since 2.6.9 and there are > > more changes queued up in -mm. The patch applies OK, but it'll need > > checking and redoing. There's a new `sysrq-f' command in the pipeline > > which causes a manual oom-killer call. > > See also the patch I just posted to lkml. OK, Andrew, are you accepting the patch? The sysrq should probably go into SYSRQ_ENABLE_SIGNAL group... > I also thought of an improved way of selecting keys to enable. > Instead of an arbitrary bitmask, would it be possible to simply list > the keys you want to enable, such as "echo sku > /proc/sys/kernel/sysrq"? That would be possible of course but you'd have to do your own parsing in kernel and you are not supposed to change the sysrq setting often - usually just compute your favourite number, put it into boot scripts and you're done. So I'm not convinced it's useful very much. The attached patch is against 2.6.10-rc1-mm1 (I also added poweroff to SYSRQ_ENABLE_BOOT group of functions). Honza -- Jan Kara <jack@suse.cz> SuSE CR Labs [-- Attachment #2: enable-sysrq-2.6.10-rc1-mm1.diff --] [-- Type: text/plain, Size: 7470 bytes --] Implement enabling of specific sysrq functions. Signed-off-by: Jan Kara <jack@suse.cz> diff -ru linux-2.6.10-rc1-mm1/Documentation/sysrq.txt linux-2.6.10-rc1-mm1-sysrq/Documentation/sysrq.txt --- linux-2.6.10-rc1-mm1/Documentation/sysrq.txt 2004-10-29 14:43:29.828759600 +0200 +++ linux-2.6.10-rc1-mm1-sysrq/Documentation/sysrq.txt 2004-10-29 15:05:41.415327672 +0200 @@ -10,13 +10,28 @@ * How do I enable the magic SysRq key? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You need to say "yes" to 'Magic SysRq key (CONFIG_MAGIC_SYSRQ)' when -configuring the kernel. When running on a kernel with SysRq compiled in, it -may be DISABLED at run-time using following command: +configuring the kernel. When running a kernel with SysRq compiled in, +/proc/sys/kernel/sysrq controls the functions allowed to be invoked via +the SysRq key. By default the file contains 1 which means that every +possible SysRq request is allowed (in older versions SysRq was disabled +by default, and you were required to specifically enable it at run-time +but this is not the case any more). Here is the list of possible values +in /proc/sys/kernel/sysrq: + 0 - disable sysrq completely + 1 - enable all functions of sysrq + >1 - bitmask of allowed sysrq functions (see below for detailed function + description): + 2 - enable control of console logging level + 4 - enable control of keyboard (SAK, unraw) + 8 - enable debugging dumps of processes etc. + 16 - enable sync command + 32 - enable remount read-only + 64 - enable signalling of processes (term, kill, oom-kill) + 128 - allow reboot/poweroff + 256 - allow entering KGDB via sysrq - echo "0" > /proc/sys/kernel/sysrq - -Note that previous versions disabled sysrq by default, and you were required -to specifically enable it at run-time. That is not the case any longer. +You can set the value in the file by the following command: + echo "number" >/proc/sys/kernel/sysrq * How do I use the magic SysRq key? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff -ru linux-2.6.10-rc1-mm1/drivers/char/sysrq.c linux-2.6.10-rc1-mm1-sysrq/drivers/char/sysrq.c --- linux-2.6.10-rc1-mm1/drivers/char/sysrq.c 2004-10-29 14:43:33.399216808 +0200 +++ linux-2.6.10-rc1-mm1-sysrq/drivers/char/sysrq.c 2004-10-29 14:59:08.513057896 +0200 @@ -35,6 +35,15 @@ #include <linux/spinlock.h> #include <asm/ptrace.h> + +extern void reset_vc(unsigned int); + +/* Whether we react on sysrq keys or just ignore them */ +int sysrq_enabled = 1; + +/* Machine specific power off function */ +void (*sysrq_power_off)(void); + #ifdef CONFIG_KGDB_SYSRQ #define GDB_OP &kgdb_op @@ -48,21 +57,13 @@ .handler = kgdb_sysrq, .help_msg = "kGdb|Fgdb", .action_msg = "Debug breakpoint\n", + .enable_mask = SYSRQ_ENABLE_BREAKPOINT, }; #else #define GDB_OP NULL #endif - -extern void reset_vc(unsigned int); - -/* Whether we react on sysrq keys or just ignore them */ -int sysrq_enabled = 1; - -/* Machine specific power off function */ -void (*sysrq_power_off)(void); - /* Loglevel sysrq handler */ static void sysrq_handle_loglevel(int key, struct pt_regs *pt_regs, struct tty_struct *tty) @@ -77,6 +78,7 @@ .handler = sysrq_handle_loglevel, .help_msg = "loglevel0-8", .action_msg = "Changing Loglevel", + .enable_mask = SYSRQ_ENABLE_LOG, }; @@ -93,6 +95,7 @@ .handler = sysrq_handle_SAK, .help_msg = "saK", .action_msg = "SAK", + .enable_mask = SYSRQ_ENABLE_KEYBOARD, }; #endif @@ -110,6 +113,7 @@ .handler = sysrq_handle_unraw, .help_msg = "unRaw", .action_msg = "Keyboard mode set to XLATE", + .enable_mask = SYSRQ_ENABLE_KEYBOARD, }; #endif /* CONFIG_VT */ @@ -124,6 +128,7 @@ .handler = sysrq_handle_reboot, .help_msg = "reBoot", .action_msg = "Resetting", + .enable_mask = SYSRQ_ENABLE_BOOT, }; static void sysrq_handle_sync(int key, struct pt_regs *pt_regs, @@ -136,6 +141,7 @@ .handler = sysrq_handle_sync, .help_msg = "Sync", .action_msg = "Emergency Sync", + .enable_mask = SYSRQ_ENABLE_SYNC, }; static void sysrq_handle_mountro(int key, struct pt_regs *pt_regs, @@ -148,6 +154,7 @@ .handler = sysrq_handle_mountro, .help_msg = "Unmount", .action_msg = "Emergency Remount R/O", + .enable_mask = SYSRQ_ENABLE_REMOUNT, }; /* END SYNC SYSRQ HANDLERS BLOCK */ @@ -165,6 +172,7 @@ .handler = sysrq_handle_showregs, .help_msg = "showPc", .action_msg = "Show Regs", + .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -177,6 +185,7 @@ .handler = sysrq_handle_showstate, .help_msg = "showTasks", .action_msg = "Show State", + .enable_mask = SYSRQ_ENABLE_DUMP, }; @@ -189,6 +198,7 @@ .handler = sysrq_handle_showmem, .help_msg = "showMem", .action_msg = "Show Memory", + .enable_mask = SYSRQ_ENABLE_DUMP, }; /* SHOW SYSRQ HANDLERS BLOCK */ @@ -219,6 +229,7 @@ .handler = sysrq_handle_term, .help_msg = "tErm", .action_msg = "Terminate All Tasks", + .enable_mask = SYSRQ_ENABLE_SIGNAL, }; static void sysrq_handle_moom(int key, struct pt_regs *pt_regs, @@ -231,6 +242,7 @@ .handler = sysrq_handle_moom, .help_msg = "Full", .action_msg = "Manual OOM execution", + .enable_mask = SYSRQ_ENABLE_SIGNAL, }; static void sysrq_handle_kill(int key, struct pt_regs *pt_regs, @@ -243,6 +255,7 @@ .handler = sysrq_handle_kill, .help_msg = "kIll", .action_msg = "Kill All Tasks", + .enable_mask = SYSRQ_ENABLE_SIGNAL, }; /* END SIGNAL SYSRQ HANDLERS BLOCK */ @@ -362,9 +375,13 @@ op_p = __sysrq_get_key_op(key); if (op_p) { - printk ("%s\n", op_p->action_msg); - console_loglevel = orig_log_level; - op_p->handler(key, pt_regs, tty); + if (sysrq_enabled == 1 || sysrq_enabled & op_p->enable_mask) { + printk ("%s\n", op_p->action_msg); + console_loglevel = orig_log_level; + op_p->handler(key, pt_regs, tty); + } + else + printk("This sysrq operation is disabled.\n"); } else { printk("HELP : "); /* Only print the help msg once per handler */ diff -ru linux-2.6.10-rc1-mm1/include/linux/sysrq.h linux-2.6.10-rc1-mm1-sysrq/include/linux/sysrq.h --- linux-2.6.10-rc1-mm1/include/linux/sysrq.h 2004-10-18 23:53:06.000000000 +0200 +++ linux-2.6.10-rc1-mm1-sysrq/include/linux/sysrq.h 2004-10-29 15:00:57.528485032 +0200 @@ -16,10 +16,22 @@ struct pt_regs; struct tty_struct; +/* Possible values of bitmask for enabling sysrq functions */ +/* 0x0001 is reserved for enable everything */ +#define SYSRQ_ENABLE_LOG 0x0002 +#define SYSRQ_ENABLE_KEYBOARD 0x0004 +#define SYSRQ_ENABLE_DUMP 0x0008 +#define SYSRQ_ENABLE_SYNC 0x0010 +#define SYSRQ_ENABLE_REMOUNT 0x0020 +#define SYSRQ_ENABLE_SIGNAL 0x0040 +#define SYSRQ_ENABLE_BOOT 0x0080 +#define SYSRQ_ENABLE_BREAKPOINT 0x0100 + struct sysrq_key_op { void (*handler)(int, struct pt_regs *, struct tty_struct *); char *help_msg; char *action_msg; + int enable_mask; }; #ifdef CONFIG_MAGIC_SYSRQ diff -ru linux-2.6.10-rc1-mm1/kernel/power/poweroff.c linux-2.6.10-rc1-mm1-sysrq/kernel/power/poweroff.c --- linux-2.6.10-rc1-mm1/kernel/power/poweroff.c 2004-10-18 23:54:08.000000000 +0200 +++ linux-2.6.10-rc1-mm1-sysrq/kernel/power/poweroff.c 2004-10-29 15:03:01.228679744 +0200 @@ -32,7 +32,8 @@ static struct sysrq_key_op sysrq_poweroff_op = { .handler = handle_poweroff, .help_msg = "powerOff", - .action_msg = "Power Off\n" + .action_msg = "Power Off\n", + .enable_mask = SYSRQ_ENABLE_BOOT, }; static int pm_sysrq_init(void) ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 13:35 ` Jan Kara @ 2004-10-29 13:44 ` Måns Rullgård 2004-10-29 14:33 ` Jan Engelhardt 1 sibling, 0 replies; 20+ messages in thread From: Måns Rullgård @ 2004-10-29 13:44 UTC (permalink / raw) To: Jan Kara; +Cc: linux-kernel, Andrew Morton Jan Kara <jack@suse.cz> writes: >> Andrew Morton <akpm@osdl.org> writes: >> >> > Jan Kara <jack@suse.cz> wrote: >> >> >> >> I know about a few people who would like to use some functionality of >> >> the Magic Sysrq but don't want to enable all the functions it provides. >> > >> > That's a new one. Can you tell us more about why people want to do such a >> > thing? >> > >> >> So I wrote a patch which should allow them to do so. It allows to >> >> configure available functions of Sysrq via /proc/sys/kernel/sysrq (the >> >> interface is backward compatible). If you think it's useful then use it :) >> >> Andrew, do you think it can go into mainline or it's just an overdesign? >> > >> > Patch looks reasonable - we just need to decide whether the requirement >> > warrants its inclusion. >> > >> > There have been a few changes in the sysrq code since 2.6.9 and there are >> > more changes queued up in -mm. The patch applies OK, but it'll need >> > checking and redoing. There's a new `sysrq-f' command in the pipeline >> > which causes a manual oom-killer call. >> >> See also the patch I just posted to lkml. > OK, Andrew, are you accepting the patch? The sysrq should probably go > into SYSRQ_ENABLE_SIGNAL group... Don't miss the update I posted a few minutes later. >> I also thought of an improved way of selecting keys to enable. >> Instead of an arbitrary bitmask, would it be possible to simply list >> the keys you want to enable, such as "echo sku > /proc/sys/kernel/sysrq"? > That would be possible of course but you'd have to do your own > parsing in kernel and you are not supposed to change the sysrq > setting often - usually just compute your favourite number, put it > into boot scripts and you're done. So I'm not convinced it's useful > very much. I'm not likely to use either of them, so I'll leave it to you. -- Måns Rullgård mru@inprovide.com ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 13:35 ` Jan Kara 2004-10-29 13:44 ` Måns Rullgård @ 2004-10-29 14:33 ` Jan Engelhardt 2004-10-29 14:50 ` Jan Kara 1 sibling, 1 reply; 20+ messages in thread From: Jan Engelhardt @ 2004-10-29 14:33 UTC (permalink / raw) To: Jan Kara; +Cc: M?ns Rullg?rd, linux-kernel, Andrew Morton >> >> I know about a few people who would like to use some functionality of >> >> the Magic Sysrq but don't want to enable all the functions it provides. >> > >> > That's a new one. Can you tell us more about why people want to do such a >> > thing? Like me, I only need sysrq's S, U, B and sometimes K ;-) How much space does it take anyway for the other sysrqs? If it's below 8K (arbitrarily chosen limit) then I can live with "all sysrqs" being in. Jan Engelhardt -- Gesellschaft für Wissenschaftliche Datenverarbeitung Am Fassberg, 37077 Göttingen, www.gwdg.de ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 14:33 ` Jan Engelhardt @ 2004-10-29 14:50 ` Jan Kara 2004-10-29 14:53 ` Jan Engelhardt 0 siblings, 1 reply; 20+ messages in thread From: Jan Kara @ 2004-10-29 14:50 UTC (permalink / raw) To: Jan Engelhardt; +Cc: linux-kernel, akpm > >> >> I know about a few people who would like to use some functionality of > >> >> the Magic Sysrq but don't want to enable all the functions it provides. > >> > > >> > That's a new one. Can you tell us more about why people want to do such a > >> > thing? > > Like me, I only need sysrq's S, U, B and sometimes K ;-) > How much space does it take anyway for the other sysrqs? > If it's below 8K (arbitrarily chosen limit) then I can live with "all sysrqs" > being in. It's not about the kernel size but about allowing user to invoke just some functions and not the other (see my other mail). Honza -- Jan Kara <jack@suse.cz> SuSE CR Labs ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 14:50 ` Jan Kara @ 2004-10-29 14:53 ` Jan Engelhardt 2004-11-01 9:09 ` Jan Kara 0 siblings, 1 reply; 20+ messages in thread From: Jan Engelhardt @ 2004-10-29 14:53 UTC (permalink / raw) To: Jan Kara; +Cc: linux-kernel, akpm > It's not about the kernel size but about allowing user to invoke just >some functions and not the other (see my other mail). That's like giving a user m$ windows without the ctrl+alt+del functionality, if you omit considering that either os has a different level of stability. But I like the idea. Maybe a bitmask which can be set via /proc/sys/.../xxx? Jan Engelhardt -- Gesellschaft für Wissenschaftliche Datenverarbeitung Am Fassberg, 37077 Göttingen, www.gwdg.de ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 14:53 ` Jan Engelhardt @ 2004-11-01 9:09 ` Jan Kara 0 siblings, 0 replies; 20+ messages in thread From: Jan Kara @ 2004-11-01 9:09 UTC (permalink / raw) To: Jan Engelhardt; +Cc: linux-kernel, akpm > > > It's not about the kernel size but about allowing user to invoke just > >some functions and not the other (see my other mail). > > That's like giving a user m$ windows without the ctrl+alt+del functionality, > if you omit considering that either os has a different level of stability. Yes. Some of the sysrq are considered insecure - for example OOM kill, which was added lately, can be used to kill some process and I could imagine security implications from cleverly killing syslogd (or some other important process) by it. OTOH some other functionalities are useful and safe... > But I like the idea. Maybe a bitmask which can be set via /proc/sys/.../xxx? And that is exactly what the patch does ;). Honza -- Jan Kara <jack@suse.cz> SuSE CR Labs ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-29 9:39 [PATCH] Configurable Magic Sysrq Jan Kara 2004-10-29 9:46 ` Andrew Morton @ 2004-10-31 18:52 ` Pavel Machek 2004-10-31 19:09 ` Dmitry Torokhov ` (2 more replies) 1 sibling, 3 replies; 20+ messages in thread From: Pavel Machek @ 2004-10-31 18:52 UTC (permalink / raw) To: Jan Kara; +Cc: linux-kernel, akpm Hi! > I know about a few people who would like to use some functionality of > the Magic Sysrq but don't want to enable all the functions it provides. > So I wrote a patch which should allow them to do so. It allows to > configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > interface is backward compatible). If you think it's useful then use it :) > Andrew, do you think it can go into mainline or it's just an overdesign? Actually, there's one more thing that wories me... Original choice of PC hotkey (alt-sysrq-key) works *very* badly on many laptop keyboards. Like sysrq is only recognized with fn, but key is not recognized when you hold fn => you have no chance to use magic sysrq. Perphaps sysrq could be made prefix notation? Like alt-sysrq, release, press s is sync? Pavel -- People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl! ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-31 18:52 ` Pavel Machek @ 2004-10-31 19:09 ` Dmitry Torokhov 2004-10-31 19:44 ` Pavel Machek 2004-10-31 19:12 ` Andreas Schwab 2004-11-01 0:52 ` Tim Connors 2 siblings, 1 reply; 20+ messages in thread From: Dmitry Torokhov @ 2004-10-31 19:09 UTC (permalink / raw) To: linux-kernel; +Cc: Pavel Machek, Jan Kara, akpm On Sunday 31 October 2004 01:52 pm, Pavel Machek wrote: > Hi! > > > I know about a few people who would like to use some functionality of > > the Magic Sysrq but don't want to enable all the functions it provides. > > So I wrote a patch which should allow them to do so. It allows to > > configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > > interface is backward compatible). If you think it's useful then use it :) > > Andrew, do you think it can go into mainline or it's just an overdesign? > > Actually, there's one more thing that wories me... Original choice of > PC hotkey (alt-sysrq-key) works *very* badly on many laptop > keyboards. Like sysrq is only recognized with fn, but key is not > recognized when you hold fn => you have no chance to use magic sysrq. > Actually if I understand it correctly it is Alt-PrtScrn-key - just let go of your "Fn" key and I think it will work fine. At least it does on my laptop. -- Dmitry ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-31 19:09 ` Dmitry Torokhov @ 2004-10-31 19:44 ` Pavel Machek 0 siblings, 0 replies; 20+ messages in thread From: Pavel Machek @ 2004-10-31 19:44 UTC (permalink / raw) To: Dmitry Torokhov; +Cc: linux-kernel, Jan Kara, akpm Hi! > > > I know about a few people who would like to use some functionality of > > > the Magic Sysrq but don't want to enable all the functions it provides. > > > So I wrote a patch which should allow them to do so. It allows to > > > configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > > > interface is backward compatible). If you think it's useful then use it :) > > > Andrew, do you think it can go into mainline or it's just an overdesign? > > > > Actually, there's one more thing that wories me... Original choice of > > PC hotkey (alt-sysrq-key) works *very* badly on many laptop > > keyboards. Like sysrq is only recognized with fn, but key is not > > recognized when you hold fn => you have no chance to use magic sysrq. > > > > Actually if I understand it correctly it is Alt-PrtScrn-key - just let go > of your "Fn" key and I think it will work fine. At least it does on my > laptop. Okay, it looks like I can actually type it on all notebooks here if I try hard enough. On HP machines, the trick is alt,fn,sysrq,releasealtandfn,key. Ouch. The thing that confused me was some SuSE script redirecting messages to other tty, so I saw nothing after magic-9, and assumed I did not press it correctly. Pavel -- People were complaining that M$ turns users into beta-testers... ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl! ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-31 18:52 ` Pavel Machek 2004-10-31 19:09 ` Dmitry Torokhov @ 2004-10-31 19:12 ` Andreas Schwab 2004-11-01 0:52 ` Tim Connors 2 siblings, 0 replies; 20+ messages in thread From: Andreas Schwab @ 2004-10-31 19:12 UTC (permalink / raw) To: Pavel Machek; +Cc: Jan Kara, linux-kernel, akpm Pavel Machek <pavel@suse.cz> writes: > Actually, there's one more thing that wories me... Original choice of > PC hotkey (alt-sysrq-key) works *very* badly on many laptop > keyboards. Like sysrq is only recognized with fn, but key is not > recognized when you hold fn => you have no chance to use magic sysrq. Doesn't it work to release fn (without releasing sysrq) before typing key? Andreas. -- Andreas Schwab, SuSE Labs, schwab@suse.de SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." ^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH] Configurable Magic Sysrq 2004-10-31 18:52 ` Pavel Machek 2004-10-31 19:09 ` Dmitry Torokhov 2004-10-31 19:12 ` Andreas Schwab @ 2004-11-01 0:52 ` Tim Connors 2 siblings, 0 replies; 20+ messages in thread From: Tim Connors @ 2004-11-01 0:52 UTC (permalink / raw) To: Pavel Machek; +Cc: Jan Kara, linux-kernel, akpm Pavel Machek <pavel@suse.cz> said on Sun, 31 Oct 2004 19:52:22 +0100: > Hi! > > > I know about a few people who would like to use some functionality of > > the Magic Sysrq but don't want to enable all the functions it provides. > > So I wrote a patch which should allow them to do so. It allows to > > configure available functions of Sysrq via /proc/sys/kernel/sysrq (the > > interface is backward compatible). If you think it's useful then use it :) > > Andrew, do you think it can go into mainline or it's just an overdesign? > > Actually, there's one more thing that wories me... Original choice of > PC hotkey (alt-sysrq-key) works *very* badly on many laptop > keyboards. Like sysrq is only recognized with fn, but key is not > recognized when you hold fn => you have no chance to use magic sysrq. > > Perphaps sysrq could be made prefix notation? Like alt-sysrq, release, > press s is sync? It seems to already do that for me. What I do have, is some bizzaaro hardware that gives some weird escape keycode for alt-sysreq, so alt-sysreq s,u,b doesn't work. Could be the fact that it is a PS2 keyboard plugged into an old AT style connector, or something else, but I don't know where to start looking to fix it. It's a relatively recent and relatively clean debian install, and I don't know what I did wrong - I noticed this behaviour pretty much from the start. Maybe I'm asking for not just alt to be the prefix, maybe give the choice of ctrl, etc. But I have a feeling ctrl is kinda funky on the console of this machine as well. -- TimC -- http://astronomy.swin.edu.au/staff/tconnors/ ALU n. Arthritic Logic Unit, or (rare) Arithmetic Logic Unit. A random number generator supplied as standard with all computer systems. --unk ^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2004-11-01 9:29 UTC | newest] Thread overview: 20+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2004-10-29 9:39 [PATCH] Configurable Magic Sysrq Jan Kara 2004-10-29 9:46 ` Andrew Morton 2004-10-29 10:17 ` Jan Kara 2004-10-29 10:24 ` Andrew Morton 2004-10-29 20:09 ` Dave Jones 2004-10-30 6:45 ` Olaf Hering 2004-11-01 9:29 ` Jan Kara 2004-10-31 18:59 ` Pavel Machek 2004-10-29 11:34 ` Måns Rullgård 2004-10-29 13:35 ` Jan Kara 2004-10-29 13:44 ` Måns Rullgård 2004-10-29 14:33 ` Jan Engelhardt 2004-10-29 14:50 ` Jan Kara 2004-10-29 14:53 ` Jan Engelhardt 2004-11-01 9:09 ` Jan Kara 2004-10-31 18:52 ` Pavel Machek 2004-10-31 19:09 ` Dmitry Torokhov 2004-10-31 19:44 ` Pavel Machek 2004-10-31 19:12 ` Andreas Schwab 2004-11-01 0:52 ` Tim Connors
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox