Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp310077pxb; Tue, 31 Aug 2021 22:36:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7FGWtAoo0GElsZlUOrMYJljz3i2H/HPbh7/ug4Ka5zKut9bEus7lyAJpADAWAizYnxU82 X-Received: by 2002:a6b:f214:: with SMTP id q20mr26223147ioh.84.1630474604223; Tue, 31 Aug 2021 22:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630474604; cv=none; d=google.com; s=arc-20160816; b=FSBo6lmt67s6PhB5x3Vn8BJmerf6qq5BfTlT/JLFxPkK6JRMDa/3iOTD1fwluOGXhc heDqOVi3SQPso8ZPBwCTfJGu4bJcgjVqePo1Dyl4YiwxYV/qPRNZ4MyJUt5wMbtNwGxA jiyGgkKV1/wEn+HITuTjlR1rppsv2xmPzlrDlcdVKGEnw4fNj2mtw0ngAC+aNTHYqgcK LiV/QvZEf5z+IQ7NSoHoIKUYtfvSl8ICo2FYqF2kOi/rceXcRsU0S3Y8Y1v8TPEOHVR0 V8YEXMjSmSXL62hc5P6BgUIFANwHMlrOCd/kO0QWqw91ZtPwZqu8UjHT19t+OQBStsXQ U60w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=w/8qMkCsZDkfkQ3Aww/zSfJ2vYvHc6uHfqVFAXK6anI=; b=ARyJsPLJ/Wpdf7qlRyPLkaDpaTORH6B5Zgdbk+devzB8vNmACq/2kP1XrpM9m1Y+to zi5vix3yDcRkXXGy5CHRuJHDJ8QkABwxyu8rth0qGJkYXJK79pWn5KkMoF66O1z9LJB3 CZlVbseF9w1GTrkGMbjNUc7ruSn81zVDijhZAQCY9cwBtuUNeHrQH1DO4TNpzaD3rnXJ aFn93M1sc/c1ULGT0bSTZXVemJMzUVaFVO0okhNZ2x8syPgo/BXDreejmTRFoemgboXP Qs2wxPQFlmv8bUMF1ExkrlW+BOV4uOs7YkX00s4Mm4hcjmuGWMgAg2ScVvo7Q82JepoR aAKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=YSoa9ViR; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a2si19793268ilp.123.2021.08.31.22.36.32; Tue, 31 Aug 2021 22:36:44 -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=@ibm.com header.s=pp1 header.b=YSoa9ViR; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242008AbhIAFff (ORCPT + 99 others); Wed, 1 Sep 2021 01:35:35 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:12528 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233857AbhIAFfe (ORCPT ); Wed, 1 Sep 2021 01:35:34 -0400 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 Content-Transfer-Encoding: 8bit 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/09/2021 0:04, Brijesh Singh wrote: > Hi Dov, > > > On 8/31/21 1:59 PM, Dov Murik wrote: >>> + >>> +    /* >>> +     * The intermediate response buffer is used while decrypting the >>> +     * response payload. Make sure that it has enough space to cover >>> the >>> +     * authtag. >>> +     */ >>> +    resp_len = sizeof(resp->data) + crypto->a_len; >>> +    resp = 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).  Maybe use a >> buffer on the stack instead of allocating and freeing? >> > > The authtag size can be up to 16 bytes, so I guess I can allocate 80 > bytes on stack and avoid the kzalloc(). > >> >>> +    if (!resp) >>> +        return -ENOMEM; >>> + >>> +    /* Issue the command to get the attestation report */ >>> +    rc = handle_guest_request(snp_dev, req.msg_version, >>> SNP_MSG_KEY_REQ, >>> +                  &req.data, sizeof(req.data), resp->data, resp_len, >>> +                  &arg->fw_err); >>> +    if (rc) >>> +        goto e_free; >>> + >>> +    /* Copy the response payload to userspace */ >>> +    if (copy_to_user((void __user *)arg->resp_data, resp, >>> sizeof(*resp))) >>> +        rc = -EFAULT; >>> + >>> +e_free: >>> +    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.  I'm not sure if any copies are made inside the >> handle_guest_request call above; maybe zero these as well. >> > > I can do that, but I guess I am trying to find a reason for it. The resp > buffer is encrypted page, so, the key is protected from the hypervisor > access. Are you thinking about an attack within the VM guest OS ? > Yes, that's the concern, specifically with sensitive buffers (keys). You don't want many copies floating around in unused memory. -Dov