[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v3 3/6] xen/arm: ffa: Tighten notification parameter validation


  • To: Bertrand Marquis <bertrand.marquis@xxxxxxx>
  • From: Mykola Kvach <xakep.amatop@xxxxxxxxx>
  • Date: Thu, 26 Nov 2026 05:01:39 +0200
  • Arc-authentication-results: i=1; mx.google.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=jL5TAhIxfCydDUFGUwtSL9jaxs1YribNpw7SOU57PeM=; fh=F3RNbjY7HGhv1K80flmiFZpRiz/hLFdWKtGPVcWuod8=; b=dkG+CejKFCW+FNljlIOq/D8hlGmvpMtB0kJ8JUAiAvOBQp4imTjygiHcr9SWq0q7jm YflquU8gFTch8x69BzVfzy3UbeUUDOhiZzKQPmBH19hCSPZLB+Au/xUHIas4e5cZQ79L eLtVIO9iJd2ZhD94Jr32WtfMpBEjURi038F0r14VYgEoajtBy815uO4F+k74XRZEu6Dj p1R3Celki6QPAxj0kdXImLyl6iKGNIuUIGR0Hu/xEbAzkLtnriGrEBmg2vTzDQvy2pPn je7ISc636DuL0UNaCFXcEWrD/DGLLsRyeaxjyrbXJ4N7uk/QPZ7gqtLpKR1UAqFyIxA4 584A==; darn=lists.xenproject.org
  • Arc-seal: i=1; a=rsa-sha256; t=1795662111; cv=none; d=google.com; s=arc-20260327; b=dhDxM8+8OeSwszU9FQp+aTuHtnV09PR+jxcnr6CLIOFfPBJJOAV+Qi/p6N/9xM+m+j BdnQhL+2La+mBA/5Ps7l1SFqhpxMaKX58lOYU3BgFgl4i4cL5vyYDrfr32k1DPikZwL+ /3HVVdEuieBFvkKFwyfGeDIw+HMpbVieizTHgny368jIZLRPKlCyXNstoTG0BISzUUdl Oq06jjzdz+GrEg3+92oyP8GC+rSrviCFrOPLtCQTALSerNW9LN5cdtXk43ASQdDdtPwd J4pqlcWVzTc9fzlm09Kjkp5+faLzO2anvTfO+pQo1aU8N4t8+CqpUNiF4gWa7EBDEwai KPaA==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20260707 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:MIME-Version"
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>, Jens Wiklander <jenswi@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jens Wiklander <jens.wiklander@xxxxxxxxxx>
  • Delivery-date: Thu, 26 Nov 2026 03:02:07 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Bertrand,

Thank you for the patch.

