Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp952412iob; Fri, 13 May 2022 17:32:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzTotupsuFiQ8FH2mQXvmPoVQnnzvpvqeavBYGjxBudkFy/DVg+ELLZhyQYGg/PJKjpgsll X-Received: by 2002:a5d:588e:0:b0:20c:edd9:9e2e with SMTP id n14-20020a5d588e000000b0020cedd99e2emr5975486wrf.231.1652488359281; Fri, 13 May 2022 17:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652488359; cv=none; d=google.com; s=arc-20160816; b=Up2Dq+MQiloumG3BBBSvNhddvuEudboPI1qPPEs6CEX0m/5eZLVWRLqcuLH19ZcGhP BVtMoX6qNwvN47xQPZYaaVQIcRN5kgFumPTqeOQ55wfMrem+Z4hzbffg81vpuN2fr7hz Y0Q+IUyU0odO+3zzRoQeI0F3r9TwhMJYiVExrQS/stbeBHorP9LnByBLCTz4avtsLww6 V7bye8CodRu1kCVIg5U1tTJn2ZaJAol8u7H6Auq9hykXeEaXAHtL0cx20xOhXJhMAsDD 8zC2GnsGZl37olyrp9YN8Xl841lECj4SVWCV1BMPN3LAq2NQQ+ZNEDJwONKENji1eVP5 UNlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=h9qNNc7KmTxiSu7indN0sAScbimmSjieBJURsL+745I=; b=thc7oA+baoEcqB0Rxoeh48RJlLZr82UDpuWSHM8dfXXDOOlLxP7C+00ovnHl1AOr2Q pc5eJP0sVFYk+L9cAaysbrO0+7YLX+DzcvgZtUDs2uft7LVHe7hTxl110YTNBsIOhfOW ia6w/6y8h4fudg2gY1gvI5NcJDRKcaoEEKal9Nl+F0IhOcLqxV8Feqs7pxMNGqKqqfEu Y38ODTMHY4QKAS1Xa8fqbKSD5jkH5zxUCTNXkK0QyaZRjnslZdF5P35khujTilliPhfR 8zQg4Zxv+eSdBHC6PJ20U3loCj5ZqT1KEsrFb15/fO1LHEJSdX+BLNqFBfo/qnDMy7Wp iGFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rpYMq81J; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id r18-20020a05600c35d200b0038f5b230c43si7826160wmq.212.2022.05.13.17.32.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 17:32:39 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rpYMq81J; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 940C9306778; Fri, 13 May 2022 16:24:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380884AbiEMOt6 (ORCPT + 99 others); Fri, 13 May 2022 10:49:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347989AbiEMOty (ORCPT ); Fri, 13 May 2022 10:49:54 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE39E63B4 for ; Fri, 13 May 2022 07:49:52 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id p12so7937720pfn.0 for ; Fri, 13 May 2022 07:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=h9qNNc7KmTxiSu7indN0sAScbimmSjieBJURsL+745I=; b=rpYMq81J4aID+QQaQNbyXclttNYEanHp98Nuj/07I6nvXdajqjM/9AvgeUvwnO8Ug4 QlZnxFADFYATmXFZvlDm58zJofyb064iWMfloHCZtAaDuXqMlpR9/ejwNC2vD8ZZOw03 xfS8PzkidmFM/SLaGtHTmW0xwB73IimfndGJ3UKhEX7im5095BA1XQrR2/q1/RsSnXEg AhKG/bmejJ/fMYa8EjKC1yRHIEt0wUbg1ya51z8YDlN6BZtt/2SQt3Y0ozNOwURutL8U VzWlu5Vs4KYph53wS0A7s1n3dPwIrhm+7p3l4Lw3LEOcNUmxBMWybJp6lHEQNgeIv4TA qOnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=h9qNNc7KmTxiSu7indN0sAScbimmSjieBJURsL+745I=; b=TjBPZt+koNABVPn+tNnpxjG0NPWVnZv5O4Apiy1QGxkgXL/HpjzzSX4y+cppxpo5j3 JfOg6BQcQ7UsU/lfKxFP4hyKgDtdhTHDlg4Vulg94kR7RiXz2o9lSE6JzVglBds/lYD8 QTe3RZbz1Z0f/tSQ/1wY+tX1iu9mEgHf/BlfwNkC2e57CX1vn+50tWjgLI3VioSCFwGF 3eIyox82ISSTzs5ruNdQlmKNod2fRIEfq0MCT1xCP6nq3kYWtFmwY6G+Rpnd92PiRuN6 9T1OHsicHkS7qugMHiOp6eTLZrBDL6O7tsam6EwEKyz75sS8nWnvEXqhi7SovK0fxcNv lHRg== X-Gm-Message-State: AOAM533yG6XFqdJNOL1YjkZKh1iLq9+Lzo2xoOP00Xr/yLHhHTIWdUXU YqofjpNjMS53KBs6NS16D99YxQ== X-Received: by 2002:a62:7ccc:0:b0:510:4e07:79f3 with SMTP id x195-20020a627ccc000000b005104e0779f3mr5127515pfc.10.1652453392173; Fri, 13 May 2022 07:49:52 -0700 (PDT) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id p1-20020aa78601000000b00512ee8a74a9sm179349pfn.217.2022.05.13.07.49.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 07:49:51 -0700 (PDT) Date: Fri, 13 May 2022 14:49:48 +0000 From: Sean Christopherson To: Peter Gonda Cc: Ashish Kalra , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Joerg Roedel , "Lendacky, Thomas" , Borislav Petkov , the arch/x86 maintainers , kvm list , LKML , Andy Nguyen , David Rientjes , John Allen Subject: Re: [PATCH] KVM: SVM: Use kzalloc for sev ioctl interfaces to prevent kernel memory leak. Message-ID: References: <20220512202328.2453895-1-Ashish.Kalra@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 13, 2022, Peter Gonda wrote: > On Thu, May 12, 2022 at 4:23 PM Ashish Kalra wrote: > > > > From: Ashish Kalra > > > > For some sev ioctl interfaces, the length parameter that is passed maybe > > 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 allocated buffer, these > > sev ioctl interface may return uninitialized kernel slab memory. > > > > Reported-by: Andy Nguyen > > Suggested-by: David Rientjes > > Suggested-by: Peter Gonda > > Cc: kvm@vger.kernel.org > > Cc: linux-kernel@vger.kernel.org > > Signed-off-by: Ashish Kalra > > --- > > arch/x86/kvm/svm/sev.c | 6 +++--- > > 1 file changed, 3 insertions(+), 3 deletions(-) > > > > Can we just update all the kmalloc()s that buffers get given to the > PSP? For instance doesn't sev_send_update_data() have an issue? > Reading the PSP spec it seems like a user can call this ioctl with a > large hdr_len and the PSP will only fill out what's actually required > like in these fixed up cases? This is assuming the PSP is written to > spec (and just the current version). I'd rather have all of these > instances updated. Agreed, the kernel should explicitly initialize any copy_to_user() to source and never rely on the PSP to fill the entire blob unless there's an ironclad guarantee the entire struct/blob will be written. E.g. it's probably ok to skip zeroing "data" in sev_ioctl_do_platform_status(), but even then it might be wortwhile as defense-in-depth. Looking through other copy_to_user() calls: - "blob" in sev_ioctl_do_pek_csr() - "id_blob" in sev_ioctl_do_get_id2() - "pdh_blob" and "cert_blob" in sev_ioctl_do_pdh_export() The last one is probably fine since the copy length comes from the PSP, but it's not like these ioctls are performance critical... /* If we query the length, FW responded with expected data. */ input.cert_chain_len = data.cert_chain_len; input.pdh_cert_len = data.pdh_cert_len;