2016-05-17 22:40:10 +00:00
|
|
|
Subject: net: sysrq via icmp
|
|
|
|
From: Carsten Emde <C.Emde@osadl.org>
|
|
|
|
Date: Tue, 19 Jul 2011 13:51:17 +0100
|
2018-01-05 09:53:38 +00:00
|
|
|
Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/4.14/older/patches-4.14.8-rt9.tar.xz
|
2016-05-17 22:40:10 +00:00
|
|
|
|
|
|
|
There are (probably rare) situations when a system crashed and the system
|
|
|
|
console becomes unresponsive but the network icmp layer still is alive.
|
|
|
|
Wouldn't it be wonderful, if we then could submit a sysreq command via ping?
|
|
|
|
|
|
|
|
This patch provides this facility. Please consult the updated documentation
|
|
|
|
Documentation/sysrq.txt for details.
|
|
|
|
|
|
|
|
Signed-off-by: Carsten Emde <C.Emde@osadl.org>
|
|
|
|
|
|
|
|
---
|
2017-06-18 17:14:20 +00:00
|
|
|
Documentation/admin-guide/sysrq.rst | 12 ++++++++++++
|
|
|
|
include/net/netns/ipv4.h | 1 +
|
|
|
|
net/ipv4/icmp.c | 30 ++++++++++++++++++++++++++++++
|
|
|
|
net/ipv4/sysctl_net_ipv4.c | 7 +++++++
|
|
|
|
4 files changed, 50 insertions(+)
|
2016-05-17 22:40:10 +00:00
|
|
|
|
2017-06-18 17:14:20 +00:00
|
|
|
--- a/Documentation/admin-guide/sysrq.rst
|
|
|
|
+++ b/Documentation/admin-guide/sysrq.rst
|
|
|
|
@@ -77,6 +77,18 @@ On all
|
2016-05-17 22:40:10 +00:00
|
|
|
|
|
|
|
echo t > /proc/sysrq-trigger
|
|
|
|
|
2017-06-18 17:14:20 +00:00
|
|
|
+On all
|
|
|
|
+ Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.::
|
2016-05-17 22:40:10 +00:00
|
|
|
+
|
2017-06-18 17:14:20 +00:00
|
|
|
+ echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
|
2016-05-17 22:40:10 +00:00
|
|
|
+
|
2017-06-18 17:14:20 +00:00
|
|
|
+ Send an ICMP echo request with this pattern plus the particular
|
|
|
|
+ SysRq command key. Example::
|
|
|
|
+
|
|
|
|
+ ping -c1 -s57 -p0102030468
|
|
|
|
+
|
|
|
|
+ will trigger the SysRq-H (help) command.
|
|
|
|
+
|
|
|
|
What are the 'command' keys?
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2016-05-17 22:40:10 +00:00
|
|
|
--- a/include/net/netns/ipv4.h
|
|
|
|
+++ b/include/net/netns/ipv4.h
|
2017-06-18 17:14:20 +00:00
|
|
|
@@ -79,6 +79,7 @@ struct netns_ipv4 {
|
2016-05-17 22:40:10 +00:00
|
|
|
|
|
|
|
int sysctl_icmp_echo_ignore_all;
|
|
|
|
int sysctl_icmp_echo_ignore_broadcasts;
|
|
|
|
+ int sysctl_icmp_echo_sysrq;
|
|
|
|
int sysctl_icmp_ignore_bogus_error_responses;
|
|
|
|
int sysctl_icmp_ratelimit;
|
|
|
|
int sysctl_icmp_ratemask;
|
|
|
|
--- a/net/ipv4/icmp.c
|
|
|
|
+++ b/net/ipv4/icmp.c
|
|
|
|
@@ -69,6 +69,7 @@
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
+#include <linux/sysrq.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/inet.h>
|
2017-11-20 14:16:49 +00:00
|
|
|
@@ -915,6 +916,30 @@ static bool icmp_redirect(struct sk_buff
|
2016-05-17 22:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
+ * 32bit and 64bit have different timestamp length, so we check for
|
|
|
|
+ * the cookie at offset 20 and verify it is repeated at offset 50
|
|
|
|
+ */
|
|
|
|
+#define CO_POS0 20
|
|
|
|
+#define CO_POS1 50
|
|
|
|
+#define CO_SIZE sizeof(int)
|
|
|
|
+#define ICMP_SYSRQ_SIZE 57
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
+ * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
|
|
|
|
+ * pattern and if it matches send the next byte as a trigger to sysrq.
|
|
|
|
+ */
|
|
|
|
+static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
|
|
|
|
+{
|
|
|
|
+ int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
|
|
|
|
+ char *p = skb->data;
|
|
|
|
+
|
|
|
|
+ if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
|
|
|
|
+ !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
|
|
|
|
+ p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
|
|
|
|
+ handle_sysrq(p[CO_POS0 + CO_SIZE]);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/*
|
|
|
|
* Handle ICMP_ECHO ("ping") requests.
|
|
|
|
*
|
|
|
|
* RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
|
2017-11-20 14:16:49 +00:00
|
|
|
@@ -941,6 +966,11 @@ static bool icmp_echo(struct sk_buff *sk
|
2016-05-17 22:40:10 +00:00
|
|
|
icmp_param.data_len = skb->len;
|
|
|
|
icmp_param.head_len = sizeof(struct icmphdr);
|
|
|
|
icmp_reply(&icmp_param, skb);
|
|
|
|
+
|
|
|
|
+ if (skb->len == ICMP_SYSRQ_SIZE &&
|
|
|
|
+ net->ipv4.sysctl_icmp_echo_sysrq) {
|
|
|
|
+ icmp_check_sysrq(net, skb);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
/* should there be an ICMP stat for ignored echos? */
|
|
|
|
return true;
|
|
|
|
--- a/net/ipv4/sysctl_net_ipv4.c
|
|
|
|
+++ b/net/ipv4/sysctl_net_ipv4.c
|
2017-11-20 14:16:49 +00:00
|
|
|
@@ -772,6 +772,13 @@ static struct ctl_table ipv4_net_table[]
|
2016-05-17 22:40:10 +00:00
|
|
|
.proc_handler = proc_dointvec
|
|
|
|
},
|
|
|
|
{
|
|
|
|
+ .procname = "icmp_echo_sysrq",
|
|
|
|
+ .data = &init_net.ipv4.sysctl_icmp_echo_sysrq,
|
|
|
|
+ .maxlen = sizeof(int),
|
|
|
|
+ .mode = 0644,
|
|
|
|
+ .proc_handler = proc_dointvec
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
.procname = "icmp_ignore_bogus_error_responses",
|
|
|
|
.data = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
|
|
|
|
.maxlen = sizeof(int),
|