Message ID | 20230131063928.388035-20-ajd@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2595316wrn; Mon, 30 Jan 2023 22:49:56 -0800 (PST) X-Google-Smtp-Source: AK7set8D3XcfbFB+iWruUuCVAZYC5yWfzF32q+JCp12Yzfq/kpoY5x/QevGGqANhTvrUZHkQWfqr X-Received: by 2002:a05:6402:2927:b0:4a2:6d1c:fb38 with SMTP id ee39-20020a056402292700b004a26d1cfb38mr585855edb.10.1675147796042; Mon, 30 Jan 2023 22:49:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675147796; cv=none; d=google.com; s=arc-20160816; b=qtGndwyofU9xfIlu2NdQjPWcJwNiOr/XkQdUeJo0SDSJ9hK5Pnx1JZSbll8ioX86Zh P0vjIcFCdykbRfwKPmw3IjFsAKTFpw8y8Y9KmYYxH2vnLAFdhI1yHURT7wrYnxs1IkDj ZInLpVBX+3Y+1f3Ml1KvdZbw6YG1eR3sjJuYawhvQ1dK7XoG3blikRnkfaWfNMhY/QUy qtq5pVExJnlZ31MRH2CEmVcQjKHDAimojoUREJ92v2GgDwiC+jahxrweOXXnqOrucSdp MIkcwaZ/zkFA5zprfoZDHSG48SfeScw40p28AMO2NlIaH+JFyVYXEXn5KtVqRrSUtq0l ytLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+3kvWVz6aOeabVr4AOc40oYztb0yqrcFdrGQzMhlefo=; b=kTX+olYdsX7H4VhgVD9Av4I3PXsSurppywuAKWhsc7LcvGo9NpRE/81mVwpO1w6nuc sG9+m3JDRZOyyXzJxwM4XuxhlPlVX4eH9HMzN+zhZkSKeDXsoTJhMNeVUoG/5XiLnBhI 1dP4wB+Blq+vPDw/Pbtur9/GiVkYr4yGJzZN3CkaVVRFvEfFYesXi729gsnJCWTXJ0Df ZhqeFOdvwGBYiywa7iQ1kycdFQJdplnP1wWBWsQWikpq4k+4iJuFpE7QK9fBDnpALzMa hHerYs7amgRpGerLsYmu+qmNHWFTKZQPKeL+8YfGJ1nGr84eR3sirW4Y/fCK1kmUIBhB a0XQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Rh4ovVcx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r5-20020a50aac5000000b004a0ae55db1asi16784588edc.114.2023.01.30.22.49.31; Mon, 30 Jan 2023 22:49:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Rh4ovVcx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231468AbjAaGld (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Tue, 31 Jan 2023 01:41:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230494AbjAaGki (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 31 Jan 2023 01:40:38 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646733F2A3; Mon, 30 Jan 2023 22:40:32 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30V5uewn010357; Tue, 31 Jan 2023 06:40:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=+3kvWVz6aOeabVr4AOc40oYztb0yqrcFdrGQzMhlefo=; b=Rh4ovVcxlVWV6HkrcSR8MRjNrjeDC06HlS7EKIl846NulxC63RBDZjA7TQppoKWwd75A 46Ut36qMHdJbDiQHoVWvL5Qx4IVwlQgSJysvBIW2zbFt6KFLRo/TztHbUBVO7eZZl1vO xyzKDSZrdMf6LLhJgh7n+MjrX3Duafn+uN9ebCQ9TJieacp/kN/PqgJMSzPQ5Pdpm3Af CHGcW6KcXgnyforFtDI4xBvMfByPzXS2QTwi4vEQQcWvRjxClkxTOvC9DfHx5OcK1S9W 3XcDpCadyahLAOIOyr61ZWm4BsndWB2JnNYvHFIf3DGZ+JbCM5S6JeKEQOkbNh+ydn3X Tw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3new9kgthu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 06:40:17 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30V6M3ww015061; Tue, 31 Jan 2023 06:40:17 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3new9kgtg4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 06:40:16 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30V29aOC004065; Tue, 31 Jan 2023 06:40:14 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3ncvv6a7dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 06:40:14 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30V6eBrd20971946 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 31 Jan 2023 06:40:11 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C223F20040; Tue, 31 Jan 2023 06:40:11 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C52ED2004B; Tue, 31 Jan 2023 06:40:10 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 31 Jan 2023 06:40:10 +0000 (GMT) Received: from jarvis-ozlabs-ibm-com.au.ibm.com (unknown [9.192.255.228]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 1760960996; Tue, 31 Jan 2023 17:40:05 +1100 (AEDT) From: Andrew Donnellan <ajd@linux.ibm.com> To: linuxppc-dev@lists.ozlabs.org, linux-integrity@vger.kernel.org Cc: ruscur@russell.cc, bgray@linux.ibm.com, nayna@linux.ibm.com, gcwilson@linux.ibm.com, gjoyce@linux.ibm.com, brking@linux.ibm.com, stefanb@linux.ibm.com, sudhakar@linux.ibm.com, erichte@linux.ibm.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, zohar@linux.ibm.com, joel@jms.id.au, npiggin@gmail.com, Michael Ellerman <mpe@ellerman.id.au> Subject: [PATCH v5 19/25] powerpc/pseries: Make caller pass buffer to plpks_read_var() Date: Tue, 31 Jan 2023 17:39:22 +1100 Message-Id: <20230131063928.388035-20-ajd@linux.ibm.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230131063928.388035-1-ajd@linux.ibm.com> References: <20230131063928.388035-1-ajd@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: n6uKZ1xReVlR6XUhAPHPDure0p3EYFUh X-Proofpoint-GUID: WDtjhlGM16apAXAnkmWek1knZRRTw946 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-01-31_02,2023-01-30_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 mlxscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 malwarescore=0 adultscore=0 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301310059 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756519775535097577?= X-GMAIL-MSGID: =?utf-8?q?1756519775535097577?= |
Series |
pSeries dynamic secure boot secvar interface + platform keyring loading
|
|
Commit Message
Andrew Donnellan
Jan. 31, 2023, 6:39 a.m. UTC
Currently, plpks_read_var() allocates a buffer to pass to the H_PKS_READ_OBJECT hcall, then allocates another buffer, of the caller's preferred size if necessary, into which the data is copied, and returns that buffer to the caller. This is a bit over the top - while we probably still want to allocate a separate buffer to pass to the hypervisor in the hcall, we can let the caller allocate the final buffer and specify the size. Don't allocate var->data in plpks_read_var(), instead expect the caller to allocate it. If the caller needs to discover the size, it can set var->data to NULL and var->datalen will be populated. Update header file to document this. Suggested-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com> Signed-off-by: Russell Currey <ruscur@russell.cc> --- v3: New patch (mpe) --- arch/powerpc/include/asm/plpks.h | 12 ++++++++++++ arch/powerpc/platforms/pseries/plpks.c | 11 ++++------- 2 files changed, 16 insertions(+), 7 deletions(-)
Comments
On 1/31/23 01:39, Andrew Donnellan wrote: > Currently, plpks_read_var() allocates a buffer to pass to the > H_PKS_READ_OBJECT hcall, then allocates another buffer, of the caller's -> buffer of the (no comma) > preferred size if necessary, into which the data is copied, and returns > that buffer to the caller. > > This is a bit over the top - while we probably still want to allocate a > separate buffer to pass to the hypervisor in the hcall, we can let the > caller allocate the final buffer and specify the size. > > Don't allocate var->data in plpks_read_var(), instead expect the caller to > allocate it. If the caller needs to discover the size, it can set > var->data to NULL and var->datalen will be populated. Update header file > to document this. It looks like there are no callers yet that would need to be adapted... Reviewed-by: Stefan Berger <stefanb@linux.ibm.com> > > Suggested-by: Michael Ellerman <mpe@ellerman.id.au> > Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com> > Signed-off-by: Russell Currey <ruscur@russell.cc> > > --- > > v3: New patch (mpe) > --- > arch/powerpc/include/asm/plpks.h | 12 ++++++++++++ > arch/powerpc/platforms/pseries/plpks.c | 11 ++++------- > 2 files changed, 16 insertions(+), 7 deletions(-) > > diff --git a/arch/powerpc/include/asm/plpks.h b/arch/powerpc/include/asm/plpks.h > index e7204e6c0ca4..0c49969b0864 100644 > --- a/arch/powerpc/include/asm/plpks.h > +++ b/arch/powerpc/include/asm/plpks.h > @@ -88,16 +88,28 @@ int plpks_remove_var(char *component, u8 varos, > > /** > * Returns the data for the specified os variable. > + * > + * Caller must allocate a buffer in var->data with length in var->datalen. > + * If no buffer is provided, var->datalen will be populated with the object's > + * size. > */ > int plpks_read_os_var(struct plpks_var *var); > > /** > * Returns the data for the specified firmware variable. > + * > + * Caller must allocate a buffer in var->data with length in var->datalen. > + * If no buffer is provided, var->datalen will be populated with the object's > + * size. > */ > int plpks_read_fw_var(struct plpks_var *var); > > /** > * Returns the data for the specified bootloader variable. > + * > + * Caller must allocate a buffer in var->data with length in var->datalen. > + * If no buffer is provided, var->datalen will be populated with the object's > + * size. > */ > int plpks_read_bootloader_var(struct plpks_var *var); > > diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c > index e5755443d4a4..926b6a927326 100644 > --- a/arch/powerpc/platforms/pseries/plpks.c > +++ b/arch/powerpc/platforms/pseries/plpks.c > @@ -581,17 +581,14 @@ static int plpks_read_var(u8 consumer, struct plpks_var *var) > goto out_free_output; > } > > - if (var->datalen == 0 || var->datalen > retbuf[0]) > + if (!var->data || var->datalen > retbuf[0]) > var->datalen = retbuf[0]; > > - var->data = kzalloc(var->datalen, GFP_KERNEL); > - if (!var->data) { > - rc = -ENOMEM; > - goto out_free_output; > - } > var->policy = retbuf[1]; > > - memcpy(var->data, output, var->datalen); > + if (var->data) > + memcpy(var->data, output, var->datalen); > + > rc = 0; > > out_free_output:
On Tue, 2023-01-31 at 11:38 -0500, Stefan Berger wrote: > > > On 1/31/23 01:39, Andrew Donnellan wrote: > > Currently, plpks_read_var() allocates a buffer to pass to the > > H_PKS_READ_OBJECT hcall, then allocates another buffer, of the > > caller's > > > -> buffer of the (no comma) I'll just remove that clause entirely, it's not really necessary
diff --git a/arch/powerpc/include/asm/plpks.h b/arch/powerpc/include/asm/plpks.h index e7204e6c0ca4..0c49969b0864 100644 --- a/arch/powerpc/include/asm/plpks.h +++ b/arch/powerpc/include/asm/plpks.h @@ -88,16 +88,28 @@ int plpks_remove_var(char *component, u8 varos, /** * Returns the data for the specified os variable. + * + * Caller must allocate a buffer in var->data with length in var->datalen. + * If no buffer is provided, var->datalen will be populated with the object's + * size. */ int plpks_read_os_var(struct plpks_var *var); /** * Returns the data for the specified firmware variable. + * + * Caller must allocate a buffer in var->data with length in var->datalen. + * If no buffer is provided, var->datalen will be populated with the object's + * size. */ int plpks_read_fw_var(struct plpks_var *var); /** * Returns the data for the specified bootloader variable. + * + * Caller must allocate a buffer in var->data with length in var->datalen. + * If no buffer is provided, var->datalen will be populated with the object's + * size. */ int plpks_read_bootloader_var(struct plpks_var *var); diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c index e5755443d4a4..926b6a927326 100644 --- a/arch/powerpc/platforms/pseries/plpks.c +++ b/arch/powerpc/platforms/pseries/plpks.c @@ -581,17 +581,14 @@ static int plpks_read_var(u8 consumer, struct plpks_var *var) goto out_free_output; } - if (var->datalen == 0 || var->datalen > retbuf[0]) + if (!var->data || var->datalen > retbuf[0]) var->datalen = retbuf[0]; - var->data = kzalloc(var->datalen, GFP_KERNEL); - if (!var->data) { - rc = -ENOMEM; - goto out_free_output; - } var->policy = retbuf[1]; - memcpy(var->data, output, var->datalen); + if (var->data) + memcpy(var->data, output, var->datalen); + rc = 0; out_free_output: