This repository was archived by the owner on May 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathconfigure-hypervisor.sh
More file actions
executable file
·398 lines (306 loc) · 9.94 KB
/
configure-hypervisor.sh
File metadata and controls
executable file
·398 lines (306 loc) · 9.94 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
#!/bin/bash
# Copyright (c) 2017-2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#---------------------------------------------------------------------
# Description: This script is the *ONLY* place where "qemu*" build options
# should be defined.
#
# Note to maintainers:
#
# XXX: Every option group *MUST* be documented explaining why it has
# been specified.
#---------------------------------------------------------------------
script_name=${0##*/}
typeset -A recognised_tags
recognised_tags=(
[arch]="architecture-specific"
[minimal]="specified to avoid building unnecessary elements"
[misc]="miscellaneous"
[security]="specified for security reasons"
[size]="minimise binary size"
[speed]="maximise startup speed"
)
# Display message to stderr and exit indicating script failed.
die()
{
local msg="$*"
echo >&2 "$script_name: ERROR: $msg"
exit 1
}
# Display usage to stdout.
usage()
{
cat <<EOT
Overview:
Display configure options required to build the specified
hypervisor.
Usage:
$script_name [options] <hypervisor-name>
Options:
-d : Dump all options along with the tags explaining why each option
is specified.
-h : Display this help.
-m : Display options one per line (includes continuation characters).
Example:
$ $script_name qemu-lite
EOT
}
show_tags_header()
{
local keys
local key
local value
cat <<EOT
# Recognised option tags:
#
EOT
# sort the tags
keys=${!recognised_tags[@]}
keys=$(echo "$keys"|tr ' ' '\n'|sort -u)
for key in $keys
do
value="${recognised_tags[$key]}"
printf "# %s\t%s.\n" "$key" "$value"
done
printf "#\n\n"
}
check_tag()
{
local tag="$1"
local entry="$2"
value="${recognised_tags[$tag]}"
[ -n "$value" ] && return
die "invalid tag '$tag' found for entry '$entry'"
}
check_tags()
{
local tags="$1"
local entry="$2"
[ -z "$tags" ] && die "entry '$entry' doesn't have any tags"
tags=$(echo "$tags"|tr ',' '\n')
for tag in $tags
do
check_tag "$tag" "$entry"
done
}
# Display an array to stdout.
#
# If 2 arguments are specified, split array across multiple lines,
# one per element with a backslash at the end of all lines except
# the last.
#
# Arguments:
#
# $1: *Name* of array variable (no leading '$'!!)
# $2: (optional) "multi" - show values across multiple lines,
# "dump" - show full hash values. Any other value results in the
# options being displayed on a single line.
show_array()
{
local -n _array="$1"
local action="$2"
local -i size="${#_array[*]}"
local -i i=1
local entry
local tags
local elem
local suffix
local one_line="no"
[ "$action" = "dump" ] && show_tags_header
for entry in "${_array[@]}"
do
tags=$(echo "$entry"|cut -s -d: -f1)
elem=$(echo "$entry"|cut -s -d: -f2-)
check_tags "$tags" "$entry"
if [ "$action" = "dump" ]
then
printf "%s\t\t%s\n" "$tags" "$elem"
elif [ "$action" = "multi" ]
then
if [ $i -eq $size ]
then
suffix=""
else
suffix=" \\"
fi
printf '%s%s\n' "$elem" "$suffix"
else
one_line="yes"
echo -n "$elem "
fi
i+=1
done
[ "$one_line" = yes ] && echo
}
# Entry point
main()
{
arch=$(arch)
# Array of configure options.
#
# Each element is comprised of two parts in the form:
#
# tags:option
#
# Where,
#
# - 'tags' is a comma-separated list of values which denote why
# the option is being specified.
#
# - 'option' is the hypervisor configuration option.
typeset -a qemu_options
action=""
while getopts "dhm" opt
do
case "$opt" in
d)
action="dump"
;;
h)
usage
exit 0
;;
m)
action="multi"
;;
esac
done
shift $[$OPTIND-1]
[ -z "$1" ] && die "need hypervisor name"
hypervisor="$1"
#---------------------------------------------------------------------
# Disabled options
# bluetooth support not required
qemu_options+=(size:--disable-bluez)
# braille support not required
qemu_options+=(size:--disable-brlapi)
# Don't build documentation
qemu_options+=(minimal:--disable-docs)
# Disable GUI (graphics)
qemu_options+=(size:--disable-curses)
qemu_options+=(size:--disable-gtk)
qemu_options+=(size:--disable-opengl)
qemu_options+=(size:--disable-sdl)
qemu_options+=(size:--disable-spice)
qemu_options+=(size:--disable-vte)
# Disable graphical network access
qemu_options+=(size:--disable-vnc)
qemu_options+=(size:--disable-vnc-jpeg)
qemu_options+=(size:--disable-vnc-png)
qemu_options+=(size:--disable-vnc-sasl)
# Disable unused filesystem support
qemu_options+=(size:--disable-fdt)
qemu_options+=(size:--disable-glusterfs)
qemu_options+=(size:--disable-libiscsi)
qemu_options+=(size:--disable-libnfs)
qemu_options+=(size:--disable-libssh2)
qemu_options+=(size:--disable-rbd)
# Disable unused compression support
qemu_options+=(size:--disable-bzip2)
qemu_options+=(size:--disable-lzo)
qemu_options+=(size:--disable-snappy)
# Disable unused security options
qemu_options+=(security:--disable-seccomp)
qemu_options+=(security:--disable-tpm)
# Disable userspace network access ("-net user")
qemu_options+=(size:--disable-slirp)
# Disable USB
qemu_options+=(size:--disable-libusb)
qemu_options+=(size:--disable-usb-redir)
# Don't build a static binary (lowers security)
qemu_options+=(security:--disable-static)
# Not required as "-uuid ..." is always passed to the qemu binary
qemu_options+=(size:--disable-uuid)
# Disable debug
qemu_options+=(size:--disable-debug-tcg)
qemu_options+=(size:--disable-qom-cast-debug)
qemu_options+=(size:--disable-tcg-interpreter)
qemu_options+=(size:--disable-tcmalloc)
# Disallow network downloads
qemu_options+=(security:--disable-curl)
# Disable Remote Direct Memory Access (Live Migration)
# https://wiki.qemu.org/index.php/Features/RDMALiveMigration
qemu_options+=(size:--disable-rdma)
# Don't build the qemu-io, qemu-nbd and qemu-image tools
qemu_options+=(size:--disable-tools)
# Disable XEN driver
qemu_options+=(size:--disable-xen)
# FIXME: why is this disabled?
# (for reference, it's explicitly enabled in Ubuntu 17.10 and
# implicitly enabled in Fedora 27).
qemu_options+=(size:--disable-linux-aio)
# In "passthrough" security mode
# (-fsdev "...,security_model=passthrough,..."), qemu uses a helper
# application called virtfs-proxy-helper(1) to make certain 9p
# operations safer. We don't need that, so disable it (and it's
# dependencies).
qemu_options+=(size:--disable-virtfs)
qemu_options+=(size:--disable-attr)
qemu_options+=(size:--disable-cap-ng)
#---------------------------------------------------------------------
# Enabled options
# Enable kernel Virtual Machine support.
# This is the default, but be explicit to avoid any future surprises
qemu_options+=(speed:--enable-kvm)
# Required for fast network access
qemu_options+=(speed:--enable-vhost-net)
# Always strip binaries
qemu_options+=(size:--enable-strip)
#---------------------------------------------------------------------
# Other options
# 64-bit only
[ "$arch" = x86_64 ] && qemu_options+=(arch:"--target-list=${arch}-softmmu")
_qemu_cflags=""
# compile with high level of optimisation
_qemu_cflags+=" -O3"
# Improve code quality by assuming identical semantics for interposed
# synmbols.
_qemu_cflags+=" -fno-semantic-interposition"
# Performance optimisation
_qemu_cflags+=" -falign-functions=32"
# SECURITY: make the compiler check for common security issues
# (such as argument and buffer overflows checks).
_qemu_cflags+=" -D_FORTIFY_SOURCE=2"
# SECURITY: Create binary as a Position Independant Executable,
# and take advantage of ASLR, making ROP attacks much harder to perform.
# (https://wiki.debian.org/Hardening)
_qemu_cflags+=" -fPIE"
# Set compile options
qemu_options+=(security,speed,size:"--extra-cflags=\"${_qemu_cflags}\"")
unset _qemu_cflags
_qemu_ldflags=""
# SECURITY: Link binary as a Position Independant Executable,
# and take advantage of ASLR, making ROP attacks much harder to perform.
# (https://wiki.debian.org/Hardening)
_qemu_ldflags+=" -pie"
# SECURITY: Disallow executing code on the stack.
_qemu_ldflags+=" -z noexecstack"
# SECURITY: Make the linker set some program sections to read-only
# before the program is run to stop certain attacks.
_qemu_ldflags+=" -z relro"
# SECURITY: Make the linker resolve all symbols immediately on program
# load.
_qemu_ldflags+=" -z now"
qemu_options+=(security:"--extra-ldflags=\"${_qemu_ldflags}\"")
unset _qemu_ldflags
# Where to install qemu libraries
[ "$arch" = x86_64 ] && qemu_options+=(arch:--libdir=/usr/lib64/${hypervisor})
# Where to install qemu helper binaries
qemu_options+=(misc:--libexecdir=/usr/libexec/${hypervisor})
# Where to install data files
qemu_options+=(misc:--datadir=/usr/share/${hypervisor})
show_array qemu_options "$action"
exit 0
}
main $@