lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <p4wbqdmytbzjmxsdovnboetjxbyvuhkwunieuwoh6rui72v7pb@huxwyphj63yv>
Date: Tue, 30 Jul 2024 12:20:38 -0500
From: Andrew Halaney <ahalaney@...hat.com>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: Bjorn Andersson <andersson@...nel.org>, 
	Konrad Dybcio <konrad.dybcio@...aro.org>, Elliot Berman <quic_eberman@...cinc.com>, 
	Amirreza Zarrabi <quic_azarrabi@...cinc.com>, linux-arm-msm@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Bartosz Golaszewski <bartosz.golaszewski@...aro.org>, Johan Hovold <johan+linaro@...nel.org>, 
	Maximilian Luz <luzmaximilian@...il.com>
Subject: Re: [PATCH 1/2] firmware: qcom: tzmem: fix virtual-to-physical
 address conversion

On Tue, Jul 30, 2024 at 05:38:48PM GMT, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> 
> We currently only correctly convert the virtual address passed by the
> caller to qcom_tzmem_to_phys() if it corresponds to the base address of
> the chunk. If the user wants to convert some pointer at an offset
> relative to that base address, we'll return 0. Let's change the
> implementation of qcom_tzmem_to_phys(): iterate over the chunks and try
> to call gen_pool_virt_to_phys() just-in-time instead of trying to call
> it only once when creating the chunk.
> 
> Fixes: 84f5a7b67b61 ("firmware: qcom: add a dedicated TrustZone buffer allocator")
> Reported-by: Johan Hovold <johan+linaro@...nel.org>
> Closes: https://lore.kernel.org/lkml/20240729095542.21097-1-johan+linaro@kernel.org/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> ---
>  drivers/firmware/qcom/qcom_tzmem.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/firmware/qcom/qcom_tzmem.c b/drivers/firmware/qcom/qcom_tzmem.c
> index 17948cfc82e7..1294233a4785 100644
> --- a/drivers/firmware/qcom/qcom_tzmem.c
> +++ b/drivers/firmware/qcom/qcom_tzmem.c
> @@ -40,7 +40,6 @@ struct qcom_tzmem_pool {
>  };
>  
>  struct qcom_tzmem_chunk {
> -	phys_addr_t paddr;
>  	size_t size;
>  	struct qcom_tzmem_pool *owner;
>  };
> @@ -385,7 +384,6 @@ void *qcom_tzmem_alloc(struct qcom_tzmem_pool *pool, size_t size, gfp_t gfp)
>  		return NULL;
>  	}
>  
> -	chunk->paddr = gen_pool_virt_to_phys(pool->genpool, vaddr);
>  	chunk->size = size;
>  	chunk->owner = pool;
>  
> @@ -442,14 +440,25 @@ EXPORT_SYMBOL_GPL(qcom_tzmem_free);
>  phys_addr_t qcom_tzmem_to_phys(void *vaddr)

We should update the kerneldoc here, it currently says:

    /**
     * qcom_tzmem_to_phys() - Map the virtual address of a TZ buffer to physical.
     * @vaddr: Virtual address of the buffer allocated from a TZ memory pool.
     *
     * Can be used in any context. The address must have been returned by a call
     * to qcom_tzmem_alloc().
     *
     * Returns: Physical address of the buffer.
     */
    phys_addr_t qcom_tzmem_to_phys(void *vaddr)

"The address must have been returned by a call to qcom_tzmem_alloc()" is
no longer a strict requirement, it can be within the buffer now.

Otherwise, I believe this should fix the problem you and Johan
highlighted and looks ok to me, thanks for the fix.

Acked-by: Andrew Halaney <ahalaney@...hat.com>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