]> rtime.felk.cvut.cz Git - hercules2020/nv-tegra/linux-4.4.git/blob - rt-patches/0195-net-sysrq-via-icmp.patch
Fix memguard and related syscalls
[hercules2020/nv-tegra/linux-4.4.git] / rt-patches / 0195-net-sysrq-via-icmp.patch
1 From 0448f4e7b9daf6d126b8ea920d871cd4a03a7806 Mon Sep 17 00:00:00 2001
2 From: Carsten Emde <C.Emde@osadl.org>
3 Date: Tue, 19 Jul 2011 13:51:17 +0100
4 Subject: [PATCH 195/366] net: sysrq via icmp
5
6 There are (probably rare) situations when a system crashed and the system
7 console becomes unresponsive but the network icmp layer still is alive.
8 Wouldn't it be wonderful, if we then could submit a sysreq command via ping?
9
10 This patch provides this facility. Please consult the updated documentation
11 Documentation/sysrq.txt for details.
12
13 Signed-off-by: Carsten Emde <C.Emde@osadl.org>
14 ---
15  Documentation/sysrq.txt    | 11 +++++++++--
16  include/net/netns/ipv4.h   |  1 +
17  net/ipv4/icmp.c            | 30 ++++++++++++++++++++++++++++++
18  net/ipv4/sysctl_net_ipv4.c |  7 +++++++
19  4 files changed, 47 insertions(+), 2 deletions(-)
20
21 diff --git a/Documentation/sysrq.txt b/Documentation/sysrq.txt
22 index 13f5619..f64d075 100644
23 --- a/Documentation/sysrq.txt
24 +++ b/Documentation/sysrq.txt
25 @@ -59,10 +59,17 @@ On PowerPC - Press 'ALT - Print Screen (or F13) - <command key>,
26  On other - If you know of the key combos for other architectures, please
27             let me know so I can add them to this section.
28  
29 -On all -  write a character to /proc/sysrq-trigger.  e.g.:
30 -
31 +On all -  write a character to /proc/sysrq-trigger, e.g.:
32                 echo t > /proc/sysrq-trigger
33  
34 +On all - Enable network SysRq by writing a cookie to icmp_echo_sysrq, e.g.
35 +               echo 0x01020304 >/proc/sys/net/ipv4/icmp_echo_sysrq
36 +        Send an ICMP echo request with this pattern plus the particular
37 +        SysRq command key. Example:
38 +               # ping -c1 -s57 -p0102030468
39 +        will trigger the SysRq-H (help) command.
40 +
41 +
42  *  What are the 'command' keys?
43  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
44  'b'     - Will immediately reboot the system without syncing or unmounting
45 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
46 index c68926b..dd0751e 100644
47 --- a/include/net/netns/ipv4.h
48 +++ b/include/net/netns/ipv4.h
49 @@ -70,6 +70,7 @@ struct netns_ipv4 {
50  
51         int sysctl_icmp_echo_ignore_all;
52         int sysctl_icmp_echo_ignore_broadcasts;
53 +       int sysctl_icmp_echo_sysrq;
54         int sysctl_icmp_ignore_bogus_error_responses;
55         int sysctl_icmp_ratelimit;
56         int sysctl_icmp_ratemask;
57 diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
58 index ef2d432..288d20f 100644
59 --- a/net/ipv4/icmp.c
60 +++ b/net/ipv4/icmp.c
61 @@ -69,6 +69,7 @@
62  #include <linux/jiffies.h>
63  #include <linux/kernel.h>
64  #include <linux/fcntl.h>
65 +#include <linux/sysrq.h>
66  #include <linux/socket.h>
67  #include <linux/in.h>
68  #include <linux/inet.h>
69 @@ -893,6 +894,30 @@ static bool icmp_redirect(struct sk_buff *skb)
70  }
71  
72  /*
73 + * 32bit and 64bit have different timestamp length, so we check for
74 + * the cookie at offset 20 and verify it is repeated at offset 50
75 + */
76 +#define CO_POS0                20
77 +#define CO_POS1                50
78 +#define CO_SIZE                sizeof(int)
79 +#define ICMP_SYSRQ_SIZE        57
80 +
81 +/*
82 + * We got a ICMP_SYSRQ_SIZE sized ping request. Check for the cookie
83 + * pattern and if it matches send the next byte as a trigger to sysrq.
84 + */
85 +static void icmp_check_sysrq(struct net *net, struct sk_buff *skb)
86 +{
87 +       int cookie = htonl(net->ipv4.sysctl_icmp_echo_sysrq);
88 +       char *p = skb->data;
89 +
90 +       if (!memcmp(&cookie, p + CO_POS0, CO_SIZE) &&
91 +           !memcmp(&cookie, p + CO_POS1, CO_SIZE) &&
92 +           p[CO_POS0 + CO_SIZE] == p[CO_POS1 + CO_SIZE])
93 +               handle_sysrq(p[CO_POS0 + CO_SIZE]);
94 +}
95 +
96 +/*
97   *     Handle ICMP_ECHO ("ping") requests.
98   *
99   *     RFC 1122: 3.2.2.6 MUST have an echo server that answers ICMP echo
100 @@ -919,6 +944,11 @@ static bool icmp_echo(struct sk_buff *skb)
101                 icmp_param.data_len        = skb->len;
102                 icmp_param.head_len        = sizeof(struct icmphdr);
103                 icmp_reply(&icmp_param, skb);
104 +
105 +               if (skb->len == ICMP_SYSRQ_SIZE &&
106 +                   net->ipv4.sysctl_icmp_echo_sysrq) {
107 +                       icmp_check_sysrq(net, skb);
108 +               }
109         }
110         /* should there be an ICMP stat for ignored echos? */
111         return true;
112 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
113 index 4612336..123ffd6 100644
114 --- a/net/ipv4/sysctl_net_ipv4.c
115 +++ b/net/ipv4/sysctl_net_ipv4.c
116 @@ -840,6 +840,13 @@ static struct ctl_table ipv4_net_table[] = {
117                 .proc_handler   = proc_dointvec
118         },
119         {
120 +               .procname       = "icmp_echo_sysrq",
121 +               .data           = &init_net.ipv4.sysctl_icmp_echo_sysrq,
122 +               .maxlen         = sizeof(int),
123 +               .mode           = 0644,
124 +               .proc_handler   = proc_dointvec
125 +       },
126 +       {
127                 .procname       = "icmp_ignore_bogus_error_responses",
128                 .data           = &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
129                 .maxlen         = sizeof(int),
130 -- 
131 1.9.1
132