On Thu, Sep 3, 2026 at 5:44 PM Bertrand Marquis
<bertrand.marquis@xxxxxxx> wrote:
>
> The notification handlers still validate overlapping subsets of their
> inputs. BIND, UNBIND, and SET each decode caller and destination IDs
> locally, GET still accepts a non-zero receiver vCPU ID and reserved flag
> bits, and SET still accepts non-zero NS-virtual flags. BIND also treats
> unsupported non-zero flag encodings as a supported-feature failure
> instead of as malformed input.
>
> Add ffa_notif_validate_params() and use it to centralize the common
> caller/destination and non-zero bitmap checks for BIND, UNBIND, and SET.
> Also reject malformed GET and SET requests locally before touching
> cached state or forwarding anything to the SPMC. Keep BIND limited to
> global notifications and reject unsupported non-zero flag encodings with
> INVALID_PARAMETERS.
>
> - add a shared parameter validator for notification caller/destination
>   checks
> - wire BIND and UNBIND through the shared helper and reject unsupported
>   bind flag encodings with INVALID_PARAMETERS
> - reject non-zero receiver vCPU and reserved flag bits in
>   FFA_NOTIFICATION_GET
> - reject non-zero flags in the NS-virtual FFA_NOTIFICATION_SET path
>
> Functional impact: malformed notification requests are rejected
> consistently earlier in the mediator.
>
> Signed-off-by: Bertrand Marquis <bertrand.marquis@xxxxxxx>
> Reviewed-by: Jens Wiklander <jens.wiklander@xxxxxxxxxx>
> ---
> Changes since v2:
> - none
> Changes since v1:
> - rename helper to ffa_notif_validate_params()
> - add R-b from Jens
> ---
>  xen/arch/arm/tee/ffa_notif.c | 61 +++++++++++++++++++++++++++++-------
>  1 file changed, 50 insertions(+), 11 deletions(-)
>
> diff --git a/xen/arch/arm/tee/ffa_notif.c b/xen/arch/arm/tee/ffa_notif.c
> index a631481e3815..1260f98a77e9 100644
> --- a/xen/arch/arm/tee/ffa_notif.c
> +++ b/xen/arch/arm/tee/ffa_notif.c
> @@ -44,21 +44,40 @@ static bool inject_notif_pending(struct domain *d)
>      return false;
>  }
>
> +static int32_t ffa_notif_validate_params(uint16_t dom_id, uint16_t caller_id,
> +                                         uint16_t dest_id, uint32_t 
> bitmap_lo,
> +                                         uint32_t bitmap_hi)
> +{
> +    if ( caller_id != dom_id || dest_id == dom_id || !dest_id )
> +        return FFA_RET_INVALID_PARAMETERS;
> +
> +    if ( !bitmap_lo && !bitmap_hi )
> +        return FFA_RET_INVALID_PARAMETERS;
> +
> +    return FFA_RET_OK;
> +}
> +
>  int32_t ffa_handle_notification_bind(struct cpu_user_regs *regs)
>  {
>      struct domain *d = current->domain;
> +    struct ffa_ctx *ctx = d->arch.tee;
> +    int32_t ret;
>      uint32_t src_dst = get_user_reg(regs, 1);
>      uint32_t flags = get_user_reg(regs, 2);
>      uint32_t bitmap_lo = get_user_reg(regs, 3);
>      uint32_t bitmap_hi = get_user_reg(regs, 4);
> +    uint16_t caller_id = src_dst & GENMASK(15, 0);
> +    uint16_t dest_id = src_dst >> 16;
>
> -    if ( (src_dst & GENMASK(15, 0)) != ffa_get_vm_id(d) )
> +    if ( flags )    /* Only global notifications are supported */
>          return FFA_RET_INVALID_PARAMETERS;
>
> -    if ( flags )    /* Only global notifications are supported */
> -        return FFA_RET_DENIED;
> +    ret = ffa_notif_validate_params(ctx->ffa_id, caller_id, dest_id,
> +                                    bitmap_lo, bitmap_hi);
> +    if ( ret )
> +        return ret;
>
> -    if ( FFA_ID_IS_SECURE(src_dst >> 16) && fw_notif_enabled )
> +    if ( FFA_ID_IS_SECURE(dest_id) && fw_notif_enabled )
>          return ffa_simple_call(FFA_NOTIFICATION_BIND, src_dst, flags,
>                                 bitmap_lo, bitmap_hi);
>
> @@ -68,16 +87,22 @@ int32_t ffa_handle_notification_bind(struct cpu_user_regs 
> *regs)
>  int32_t ffa_handle_notification_unbind(struct cpu_user_regs *regs)
>  {
>      struct domain *d = current->domain;
> +    struct ffa_ctx *ctx = d->arch.tee;
> +    int32_t ret;
>      uint32_t src_dst = get_user_reg(regs, 1);
>      uint32_t bitmap_lo = get_user_reg(regs, 3);
>      uint32_t bitmap_hi = get_user_reg(regs, 4);
> +    uint16_t caller_id = src_dst & GENMASK(15, 0);
> +    uint16_t dest_id = src_dst >> 16;
>
> -    if ( (src_dst & GENMASK(15, 0)) != ffa_get_vm_id(d) )
> -        return FFA_RET_INVALID_PARAMETERS;
> +    ret = ffa_notif_validate_params(ctx->ffa_id, caller_id, dest_id,
> +                                    bitmap_lo, bitmap_hi);
> +    if ( ret )
> +        return ret;
>
> -    if ( FFA_ID_IS_SECURE(src_dst >> 16) && fw_notif_enabled )
> -        return  ffa_simple_call(FFA_NOTIFICATION_UNBIND, src_dst, 0, 
> bitmap_lo,
> -                                bitmap_hi);
> +    if ( FFA_ID_IS_SECURE(dest_id) && fw_notif_enabled )
> +        return ffa_simple_call(FFA_NOTIFICATION_UNBIND, src_dst, 0, 
> bitmap_lo,
> +                               bitmap_hi);
>
>      return FFA_RET_NOT_SUPPORTED;
>  }
> @@ -144,6 +169,12 @@ void ffa_handle_notification_get(struct cpu_user_regs 
> *regs)
>          return;
>      }
>
> +    if ( recv >> 16 || (flags & GENMASK(31, 4)) )

