Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp176430pxj; Tue, 18 May 2021 00:21:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfQ+YP8XHTXqt0cDd0VNiNy3upEO5nzGnZteokv9CwC3v8aO2MsMp3KktZR90FpzRv+MkN X-Received: by 2002:a17:906:590d:: with SMTP id h13mr4532532ejq.169.1621322511241; Tue, 18 May 2021 00:21:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621322511; cv=none; d=google.com; s=arc-20160816; b=Nn+JDxP0vuotP0MA1pjgo8crMjZNo1tMerCUkG/GMgOmRn2iGntKBDo1veGXtW4bj2 oYQJ1H0ntsPcOp/LajIU9A9o5N9meK9EEtzvP4RsMcmAPLZ74FqzwCohTladDBpiW383 csCa9Ezaobo9fSoR4wlSSxH0sLTSqde0zC5oJzZwziDZ7Hp7gu81rUMZB/51fCZioaBX 6RrsxFhTE8aSRm8GT72DHfoTIlUP5zl9jJ9tNHnEjs/LsobZtAAI5fV9M937Oa51Ls3L sSlezX8potbEhQb1N6Yz48enPdBJgh5kA26a0fJZ7EHx9kCws5qxW2NAyuyfrNVFNwbk F1pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NdHg+HCdo+v5YcxCSIcdfqBZlCv+fUuVR/7Z4NB3QPg=; b=TET26gsfn6s4HK/zXpeTLFyBEN6ZrIXPodXd3b7K5scnovnbQVNc+ELpCIuMSNV7Ua gBLp2FwWrLPoXhumtmoKM4lfrad4mlOQo+fwOpvPDbWKG6pJMsgOkqMIJVknqpNpn/Zr 0CN4V8cUNk440et0wZAij1Q1MYhl7GQR0CvnM+vPx2sejyp2SNNgB0d06KNqZC2r02wy RW0lzWls8f6sWfLtt799IibIbLy11FVgXOm7wKWkVoYx9Y3WJNeqK14v1USPNoSXPHg2 kjhdP5Qv/AgtWoMR5zh/k5rFvXSD370fWa/rn9HR+ld8gqzSc+K6M8ghnAdNsJeCya31 qgSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=soD9Dfll; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb7si16848798ejc.507.2021.05.18.00.21.28; Tue, 18 May 2021 00:21:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=soD9Dfll; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242025AbhEQOy1 (ORCPT + 99 others); Mon, 17 May 2021 10:54:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:37902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241774AbhEQOqB (ORCPT ); Mon, 17 May 2021 10:46:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD9F061448; Mon, 17 May 2021 14:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621261280; bh=Kt9kyEWJd9xaRMNQHUWBMtEao+CZbeSDxxLpH2azuwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=soD9DfllXu2RsQK11meg+2tnd+Go3jV/5xX6DmE1NThAWBYXgQ/nyy7kQkRDexuXs Scug8P3A3ZSILQ5RRo88e4CMFURXhU5+596hfupJ2JcQv9/+PdIedZPGEXenOznipF nUROJMetTFDQE8v59SrjHLvGBbi768tQauPMA8Ak= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Nick Desaulniers , Jarkko Sakkinen Subject: [PATCH 5.10 001/289] KEYS: trusted: Fix memory leak on object td Date: Mon, 17 May 2021 15:58:46 +0200 Message-Id: <20210517140305.198832527@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Colin Ian King commit 83a775d5f9bfda95b1c295f95a3a041a40c7f321 upstream. Two error return paths are neglecting to free allocated object td, causing a memory leak. Fix this by returning via the error return path that securely kfree's td. Fixes clang scan-build warning: security/keys/trusted-keys/trusted_tpm1.c:496:10: warning: Potential memory leak [unix.Malloc] Cc: stable@vger.kernel.org Fixes: 5df16caada3f ("KEYS: trusted: Fix incorrect handling of tpm_get_random()") Signed-off-by: Colin Ian King Reviewed-by: Nick Desaulniers Reviewed-by: Jarkko Sakkinen Signed-off-by: Jarkko Sakkinen Signed-off-by: Greg Kroah-Hartman --- security/keys/trusted-keys/trusted_tpm1.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/security/keys/trusted-keys/trusted_tpm1.c +++ b/security/keys/trusted-keys/trusted_tpm1.c @@ -500,10 +500,12 @@ static int tpm_seal(struct tpm_buf *tb, ret = tpm_get_random(chip, td->nonceodd, TPM_NONCE_SIZE); if (ret < 0) - return ret; + goto out; - if (ret != TPM_NONCE_SIZE) - return -EIO; + if (ret != TPM_NONCE_SIZE) { + ret = -EIO; + goto out; + } ordinal = htonl(TPM_ORD_SEAL); datsize = htonl(datalen);