Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2962398pxj; Mon, 17 May 2021 14:14:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzCseL8Kifofa9Y4EpP8Qh7/uraiXtJMHPOGnXWS5Af3SLTPXFlClGf2XBIG9OB3kAPPVi/ X-Received: by 2002:a50:aa95:: with SMTP id q21mr2343740edc.329.1621286043671; Mon, 17 May 2021 14:14:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621286043; cv=none; d=google.com; s=arc-20160816; b=J/pyznh5Aty2+61UTGgwZA0vAAmkG8lZnIh4I43lZdF6sdM2Dbs0LjCRrSlIRFLEZp gTb35Wldx+lgG9QyzW3uaLwC01MY0ajbyagqzFQfzd81SOyRUvn+W+rK5qMdUb/EhSgw HEj00RLcnuN56USHguHqd2lIw1JTA1zweWVFJqa8Fjazwdpc+TqKEPSqI+sZANZcGnkc K42PJGWxT+sHSvkWyKPQTOx1zVYYTbsmOX/NJPZ48hdF5xJ539Elx1iZi8ljD9mBLl5v 7LbdOmfaGUWaGNHeegLPBZ7LBlkaX3uSnM+udl+T/hjtljJt+ZjwhQewRBoexDwYtESZ xuiQ== 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=V7YE0q06Df8RAK7ryWmwGi92bJNHuvl3pPr/uka0MpBiqlc70Vu8NvJ5VY5X0Ein1m CxWJ4RXqlscV091cFusdC1mHGnUIcev8ETSuRg1vvYp0eclsLyZNDQD84A1bsPnv5hfk GfjN0Xie+IS1D0IC5brLWbJfITGq2KqywN5TobX3iDg/Pf2MCeyqZf6DuYZn/ZjsjZ46 l2+bo+X9FkiOIX2Fg7UVi9Mn4jKupNkX1hH/XVnoOBaX5Bzhj/U5PrrMmbcxUmUDALn8 1osXqtW7OBPLiwOkmdY26hjg3EjhZG86/8HJGs+yxmc4TmXiytxtRlpDzqSOzUmO/9gD eMxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wIyNvOu3; 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 o15si15207155edc.604.2021.05.17.14.13.39; Mon, 17 May 2021 14:14:03 -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=wIyNvOu3; 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 S238170AbhEQOIp (ORCPT + 99 others); Mon, 17 May 2021 10:08:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:58460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237946AbhEQOGy (ORCPT ); Mon, 17 May 2021 10:06:54 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 315E66135D; Mon, 17 May 2021 14:05:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260330; bh=Kt9kyEWJd9xaRMNQHUWBMtEao+CZbeSDxxLpH2azuwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wIyNvOu3N2MrjwTA15LVX62xcFBeTuCijmISSOZkxzwdt85lD5m3bycvwqwRcy1tE vaTCLNN1mqjG4Y7HLbvcq3h/SSrFjMNlphUUwF6V85Z9kTwzT4daYsRTgqdgP2WNDc iTUu4t4BpRwZ5lQ4yzFv4cmmj6VqeQjAN04X0Wko= 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.12 001/363] KEYS: trusted: Fix memory leak on object td Date: Mon, 17 May 2021 15:57:47 +0200 Message-Id: <20210517140302.560019789@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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);