Multicall compat translation and hypercall continuation handling can
also be shrunk to the processing of just (up to) 5 arguments.
Take the opportunity to
- make exceeding the limit noisy in hypercall_create_continuation(),
- use speculation-safe array access in hypercall_create_continuation(),
- avoid a Misra C:2012 Rule 19.1 violation in xlat_multicall_entry(),
- further tidy xlat_multicall_entry() and __trace_multicall_call()
style-wise.
Amends:
2f531c122e95 ("x86: limit number of hypercall parameters to 5")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org> # arm
if ( mcs->flags & MCSF_in_multicall )
{
for ( i = 0; *p != '\0'; i++ )
- mcs->call.args[i] = NEXT_ARG(p, args);
+ {
+ if ( i >= ARRAY_SIZE(mcs->call.args) )
+ goto bad_fmt;
+ array_access_nospec(mcs->call.args, i) = NEXT_ARG(p, args);
+ }
/* Return value gets written back to mcs->call.result */
rc = mcs->call.result;
case 2: regs->x2 = arg; break;
case 3: regs->x3 = arg; break;
case 4: regs->x4 = arg; break;
- case 5: regs->x5 = arg; break;
+ default: goto bad_fmt;
}
}
case 2: regs->r2 = arg; break;
case 3: regs->r3 = arg; break;
case 4: regs->r4 = arg; break;
- case 5: regs->r5 = arg; break;
+ default: goto bad_fmt;
}
}
if ( mcs->flags & MCSF_in_multicall )
{
for ( i = 0; *p != '\0'; i++ )
- mcs->call.args[i] = NEXT_ARG(p, args);
+ {
+ if ( i >= ARRAY_SIZE(mcs->call.args) )
+ goto bad_fmt;
+ array_access_nospec(mcs->call.args, i) = NEXT_ARG(p, args);
+ }
}
else
{
case 2: regs->rdx = arg; break;
case 3: regs->r10 = arg; break;
case 4: regs->r8 = arg; break;
- case 5: regs->r9 = arg; break;
+ default: goto bad_fmt;
}
}
}
case 2: regs->rdx = arg; break;
case 3: regs->rsi = arg; break;
case 4: regs->rdi = arg; break;
- case 5: regs->rbp = arg; break;
+ default: goto bad_fmt;
}
}
}
case 2: reg = ®s->rdx; break;
case 3: reg = ®s->rsi; break;
case 4: reg = ®s->rdi; break;
- case 5: reg = ®s->rbp; break;
default: BUG(); reg = NULL; break;
}
if ( (mask & 1) )
static inline void xlat_multicall_entry(struct mc_state *mcs)
{
- int i;
- for (i=0; i<6; i++)
- mcs->compat_call.args[i] = mcs->call.args[i];
+ unsigned int i;
+ typeof(mcs->compat_call.args[0]) args[ARRAY_SIZE(mcs->call.args)];
+
+ for ( i = 0; i < ARRAY_SIZE(args); i++ )
+ args[i] = mcs->call.args[i];
+
+ memcpy(mcs->compat_call.args, args, sizeof(args));
}
#define multicall_entry compat_multicall_entry
static void __trace_multicall_call(multicall_entry_t *call)
{
- xen_ulong_t args[6];
- int i;
+ xen_ulong_t args[ARRAY_SIZE(call->args)];
+ unsigned int i;
for ( i = 0; i < ARRAY_SIZE(args); i++ )
args[i] = call->args[i];
*/
struct multicall_entry {
xen_ulong_t op, result;
+#ifndef __XEN__
xen_ulong_t args[6];
+#else /* Only 5 arguments are supported in reality. */
+ xen_ulong_t args[5], unused;
+#endif
};
typedef struct multicall_entry multicall_entry_t;
DEFINE_XEN_GUEST_HANDLE(multicall_entry_t);