Skip to contentSkip to conversation

x86/hypercall: fix gnttab hypercall args conditional build on pvshim

PATCH In review Roger Pau Monne 2 participants 6 messages Jan 8, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hypercall: fix gnttab hypercall args conditional build on pvshim

A pvshim build doesn't require the grant table functionality built in, but it does require knowing the number of arguments the hypercall has so the hypercall parameter clobbering works properly.

Note this hasn't been detected by osstest because the tools pvshim build is done without debug enabled, so the hypercall parameter clobbering doesn't happen.

Fixes d2151152dd2 ('xen: make grant table support configurable')
---
 xen/arch/x86/hypercall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hypercall.c +1 -1
index dd00983005..8d18ef80cc 100644
@@ -47,7 +47,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(xen_version, 2),
     ARGS(console_io, 3),
     ARGS(physdev_op_compat, 1),
-#ifdef CONFIG_GRANT_TABLE
+#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
     ARGS(grant_table_op, 3),
 #endif
     ARGS(vm_assist, 2),
Signature · 1 line
2.29.2
#1 lore raw

xen/arch/x86/hypercall.c const hypercall_args_t hypercall_args_table[NR_hypercalls] = · line 53

Quoted 11 lines · Roger Pau Monne
xen/arch/x86/hypercall.c +1 -1
@@ -47,7 +47,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(xen_version, 2),
     ARGS(console_io, 3),
     ARGS(physdev_op_compat, 1),
-#ifdef CONFIG_GRANT_TABLE
+#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
     ARGS(grant_table_op, 3),
 #endif
     ARGS(vm_assist, 2),

This is correct when a shim-enabled build runs as shim, but not when it runs as normal hypervisor. Just like the hypercall handler gets patched into the hypercall table (in pv_shim_setup_dom()), the argument count will also want updating there, I think.

Jan

#2 lore raw
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
xen/arch/x86/hypercall.c +1 -1
@@ -47,7 +47,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(xen_version, 2),
     ARGS(console_io, 3),
     ARGS(physdev_op_compat, 1),
-#ifdef CONFIG_GRANT_TABLE
+#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
     ARGS(grant_table_op, 3),
Quoted 8 lines

xen/arch/x86/hypercall.c const hypercall_args_t hypercall_args_table[NR_hypercalls] = · line 53

Quoted 2 lines
xen/arch/x86/hypercall.c +0 -0
 #endif
     ARGS(vm_assist, 2),

This is correct when a shim-enabled build runs as shim, but not when it runs as normal hypervisor. Just like the hypercall handler gets patched into the hypercall table (in pv_shim_setup_dom()), the argument count will also want updating there, I think.

Having the argument count set when the hypercall handler is NULL is fine, as Xen won't get into processing hypercall_args_table if the handler is NULL. While it's true that can be fixed at run time in the same way that we patch the handler it seems more cumbersome, that's why I went for this IMO simpler fix.

Thanks, Roger.

Reviewed-by
#3 lore raw
Quoted 20 lines · Roger Pau Monné
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
xen/arch/x86/hypercall.c +1 -1
@@ -47,7 +47,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(xen_version, 2),
     ARGS(console_io, 3),
     ARGS(physdev_op_compat, 1),
-#ifdef CONFIG_GRANT_TABLE
+#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
     ARGS(grant_table_op, 3),
Quoted 8 lines

xen/arch/x86/hypercall.c const hypercall_args_t hypercall_args_table[NR_hypercalls] = · line 53

Quoted 2 lines
xen/arch/x86/hypercall.c +0 -0
 #endif
     ARGS(vm_assist, 2),

This is correct when a shim-enabled build runs as shim, but not when it runs as normal hypervisor. Just like the hypercall handler gets patched into the hypercall table (in pv_shim_setup_dom()), the argument count will also want updating there, I think.

Quoted 3 lines

Having the argument count set when the hypercall handler is NULL is fine, as Xen won't get into processing hypercall_args_table if the handler is NULL.

Oh, good point.

Quoted 3 lines

While it's true that can be fixed at run time in the same way that we patch the handler it seems more cumbersome, that's why I went for this IMO simpler fix.

Agreed:

Jan

#4 lore raw
Quoted 21 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 18 lines · Jan Beulich

xen/arch/x86/hypercall.c const hypercall_args_t hypercall_args_table[NR_hypercalls] = · line 53

Quoted 11 lines · Roger Pau Monne
xen/arch/x86/hypercall.c +1 -1
@@ -47,7 +47,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(xen_version, 2),
     ARGS(console_io, 3),
     ARGS(physdev_op_compat, 1),
-#ifdef CONFIG_GRANT_TABLE
+#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
     ARGS(grant_table_op, 3),
 #endif
     ARGS(vm_assist, 2),

This is correct when a shim-enabled build runs as shim, but not when it runs as normal hypervisor. Just like the hypercall handler gets patched into the hypercall table (in pv_shim_setup_dom()), the argument count will also want updating there, I think.

Quoted 5 lines
Quoted 3 lines

Having the argument count set when the hypercall handler is NULL is fine, as Xen won't get into processing hypercall_args_table if the handler is NULL.

Oh, good point.

Albeit then - why not drop the #ifdef altogether?

Jan

#5 lore raw
In reply to Jan Beulich
Quoted 25 lines · Jan Beulich
Quoted 20 lines · Roger Pau Monné
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Roger Pau Monne
xen/arch/x86/hypercall.c +1 -1
@@ -47,7 +47,7 @@ const hypercall_args_t hypercall_args_table[NR_hypercalls] =
     ARGS(xen_version, 2),
     ARGS(console_io, 3),
     ARGS(physdev_op_compat, 1),
-#ifdef CONFIG_GRANT_TABLE
+#if defined(CONFIG_GRANT_TABLE) || defined(CONFIG_PV_SHIM)
     ARGS(grant_table_op, 3),
Quoted 8 lines

xen/arch/x86/hypercall.c const hypercall_args_t hypercall_args_table[NR_hypercalls] = · line 53

Quoted 2 lines
xen/arch/x86/hypercall.c +0 -0
 #endif
     ARGS(vm_assist, 2),

This is correct when a shim-enabled build runs as shim, but not when it runs as normal hypervisor. Just like the hypercall handler gets patched into the hypercall table (in pv_shim_setup_dom()), the argument count will also want updating there, I think.

Quoted 3 lines

Having the argument count set when the hypercall handler is NULL is fine, as Xen won't get into processing hypercall_args_table if the handler is NULL.

Quoted 8 lines

Oh, good point.

Quoted 3 lines

While it's true that can be fixed at run time in the same way that we patch the handler it seems more cumbersome, that's why I went for this IMO simpler fix.

Agreed:

Thanks.

In fact I'm not sure it's helpful to have any build time conditionals in hypercall_args_table, but let's leave that for another fix.

Roger.