1 |
---------- Forwarded message ---------- |
2 |
From: Alice Ferrazzi <alicef@g.o> |
3 |
Date: Sun, Jun 11, 2017 at 7:28 PM |
4 |
Subject: [GSoC 2017 - week 02] Report summary |
5 |
To: gentoo-soc@l.g.o |
6 |
Cc: Mike Pagano <mpagano@g.o>, Gokturk Yuksek <gokturk@g.o> |
7 |
|
8 |
|
9 |
|
10 |
Hello everyone, |
11 |
Here is my week 02 report summary. |
12 |
|
13 |
Day 04 |
14 |
|
15 |
1-What was my plan for the day? |
16 |
|
17 |
working on kpatch packaging |
18 |
|
19 |
2- Did I achieve it? if not, what do I intend to do to remedy |
20 |
that? |
21 |
|
22 |
Working on fixing the kpatch ebuild pull request. |
23 |
I fixed the license like Gokturk said. |
24 |
but also: |
25 |
fixed metadata.xml indentation |
26 |
sorted lexical |
27 |
Added new line after HOMEPAGE |
28 |
|
29 |
now i'm rebuilding the kernel for testing it again with some |
30 |
new changes |
31 |
|
32 |
3- what will I do next day? |
33 |
Going on on fixing the kpatch package |
34 |
https://github.com/gentoo/gentoo/pull/4844 |
35 |
|
36 |
The next day I will work on the review of the kpatch if there |
37 |
is, trying to package ksplice maybe and making my |
38 |
gitweb.gentoo.org repository. |
39 |
|
40 |
Day 05 |
41 |
|
42 |
1-What was my plan for the day? |
43 |
|
44 |
working on kpatch packaging |
45 |
|
46 |
2- Did I achieve it? if not, what do I intend to do to remedy that? |
47 |
|
48 |
Kpatch is now upstream in the gentoo repository |
49 |
https://github.com/gentoo/gentoo/pull/4844 |
50 |
|
51 |
also created the repository for Gentoo Kernel Live patching system |
52 |
and created the mirror repository on git.gentoo.org |
53 |
|
54 |
now called elivepatch because I thought we can probably use it not |
55 |
only for security patch but also for more general patching. |
56 |
This repository will try to solve the trouble of live patching |
57 |
the kernel on different Gentoo systems. |
58 |
https://github.com/aliceinwire/elivepatch |
59 |
|
60 |
3- what will I do next day? |
61 |
Try to understand how Kpatch works |
62 |
|
63 |
Day 06 |
64 |
|
65 |
1-What was my plan for the day? |
66 |
|
67 |
use kpatch and write some documentation. |
68 |
|
69 |
2- Did I achieve it? if not, what do I intend to do to remedy that? |
70 |
|
71 |
Kpatch examples are bit systemd hardcode dependant but anyway |
72 |
they works. |
73 |
Here kpatch is using systemctl for start kpatch systemd service |
74 |
https://github.com/dynup/kpatch/blob/810f9243826219cca9276d364512bb |
75 |
88411aa863/kpatch/kpatch#L289 |
76 |
Would be nice to make it work also with openrc. |
77 |
I will start making some documentation for Kpatch and add it |
78 |
to the gentoo wiki. |
79 |
|
80 |
|
81 |
3- what will I do next day? |
82 |
Going on on working with kpatch and writing documentation. |
83 |
|
84 |
Day 07 |
85 |
|
86 |
1-What was my plan for the day? |
87 |
|
88 |
use kpatch and write some documentation. |
89 |
|
90 |
2- Did I achieve it? if not, what do I intend to do to remedy that? |
91 |
|
92 |
today I got aware that instead of unset ARCH i could just run |
93 |
set_arch_to_kernel Gentoo script. |
94 |
And that was one of the change of today. |
95 |
I also went on starting to use kpatch and checking that everything |
96 |
is working correctly. |
97 |
Kpatch is actually working correctly, it could load module but I |
98 |
had some problem |
99 |
unloading module |
100 |
|
101 |
kpatch - hot patch module management |
102 |
|
103 |
loading the module: |
104 |
gsoc-2017 testmod (gentoo*) # kpatch load testmod.ko |
105 |
loading patch module: testmod.ko |
106 |
dmesg output: |
107 |
[98196.595313] kpatch: loading out-of-tree module taints kernel. |
108 |
[98196.595329] kpatch: module verification failed: signature and/or |
109 |
required key missing - tainting kernel |
110 |
|
111 |
unloading the module: |
112 |
gsoc-2017 testmod (gentoo*) # kpatch unload testmod.ko |
113 |
kpatch: patch module testmod.ko is not loaded |
114 |
|
115 |
but I could unload correctly using rmmod testmod |
116 |
|
117 |
|
118 |
kpatch list is also working as expected: |
119 |
gsoc-2017 testmod (gentoo*) # kpatch list |
120 |
Loaded patch modules: |
121 |
|
122 |
Installed patch modules: |
123 |
testmod (4.9.16-gentoo) |
124 |
|
125 |
and kpatch info |
126 |
gsoc-2017 testmod (gentoo*) # kpatch info testmod |
127 |
Patch information for testmod: |
128 |
filename: /var/lib/kpatch/4.9.16-gentoo/testmod.ko |
129 |
license: GPL |
130 |
depends: |
131 |
vermagic: 4.9.16-gentoo SMP mod_unload modversions |
132 |
|
133 |
|
134 |
kpatch install and uninstall looks also working but is not sure |
135 |
|
136 |
gsoc-2017 testmod (gentoo*) # kpatch install testmod.ko |
137 |
installing testmod.ko (4.9.16-gentoo) |
138 |
/usr/local/sbin/kpatch: line 289: systemctl: command not found |
139 |
|
140 |
kpatch uninstall testmod.ko |
141 |
uninstalling testmod.ko (4.9.16-gentoo) |
142 |
|
143 |
|
144 |
The problems became more obvious by using kpatch-build |
145 |
kpatch-build is the script for automatically make live patch kernel |
146 |
module from |
147 |
patch files. |
148 |
|
149 |
gsoc-2017 kpatch (master) # kpatch-build -t -v |
150 |
/boot/vmlinuz-4.4.44-gentoo examples/tcp_cubic-better- |
151 |
follow-cubic-curve-converted.patch --skip-gcc-check |
152 |
WARNING: Skipping gcc version matching check (not recommended) |
153 |
ERROR: Unsupported distribution. |
154 |
|
155 |
and that is because is hard checking the distribution from |
156 |
/etc/os-release |
157 |
so I started writing a patch |
158 |
https://github.com/aliceinwire/kpatch/commit/ |
159 |
9f7f236cfe9d4592267a6b08483751ad5a1da069 |
160 |
|
161 |
but others problem come out like claming that some binary is not |
162 |
there |
163 |
I'm thinking that one way to go is by using the -s option Specify |
164 |
kernel source directory |
165 |
gsoc-2017 kpatch (gentoo) # kpatch-build/kpatch-build -t -v |
166 |
/boot/vmlinuz-4.4.44-gentoo examples/tcp_cubic-better- |
167 |
follow-cubic-curve-converted.patch --skip-gcc-check |
168 |
WARNING: Skipping gcc version matching check (not recommended) |
169 |
ERROR: kernel-debuginfo-4.9.16-gentoo not installed. |
170 |
|
171 |
by using -s option is going on with the work but still stopping |
172 |
little after |
173 |
gsoc-2017 kpatch (gentoo) # kpatch-build/kpatch-build -t -s |
174 |
/usr/src/linux-4.9.16-gentoo/vmlinux -v /boot/vmlinuz-4.9.16-gentoo |
175 |
examples/tcp_cubic-better-follow-cubic-curve-converted.patch |
176 |
--skip-gcc-check |
177 |
WARNING: Skipping gcc version matching check (not recommended) |
178 |
ERROR: can't find supporting tools. |
179 |
|
180 |
and this is because of this code |
181 |
The tools mentioned are the TOOLSDIR/SCRIPTDIR |
182 |
118 if [[ -e "$SCRIPTDIR/create-diff-object" ]]; then |
183 |
119 # git repo |
184 |
120 TOOLSDIR="$SCRIPTDIR" |
185 |
121 DATADIR="$(readlink -f $SCRIPTDIR/../kmod)" |
186 |
122 elif [[ -e "$SCRIPTDIR/../libexec/kpatch/create-diff-object" |
187 |
]]; then |
188 |
123 # installation path |
189 |
124 TOOLSDIR="$(readlink -f $SCRIPTDIR/../libexec/kpatch)" |
190 |
125 DATADIR="$(readlink -f $SCRIPTDIR/../share/kpatch)" |
191 |
126 else |
192 |
127 return 1 |
193 |
128 fi |
194 |
|
195 |
SCRIPTDIR="$(readlink -f $(dirname $(type -p $0)))" |
196 |
|
197 |
|
198 |
+ find_dirs |
199 |
+ [[ -e /root/kpatch/kpatch-build/create-diff-object ]] |
200 |
+ [[ -e /root/kpatch/kpatch-build/../libexec/kpatch/create-diff-object |
201 |
]] |
202 |
+ return 1 |
203 |
+ die 'can'\''t find supporting tools' |
204 |
|
205 |
and i'm still investigating this part |
206 |
|
207 |
Yesterday I tried to use some real patch downloaded from linux git |
208 |
and I could load also such patch after converting it with the |
209 |
testing tools in the |
210 |
testing folder of kpatch |
211 |
but other dmesg saying I loaded the patch I couldn't understand |
212 |
what it was doing |
213 |
|
214 |
so would be better to write some fake module by myself with some |
215 |
real output |
216 |
like just adding some printk |
217 |
printk("Module being loaded.\n"); |
218 |
would be enough i susptect |
219 |
|
220 |
after changing the patch file like this |
221 |
|
222 |
--- testmod_drv.c 2017-06-09 02:37:43.980000000 +0000 |
223 |
+++ testmod_drv.c.orig 2017-06-09 02:36:56.100000000 +0000 |
224 |
@@ -11,7 +11,7 @@ int value = 2; |
225 |
static ssize_t value_show(struct kobject *kobj, |
226 |
struct |
227 |
kobj_attribute *attr, char *buf) |
228 |
{ |
229 |
- return sprintf(buf, "%d\n", value+1); |
230 |
+ return sprintf(buf, "%d\n", value); |
231 |
} |
232 |
|
233 |
static struct kobj_attribute testmod_value_attr = |
234 |
__ATTR_RO(value); |
235 |
+ @@ -29,7 +29,6 @@ static int testmod_init(void) |
236 |
+ kobject_put(testmod_kobj); |
237 |
+ return ret; |
238 |
+ } |
239 |
+ - printk("Module being loaded.\n"); |
240 |
+ |
241 |
+ return 0; |
242 |
|
243 |
i could get correctly: |
244 |
[98196.595313] kpatch: loading out-of-tree module taints kernel. |
245 |
[98196.595329] kpatch: module verification failed: signature and/or |
246 |
required key missing - tainting kernel |
247 |
[207928.744194] Module being loaded. |
248 |
|
249 |
|
250 |
generated patch |
251 |
gsoc-2017 testmod (master*) # file testmod.ko |
252 |
testmod.ko: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), |
253 |
BuildID[sha1]=9f7ab4eec1a8ee28b6e0bd7850388aca35da65b6, not stripped, with |
254 |
debug_info |
255 |
|
256 |
gcc-version get checked correctly |
257 |
|
258 |
readelf -p .comment /usr/src/linux-4.9.16-gentoo/vmlinux |
259 |
|
260 |
String dump of section '.comment': |
261 |
[ 0] GCC: (Gentoo 5.4.0-r3 p1.3, pie-0.6.5) 5.4.0 |
262 |
|
263 |
I also wondered if would be nice to try also ksplice but from what |
264 |
i could see |
265 |
looks like ksplice works only for kernel 3.* |
266 |
if this is the case so I don't think is needed for our project |
267 |
as Gentoo Kernel is moving to releasing manly Gentoo kernel 4.* |
268 |
https://github.com/jirislaby/ksplice/issues/7 |
269 |
|
270 |
so in conclusion using kpatch by hand is working as far as I know |
271 |
|
272 |
3- what will I do next day? |
273 |
Going on writing script for making kpatch-build work on Gentoo |
274 |
|
275 |
Day 08 |
276 |
|
277 |
What i have to do today? |
278 |
|
279 |
Going on investigating using kpatch in different machine. |
280 |
|
281 |
What i did today? |
282 |
|
283 |
gsoc-2017 kpatch (gentoo*) # kpatch-build/kpatch-build -s |
284 |
/usr/src/linux-4.9.16-gentoo/ -v /usr/src/linux-4.9.16-gentoo/vmlinux |
285 |
examples/test.patch --skip-gcc-check |
286 |
WARNING: Skipping gcc version matching check (not recommended) |
287 |
Using source directory at /usr/src/linux-4.9.16-gentoo |
288 |
Testing patch file |
289 |
checking file fs/xfs/libxfs/xfs_bmap.c |
290 |
Reading special section data |
291 |
Building original kernel |
292 |
Building patched kernel |
293 |
Extracting new and modified ELF sections |
294 |
xfs_bmap.o: changed function: xfs_bmap_add_extent_hole_real |
295 |
xfs_bmap.o: changed function: xfs_bmap_split_extent_at |
296 |
xfs_bmap.o: changed function: xfs_bmap_add_extent_unwritten_real |
297 |
xfs_bmap.o: changed function: xfs_bmap_add_extent_delay_real |
298 |
xfs_bmap.o: changed function: xfs_bmse_merge.isra.4.constprop.10 |
299 |
xfs_bmap.o: changed function: xfs_bmse_shift_one.constprop.7 |
300 |
xfs_bmap.o: changed function: xfs_bmap_del_extent |
301 |
xfs_bmap.o: changed function: xfs_bmapi_read |
302 |
xfs_bmap.o: changed function: xfs_bmapi_write |
303 |
xfs_bmap.o: changed function: __xfs_bunmapi |
304 |
xfs_bmap.o: changed function: xfs_bmap_shift_extents |
305 |
Patched objects: vmlinux |
306 |
Building patch module: kpatch-test.ko |
307 |
SUCCESS |
308 |
|
309 |
kpatch load kpatch-test.ko |
310 |
dmesg: |
311 |
[Jun 9 22:57] kpatch: tainting kernel with TAINT_LIVEPATCH |
312 |
[ +0.000002] kpatch: loaded patch module 'kpatch_test' |
313 |
|
314 |
looks like is a success for now! |
315 |
|
316 |
I will start to build the patch for a different system |
317 |
|
318 |
So I will set a second Gentoo enviroment with 4.9.16 on qemu |
319 |
|
320 |
* CONFIG_FUNCTION_TRACER must be enabled in the kernel's config file |
321 |
* CONFIG_KALLSYMS_ALL must be enabled in the kernel's config file |
322 |
|
323 |
made the livepatch worker for elivepatch waiting compiling the kernel |
324 |
https://github.com/aliceinwire/elivepatch/blob/master/elivepatch_server/ |
325 |
resources/livepatch.py |
326 |
|
327 |
kernel compile is finished and I moved the kpatch.ko to a different |
328 |
machine |
329 |
and it dosen't work... |
330 |
|
331 |
this are the difference in the two kernel configuration files |
332 |
|
333 |
--- /usr/src/linux/.config 2017-06-10 19:51:48.930000000 +0000 |
334 |
+++ config 2017-06-10 21:01:18.340000000 +0000 |
335 |
@@ -621,7 +621,7 @@ CONFIG_LEGACY_VSYSCALL_EMULATE=y |
336 |
# CONFIG_CMDLINE_BOOL is not set |
337 |
CONFIG_MODIFY_LDT_SYSCALL=y |
338 |
CONFIG_HAVE_LIVEPATCH=y |
339 |
-CONFIG_LIVEPATCH=y |
340 |
+# CONFIG_LIVEPATCH is not set |
341 |
CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y |
342 |
CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y |
343 |
CONFIG_USE_PERCPU_NUMA_NODE_ID=y |
344 |
@@ -3758,7 +3758,11 @@ CONFIG_MESSAGE_LOGLEVEL_DEFAULT=4 |
345 |
# |
346 |
# Compile-time checks and compiler options |
347 |
# |
348 |
-# CONFIG_DEBUG_INFO is not set |
349 |
+CONFIG_DEBUG_INFO=y |
350 |
+# CONFIG_DEBUG_INFO_REDUCED is not set |
351 |
+# CONFIG_DEBUG_INFO_SPLIT is not set |
352 |
+CONFIG_DEBUG_INFO_DWARF4=y |
353 |
+# CONFIG_GDB_SCRIPTS is not set |
354 |
CONFIG_ENABLE_WARN_DEPRECATED=y |
355 |
CONFIG_ENABLE_MUST_CHECK=y |
356 |
CONFIG_FRAME_WARN=2048 |
357 |
|
358 |
|
359 |
ok Let's try with the same kernel config and then give the summary. |
360 |
looks like is failing as same |
361 |
|
362 |
kernel_dev ~ # kpatch load testmod.ko |
363 |
loading core module: /usr/local/lib/kpatch/4.9.16-gentoo/kpatch.ko |
364 |
insmod: ERROR: could not insert module |
365 |
/usr/local/lib/kpatch/4.9.16-gentoo/kpatch.ko: |
366 |
Invalid module format |
367 |
kpatch: failed to load core module |
368 |
|
369 |
|
370 |
Tried to use insmod: |
371 |
[ 883.481889] kpatch: disagrees about version of symbol |
372 |
module_layout |
373 |
[ 940.346754] testmod: loading out-of-tree module taints kernel. |
374 |
[ 940.346767] testmod: module verification failed: signature |
375 |
and/or required key missing - tainting kernel |
376 |
[ 940.346921] Module being loaded. |
377 |
|
378 |
module being loaded. is the correct output of the live patch. |
379 |
|
380 |
about the kpatch ebuild i divided 'make all' in src_compile and 'make |
381 |
install' in src_install |
382 |
on Gokturk suggestion |
383 |
https://github.com/aliceinwire/elivepatch/blob/master/sys-kernel/kpatch/ |
384 |
kpatch-0.4.0.ebuild |
385 |
|
386 |
|
387 |
Different live patch system: |
388 |
kGraft |
389 |
This system of live patching consist in keeping active the old |
390 |
function and the new function and redirect the call to the old function to |
391 |
the new one. |
392 |
Not compatible with 4.x |
393 |
kpatch |
394 |
Is using stop_machine() for halting all the cpu and examine the |
395 |
stack for check that nothing is using the function, and then use ftrace |
396 |
handler for bypass the oldfunction in the new one. |
397 |
Here the problem come with function that are always active and this |
398 |
means that such functions cannot be changed (like irq_thread()). |
399 |
LIVEPATCH |
400 |
Recently introduced in the kernel is similar to kpatch but with |
401 |
less feature. |
402 |
|
403 |
|
404 |
kpatch code module. |
405 |
For each function patched by the module we must: |
406 |
Call stop_machine |
407 |
Ensure that no task has the old function in its call stack |
408 |
Add the new function address to kpatch_func_hash |
409 |
|
410 |
-- |
411 |
アリス フェッラッツィ |
412 |
Alice Ferrazzi |
413 |
|
414 |
Gentoo Kernel Project Leader |
415 |
Mail: Alice Ferrazzi <alicef@g.o> |
416 |
PGP: 2E4E 0856 461C 0585 1336 F496 5621 A6B2 8638 781A |