Skip to content

Commit f26a525

Browse files
Snehal-ReddyMarc Zyngier
authored andcommitted
KVM: arm64: Add memory length checks and remove inline in do_ffa_mem_xfer
When we share memory through FF-A and the description of the buffers exceeds the size of the mapped buffer, the fragmentation API is used. The fragmentation API allows specifying chunks of descriptors in subsequent FF-A fragment calls and no upper limit has been established for this. The entire memory region transferred is identified by a handle which can be used to reclaim the transferred memory. To be able to reclaim the memory, the description of the buffers has to fit in the ffa_desc_buf. Add a bounds check on the FF-A sharing path to prevent the memory reclaim from failing. Also do_ffa_mem_xfer() does not need __always_inline, except for the BUILD_BUG_ON() aspect, which gets moved to a macro. [maz: fixed the BUILD_BUG_ON() breakage with LLVM, thanks to Wei-Lin Chang for the timely report] Fixes: 634d90c ("KVM: arm64: Handle FFA_MEM_LEND calls from the host") Cc: [email protected] Reviewed-by: Sebastian Ene <[email protected]> Signed-off-by: Snehal Koukuntla <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent e0b7de4 commit f26a525

File tree

1 file changed

+15
-6
lines changed
  • arch/arm64/kvm/hyp/nvhe

1 file changed

+15
-6
lines changed

arch/arm64/kvm/hyp/nvhe/ffa.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_res *res,
426426
return;
427427
}
428428

429-
static __always_inline void do_ffa_mem_xfer(const u64 func_id,
430-
struct arm_smccc_res *res,
431-
struct kvm_cpu_context *ctxt)
429+
static void __do_ffa_mem_xfer(const u64 func_id,
430+
struct arm_smccc_res *res,
431+
struct kvm_cpu_context *ctxt)
432432
{
433433
DECLARE_REG(u32, len, ctxt, 1);
434434
DECLARE_REG(u32, fraglen, ctxt, 2);
@@ -440,9 +440,6 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
440440
u32 offset, nr_ranges;
441441
int ret = 0;
442442

443-
BUILD_BUG_ON(func_id != FFA_FN64_MEM_SHARE &&
444-
func_id != FFA_FN64_MEM_LEND);
445-
446443
if (addr_mbz || npages_mbz || fraglen > len ||
447444
fraglen > KVM_FFA_MBOX_NR_PAGES * PAGE_SIZE) {
448445
ret = FFA_RET_INVALID_PARAMETERS;
@@ -461,6 +458,11 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
461458
goto out_unlock;
462459
}
463460

461+
if (len > ffa_desc_buf.len) {
462+
ret = FFA_RET_NO_MEMORY;
463+
goto out_unlock;
464+
}
465+
464466
buf = hyp_buffers.tx;
465467
memcpy(buf, host_buffers.tx, fraglen);
466468

@@ -512,6 +514,13 @@ static __always_inline void do_ffa_mem_xfer(const u64 func_id,
512514
goto out_unlock;
513515
}
514516

517+
#define do_ffa_mem_xfer(fid, res, ctxt) \
518+
do { \
519+
BUILD_BUG_ON((fid) != FFA_FN64_MEM_SHARE && \
520+
(fid) != FFA_FN64_MEM_LEND); \
521+
__do_ffa_mem_xfer((fid), (res), (ctxt)); \
522+
} while (0);
523+
515524
static void do_ffa_mem_reclaim(struct arm_smccc_res *res,
516525
struct kvm_cpu_context *ctxt)
517526
{

0 commit comments

Comments
 (0)