Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp46666ybx; Tue, 5 Nov 2019 19:11:18 -0800 (PST) X-Google-Smtp-Source: APXvYqyZF6biFOdxciEIvPrCz2+H+U28holTLxHRBwETDsMt3zVnPKxshIVDxFZzqT90/CcJ6CLy X-Received: by 2002:a17:906:751:: with SMTP id z17mr16383593ejb.313.1573009878568; Tue, 05 Nov 2019 19:11:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573009878; cv=none; d=google.com; s=arc-20160816; b=rJKj5wJgQC7KklHCH3oXzoe2HZMw27vBRXA0b4s3BZ74KgANqGQkk6hbrvroniSQR4 Tq9iAmFfhnb84ngqIHS9CvPFdmvVcblXJBqRzkF21+QNFgcCD2g2v6nNLZfllyw+CLFJ wF3nGbHohQkkrA5PeDWdmIaPpZ93oLz224r2v57vw5hcOzgPjI9woYJoOYVSc43zlDDJ z7v+mxSERp1gXARktP3JvQRftqq9R/R6o0vxoaTyFsL0RFZR0U/u/YlsHDNN9UJrrXlz NJfwiCdnvVPAk7NYBerhgjae1na5rBkGgClEt6eTef70PgRdQ4BXNqcNJ5rQ9gJmFfww TKYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature:dkim-filter; bh=t+UX8ssq46MLjcIIguwgYQLFTqBQfN20laK/0LJnJMk=; b=aj0S2SyPunE4h/CX9nDuvk8rqvynLnorrLkxlAAhyz9BnQK8UnO2KZkj9uwaC2zilS wwUNlDRe7dZfDnspGCZPwqvBg5xIFQfxOYGohfxdqYJPDjpn/6c+vAy9WquAYd5FSs+i Ey1Vfzaq14hqa9wPNxI8xbIkQaup8vBZ7EvpknbVTY+Efu5cerJARMmbikI+TjScHWFW WrqfqP98jJBGz9EkDuss9X0gljYmMgyGsfIeLsDOIFBsq5brCI7WPkAV6yTl45Wpl9C6 6lVa3WYHmTqvj+h9GvOLNt+s9gDI6xzyWRQCYWyj5HWGahTNwKbXKf5OGcQjgNpTKWbX XteQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=b5tCaED+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4si4168942ejx.214.2019.11.05.19.10.54; Tue, 05 Nov 2019 19:11:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=b5tCaED+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387929AbfKFDHh (ORCPT + 99 others); Tue, 5 Nov 2019 22:07:37 -0500 Received: from linux.microsoft.com ([13.77.154.182]:41418 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387917AbfKFDHg (ORCPT ); Tue, 5 Nov 2019 22:07:36 -0500 Received: from [10.137.112.111] (unknown [131.107.147.111]) by linux.microsoft.com (Postfix) with ESMTPSA id 7FD8720B7192; Tue, 5 Nov 2019 19:07:35 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7FD8720B7192 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1573009655; bh=t+UX8ssq46MLjcIIguwgYQLFTqBQfN20laK/0LJnJMk=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=b5tCaED+1a14jU4yDtJu7DHZpYKeU9bgyFe7/6cyEQ9AMFm/YaUzZN3tW3ammEHen 3XQnptYEN3Xga6e/24SucJMjEQ/auFnVvUJ7eTfQW8LMG1nQVLpe/LyWzLc6mUNPRR 6zW1QXKCY3gFLNwPy+gFg1B+uGOBz9wacrmAJUWA= Subject: Re: [PATCH v6 1/4] powerpc/powernv: Add OPAL API interface to access secure variable To: Eric Richter , linuxppc-dev@ozlabs.org, linux-efi@vger.kernel.org, linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Ard Biesheuvel , Jeremy Kerr , Matthew Garret , Mimi Zohar , Greg Kroah-Hartman , Claudio Carvalho , George Wilson , Elaine Palmer , Oliver O'Halloran , Nayna Jain References: <20191105082450.14746-1-erichte@linux.ibm.com> <20191105082450.14746-2-erichte@linux.ibm.com> From: Lakshmi Ramasubramanian Message-ID: <3d2e3792-e78e-95a8-623e-1ddcf3ccf241@linux.microsoft.com> Date: Tue, 5 Nov 2019 19:07:55 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 In-Reply-To: <20191105082450.14746-2-erichte@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/5/2019 12:24 AM, Eric Richter wrote: > From: Nayna Jain > > The X.509 certificates trusted by the platform and required to secure boot > the OS kernel are wrapped in secure variables, which are controlled by > OPAL. > > This patch adds firmware/kernel interface to read and write OPAL secure > variables based on the unique key. I feel splitting this patch into smaller set of changes would make it easier to review. For instance roughly as below: 1, opal-api.h which adds the #defines OPAL_SECVAR_ and the API signature. 2, secvar.h then adds secvar_operations struct 3, powerpc/kernel for the Interface definitions 4, powernv/opal-secvar.c for the API implementations 5, powernv/opal-call.c for the API calls 6, powernv/opal.c for the secvar init calls. > diff --git a/arch/powerpc/include/asm/opal-api.h b/arch/powerpc/include/asm/opal-api.h > index 378e3997845a..c1f25a760eb1 100644 > --- a/arch/powerpc/include/asm/opal-api.h > +++ b/arch/powerpc/include/asm/opal-api.h > @@ -211,7 +211,10 @@ > #define OPAL_MPIPL_UPDATE 173 > #define OPAL_MPIPL_REGISTER_TAG 174 > #define OPAL_MPIPL_QUERY_TAG 175 > -#define OPAL_LAST 175 > +#define OPAL_SECVAR_GET 176 > +#define OPAL_SECVAR_GET_NEXT 177 > +#define OPAL_SECVAR_ENQUEUE_UPDATE 178 > +#define OPAL_LAST 178 Please fix the indentation for the #defines > +static int opal_get_variable(const char *key, uint64_t ksize, > + u8 *data, uint64_t *dsize) > +{ > + int rc; > + > + if (!key || !dsize) > + return -EINVAL; > + > + *dsize = cpu_to_be64(*dsize); > + > + rc = opal_secvar_get(key, ksize, data, dsize); > + > + *dsize = be64_to_cpu(*dsize); Should the return status (rc) from opal_secvar_get be checked before attempting to do the conversion (be64_to_cpu)? > +static int opal_get_next_variable(const char *key, uint64_t *keylen, > + uint64_t keybufsize) > +{ > + int rc; > + > + if (!key || !keylen) > + return -EINVAL; > + > + *keylen = cpu_to_be64(*keylen); > + > + rc = opal_secvar_get_next(key, keylen, keybufsize); > + > + *keylen = be64_to_cpu(*keylen); Same comment as above - should rc be checke before attempting to convert? > + > + return opal_status_to_err(rc); > +} > + > +static int opal_set_variable(const char *key, uint64_t ksize, u8 *data, > + uint64_t dsize) > +{ > + int rc; > + > + if (!key || !data) > + return -EINVAL; Is the key and data received here from a trusted caller? If not, should there be some validation checks done here before enqueuing the data? -lakshmi