From patchwork Mon Nov 27 14:15:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13469717 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8797BC4167B for ; Mon, 27 Nov 2023 14:17:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EaQ+njn7+Y5q2Zm31IWb3b389tEmvVVKZLWOJHs1APQ=; b=fMERtjo+k2w2u0 h1HC/op97audRfIR6b00Uvo+XPoWGcVmLadAoumEMu7QO39gid5DO7SOuIAiTh5ch4M9bJvSt+0cC gU4kbFv6hIhz4zYR28ECBhwBOXmBkDdTsi9rLZxIgcPXqC75za6fj+Qjp8yWS70+wvXqiOlc4tY+I 86uM/S0dIMzd6OIl5zT7/hKCl5nts1p4Jta45Wr26WMtk/RgSTeQxOf8oe3WvLaDSXJBeij8i/HzV 5r8m7daA+Z4bcjc15mwf6SJc5oi0a7GiRWAFoyy2nBiOuYFsLHEnDnoTVtppK/TqjgarbBTB/LYoE uF/Hmq84xCaWgFYMp5ZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7cPP-002fM6-2S; Mon, 27 Nov 2023 14:16:24 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7cPK-002fHa-0e for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 14:16:20 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-40b473dce26so6379955e9.3 for ; Mon, 27 Nov 2023 06:16:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1701094570; x=1701699370; darn=lists.infradead.org; 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=6p7Yk0pPh+5XOIFlXKbXoyDeljmm58+0nwJPnMfZeAs=; b=QYu8Dqtoqo30oKuYaXnqIn2/dWW6sikcyGNGaMmCiOMEeFybB7GntAxnpChrUPE03o 1+L5gJ8IOclYmyPmePttf7HQvIvQFYPjp/wsr2ZXTviLtXeotJWsn/eZ2z38I21Ak4lz RNSFYlLRush95siPDD2OWvvsTBtYTiAnNuJKsu6+Sdmt3DhEfBmKluEuvlxsIrh1UqkA juTmqDYKqpFx7l2Q4glekZ+1XakLotj194ue2PQdxldxXs9Ra+8k2OA6Igi0uUqMSn8+ 6z8VyuifHdO2mp2fMPSCSkQtwN4y3UAcVhmEKWSKOFrHU3HX91vQCcILIs9m6/A8mm7b JGEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701094570; x=1701699370; 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=6p7Yk0pPh+5XOIFlXKbXoyDeljmm58+0nwJPnMfZeAs=; b=uKKC51Ja+GifxP9hiB2Fo71VeLG5Z9TEJ6W1XxWK6qnEzNq0lOWFZb5eEXs19uSarx RcZ6cm4wPTeSZA/SXx2qGO08otEvppS7E6wc64YWIDNlWlga3vJBp7Gj9/LfQ9nEPjpy C3+cARlpPe8yEShleHr8sDMKP59XihxZxAIzH5J0bmRnLVK2spq1CB/nwsmD+n1T1pTz ydRq4MKiSGFf38eXK0z2rv1KwAXRzG3kx8bRvSAgaYGMa9dwojVrU9L+zM1UYPS/sNlY uzNC15qZcOBYOe1QBAWJojXco4F/n1cXiNmnRUIUwzvgPIJAszzXVP4WarJEeETw4FQj 1r1Q== X-Gm-Message-State: AOJu0YyCJiCYUtqM7vY4hmb/G+cuC54hhfmDd0klDHBwWlKyNKeK02jY gu4MaXJT4c1+PE0YEZkASCNcUA== X-Google-Smtp-Source: AGHT+IGdj2lm+H87M+BbCZltT0WCKLIysUDz4kXF1jFX0sJyav3qV/p+Wda+ZHxLQ7t6J9lKOHi9pQ== X-Received: by 2002:a05:600c:684:b0:408:56ea:f061 with SMTP id a4-20020a05600c068400b0040856eaf061mr9276619wmn.24.1701094570027; Mon, 27 Nov 2023 06:16:10 -0800 (PST) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:bf33:77c7:8131:5e64]) by smtp.gmail.com with ESMTPSA id be7-20020a05600c1e8700b00405442edc69sm14658830wmb.14.2023.11.27.06.16.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 06:16:09 -0800 (PST) From: Bartosz Golaszewski To: Andy Gross , Bjorn Andersson , Konrad Dybcio , Elliot Berman , Krzysztof Kozlowski , Guru Das Srinagesh , Andrew Halaney , Maximilian Luz , Alex Elder , Srini Kandagatla Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@quicinc.com, Bartosz Golaszewski , kernel test robot , Dan Carpenter Subject: [PATCH v6 01/13] firmware: qcom: qseecom: fix memory leaks in error paths Date: Mon, 27 Nov 2023 15:15:48 +0100 Message-Id: <20231127141600.20929-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231127141600.20929-1-brgl@bgdev.pl> References: <20231127141600.20929-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231127_061618_397684_0D7A768B X-CRM114-Status: GOOD ( 13.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski Fix instances of returning error codes directly instead of jumping to the relevant labels where memory allocated for the SCM calls would be freed. Fixes: 759e7a2b62eb ("firmware: Add support for Qualcomm UEFI Secure Application") Reported-by: kernel test robot Reported-by: Dan Carpenter Closes: https://lore.kernel.org/r/202311270828.k4HGcjiL-lkp@intel.com/ Signed-off-by: Bartosz Golaszewski Reviewed-by: Maximilian Luz --- .../firmware/qcom/qcom_qseecom_uefisecapp.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c index a33acdaf7b78..32188f098ef3 100644 --- a/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c +++ b/drivers/firmware/qcom/qcom_qseecom_uefisecapp.c @@ -325,8 +325,10 @@ static efi_status_t qsee_uefi_get_variable(struct qcuefi_client *qcuefi, const e req_data->length = req_size; status = ucs2_strscpy(((void *)req_data) + req_data->name_offset, name, name_length); - if (status < 0) - return EFI_INVALID_PARAMETER; + if (status < 0) { + efi_status = EFI_INVALID_PARAMETER; + goto out_free; + } memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); @@ -471,8 +473,10 @@ static efi_status_t qsee_uefi_set_variable(struct qcuefi_client *qcuefi, const e req_data->length = req_size; status = ucs2_strscpy(((void *)req_data) + req_data->name_offset, name, name_length); - if (status < 0) - return EFI_INVALID_PARAMETER; + if (status < 0) { + efi_status = EFI_INVALID_PARAMETER; + goto out_free; + } memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); @@ -563,8 +567,10 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, memcpy(((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); status = ucs2_strscpy(((void *)req_data) + req_data->name_offset, name, *name_size / sizeof(*name)); - if (status < 0) - return EFI_INVALID_PARAMETER; + if (status < 0) { + efi_status = EFI_INVALID_PARAMETER; + goto out_free; + } status = qcom_qseecom_app_send(qcuefi->client, req_data, req_size, rsp_data, rsp_size); if (status) { @@ -635,7 +641,7 @@ static efi_status_t qsee_uefi_get_next_variable(struct qcuefi_client *qcuefi, * have already been validated above, causing this function to * bail with EFI_BUFFER_TOO_SMALL. */ - return EFI_DEVICE_ERROR; + efi_status = EFI_DEVICE_ERROR; } out_free: