KVM: arm64: Forward FFA_NOTIFICATION* calls to TrustZone
v5 cover KVM: arm64: Forward FFA_NOTIFICATION* calls to TrustZone
Remove the FFA_NOTIFICATION* calls from the blocklist used by the pKVM FF-A proxy. This restriction was preventing the use of asynchronous signaling mechanisms defined by the Arm FF-A specification to communicate with the secure services.
While these calls are markes as optional, there is no reason why the hypervisor proxy would block them because:
1. Host is the Sole Non-Secure Endpoint: The Host operates as the only Non-Secure VM ID (VM ID 0) recognized by the Secure World. Because all forwarded notifications are inherently attributed to the Host by the SPMC, there is no risk of VM ID spoofing originating from the Normal World.
2. No Memory Pointers or Addresses: The FFA_NOTIFICATION_* ABIs operate strictly via register-based parameters, passing only VM IDs, VCPU IDs, flags, and bitmaps. Because these calls do not contain memory addresses, offsets, or pointers, forwarding them doesn't pose a risk of memory-based confused deputy attack (e.g., tricking the SPMC into overwriting protected memory).
While the pKVM proxy behaves as a relayer, it doesn't currently have its own FF-A ID(only the host has the ID 0). The behavior of the setup flow is covered by the spec in the: '10.9 Notification support without a Hypervisor'.
---
Changes in v5:
- handle 32-bit smc variants correctly when doing the MBZ enforcement
- add check for FFA_FEATURES
- handle missing FFA_FN64_NOTIFICATION_INFO_GET
- collected the Review tags from Vincent, thank you
Changes in v4:
- previous series(v3) had serious issues with the patch number and it appeared like it used a mixed bag from v2 as well. Resend this to restore the correct order of the patches.
- fix strict check in ffa_check_unused_args_sbz and make it "<= 17"
- check the receiver endpoint Id in FFA_NOTIFICATION_BIND/FFA_NOTIFICATION_UNBIND instead of the sender
- use hyp_smccc_1_2_smc all along
- check the receiver endpoit Id when doing FFA_NOTIFICATION_GET
Changes in v3:
- applied Will's suggestion to use the introduced method ffa_check_unused_args_sbz for existing calls and added a new
patch in the beggining of the series to do this.
- merged the handling of FFA_NOTIFICATION_BITMAP_CREATE/FFA_NOTIFICATION_BITMAP_DESTROY into
one patch as Vincent suggested and create one handler for both.
Changes in v2:
- enforce the MBZ/SBZ fields
- split the calls into separate patches
- rebase on 7.1-rc7
Link to v4:
https://lore.kernel.org/all/[email protected]/
Link to v3:
https://lore.kernel.org/all/[email protected]/
Link to v2:
https://lore.kernel.org/all/[email protected]/
Link to v1:
https://lore.kernel.org/all/[email protected]/
Sebastian Ene (7):
KVM: arm64: Enforce strict SBZ checks in the FF-A proxy
KVM: arm64: Forward FFA_NOTIFICATION_BITMAP calls to Trustzone
KVM: arm64: Support FFA_NOTIFICATION_BIND in host handler
KVM: arm64: Support FFA_NOTIFICATION_UNBIND in host handler
KVM: arm64: Support FFA_NOTIFICATION_SET in host handler
KVM: arm64: Support FFA_NOTIFICATION_GET in host handler
KVM: arm64: Support FFA_NOTIFICATION_INFO_GET in host handler
arch/arm64/kvm/hyp/nvhe/ffa.c | 219 ++++++++++++++++++++++++++++++++-- 1 file changed, 211 insertions(+), 8 deletions(-)
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
PATCH v5 1/7 KVM: arm64: Enforce strict SBZ checks in the FF-A proxy
Introduce a helper method ffa_check_unused_args_sbz to enforce strict arguments checking when the hypervisor acts as a relayer between the host and Trustzone.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)
arch/arm64/kvm/hyp/nvhe/ffa.c +54 -0
@@ -71,6 +71,20 @@ static u32 hyp_ffa_version;static bool has_version_negotiated;static hyp_spinlock_t version_lock; +static bool ffa_check_unused_args_sbz (struct kvm_cpu_context *ctxt,int first_reg) +{ +DECLARE_REG (u32, func_id, ctxt,0 ); +int reg, end_reg; + + end_reg =ARM_SMCCC_IS_64 (func_id) ?17 :7 ; +for (reg = first_reg; reg <= end_reg; reg++) { +if (cpu_reg (ctxt, reg)) +return true; + } + +return false; +} +static void ffa_to_smccc_error (struct arm_smccc_1_2_regs *res,u64 ffa_errno) { *res = (struct arm_smccc_1_2_regs ) {
@@ -239,6 +253,11 @@ static void do_ffa_rxtx_map(struct arm_smccc_1_2_regs *res,int ret =0 ;void *rx_virt, *tx_virt; +if (ffa_check_unused_args_sbz (ctxt,4 )) { + ret =FFA_RET_INVALID_PARAMETERS ; + goto out; + } +if (npages != (KVM_FFA_MBOX_NR_PAGES *PAGE_SIZE ) /FFA_PAGE_SIZE ) { ret =FFA_RET_INVALID_PARAMETERS ; goto out;
@@ -315,6 +334,11 @@ static void do_ffa_rxtx_unmap(struct arm_smccc_1_2_regs *res,DECLARE_REG (u32, id, ctxt,1 );int ret =0 ; +if (ffa_check_unused_args_sbz (ctxt,2 )) { + ret =FFA_RET_INVALID_PARAMETERS ; + goto out; + } +if (id !=HOST_FFA_ID ) { ret =FFA_RET_INVALID_PARAMETERS ; goto out;
@@ -421,6 +445,11 @@ static void do_ffa_mem_frag_tx(struct arm_smccc_1_2_regs *res,int ret =FFA_RET_INVALID_PARAMETERS ;u32 nr_ranges; +if (ffa_check_unused_args_sbz (ctxt,5 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } +if (fraglen >KVM_FFA_MBOX_NR_PAGES *PAGE_SIZE ) goto out;
@@ -482,6 +511,11 @@ static void __do_ffa_mem_xfer(const u64 func_id,u32 offset, nr_ranges, checked_offset;int ret =0 ; +if (ffa_check_unused_args_sbz (ctxt,5 )) { + ret =FFA_RET_INVALID_PARAMETERS ; + goto out; + } +if (addr_mbz || npages_mbz || fraglen > len || fraglen >KVM_FFA_MBOX_NR_PAGES *PAGE_SIZE ) { ret =FFA_RET_INVALID_PARAMETERS ;
@@ -581,6 +615,11 @@ static void do_ffa_mem_reclaim(struct arm_smccc_1_2_regs *res,int ret =0 ;u64 handle; +if (ffa_check_unused_args_sbz (ctxt,4 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + handle =PACK_HANDLE (handle_lo, handle_hi);hyp_spin_lock (&host_buffers.lock);
@@ -769,6 +808,11 @@ static void do_ffa_version(struct arm_smccc_1_2_regs *res, {DECLARE_REG (u32, ffa_req_version, ctxt,1 ); +if (ffa_check_unused_args_sbz (ctxt,2 )) { + res->a0 =FFA_RET_NOT_SUPPORTED ; +return ; + } +if (FFA_MAJOR_VERSION (ffa_req_version) !=1 ) { res->a0 =FFA_RET_NOT_SUPPORTED ;return ;
@@ -818,6 +862,11 @@ static void do_ffa_part_get(struct arm_smccc_1_2_regs *res,DECLARE_REG (u32, flags, ctxt,5 );u32 count, partition_sz, copy_sz; +if (ffa_check_unused_args_sbz (ctxt,6 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } +hyp_spin_lock (&host_buffers.lock);if (!host_buffers.rx) {ffa_to_smccc_res (res,FFA_RET_BUSY );
@@ -890,6 +939,11 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)switch (func_id) {case FFA_FEATURES : +if (ffa_check_unused_args_sbz (host_ctxt,3 )) { +ffa_to_smccc_res (&res,FFA_RET_INVALID_PARAMETERS ); + goto out_handled; + } +if (!do_ffa_features (&res, host_ctxt))return false; goto out_handled;
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
[email protected]
AI reviewRe: [PATCH v5 1/7] KVM: arm64: Enforce strict SBZ checks in the FF-A proxy
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The strict SBZ check for unused arguments does not ignore the upper 32 bits for SMC32 calls…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The strict SBZ check for unused arguments does not ignore the upper 32 bits for SMC32 calls, violating the SMCCC and FF-A specifications.
- [Medium] The FFA_FEATURES handler incorrectly returns FFA_RET_INVALID_PARAMETERS instead of FFA_RET_NOT_SUPPORTED when unused arguments are non-zero. --
commit d261b7516c8a6d707698f336a32184a5de586911
Author: Sebastian Ene <[email protected]>
KVM: arm64: Enforce strict SBZ checks in the FF-A proxy
Introduce a helper method ffa_check_unused_args_sbz to enforce strict arguments checking when the hypervisor acts as a relayer between the host and Trustzone.
Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0@@ -71,6 +71,20 @@ static u32 hyp_ffa_version;static bool has_version_negotiated;
arch/arm64/kvm/hyp/nvhe/ffa.c static u32 hyp_ffa_version; · line 81
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +8
-0static hyp_spinlock_t version_lock; +static bool ffa_check_unused_args_sbz (struct kvm_cpu_context *ctxt,int first_reg) +{ +DECLARE_REG (u32, func_id, ctxt,0 ); +int reg, end_reg; + + end_reg =ARM_SMCCC_IS_64 (func_id) ?17 :7 ; +for (reg = first_reg; reg <= end_reg; reg++) { +if (cpu_reg (ctxt, reg))
[Severity: High]
Does this correctly handle the upper 32 bits for SMC32 calls?
According to the SMCCC, for SMC32 calls, the upper 32 bits of X registers are unknown, and the host is not required to clear them. Since cpu_reg() returns the full 64-bit register value, this might erroneously reject valid host FF-A SMC32 calls if there is residual data in the upper 32 bits.
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +5
-0+return true; + } + +return false; +}
[ ... ]
arch/arm64/kvm/hyp/nvhe/ffa.c bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id) · line 943
Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +2
-0@@ -890,6 +939,11 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)switch (func_id) {case FFA_FEATURES : +if (ffa_check_unused_args_sbz (host_ctxt,3 )) { +ffa_to_smccc_res (&res,FFA_RET_INVALID_PARAMETERS );
[Severity: Medium]
Should this return FFA_RET_NOT_SUPPORTED instead?
According to the FF-A specification, if an unused parameter is non-zero in an FFA_FEATURES call, the implementation must return FFA_RET_NOT_SUPPORTED. Returning FFA_RET_INVALID_PARAMETERS might violate the FF-A ABI and confuse the host driver during capability negotiation.
Quoted 6 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +3
-0+ goto out_handled; + } +if (!do_ffa_features (&res, host_ctxt))return false; goto out_handled;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Will Deacon
maintainerRe: [PATCH v5 1/7] KVM: arm64: Enforce strict SBZ checks in the FF-A proxy
In reply to Sebastian EneHi all,
Quoted 21 lines · Sebastian Ene
Introduce a helper method
ffa_check_unused_args_sbzto enforce strict arguments checking when the hypervisor acts as a relayer between the host and Trustzone.Signed-off-by Sebastian Ene <[email protected]>Reviewed-by Vincent Donnefort <[email protected]>--- arch/arm64/kvm/hyp/nvhe/ffa.c | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)arch/arm64/kvm/hyp/nvhe/ffa.c +3
-0@@ -71,6 +71,20 @@ static u32 hyp_ffa_version;static bool has_version_negotiated;static hyp_spinlock_t version_lock; +static bool ffa_check_unused_args_sbz (struct kvm_cpu_context *ctxt,int first_reg) +{ +DECLARE_REG (u32, func_id, ctxt,0 );
arch/arm64/kvm/hyp/nvhe/ffa.c static u32 hyp_ffa_version; · line 86
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +10
-0+int reg, end_reg; + + end_reg =ARM_SMCCC_IS_64 (func_id) ?17 :7 ; +for (reg = first_reg; reg <= end_reg; reg++) { +if (cpu_reg (ctxt, reg)) +return true; + } + +return false; +}
Seb and I tried taking this for a spin on some Android devices and, sadly, it leads to fireworks. The reason is that the FF-A spec quietly changed the list of unused parameter registers for 64-bit SMCs from v1.1 to v1.2 of the spec so that pre-existing calls were affected.
For example, in v1.1 a 64-bit RXTX_MAP only has x4-x7 as MBZ, whereas in v1.2 the same call has x4-x17 as SBZ.
We can follow the spec by predicating the additional check on the FF-A version being >= 1.2, but I'm not hopeful that existing drivers are compliant. I also suggest moving this patch to the end of the series in case we need to revert it.
Cheers,
Will
Re: [PATCH v5 1/7] KVM: arm64: Enforce strict SBZ checks in the FF-A proxy
Quoted 21 lines · Will Deacon
Hi all,
Quoted 18 lines · Sebastian Ene
Introduce a helper method
ffa_check_unused_args_sbzto enforce strict arguments checking when the hypervisor acts as a relayer between the host and Trustzone.Signed-off-by Sebastian Ene <[email protected]>Reviewed-by Vincent Donnefort <[email protected]>--- arch/arm64/kvm/hyp/nvhe/ffa.c | 54 +++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+)arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0@@ -71,6 +71,20 @@ static u32 hyp_ffa_version;static bool has_version_negotiated;static hyp_spinlock_t version_lock;
Quoted 13 lines
arch/arm64/kvm/hyp/nvhe/ffa.c static u32 hyp_ffa_version; · line 86
Quoted 13 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +13
-0+static bool ffa_check_unused_args_sbz (struct kvm_cpu_context *ctxt,int first_reg) +{ +DECLARE_REG (u32, func_id, ctxt,0 ); +int reg, end_reg; + + end_reg =ARM_SMCCC_IS_64 (func_id) ?17 :7 ; +for (reg = first_reg; reg <= end_reg; reg++) { +if (cpu_reg (ctxt, reg)) +return true; + } + +return false; +}
Hello Will,
Quoted 6 lines
Seb and I tried taking this for a spin on some Android devices and, sadly, it leads to fireworks. The reason is that the FF-A spec quietly changed the list of unused parameter registers for 64-bit SMCs from v1.1 to v1.2 of the spec so that pre-existing calls were affected.
Quoted 7 lines
For example, in v1.1 a 64-bit
RXTX_MAPonly has x4-x7 as MBZ, whereas in v1.2 the same call has x4-x17 as SBZ.We can follow the spec by predicating the additional check on the FF-A version being >= 1.2, but I'm not hopeful that existing drivers are compliant. I also suggest moving this patch to the end of the series in case we need to revert it.
I spinned up a new series (v6) which moves the check at the end of the series and I made it so that it takes the ff-a version into account.
https://lore.kernel.org/all/[email protected]/
Quoted 4 lines
Cheers,
Will
Thanks
Sebastian
PATCH v5 2/7 KVM: arm64: Forward FFA_NOTIFICATION_BITMAP calls to Trustzone
In reply to Sebastian EneAllow FF-A notification bitmap messages to be forwarded to Trustzone from the host kernel driver enforce checking for SBZ fields.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +25 -2
@@ -715,8 +715,6 @@ static bool ffa_call_supported(u64 func_id)case FFA_MEM_DONATE :case FFA_MEM_RETRIEVE_REQ :/* Optional notification interfaces added in FF-A 1.1 */ -case FFA_NOTIFICATION_BITMAP_CREATE : -case FFA_NOTIFICATION_BITMAP_DESTROY :case FFA_NOTIFICATION_BIND :case FFA_NOTIFICATION_UNBIND :case FFA_NOTIFICATION_SET :
@@ -911,6 +909,27 @@ static void do_ffa_part_get(struct arm_smccc_1_2_regs *res,hyp_spin_unlock (&host_buffers.lock); } +static void do_ffa_notif_bitmap (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, func_id, ctxt,0 ); +DECLARE_REG (u32, vmid, ctxt,1 ); +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt, func_id ==FFA_NOTIFICATION_BITMAP_CREATE ?3 :2 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (vmid !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +} +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) {struct arm_smccc_1_2_regs res;
@@ -974,6 +993,10 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)case FFA_PARTITION_INFO_GET :do_ffa_part_get (&res, host_ctxt); goto out_handled; +case FFA_NOTIFICATION_BITMAP_CREATE : +case FFA_NOTIFICATION_BITMAP_DESTROY : +do_ffa_notif_bitmap (&res, host_ctxt); + goto out_handled; }if (ffa_call_supported (func_id))
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
PATCH v5 3/7 KVM: arm64: Support FFA_NOTIFICATION_BIND in host handler
In reply to Sebastian EneVerify the arguments of the FF-A notification bind call and forward the message to Trustzone.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +31 -1
@@ -42,6 +42,8 @@*/ #define HOST_FFA_ID 0 +#define FFA_NOTIF_RECEIVER_ENDP_MASK GENMASK(15, 0) +/* * A buffer to hold the maximum descriptor size we can see from the host, * which is required when the SPMD returns a fragmented FFA_MEM_RETRIEVE_RESP
@@ -715,7 +717,6 @@ static bool ffa_call_supported(u64 func_id)case FFA_MEM_DONATE :case FFA_MEM_RETRIEVE_REQ :/* Optional notification interfaces added in FF-A 1.1 */ -case FFA_NOTIFICATION_BIND :case FFA_NOTIFICATION_UNBIND :case FFA_NOTIFICATION_SET :case FFA_NOTIFICATION_GET :
@@ -930,6 +931,32 @@ static void do_ffa_notif_bitmap(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_bind (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, flags, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt,5 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (FIELD_GET (FFA_NOTIF_RECEIVER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (flags >1 ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +} +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) {struct arm_smccc_1_2_regs res;
@@ -997,6 +1024,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)case FFA_NOTIFICATION_BITMAP_DESTROY :do_ffa_notif_bitmap (&res, host_ctxt); goto out_handled; +case FFA_NOTIFICATION_BIND : +do_ffa_notif_bind (&res, host_ctxt); + goto out_handled; }if (ffa_call_supported (func_id))
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
[email protected]
AI reviewRe: [PATCH v5 3/7] KVM: arm64: Support FFA_NOTIFICATION_BIND in host handler
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] FFA_NOTIFICATION_BIND rejects per-vCPU bindings for VCPU IDs > 0 due to unconditional unused argument check on w5.
Pre-existing issues:
- [High] ffa_check_unused_args_sbz() validates the full 64-bit register for SMC32 calls, violating the SMCCC specification. --
commit 0b8b8b81a4ddcd427b7ffa364b793f45c2dd4f37
Author: Sebastian Ene <[email protected]>
KVM: arm64: Support FFA_NOTIFICATION_BIND in host handler
Verify the arguments of the FF-A notification bind call and forward the message to Trustzone.
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0
[ ... ]
arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_notif_bitmap(struct arm_smccc_1_2_regs *res, · line 941
Quoted 12 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +8
-0@@ -930,6 +931,32 @@ static void do_ffa_notif_bitmap(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_bind (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, flags, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt,5 )) {
[Severity: High]
Does this unconditionally reject per-vCPU bindings for VCPU IDs greater than 0?
According to the FF-A 1.1 specification, when Flags bit 0 is set to 1, w5 contains the VCPU ID. This means w5 is not an unused argument when binding a per-vCPU notification.
Could we skip the sbz check for w5 when the per-vCPU flag is set?
[Severity: High]
This is a pre-existing issue, but I noticed a problem with how ffa_check_unused_args_sbz() processes SMC32 calls like this one.
When it checks the registers:
static bool ffa_check_unused_args_sbz(struct kvm_cpu_context *ctxt, int first_reg)
{
...
for (reg = first_reg; reg <= end_reg; reg++) {
if (cpu_reg(ctxt, reg))
return true;
}
...
}It reads the full 64-bit register using cpu_reg(). However, the SMCCC 1.2 specification states that the upper 32 bits of W0-W7 are unpredictable for SMC32 calls.
Will this cause KVM to spuriously reject valid SMC32 FF-A calls if the host OS leaves non-zero garbage in the upper 32 bits of the unused registers?
Quoted 17 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +17
-0+ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (FIELD_GET (FFA_NOTIF_RECEIVER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (flags >1 ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +}
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v5 4/7 KVM: arm64: Support FFA_NOTIFICATION_UNBIND in host handler
In reply to Sebastian EneVerify the arguments of the FF-A notification unbind call and forward the message to Trustzone.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +24 -1
@@ -717,7 +717,6 @@ static bool ffa_call_supported(u64 func_id)case FFA_MEM_DONATE :case FFA_MEM_RETRIEVE_REQ :/* Optional notification interfaces added in FF-A 1.1 */ -case FFA_NOTIFICATION_UNBIND :case FFA_NOTIFICATION_SET :case FFA_NOTIFICATION_GET :case FFA_NOTIFICATION_INFO_GET :
@@ -957,6 +956,27 @@ static void do_ffa_notif_bind(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_unbind (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, reserved, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt,5 ) || reserved) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (FIELD_GET (FFA_NOTIF_RECEIVER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +} +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) {struct arm_smccc_1_2_regs res;
@@ -1027,6 +1047,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)case FFA_NOTIFICATION_BIND :do_ffa_notif_bind (&res, host_ctxt); goto out_handled; +case FFA_NOTIFICATION_UNBIND : +do_ffa_notif_unbind (&res, host_ctxt); + goto out_handled; }if (ffa_call_supported (func_id))
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
[email protected]
AI reviewRe: [PATCH v5 4/7] KVM: arm64: Support FFA_NOTIFICATION_UNBIND in host handler
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] FFA_NOTIFICATION_UNBIND incorrectly treats the Notification ID bitmap parameter (W2) as a reserved…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] FFA_NOTIFICATION_UNBIND incorrectly treats the Notification ID bitmap parameter (W2) as a reserved field and requires it to be 0, preventing the host from unbinding notifications and causing a firmware resource leak. --
commit 33f494c35955148d0babe5e028baf1876db19208
Author: Sebastian Ene <[email protected]>
KVM: arm64: Support FFA_NOTIFICATION_UNBIND in host handler
This commit adds support for the FFA_NOTIFICATION_UNBIND interface in the host handler, verifying arguments before forwarding the message to TrustZone.
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0
[ ... ]
Quoted 5 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +1
-0@@ -957,6 +956,27 @@ static void do_ffa_notif_bind(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_unbind(struct arm_smccc_1_2_regs *res,
arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_notif_bind(struct arm_smccc_1_2_regs *res, · line 969
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +10
-0+ struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, reserved, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt,5 ) || reserved) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + }
[Severity: High]
Does this reject valid unbind requests by forcing W2 to be zero?
It looks like W2 is extracted as reserved and required to be 0 here. However, the FF-A specification uses W2 to pass the Notification ID bitmap for the FFA_NOTIFICATION_UNBIND call.
If the host attempts to unbind a notification with a non-zero bitmap, this check will reject the call with FFA_RET_INVALID_PARAMETERS. Could this prevent the host from successfully unbinding notifications, potentially causing a notification tracking resource leak in the secure monitor over time?
Quoted 9 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +9
-0+ +if (FIELD_GET (FFA_NOTIF_RECEIVER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v5 5/7 KVM: arm64: Support FFA_NOTIFICATION_SET in host handler
In reply to Sebastian EneAllow FF-A notification SET messages to be proxied from the pKVM hypervisor to Trustzone and enforce MBZ/SBZ fields.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +30 -1
@@ -43,6 +43,7 @@#define HOST_FFA_ID 0#define FFA_NOTIF_RECEIVER_ENDP_MASK GENMASK(15, 0) +#define FFA_NOTIF_SENDER_ENDP_MASK GENMASK(31, 16)/* * A buffer to hold the maximum descriptor size we can see from the host,
@@ -717,7 +718,6 @@ static bool ffa_call_supported(u64 func_id)case FFA_MEM_DONATE :case FFA_MEM_RETRIEVE_REQ :/* Optional notification interfaces added in FF-A 1.1 */ -case FFA_NOTIFICATION_SET :case FFA_NOTIFICATION_GET :case FFA_NOTIFICATION_INFO_GET :/* Optional interfaces added in FF-A 1.2 */
@@ -977,6 +977,32 @@ static void do_ffa_notif_unbind(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_set (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, flags, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (FIELD_GET (FFA_NOTIF_SENDER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (ffa_check_unused_args_sbz (ctxt,5 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (flags &GENMASK (15 ,2 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +} +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) {struct arm_smccc_1_2_regs res;
@@ -1050,6 +1076,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)case FFA_NOTIFICATION_UNBIND :do_ffa_notif_unbind (&res, host_ctxt); goto out_handled; +case FFA_NOTIFICATION_SET : +do_ffa_notif_set (&res, host_ctxt); + goto out_handled; }if (ffa_call_supported (func_id))
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
[email protected]
AI reviewRe: [PATCH v5 5/7] KVM: arm64: Support FFA_NOTIFICATION_SET in host handler
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The `FFA_NOTIFICATION_SET` handler incorrectly uses `GENMASK(15, 2)` for flags validation…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The FFA_NOTIFICATION_SET handler incorrectly uses GENMASK(15, 2) for flags validation, failing to enforce the MBZ requirement for bits [31:16]. --
commit 39a7cfefe221df6ca3d0e5547b28dcec40a5e09a
Author: Sebastian Ene <[email protected]>
KVM: arm64: Support FFA_NOTIFICATION_SET in host handler
This commit adds support for proxying the FFA_NOTIFICATION_SET message from the host to TrustZone in the pKVM hypervisor. It also implements enforcement of MBZ/SBZ fields for the hypercall arguments.
Quoted 3 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0
[ ... ]
Quoted 15 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +11
-0@@ -977,6 +977,32 @@ static void do_ffa_notif_unbind(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_set (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, flags, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (FIELD_GET (FFA_NOTIF_SENDER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + }
arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_notif_unbind(struct arm_smccc_1_2_regs *res, · line 1000
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +10
-0+ +if (ffa_check_unused_args_sbz (ctxt,5 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (flags &GENMASK (15 ,2 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + }
[Severity: Medium]
Does this flags validation completely enforce the MBZ requirement?
The commit message mentions enforcing MBZ/SBZ fields, but checking against GENMASK(15, 2) appears to leave bits [31:16] unchecked. If an untrusted host invokes the FFA_NOTIFICATION_SET hypercall with non-zero values in the upper bits of the flags register (w2), it looks like this validation would evaluate to false and allow the malformed arguments to be proxied to EL3.
Should this mask be expanded to include GENMASK(31, 16)?
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +4
-0+ + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v5 6/7 KVM: arm64: Support FFA_NOTIFICATION_GET in host handler
In reply to Sebastian EneAllow FF-A notification GET messages to be proxied from the pKVM hypervisor to Trustzone and enforce MBZ/SBZ fields.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +29 -1
@@ -718,7 +718,6 @@ static bool ffa_call_supported(u64 func_id)case FFA_MEM_DONATE :case FFA_MEM_RETRIEVE_REQ :/* Optional notification interfaces added in FF-A 1.1 */ -case FFA_NOTIFICATION_GET :case FFA_NOTIFICATION_INFO_GET :/* Optional interfaces added in FF-A 1.2 */ case FFA_MSG_SEND_DIRECT_REQ2 :/* Optional per 7.5.1 */
@@ -1003,6 +1002,32 @@ static void do_ffa_notif_set(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_get (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +DECLARE_REG (u32, endp_id, ctxt,1 ); +DECLARE_REG (u32, flags, ctxt,2 ); +struct arm_smccc_1_2_regs *args; + +if (FIELD_GET (FFA_NOTIF_RECEIVER_ENDP_MASK , endp_id) !=HOST_FFA_ID ) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (ffa_check_unused_args_sbz (ctxt,3 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + +if (flags &GENMASK (31 ,4 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +} +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) {struct arm_smccc_1_2_regs res;
@@ -1079,6 +1104,9 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)case FFA_NOTIFICATION_SET :do_ffa_notif_set (&res, host_ctxt); goto out_handled; +case FFA_NOTIFICATION_GET : +do_ffa_notif_get (&res, host_ctxt); + goto out_handled; }if (ffa_call_supported (func_id))
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
PATCH v5 7/7 KVM: arm64: Support FFA_NOTIFICATION_INFO_GET in host handler
In reply to Sebastian EneAllow the host to query the FF-A notifiction status and proxy the info get message to Trustzone. Make sure that the SBZ fields are enforced.
--- arch/arm64/kvm/hyp/nvhe/ffa.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
arch/arm64/kvm/hyp/nvhe/ffa.c +18 -2
@@ -717,8 +717,6 @@ static bool ffa_call_supported(u64 func_id)case FFA_RXTX_MAP :case FFA_MEM_DONATE :case FFA_MEM_RETRIEVE_REQ : -/* Optional notification interfaces added in FF-A 1.1 */ -case FFA_NOTIFICATION_INFO_GET :/* Optional interfaces added in FF-A 1.2 */ case FFA_MSG_SEND_DIRECT_REQ2 :/* Optional per 7.5.1 */ case FFA_MSG_SEND_DIRECT_RESP2 :/* Optional per 7.5.1 */
@@ -1028,6 +1026,20 @@ static void do_ffa_notif_get(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_info_get (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt,1 )) { +ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +} +bool kvm_host_ffa_handler (struct kvm_cpu_context *host_ctxt,u32 func_id) {struct arm_smccc_1_2_regs res;
@@ -1107,6 +1119,10 @@ bool kvm_host_ffa_handler(struct kvm_cpu_context *host_ctxt, u32 func_id)case FFA_NOTIFICATION_GET :do_ffa_notif_get (&res, host_ctxt); goto out_handled; +case FFA_NOTIFICATION_INFO_GET : +case FFA_FN64_NOTIFICATION_INFO_GET : +do_ffa_notif_info_get (&res, host_ctxt); + goto out_handled; }if (ffa_call_supported (func_id))
Signature · 1 line
2.55.0.rc0.786.g65d90a0328-goog
[email protected]
AI reviewRe: [PATCH v5 7/7] KVM: arm64: Support FFA_NOTIFICATION_INFO_GET in host handler
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] Overly strict validation of the W1 parameter in `do_ffa_notif_info_get` incorrectly treats it as…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Overly strict validation of the W1 parameter in do_ffa_notif_info_get incorrectly treats it as a Should-Be-Zero (SBZ) field, rejecting valid FFA_NOTIFICATION_INFO_GET requests. --
commit 8b1c1179ab464455664a3ac244072d9355b5e039
Author: Sebastian Ene <[email protected]>
KVM: arm64: Support FFA_NOTIFICATION_INFO_GET in host handler
This commit allows the host to query the FF-A notification status by proxying the info get message to Trustzone, whilst ensuring that the SBZ fields are enforced.
Quoted 4 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +0
-0
[ ... ]
arch/arm64/kvm/hyp/nvhe/ffa.c static void do_ffa_notif_get(struct arm_smccc_1_2_regs *res, · line 1034
Quoted 10 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +6
-0@@ -1028,6 +1026,20 @@ static void do_ffa_notif_get(struct arm_smccc_1_2_regs *res,hyp_smccc_1_2_smc (args, res); } +static void do_ffa_notif_info_get (struct arm_smccc_1_2_regs *res, +struct kvm_cpu_context *ctxt) +{ +struct arm_smccc_1_2_regs *args; + +if (ffa_check_unused_args_sbz (ctxt,1 )) {
[Severity: Medium]
Does this overly strict validation reject valid requests?
For FFA_NOTIFICATION_INFO_GET, W1 is used to specify the ID type (e.g., 1 for Partition/vCPU IDs). By starting the unused arguments check at index 1, this incorrectly treats the ID type parameter as a Should-Be-Zero field.
If the host attempts to query notification info for specific partitions or vCPUs by setting W1 to a non-zero valid ID list type, this will return FFA_RET_INVALID_PARAMETERS.
Should the SBZ check start from a later index instead?
Quoted 7 lines
arch/arm64/kvm/hyp/nvhe/ffa.c +7
-0+ffa_to_smccc_res (res,FFA_RET_INVALID_PARAMETERS ); +return ; + } + + args = (void *)&ctxt->regs.regs[0 ]; +hyp_smccc_1_2_smc (args, res); +}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7