From nobody Sat Feb 7 07:26:52 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA6F2C00140 for ; Mon, 15 Aug 2022 22:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243731AbiHOWCe (ORCPT ); Mon, 15 Aug 2022 18:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347278AbiHOWA0 (ORCPT ); Mon, 15 Aug 2022 18:00:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BAB5BD8; Mon, 15 Aug 2022 12:35:17 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 31829611A1; Mon, 15 Aug 2022 19:35:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39AFCC433D6; Mon, 15 Aug 2022 19:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592116; bh=oaG8uRFFATYpJIIbw+3NNlxAQIMb14Wg6pkWXbXB2uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xlWPHk4iEBy+uMWpYjHAFSDuRBVcafsUhUgL4OwBenKZOsc2Nqhvj2ckZCwd9H9BN 6O1CZRCKTV23P8cJ3JyGHDsBcd5smSOer2tMiIJDD9AlBEC7MS5RVm3dgvNfPPUUnu xNaw9V6bj0a/EnSQTiSRdQNqy69VF84YXc+kG4h4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Nguyen , David Rientjes , Peter Gonda , John Allen , Herbert Xu Subject: [PATCH 5.19 0061/1157] crypto: ccp - Use kzalloc for sev ioctl interfaces to prevent kernel memory leak Date: Mon, 15 Aug 2022 19:50:17 +0200 Message-Id: <20220815180441.951140835@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: John Allen commit 13dc15a3f5fd7f884e4bfa8c011a0ae868df12ae upstream. For some sev ioctl interfaces, input may be passed that is less than or equal to SEV_FW_BLOB_MAX_SIZE, but larger than the data that PSP firmware returns. In this case, kmalloc will allocate memory that is the size of the input rather than the size of the data. Since PSP firmware doesn't fully overwrite the buffer, the sev ioctl interfaces with the issue may return uninitialized slab memory. Currently, all of the ioctl interfaces in the ccp driver are safe, but to prevent future problems, change all ioctl interfaces that allocate memory with kmalloc to use kzalloc and memset the data buffer to zero in sev_ioctl_do_platform_status. Fixes: 38103671aad3 ("crypto: ccp: Use the stack and common buffer for stat= us commands") Fixes: e799035609e15 ("crypto: ccp: Implement SEV_PEK_CSR ioctl command") Fixes: 76a2b524a4b1d ("crypto: ccp: Implement SEV_PDH_CERT_EXPORT ioctl com= mand") Fixes: d6112ea0cb344 ("crypto: ccp - introduce SEV_GET_ID2 command") Cc: stable@vger.kernel.org Reported-by: Andy Nguyen Suggested-by: David Rientjes Suggested-by: Peter Gonda Signed-off-by: John Allen Reviewed-by: Peter Gonda Acked-by: David Rientjes Signed-off-by: Herbert Xu Signed-off-by: Greg Kroah-Hartman --- drivers/crypto/ccp/sev-dev.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/drivers/crypto/ccp/sev-dev.c +++ b/drivers/crypto/ccp/sev-dev.c @@ -577,6 +577,8 @@ static int sev_ioctl_do_platform_status( struct sev_user_data_status data; int ret; =20 + memset(&data, 0, sizeof(data)); + ret =3D __sev_do_cmd_locked(SEV_CMD_PLATFORM_STATUS, &data, &argp->error); if (ret) return ret; @@ -630,7 +632,7 @@ static int sev_ioctl_do_pek_csr(struct s if (input.length > SEV_FW_BLOB_MAX_SIZE) return -EFAULT; =20 - blob =3D kmalloc(input.length, GFP_KERNEL); + blob =3D kzalloc(input.length, GFP_KERNEL); if (!blob) return -ENOMEM; =20 @@ -854,7 +856,7 @@ static int sev_ioctl_do_get_id2(struct s input_address =3D (void __user *)input.address; =20 if (input.address && input.length) { - id_blob =3D kmalloc(input.length, GFP_KERNEL); + id_blob =3D kzalloc(input.length, GFP_KERNEL); if (!id_blob) return -ENOMEM; =20 @@ -973,14 +975,14 @@ static int sev_ioctl_do_pdh_export(struc if (input.cert_chain_len > SEV_FW_BLOB_MAX_SIZE) return -EFAULT; =20 - pdh_blob =3D kmalloc(input.pdh_cert_len, GFP_KERNEL); + pdh_blob =3D kzalloc(input.pdh_cert_len, GFP_KERNEL); if (!pdh_blob) return -ENOMEM; =20 data.pdh_cert_address =3D __psp_pa(pdh_blob); data.pdh_cert_len =3D input.pdh_cert_len; =20 - cert_blob =3D kmalloc(input.cert_chain_len, GFP_KERNEL); + cert_blob =3D kzalloc(input.cert_chain_len, GFP_KERNEL); if (!cert_blob) { ret =3D -ENOMEM; goto e_free_pdh;