Skip to contentSkip to conversation

xen: Prevent buffer overflow in privcmd ioctl

PATCH Applied Dan Carpenter 3 participants 4 messages Apr 4, 2019 – Apr 5, 2019

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

PATCH 1/1 xen: Prevent buffer overflow in privcmd ioctl

The "call" variable comes from the user in privcmd_ioctl_hypercall(). It's an offset into the hypercall_page[] which has (PAGE_SIZE / 32) elements. We need to put an upper bound on it to prevent an out of bounds access.

Fixes 1246ae0bb992 ("xen: add variable hypercall caller")
---
 arch/x86/include/asm/xen/hypercall.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/xen/hypercall.h +3 -0
index de6f0d59a24f..2863c2026655 100644
@@ -206,6 +206,9 @@ xen_single_call(unsigned int call,
 	__HYPERCALL_DECLS;
 	__HYPERCALL_5ARG(a1, a2, a3, a4, a5);
 
+	if (call >= PAGE_SIZE / sizeof(hypercall_page[0]))
+		return -EINVAL;
+
 	asm volatile(CALL_NOSPEC
 		     : __HYPERCALL_5PARAM
 		     : [thunk_target] "a" (&hypercall_page[call])
Signature · 1 line
2.17.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dan Carpenter

The "call" variable comes from the user in privcmd_ioctl_hypercall(). It's an offset into the hypercall_page[] which has (PAGE_SIZE / 32) elements. We need to put an upper bound on it to prevent an out of bounds access.

Fixes 1246ae0bb992 ("xen: add variable hypercall caller")

I am also adding [email protected]

-boris

Quoted 18 lines
---
 arch/x86/include/asm/xen/hypercall.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/xen/hypercall.h +3 -0
index de6f0d59a24f..2863c2026655 100644
@@ -206,6 +206,9 @@ xen_single_call(unsigned int call,
 	__HYPERCALL_DECLS;
 	__HYPERCALL_5ARG(a1, a2, a3, a4, a5);
 
+	if (call >= PAGE_SIZE / sizeof(hypercall_page[0]))
+		return -EINVAL;
+
 	asm volatile(CALL_NOSPEC
 		     : __HYPERCALL_5PARAM
 		     : [thunk_target] "a" (&hypercall_page[call])
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

The "call" variable comes from the user in privcmd_ioctl_hypercall(). It's an offset into the hypercall_page[] which has (PAGE_SIZE / 32) elements. We need to put an upper bound on it to prevent an out of bounds access.

Fixes 1246ae0bb992 ("xen: add variable hypercall caller")

I am also adding [email protected]

-boris

Quoted 9 lines
---
 arch/x86/include/asm/xen/hypercall.h | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/include/asm/xen/hypercall.h +0 -0
index de6f0d59a24f..2863c2026655 100644

arch/x86/include/asm/xen/hypercall.h xen_single_call(unsigned int call, · line 214

Quoted 9 lines
arch/x86/include/asm/xen/hypercall.h +3 -0
@@ -206,6 +206,9 @@ xen_single_call(unsigned int call,
 	__HYPERCALL_DECLS;
 	__HYPERCALL_5ARG(a1, a2, a3, a4, a5);
 
+	if (call >= PAGE_SIZE / sizeof(hypercall_page[0]))
+		return -EINVAL;
+
 	asm volatile(CALL_NOSPEC
 		     : __HYPERCALL_5PARAM
 		     : [thunk_target] "a" (&hypercall_page[call])

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

The "call" variable comes from the user in privcmd_ioctl_hypercall(). It's an offset into the hypercall_page[] which has (PAGE_SIZE / 32) elements. We need to put an upper bound on it to prevent an out of bounds access.

Fixes 1246ae0bb992 ("xen: add variable hypercall caller")

Pushed to xen/tip.git for-linus-5.1b

Juergen