Skip to contentSkip to conversation

selftests/livepatch: filter 'taints' from dmesg comparison

PATCH In review Joe Lawrence 4 participants 9 messages Nov 6, 2019 – Nov 7, 2019

Subsystems (2)
lore
Share & tools
lore

Joe Lawrence

author maintainer
#0 lore raw

PATCH 1/1 selftests/livepatch: filter 'taints' from dmesg comparison

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

---

Note: I stumbled across this in a testing scenario and thought it might be generally useful to extend this admittedly fragile mechanism. Since there are no related livepatch-core changes, this can go through Shuah's kselftest tree if she prefers. -- Joe

 tools/testing/selftests/livepatch/functions.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/livepatch/functions.sh +1 -1
index 79b0affd21fb..57975c323542 100644
@@ -221,7 +221,7 @@ function check_result {
 	local expect="$*"
 	local result
 
-	result=$(dmesg | grep -v 'tainting' | grep -e 'livepatch:' -e 'test_klp' | sed 's/^\[[ 0-9.]*\] //')
+	result=$(dmesg | grep -ve '\<taints\>' -ve '\<tainting\>' | grep -e 'livepatch:' -e 'test_klp' | sed 's/^\[[ 0-9.]*\] //')
 
 	if [[ "$expect" == "$result" ]] ; then
 		echo "ok"
Signature · 1 line
2.21.0
maintainer
#1 lore raw
Quoted 8 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

That is true, but "tainting kernel with TAINT_LIVEPATCH" should be printed out even in this case. check_modinfo_livepatch() is called for all modules and relies on MODINFO(livepatch, Y).

So either the bug is elsewhere or I need one more cup of tea.

Miroslav

Quoted 27 lines

---

Note: I stumbled across this in a testing scenario and thought it might be generally useful to extend this admittedly fragile mechanism. Since there are no related livepatch-core changes, this can go through Shuah's kselftest tree if she prefers. -- Joe

 tools/testing/selftests/livepatch/functions.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/livepatch/functions.sh +1 -1
index 79b0affd21fb..57975c323542 100644
@@ -221,7 +221,7 @@ function check_result {
 	local expect="$*"
 	local result
 
-	result=$(dmesg | grep -v 'tainting' | grep -e 'livepatch:' -e 'test_klp' | sed 's/^\[[ 0-9.]*\] //')
+	result=$(dmesg | grep -ve '\<taints\>' -ve '\<tainting\>' | grep -e 'livepatch:' -e 'test_klp' | sed 's/^\[[ 0-9.]*\] //')
 
 	if [[ "$expect" == "$result" ]] ; then
 		echo "ok"
Signature · 1 line
2.21.0
author maintainer
#2 lore raw
Quoted 7 lines · Miroslav Benes
Quoted 5 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Quoted 9 lines
Quoted 3 lines

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

That is true, but "tainting kernel with TAINT_LIVEPATCH" should be printed out even in this case. check_modinfo_livepatch() is called for all modules and relies on MODINFO(livepatch, Y).

Quoted 1 line

So either the bug is elsewhere or I need one more cup of tea.

I'm only half a cup in this morning myself, but...

In my scenario, I saw in the kernel log:

% modprobe test_klp_livepatch
test_klp_livepatch: loading out-of-tree module taints kernel.
test_klp_livepatch: module verification failed: signature and/or
required key missing - tainting kernel
...

and because check_result() only removes 'tainting' with grep -v, the expected log message failed to match with the actual filtered message because of the first 'taints' message.

So this change just adds more to the filtered out strings:

result = dmesg | grep -v <filtered out strings> | grep <interesting
strings>

BTW, none of the callers of check_result() bother to include either taint message since I think they are only ever emitted on the first occurance.

-- Joe

maintainer Acked-by
#3 lore raw
Quoted 8 lines · Joe Lawrence
Quoted 7 lines · Miroslav Benes
Quoted 5 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

That is true, but "tainting kernel with TAINT_LIVEPATCH" should be printed out even in this case. check_modinfo_livepatch() is called for all modules and relies on MODINFO(livepatch, Y).

Quoted 1 line

So either the bug is elsewhere or I need one more cup of tea.

Ok, the above is not relevant here.

I'm only wondering about the execution steps, because supporting modules lib/livepatch/ should be built as in-tree. No?

Quoted 9 lines

I'm only half a cup in this morning myself, but...

In my scenario, I saw in the kernel log:

% modprobe test_klp_livepatch
test_klp_livepatch: loading out-of-tree module taints kernel.
test_klp_livepatch: module verification failed: signature and/or
required key missing - tainting kernel
...

So modprobe here should not print anything like this.

Quoted 8 lines

and because check_result() only removes 'tainting' with grep -v, the expected log message failed to match with the actual filtered message because of the first 'taints' message.

So this change just adds more to the filtered out strings:

result = dmesg | grep -v <filtered out strings> | grep <interesting
strings>

The code is definitely correct. You can add my

M

author maintainer
#4 lore raw
Quoted 19 lines · Miroslav Benes
Quoted 8 lines · Joe Lawrence
Quoted 7 lines · Miroslav Benes
Quoted 5 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

That is true, but "tainting kernel with TAINT_LIVEPATCH" should be printed out even in this case. check_modinfo_livepatch() is called for all modules and relies on MODINFO(livepatch, Y).

Quoted 1 line

So either the bug is elsewhere or I need one more cup of tea.

Quoted 5 lines

Ok, the above is not relevant here.

I'm only wondering about the execution steps, because supporting modules lib/livepatch/ should be built as in-tree. No?

Ah, I see. Well as you noted they are modprobed, so theoretically they could come from anywhere OOT, right?

In my test, I had a kernel tree, but only wanted to build the test modules. Once I did a 'make modules SUBDIR=' or 'make M= ...' KBUILD_EXTMOD got flipped on and the modules lost in-tree status. No amount of googling could tell me how to build a single in-tree directory of modules :( And then it seemed that opening the tests for OOT modules was reasonable anyway.

-- Joe

maintainer
#5 lore raw
Quoted 20 lines · Joe Lawrence
Quoted 19 lines · Miroslav Benes
Quoted 16 lines · Joe Lawrence
Quoted 15 lines · Miroslav Benes
Quoted 8 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

That is true, but "tainting kernel with TAINT_LIVEPATCH" should be printed out even in this case. check_modinfo_livepatch() is called for all modules and relies on MODINFO(livepatch, Y).

Quoted 1 line

So either the bug is elsewhere or I need one more cup of tea.

Quoted 8 lines
Quoted 5 lines

Ok, the above is not relevant here.

I'm only wondering about the execution steps, because supporting modules lib/livepatch/ should be built as in-tree. No?

Ah, I see. Well as you noted they are modprobed, so theoretically they could come from anywhere OOT, right?

Yes.

Quoted 4 lines

In my test, I had a kernel tree, but only wanted to build the test modules. Once I did a 'make modules SUBDIR=' or 'make M= ...' KBUILD_EXTMOD got flipped on and the modules lost in-tree status. No amount of googling could tell me how to build a single in-tree directory of modules :(

"make lib/livepatch/test_klp_livepatch.ko" should do the trick. "make lib/livepatch/" only builds the object files and I haven't found a way to make it link .ko modules other than specifying them one by one directly.

Quoted 2 lines

And then it seemed that
opening the tests for OOT modules was reasonable anyway.

That's an interesting idea. If a module is in tree, it is under our control. So we know what "testing capabilities" it offers. I guess that with OOT testing modules the selftests would have to be smarter.

Miroslav

author maintainer
#6 lore raw
Quoted 9 lines · Miroslav Benes
Quoted 4 lines

In my test, I had a kernel tree, but only wanted to build the test modules. Once I did a 'make modules SUBDIR=' or 'make M= ...' KBUILD_EXTMOD got flipped on and the modules lost in-tree status. No amount of googling could tell me how to build a single in-tree directory of modules :(

"make lib/livepatch/test_klp_livepatch.ko" should do the trick. "make lib/livepatch/" only builds the object files and I haven't found a way to make it link .ko modules other than specifying them one by one directly.

Forgot to mention that this works too, but I was looking to script it and not have each .ko hardcoded in a series of make commands. Anyway, it's a strange use-case and it was something I was only cooking up for an in-house continuous testing scenario.

Quoted 7 lines
Quoted 2 lines

And then it seemed that
opening the tests for OOT modules was reasonable anyway.

That's an interesting idea. If a module is in tree, it is under our control. So we know what "testing capabilities" it offers. I guess that with OOT testing modules the selftests would have to be smarter.

It would probably go hand in hand with custom test scripts that would understand the OOT module capabilities, I think. I doubt anyone will try it (besides me), but the grep filter was there and it was an easy tweak.

-- Joe

Reviewed-by on v1 1/1
#7 lore raw
In reply to Joe Lawrence
Quoted 10 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

Signature · 1 line
Kamalesh
maintainer Reviewed-by on v1 1/1
#8 lore raw
In reply to Joe Lawrence
Quoted 8 lines · Joe Lawrence

The livepatch selftests compare expected dmesg output to verify kernel behavior. They currently filter out "tainting kernel with TAINT_LIVEPATCH" messages which may be logged when loading livepatch modules.

Further filter the log to also drop "loading out-of-tree module taints kernel" messages in case the klp_test modules have been build without the in-tree module flag.

It needs a special way how to build the selftest modules. But it is clearly possible.

Quoted 1 line
Quoted 4 lines

---

Since there are no related livepatch-core changes, this can go through Shuah's kselftest tree if she prefers.

Shuah, would you like to take it via kselftest tree, please?

Or I could add it into livepatch tree if you would prefer it.

Best Regards,
Petr