On Fri, Sep 11, 2020 at 12:16:40PM +0800, Hillf Danton wrote:
> Detect race destroying ctx in order to avoid UAF.
> 
> +++ b/drivers/infiniband/core/ucma.c
> @@ -625,6 +625,10 @@ static ssize_t ucma_destroy_id(struct uc
>               return PTR_ERR(ctx);
>  
>       mutex_lock(&ctx->file->mut);
> +     if (ctx->destroying == 1) {
> +             mutex_unlock(&ctx->file->mut);
> +             return -ENXIO;
> +     }
>       ctx->destroying = 1;
>       mutex_unlock(&ctx->file->mut);
>  
> @@ -1826,6 +1830,8 @@ static int ucma_close(struct inode *inod
>  
>       mutex_lock(&file->mut);
>       list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) {
> +             if (ctx->destroying == 1)
> +                     continue;
>               ctx->destroying = 1;
>               mutex_unlock(&file->mut);
>  

ucma_destroy_id() is called from write() and ucma_close is release(),
so there is no way these can race?

Jason

Reply via email to