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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C03B3C38142 for ; Fri, 27 Jan 2023 18:43:20 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6C861856E7; Fri, 27 Jan 2023 19:43:17 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iqVaIZH8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 84D6A856F7; Fri, 27 Jan 2023 19:43:15 +0100 (CET) Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 778CC856DD for ; Fri, 27 Jan 2023 19:42:50 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ivan.khoronzhuk@gmail.com Received: by mail-ej1-x631.google.com with SMTP id me3so16118510ejb.7 for ; Fri, 27 Jan 2023 10:42:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=l3wKbz5xJDqYL/K9O71j8xwoNED1qU93hHh6sQnJDJY=; b=iqVaIZH8a0/d/bggGmN9jTp4qfHvgfaXmX6/GhfAzyBTZhA1dDVvIQbezJl6YmcwCU tLUPyUr8FF9ijkKftRjLRkrIUaNDTQoPPhGngUpFRX5N+DkYLnmFGeGSKN7dkfooeemS JjbGuGRz+q/xt1GpXf8WCYvfGZZCpOJ1if92sF0BzV7+m9DPexMz0wiAtcfUpl/iZONN 5nQyTcQ2LytdOr9VUUsMegGHV1kL8wLL+5I/lT7x2TSHBrX246sRddpJF8xk4U4kmZ9F LNnBHXlT53HxaiNK9rsylE6Ty1NGjwUUe32M4/SJ23a2BGtyipnowoSvFKEbhn/tmkrZ 78Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=l3wKbz5xJDqYL/K9O71j8xwoNED1qU93hHh6sQnJDJY=; b=y+K2w7Ar5qpu9eVo9oAAmzzWxQAZ5svWmRzu4slOpiFmuBdOqRU/cuMtlhWGQp57rf 9s3fAjnKRCWRkA6tI82mZH/5XT3vYmU/bBEkK/MaV4MarvIDfHucDQna6FCjoTx+E+UF 3AwXHDXXwAPZUNKKVQMf7H2mWAdggsdenP7YXqoMaylPojTW4+rZH+X8NCpkODosStlK DV+EYFZADUOeBMCt/QdhVuBI7bYqA19cHXvlrnvh0pmuQk3E8IarmnxSl1CNk/wyzG03 OWIb5LSPWZqWEhYgS6Y8hO7osoi4upm4La/fIInUWczFQPFLIRmSuiMATSwzEnBH0oMS xCpw== X-Gm-Message-State: AO0yUKXrP4pvsw9H1VYM5lkMC0sIpzY6WJeS7qEj08eFYo13qARr1I1F B55c1nAwfayiqbpxKhtBhG4= X-Google-Smtp-Source: AK7set9xKzPzlfKBhg+kgO+i2ZazGdrk3gTSC/+vMFIn0dBGmaJO+YpPoSMoSn2KCX+CLrmppsncwg== X-Received: by 2002:a17:907:3f8d:b0:878:59f7:3627 with SMTP id hr13-20020a1709073f8d00b0087859f73627mr10231554ejc.49.1674844969936; Fri, 27 Jan 2023 10:42:49 -0800 (PST) Received: from ikhor.synapse.com ([46.211.104.218]) by smtp.gmail.com with ESMTPSA id o25-20020a170906861900b008675df83251sm2638797ejx.34.2023.01.27.10.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 10:42:49 -0800 (PST) From: Ivan Khoronzhuk X-Google-Original-From: Ivan Khoronzhuk To: igor.opaniuk@gmail.com, u-boot@lists.denx.de Cc: Jens Wiklander , Ivan Khoronzhuk Subject: [PATCH v3] common: avb_verify: prevent opening incorrect session Date: Fri, 27 Jan 2023 20:42:44 +0200 Message-Id: <20230127184244.283463-1-ivan.khoronzhuk@globallogic.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230122024130.4028621-1-ivan.khoronzhuk@gmail.com> References: <20230122024130.4028621-1-ivan.khoronzhuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The arg->session is not valid if arg->ret != NULL, so can't be assigned, correct this. Also remove "while" loop as there is no reason for looping till correct session is opened. Signed-off-by: Ivan Khoronzhuk --- common/avb_verify.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/common/avb_verify.c b/common/avb_verify.c index 0520a71455..c3cccd986d 100644 --- a/common/avb_verify.c +++ b/common/avb_verify.c @@ -605,26 +605,26 @@ static AvbIOResult validate_vbmeta_public_key(AvbOps *ops, #ifdef CONFIG_OPTEE_TA_AVB static int get_open_session(struct AvbOpsData *ops_data) { - struct udevice *tee = NULL; - - while (!ops_data->tee) { - const struct tee_optee_ta_uuid uuid = TA_AVB_UUID; - struct tee_open_session_arg arg; - int rc; - - tee = tee_find_device(tee, NULL, NULL, NULL); - if (!tee) - return -ENODEV; - - memset(&arg, 0, sizeof(arg)); - tee_optee_ta_uuid_to_octets(arg.uuid, &uuid); - rc = tee_open_session(tee, &arg, 0, NULL); - if (!rc) { - ops_data->tee = tee; - ops_data->session = arg.session; - } - } + const struct tee_optee_ta_uuid uuid = TA_AVB_UUID; + struct tee_open_session_arg arg; + struct udevice *tee; + int rc; + + if (ops_data->tee) + return 0; + + tee = tee_find_device(NULL, NULL, NULL, NULL); + if (!tee) + return -ENODEV; + + memset(&arg, 0, sizeof(arg)); + tee_optee_ta_uuid_to_octets(arg.uuid, &uuid); + rc = tee_open_session(tee, &arg, 0, NULL); + if (rc || arg.ret) + return -EIO; + ops_data->tee = tee; + ops_data->session = arg.session; return 0; } -- 2.34.1