forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1009-tools-xenconsole-replace-ESC-char-on-xenconsole-outp.patch
156 lines (141 loc) · 4.97 KB
/
1009-tools-xenconsole-replace-ESC-char-on-xenconsole-outp.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From e952a87a9869f87f8cb6183d7c2d4ab4e5d234f7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Sun, 10 Feb 2019 02:11:50 +0100
Subject: [PATCH] tools/xenconsole: replace ESC char on xenconsole output by
default
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
And add --no-replace-escape option to disable it.
This is done to prevent domU from exploiting hypothetical bug in
terminal emulator.
Add an -r/--no-replace-escape option to xenconsole client to disable
replacing ESC. Carry it from xl command through env variable.
Signed-off-by: Marek Marczykowski-Górecki <[email protected]>
---
tools/console/client/main.c | 21 ++++++++++++++++++---
tools/xl/xl_cmdtable.c | 3 ++-
tools/xl/xl_console.c | 7 ++++++-
3 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/tools/console/client/main.c b/tools/console/client/main.c
index d2dcc3ddcac3..3d6cea805908 100644
--- a/tools/console/client/main.c
+++ b/tools/console/client/main.c
@@ -78,6 +78,7 @@ static void usage(const char *program) {
" --type TYPE console type. must be 'pv', 'serial' or 'vuart'\n"
" --start-notify-fd N file descriptor used to notify parent\n"
" --escape E escape sequence to exit console\n"
+ " -r, --no-replace-escape Do not replace ESC character with dot\n"
, program);
}
@@ -175,7 +176,8 @@ static void restore_term(int fd, struct termios *old)
}
static int console_loop(int fd, struct xs_handle *xs, char *pty_path,
- bool interactive, char escape_character)
+ bool interactive, char escape_character,
+ bool replace_escape)
{
int ret, xs_fd = xs_fileno(xs), max_fd = -1;
@@ -249,6 +251,12 @@ static int console_loop(int fd, struct xs_handle *xs, char *pty_path,
fd = -1;
continue;
}
+ if (replace_escape) {
+ int i;
+ for (i = 0; i < len; i++)
+ if (msg[i] == '\033')
+ msg[i] = '.';
+ }
if (!write_sync(STDOUT_FILENO, msg, len)) {
perror("write() failed");
@@ -325,7 +333,7 @@ int main(int argc, char **argv)
{
struct termios attr;
int domid;
- const char *sopt = "hn:";
+ const char *sopt = "hn:r";
int ch;
unsigned int num = 0;
int opt_ind=0;
@@ -337,6 +345,7 @@ int main(int argc, char **argv)
{ "start-notify-fd", 1, 0, 's' },
{ "interactive", 0, 0, 'i' },
{ "escape", 1, 0, 'e' },
+ { "no-replace-escape", 0, 0, 'r' },
{ 0 },
};
@@ -346,9 +355,13 @@ int main(int argc, char **argv)
char *end;
console_type type = CONSOLE_INVAL;
bool interactive = 0;
+ bool replace_escape = 1;
const char *console_names = "serial, pv, vuart";
char escape_character = DEFAULT_ESCAPE_CHARACTER;
+ if (getenv("XEN_CONSOLE_REPLACE_ESCAPE"))
+ replace_escape = atoi(getenv("XEN_CONSOLE_REPLACE_ESCAPE"));
+
while((ch = getopt_long(argc, argv, sopt, lopt, &opt_ind)) != -1) {
switch(ch) {
case 'h':
@@ -387,6 +400,8 @@ int main(int argc, char **argv)
fprintf(stderr, "Invalid escape argument\n");
exit(EINVAL);
}
+ case 'r':
+ replace_escape = 0;
break;
default:
fprintf(stderr, "Invalid argument\n");
@@ -506,7 +521,7 @@ int main(int argc, char **argv)
close(start_notify_fd);
}
- console_loop(spty, xs, path, interactive, escape_character);
+ console_loop(spty, xs, path, interactive, escape_character, replace_escape);
free(path);
free(dom_path);
diff --git a/tools/xl/xl_cmdtable.c b/tools/xl/xl_cmdtable.c
index 42751228c1d1..2185777525d2 100644
--- a/tools/xl/xl_cmdtable.c
+++ b/tools/xl/xl_cmdtable.c
@@ -142,7 +142,8 @@ const struct cmd_spec cmd_table[] = {
"[options] <Domain>\n"
"-t <type> console type, pv , serial or vuart\n"
"-n <number> console number\n"
- "-e <escape> escape character"
+ "-e <escape> escape character\n"
+ "-r do not replace ESC character with dot"
},
{ "vncviewer",
&main_vncviewer, 0, 0,
diff --git a/tools/xl/xl_console.c b/tools/xl/xl_console.c
index 5633c6f6f7e6..0d8b3e858303 100644
--- a/tools/xl/xl_console.c
+++ b/tools/xl/xl_console.c
@@ -27,10 +27,11 @@ int main_console(int argc, char **argv)
uint32_t domid;
int opt = 0, num = 0;
libxl_console_type type = 0;
+ bool replace_escape = true;
const char *console_names = "pv, serial, vuart";
char* escape_character = NULL;
- SWITCH_FOREACH_OPT(opt, "n:t:e:", NULL, "console", 1) {
+ SWITCH_FOREACH_OPT(opt, "n:t:e:r", NULL, "console", 1) {
case 't':
if (!strcmp(optarg, "pv"))
type = LIBXL_CONSOLE_TYPE_PV;
@@ -48,9 +49,13 @@ int main_console(int argc, char **argv)
break;
case 'e':
escape_character = optarg;
+ case 'r':
+ replace_escape = false;
break;
}
+ setenv("XEN_CONSOLE_REPLACE_ESCAPE", replace_escape ? "1" : "0", 1);
+
domid = find_domain(argv[optind]);
if (!type)
libxl_primary_console_exec(ctx, domid, -1, escape_character);
--
2.44.0