{hyper,multi}call: further limit arguments to just 5

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: 2f531c122e ("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
This commit is contained in:
Jan Beulich committed 2025-05-02 09:43:23 +02:00
1 parent 19772b6704
commit e81baffaff
4 files changed
+27 -12

No files matched your search

+7 -3
View File
@@ -391,7 +391,11 @@ unsigned long hypercall_create_continuation(
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;
@@ -416,7 +420,7 @@ unsigned long hypercall_create_continuation(
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;
}
}
@@ -439,7 +443,7 @@ unsigned long hypercall_create_continuation(
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;
}
}
+7 -4
View File
@@ -41,7 +41,11 @@ unsigned long hypercall_create_continuation(
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
{
@@ -65,7 +69,7 @@ unsigned long hypercall_create_continuation(
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;
}
}
}
@@ -81,7 +85,7 @@ unsigned long hypercall_create_continuation(
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;
}
}
}
@@ -177,7 +181,6 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,
case 2: reg = &regs->rdx; break;
case 3: reg = &regs->rsi; break;
case 4: reg = &regs->rdi; break;
case 5: reg = &regs->rbp; break;
default: BUG(); reg = NULL; break;
}
if ( (mask & 1) )
+9 -5
View File
@@ -14,9 +14,13 @@ typedef int ret_t;
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
@@ -29,8 +33,8 @@ static inline void xlat_multicall_entry(struct mc_state *mcs)
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];
+4
View File
@@ -640,7 +640,11 @@ DEFINE_XEN_GUEST_HANDLE(mmu_update_t);
*/
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);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.