w1 bits [31:16] are the receiver vCPU ID (DEN0077A 1.2, Table 16.23).
Linux always puts smp_processor_id() in this field
(ffa_notification_get() in drivers/firmware/arm_ffa/driver.c), even for
a VM that only has global bindings.

For example, vCPU0 is offline and inject_notif_pending() sends the NPI
to vCPU1. Linux handles the NPI on vCPU1 and calls GET from there, so
the vCPU ID in w1 is non-zero. This check returns
FFA_RET_INVALID_PARAMETERS before the guest can read any bitmap. Patch
1/6 delivers the RX-buffer-full NPI to vCPU1 in exactly this case, and
that notification lives in Xen's local hyp_pending bitmap, so GET has
to work there too.

Can we check the reserved bits in flags separately and accept
a non-zero receiver vCPU ID (or at most reject values >= d->max_vcpus)?

When forwarding to the SPMC I would mask the field to vCPU0, since Xen
only tracks global notifications.

Best regards,
Mykola

> +    {
> +        ffa_set_regs_error(regs, FFA_RET_INVALID_PARAMETERS);
> +        return;
> +    }
> +
>      if ( fw_notif_enabled && (flags & ( FFA_NOTIF_FLAG_BITMAP_SP |
>                                          FFA_NOTIF_FLAG_BITMAP_SPM )) )
>      {
> @@ -208,11 +239,19 @@ int32_t ffa_handle_notification_set(struct 
> cpu_user_regs *regs)
>      uint32_t flags = get_user_reg(regs, 2);
>      uint32_t bitmap_lo = get_user_reg(regs, 3);
>      uint32_t bitmap_hi = get_user_reg(regs, 4);
> +    uint16_t caller_id = src_dst >> 16;
> +    uint16_t dest_id = src_dst & GENMASK(15, 0);
> +    int32_t ret;
> +
> +    ret = ffa_notif_validate_params(ffa_get_vm_id(d), caller_id, dest_id,
> +                                    bitmap_lo, bitmap_hi);
> +    if ( ret )
> +        return ret;
>
> -    if ( (src_dst >> 16) != ffa_get_vm_id(d) )
> +    if ( flags )
>          return FFA_RET_INVALID_PARAMETERS;
>
> -    if ( FFA_ID_IS_SECURE(src_dst & GENMASK(15, 0)) && fw_notif_enabled )
> +    if ( FFA_ID_IS_SECURE(dest_id) && fw_notif_enabled )
>          return ffa_simple_call(FFA_NOTIFICATION_SET, src_dst, flags, 
> bitmap_lo,
>                                 bitmap_hi);
>
> --
> 2.53.0
>
>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.