Re: [PATCH v2 21/30] crypto: sa2ul - reject exhausted context IDs

From: Thorsten Blum

Date: Wed Nov 04 2026 - 08:31:53 EST


On Wed, Nov 04, 2026 at 11:14:31AM +0530, Manorit Chawdhry wrote:
> When every security-context ID is allocated, the bitmap search returns
> SA_MAX_NUM_CTX. Setting that out-of-range bit can corrupt adjacent state
> in the device structure. Reject allocation while still holding the lock
> so no bitmap or context count is changed.
>
> Fixes: 7694b6ca649f ("crypto: sa2ul - Add crypto driver")
> Signed-off-by: Manorit Chawdhry <m-chawdhry@xxxxxx>
> ---
> drivers/crypto/sa2ul.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/crypto/sa2ul.c b/drivers/crypto/sa2ul.c
> index ead12f77ff67..2964aa44d50e 100644
> --- a/drivers/crypto/sa2ul.c
> +++ b/drivers/crypto/sa2ul.c
> @@ -717,6 +717,10 @@ static int sa_init_ctx_info(struct sa_ctx_info *ctx,
>
> spin_lock(&data->scid_lock);
> bn = find_first_zero_bit(data->ctx_bm, SA_MAX_NUM_CTX);
> + if (bn >= SA_MAX_NUM_CTX) {
> + spin_unlock(&data->scid_lock);
> + return -ENOSPC;
> + }
> __set_bit(bn, data->ctx_bm);
> data->sc_id++;
> spin_unlock(&data->scid_lock);

Reviewed-by: Thorsten Blum <blum@xxxxxxxxxx>