Skip to contentSkip to conversation

sysctl01: fix fails on live-patched kernels

PATCH New Jan Baier 2 participants 3 messages Mar 7, 2019

lore
Share & tools
lore

Jan Baier

author
#0 lore raw

PATCH 1/1 sysctl01: fix fails on live-patched kernels

Version from uname and /proc/sys/kernel/version does not match on live-patched kernels (bsc#1100130, poo#38483).

Adjust the string from uname in such cases.

---
 testcases/kernel/syscalls/sysctl/sysctl01.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/syscalls/sysctl/sysctl01.c +14 -0
index 70905d806..fda29f060 100644
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * Copyright (c) 2018 Xiao Yang <[email protected]>
+ * 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)
+			strcpy(klp_tag, right_brace);
+	}
 }
 
 static struct tst_test test = {
Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 sysctl01: fix fails on live-patched kernels

Hi!

Quoted 2 lines

Version from uname and /proc/sys/kernel/version does not match on live-patched kernels (bsc#1100130, poo#38483).

As far as I can tell the bug and progress issue are not accessible to public, there is no point in including them in the commit message.

It would be better to describe here what causes the difference and how the difference looks like.

Quoted 25 lines

Adjust the string from uname in such cases.

---
 testcases/kernel/syscalls/sysctl/sysctl01.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/syscalls/sysctl/sysctl01.c +3 -0
index 70905d806..fda29f060 100644
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * Copyright (c) 2018 Xiao Yang <[email protected]>
+ * 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 */

kernel/syscalls/sysctl/sysctl01.c static void setup(void) · line 92

Quoted 10 lines
kernel/syscalls/sysctl/sysctl01.c +10 -0
+	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)
+			strcpy(klp_tag, right_brace);

This is not generally safe, the parameters passed to strcpy() must not overlap. I guess that the safe option would be copying the content into a new buffer.

Quoted 10 lines
kernel/syscalls/sysctl/sysctl01.c +1 -0
+	}
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.21.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#2 lore raw

PATCH 1/1 sysctl01: fix fails on live-patched kernels

Hi!

Quoted 8 lines
Quoted 2 lines

Version from uname and /proc/sys/kernel/version does not match on live-patched kernels (bsc#1100130, poo#38483).

As far as I can tell the bug and progress issue are not accessible to public, there is no point in including them in the commit message.

It would be better to describe here what causes the difference and how the difference looks like.

That is a good point, I thought the bug on bugzilla is public (but apparently it is not).

Quoted 31 lines
Quoted 31 lines

Adjust the string from uname in such cases.

---
 testcases/kernel/syscalls/sysctl/sysctl01.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
kernel/syscalls/sysctl/sysctl01.c +9 -0
index 70905d806..fda29f060 100644
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * Copyright (c) 2018 Xiao Yang <[email protected]>
+ * 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-");
Quoted 8 lines

kernel/syscalls/sysctl/sysctl01.c static void setup(void) · line 92

Quoted 4 lines
kernel/syscalls/sysctl/sysctl01.c +4 -0
+	if (klp_tag) {
+		right_brace = strchr(klp_tag, ')');
+		if (right_brace)
+			strcpy(klp_tag, right_brace);

This is not generally safe, the parameters passed to strcpy() must not overlap. I guess that the safe option would be copying the content into a new buffer.

Oh, my fault. I changed that from memmove and did not realize this consequence. I will refactor this part.

Quoted 11 lines
Quoted 10 lines
kernel/syscalls/sysctl/sysctl01.c +1 -0
+	}
 }
 
 static struct tst_test test = {
Signature · 5 lines
2.21.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

--
Jan Baier
QA/Maintenance

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linux.it/pipermail/ltp/attachments/20190307/c145f133/attachment.sig>