From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C43BFC47095 for ; Wed, 9 Jun 2021 03:29:26 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 731416128D for ; Wed, 9 Jun 2021 03:29:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 731416128D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 328FA82EB9; Wed, 9 Jun 2021 05:29:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; secure) header.d=protonmail.com header.i=@protonmail.com header.b="eRMuC1R1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1812982D58; Tue, 8 Jun 2021 12:07:40 +0200 (CEST) Received: from mail2.protonmail.ch (mail2.protonmail.ch [185.70.40.22]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8D5C682D58 for ; Tue, 8 Jun 2021 12:07:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=litchi.pi@protonmail.com Date: Tue, 08 Jun 2021 10:07:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1623146854; bh=cckIJqEuMl3176QkcvMP4bTQdeh0LfMtushI0PbBszM=; h=Date:To:From:Cc:Reply-To:Subject:From; b=eRMuC1R1T/nRheXDrLNNnoEvnjCFaxEv+EJnrrS5nNsM3SujHOtvMm89Y8+lL1V1U TK2Rqn8Wsh2q9QOBuVvOLBTBoDx+9NRB25BO9mmadJhWddkkSGC8f3V6ebcHOgsgKc pap7ot+iZltCPmP6quQ1kCx7GfYHL/O2ZTgjLSoc= To: u-boot@lists.denx.de From: =?utf-8?Q?Timoth=C3=A9e_Cercueil?= Cc: Jens Wiklander , Heinrich Schuchardt , =?utf-8?Q?Timoth=C3=A9e_Cercueil?= Subject: [PATCH] optee/rpmb.c: Fix driver routing memory alignment using a temporary buffer Message-ID: <20210608100717.17567-1-litchi.pi@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Wed, 09 Jun 2021 05:29:11 +0200 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: =?utf-8?Q?Timoth=C3=A9e_Cercueil?= Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean From: Timoth=C3=A9e Cercueil OP-TEE OS inserts a 6-byte header before a raw RPMB frame which makes RPMB data buffer not 32bit aligned. Many RPMB drivers implicitly expect 32bit alignment of the eMMC frame including arm_pl180_mmci.c, sandbox_mmc.c and stm32_sdmmc2.c To prevent breaking ABI with OPTEE-OS RPC memrefs, allocate a temporary buffer to copy the data into an aligned memory. Signed-off-by: Timoth=C3=A9e Cercueil Change-Id: Id78d638851a666a35af907ca8de71dae00946457 Signed-off-by: Timoth=C3=A9e Cercueil --- drivers/tee/optee/rpmb.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/tee/optee/rpmb.c b/drivers/tee/optee/rpmb.c index 0804fc963c..4713df711c 100644 --- a/drivers/tee/optee/rpmb.c +++ b/drivers/tee/optee/rpmb.c @@ -122,6 +122,10 @@ static u32 rpmb_process_request(struct optee_private *= priv, void *req, { =09struct rpmb_req *sreq =3D req; =09struct mmc *mmc; +=09void *rpmb_data; +=09void *rpmb_frame_buffer =3D NULL; +=09size_t rpmb_data_sz; +=09int ret; =09if (req_size < sizeof(*sreq)) =09=09return TEE_ERROR_BAD_PARAMETERS; @@ -131,9 +135,23 @@ static u32 rpmb_process_request(struct optee_private *= priv, void *req, =09=09mmc =3D get_mmc(priv, sreq->dev_id); =09=09if (!mmc) =09=09=09return TEE_ERROR_ITEM_NOT_FOUND; -=09=09if (mmc_rpmb_route_frames(mmc, RPMB_REQ_DATA(req), -=09=09=09=09=09 req_size - sizeof(struct rpmb_req), -=09=09=09=09=09 rsp, rsp_size)) + +=09=09rpmb_data =3D RPMB_REQ_DATA(req); +=09=09rpmb_data_sz =3D req_size - sizeof(struct rpmb_req); +=09=09if (!IS_ALIGNED((uintptr_t)rpmb_data, sizeof(u32))) { +=09=09=09/* 32bit data alignment is required by RPMB driver */ +=09=09=09rpmb_frame_buffer =3D malloc(rpmb_data_sz); +=09=09=09if (!rpmb_frame_buffer) +=09=09=09=09return TEE_ERROR_OUT_OF_MEMORY; + +=09=09=09memcpy(rpmb_frame_buffer, rpmb_data, rpmb_data_sz); +=09=09=09rpmb_data =3D rpmb_frame_buffer; +=09=09} + +=09=09ret =3D mmc_rpmb_route_frames(mmc, rpmb_data, rpmb_data_sz, +=09=09=09=09=09 rsp, rsp_size); +=09=09free(rpmb_frame_buffer); +=09=09if (ret) =09=09=09return TEE_ERROR_BAD_PARAMETERS; =09=09return TEE_SUCCESS; -- 2.17.1