* [LTP] [PATCH v2] sysctl01: fix fails on live-patched kernels
@ 2019-03-07 18:37 Jan Baier
2019-03-08 11:58 ` Petr Vorel
0 siblings, 1 reply; 3+ messages in thread
From: Jan Baier @ 2019-03-07 18:37 UTC (permalink / raw)
To: ltp
During live-patching, the uname syscall is overridden to reflect the
fact that the kernel has been live-patched. The version string
obtainable through /proc/sys/kernel/version is defined during
compilation and it is not touched by the live-patch. In this case, the
two interfaces can report different kernel versions.
Adjust the string from uname in such cases and remove the tag added
during live-patching.
Signed-off-by: Jan Baier <jbaier@suse.cz>
---
testcases/kernel/syscalls/sysctl/sysctl01.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git testcases/kernel/syscalls/sysctl/sysctl01.c testcases/kernel/syscalls/sysctl/sysctl01.c
index 70905d806..9b4b1950c 100644
--- testcases/kernel/syscalls/sysctl/sysctl01.c
+++ testcases/kernel/syscalls/sysctl/sysctl01.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) International Business Machines Corp., 2001
* Copyright (c) 2018 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) 2019 SUSE. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -77,6 +78,19 @@ static void setup(void)
/* get kernel name and information */
if (uname(&buf) == -1)
tst_brk(TBROK | TERRNO, "uname() failed");
+
+ /* revert uname change in case of kGraft/livepatch */
+ char *klp_tag;
+ char *right_brace;
+
+ klp_tag = strstr(buf.version, "/kGraft-");
+ if (!klp_tag)
+ klp_tag = strstr(buf.version, "/lp-");
+ if (klp_tag) {
+ right_brace = strchr(klp_tag, ')');
+ if (right_brace)
+ memmove(klp_tag, right_brace, sizeof(char) * (strlen(right_brace)+1));
+ }
}
static struct tst_test test = {
--
2.21.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [LTP] [PATCH v2] sysctl01: fix fails on live-patched kernels
2019-03-07 18:37 [LTP] [PATCH v2] sysctl01: fix fails on live-patched kernels Jan Baier
@ 2019-03-08 11:58 ` Petr Vorel
2019-03-08 16:24 ` Petr Vorel
0 siblings, 1 reply; 3+ messages in thread
From: Petr Vorel @ 2019-03-08 11:58 UTC (permalink / raw)
To: ltp
Hi,
LGTM, with 2 minor changes (no need to repost if you agree).
> During live-patching, the uname syscall is overridden to reflect the
> fact that the kernel has been live-patched. The version string
> obtainable through /proc/sys/kernel/version is defined during
> compilation and it is not touched by the live-patch. In this case, the
> two interfaces can report different kernel versions.
I'd add a comment that we're removing "/kGraft-<git_new_hash>"
from "(<git_hash>/{lp,kGraft}-<git_new_hash>)"
But maybe that's known and obvious from the code.
> Adjust the string from uname in such cases and remove the tag added
> during live-patching.
> Signed-off-by: Jan Baier <jbaier@suse.cz>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
...
> + klp_tag = strstr(buf.version, "/kGraft-");
> + if (!klp_tag)
> + klp_tag = strstr(buf.version, "/lp-");
> + if (klp_tag) {
> + right_brace = strchr(klp_tag, ')');
> + if (right_brace)
> + memmove(klp_tag, right_brace, sizeof(char) * (strlen(right_brace)+1));
sizeof(char) == 1 by definition :)
...
Kind regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
* [LTP] [PATCH v2] sysctl01: fix fails on live-patched kernels
2019-03-08 11:58 ` Petr Vorel
@ 2019-03-08 16:24 ` Petr Vorel
0 siblings, 0 replies; 3+ messages in thread
From: Petr Vorel @ 2019-03-08 16:24 UTC (permalink / raw)
To: ltp
Hi Jan,
> ...
> > + klp_tag = strstr(buf.version, "/kGraft-");
> > + if (!klp_tag)
> > + klp_tag = strstr(buf.version, "/lp-");
> > + if (klp_tag) {
> > + right_brace = strchr(klp_tag, ')');
> > + if (right_brace)
> > + memmove(klp_tag, right_brace, sizeof(char) * (strlen(right_brace)+1));
> sizeof(char) == 1 by definition :)
Merged, with this tiny fix + extended commit message.
Thanks for your patch!
Kind regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-08 16:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-07 18:37 [LTP] [PATCH v2] sysctl01: fix fails on live-patched kernels Jan Baier
2019-03-08 11:58 ` Petr Vorel
2019-03-08 16:24 ` Petr Vorel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox