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 X-Spam-Level: X-Spam-Status: No, score=-6.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61446C432BE for ; Wed, 1 Sep 2021 05:33:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 01B4661059 for ; Wed, 1 Sep 2021 05:33:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 01B4661059 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.ibm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 7DFB68D0001; Wed, 1 Sep 2021 01:33:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78F9C6B0071; Wed, 1 Sep 2021 01:33:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6304D8D0001; Wed, 1 Sep 2021 01:33:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 55B656B006C for ; Wed, 1 Sep 2021 01:33:52 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0A7A2267CD for ; Wed, 1 Sep 2021 05:33:52 +0000 (UTC) X-FDA: 78537887904.11.11EE8A0 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf20.hostedemail.com (Postfix) with ESMTP id 54D44D0000AA for ; Wed, 1 Sep 2021 05:33:51 +0000 (UTC) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 18153fgS134449; Wed, 1 Sep 2021 01:33:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=w/8qMkCsZDkfkQ3Aww/zSfJ2vYvHc6uHfqVFAXK6anI=; b=YSoa9ViR8owy6FYW5J04AucsFH18U+Dgb81Fh8nNvd64TQtXlWVd1NlkFwkv8Y6F8ike x1BdwGXgx+WuMneWlyUyXfPYOKLoFOfOEjG619BnT9um52Wl349EFSWmiSFNraDKjYCs kVy5yB/PFqxwvYaITAKNqKL9NGzD1D/OQd6DDueH1ULYkYxOpYG0F0InPgXI1H5mXqJK xbWRS+bXlU8i2IWHlz6qnKsCCO/HPTpvwPxNB6k5Gl60LYDw72iJF0U+Krip4ucoJ5i0 2x25sSkBH+0bn2gXx0OnIXQmv3wEJ0OvkV4rR1Jgu1tF1yqbUXwaC9Gwea2iKYf4CUwW MA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3at1p0tdu3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 01:33:26 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1815CVL3170574; Wed, 1 Sep 2021 01:33:25 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 3at1p0tdtb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 01:33:25 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1815QhD0019602; Wed, 1 Sep 2021 05:33:23 GMT Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by ppma05wdc.us.ibm.com with ESMTP id 3aqcscxxsy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 01 Sep 2021 05:33:23 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1815XMaH37290252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 1 Sep 2021 05:33:22 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9463D7806E; Wed, 1 Sep 2021 05:33:22 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E265478067; Wed, 1 Sep 2021 05:33:13 +0000 (GMT) Received: from [9.65.248.250] (unknown [9.65.248.250]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 1 Sep 2021 05:33:13 +0000 (GMT) Subject: Re: [PATCH Part1 v5 37/38] virt: sevguest: Add support to derive key To: Brijesh Singh , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, Dov Murik References: <20210820151933.22401-1-brijesh.singh@amd.com> <20210820151933.22401-38-brijesh.singh@amd.com> From: Dov Murik Message-ID: <55df11df-bf30-171e-9774-e6a6d380802a@linux.ibm.com> Date: Wed, 1 Sep 2021 08:33:11 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-GUID: VtNtiwnrUaraj9V-sE0mBNx1ZR9ze6u5 X-Proofpoint-ORIG-GUID: h7LxjRRoKWqtuCZrvNqMelbALA8Fm4AA X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-09-01_01:2021-08-31,2021-09-01 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 clxscore=1015 malwarescore=0 mlxscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2109010027 Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=YSoa9ViR; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf20.hostedemail.com: domain of dovmurik@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=dovmurik@linux.ibm.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 54D44D0000AA X-Stat-Signature: 4wg9u1wfxqnbnzh63iadu5hppw5rcf43 X-HE-Tag: 1630474431-781322 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 01/09/2021 0:04, Brijesh Singh wrote: > Hi Dov, >=20 >=20 > On 8/31/21 1:59 PM, Dov Murik wrote: >>> + >>> +=C2=A0=C2=A0=C2=A0 /* >>> +=C2=A0=C2=A0=C2=A0=C2=A0 * The intermediate response buffer is used = while decrypting the >>> +=C2=A0=C2=A0=C2=A0=C2=A0 * response payload. Make sure that it has e= nough space to cover >>> the >>> +=C2=A0=C2=A0=C2=A0=C2=A0 * authtag. >>> +=C2=A0=C2=A0=C2=A0=C2=A0 */ >>> +=C2=A0=C2=A0=C2=A0 resp_len =3D sizeof(resp->data) + crypto->a_len; >>> +=C2=A0=C2=A0=C2=A0 resp =3D kzalloc(resp_len, GFP_KERNEL_ACCOUNT); >> >> The length of resp->data is 64 bytes; I assume crypto->a_len is not a >> lot more (and probably known in advance for AES GCM).=C2=A0 Maybe use = a >> buffer on the stack instead of allocating and freeing? >> >=20 > The authtag size can be up to 16 bytes, so I guess I can allocate 80 > bytes on stack and avoid the kzalloc(). >=20 >> >>> +=C2=A0=C2=A0=C2=A0 if (!resp) >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return -ENOMEM; >>> + >>> +=C2=A0=C2=A0=C2=A0 /* Issue the command to get the attestation repor= t */ >>> +=C2=A0=C2=A0=C2=A0 rc =3D handle_guest_request(snp_dev, req.msg_vers= ion, >>> SNP_MSG_KEY_REQ, >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &req.data, sizeof(req.data), resp->data= , resp_len, >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 &arg->fw_err); >>> +=C2=A0=C2=A0=C2=A0 if (rc) >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto e_free; >>> + >>> +=C2=A0=C2=A0=C2=A0 /* Copy the response payload to userspace */ >>> +=C2=A0=C2=A0=C2=A0 if (copy_to_user((void __user *)arg->resp_data, r= esp, >>> sizeof(*resp))) >>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 rc =3D -EFAULT; >>> + >>> +e_free: >>> +=C2=A0=C2=A0=C2=A0 kfree(resp); >> >> Since resp contains key material, I think you should explicit_memzero(= ) >> it before freeing, so the key bytes don't linger around in unused >> memory.=C2=A0 I'm not sure if any copies are made inside the >> handle_guest_request call above; maybe zero these as well. >> >=20 > I can do that, but I guess I am trying to find a reason for it. The res= p > buffer is encrypted page, so, the key is protected from the hypervisor > access. Are you thinking about an attack within the VM guest OS ? >=20 Yes, that's the concern, specifically with sensitive buffers (keys). You don't want many copies floating around in unused memory. -Dov