Skip to contentSkip to conversation

x86: vm86 fix and test

PATCH New Andy Lutomirski 2 participants 5 messages Oct 31, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86: vm86 fix and test

Calling vm86 and then forking will corrupt things. Fix it.

This is for x86/urgent. It fixes a 4.3 regression.

Andy Lutomirski (2):
selftests/x86: Add a fork() to entry_from_vm86 to catch fork bugs x86/vm86: Set thread.vm86 to NULL on fork/clone

 arch/x86/kernel/process.c                     | 3 +++
 tools/testing/selftests/x86/entry_from_vm86.c | 4 ++++
 2 files changed, 7 insertions(+)
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/2 selftests/x86: Add a fork() to entry_from_vm86 to catch fork bugs

Mere possession of vm86 state is strange. Make sure that nothing gets corrupted if we fork after calling vm86().

---
 tools/testing/selftests/x86/entry_from_vm86.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/x86/entry_from_vm86.c +4 -0
index 9a43a59a9bb4..13b2965472e3 100644
@@ -229,5 +229,9 @@ int main(void)
 	}
 	clearhandler(SIGSEGV);
 
+	/* Make sure nothing explodes if we fork. */
+	if (fork() > 0)
+		return 0;
+
 	return (nerrs == 0 ? 0 : 1);
 }
Signature · 1 line
2.4.3
#3 lore raw

PATCH 2/2 x86/vm86: Set thread.vm86 to NULL on fork/clone

In reply to Andy Lutomirski

thread.vm86 points to per-task information -- the pointer should not be copied on clone.

Fixes d4ce0f26c790 ("x86/vm86: Move fields from 'struct kernel_vm86_struct' to 'struct vm86'")
---
 arch/x86/kernel/process.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/process.c +3 -0
index 2199d9b774c8..b9ac5434e176 100644
@@ -83,6 +83,9 @@ EXPORT_SYMBOL_GPL(idle_notifier_unregister);
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 {
 	memcpy(dst, src, arch_task_struct_size);
+#ifdef CONFIG_VM86
+	dst->thread.vm86 = NULL;
+#endif
 
 	return fpu__copy(&dst->thread.fpu, &src->thread.fpu);
 }
Signature · 1 line
2.4.3
#2 lore raw

[tip:x86/urgent] selftests/x86: Add a fork() to entry_from_vm86 to catch fork bugs

In reply to Andy Lutomirski
selftests/x86: Add a fork() to entry_from_vm86 to catch fork bugs
Commit-ID:  226f1f729ce277720fab60c91dd1b12574cfe66c
Gitweb:     http://git.kernel.org/tip/226f1f729ce277720fab60c91dd1b12574cfe66c
Author:     Andy Lutomirski <[email protected]>
AuthorDate: Fri, 30 Oct 2015 22:42:45 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 31 Oct 2015 09:50:25 +0100

selftests/x86: Add a fork() to entry_from_vm86 to catch fork bugs

Mere possession of vm86 state is strange. Make sure that nothing gets corrupted if we fork after calling vm86().

---
 tools/testing/selftests/x86/entry_from_vm86.c | 4 ++++
 1 file changed, 4 insertions(+)
tools/testing/selftests/x86/entry_from_vm86.c +4 -0
index 421c607..d075ea0 100644
@@ -230,5 +230,9 @@ int main(void)
 	}
 	clearhandler(SIGSEGV);
 
+	/* Make sure nothing explodes if we fork. */
+	if (fork() > 0)
+		return 0;
+
 	return (nerrs == 0 ? 0 : 1);
 }
#4 lore raw

[tip:x86/urgent] x86/vm86: Set thread.vm86 to NULL on fork/clone

In reply to Andy Lutomirski
x86/vm86: Set thread.vm86 to NULL on fork/clone
Commit-ID:  2459ee8651dc5ab72790c2ffa99af288c7641b64
Gitweb:     http://git.kernel.org/tip/2459ee8651dc5ab72790c2ffa99af288c7641b64
Author:     Andy Lutomirski <[email protected]>
AuthorDate: Fri, 30 Oct 2015 22:42:46 -0700
Committer:  Thomas Gleixner <[email protected]>
CommitDate: Sat, 31 Oct 2015 09:50:25 +0100

x86/vm86: Set thread.vm86 to NULL on fork/clone

thread.vm86 points to per-task information -- the pointer should not be copied on clone.

Fixes d4ce0f26c790 ("x86/vm86: Move fields from 'struct kernel_vm86_struct' to 'struct vm86'")
Cc Brian Gerst <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Borislav Petkov <[email protected]>
Cc Stas Sergeev <[email protected]>
---
 arch/x86/kernel/process.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/process.c +3 -0
index e28db18..9f7c21c 100644
@@ -84,6 +84,9 @@ EXPORT_SYMBOL_GPL(idle_notifier_unregister);
 int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
 {
 	memcpy(dst, src, arch_task_struct_size);
+#ifdef CONFIG_VM86
+	dst->thread.vm86 = NULL;
+#endif
 
 	return fpu__copy(&dst->thread.fpu, &src->thread.fpu);
 }