From: Tom Lendacky <thomas.lendacky@amd.com>
To: Dionna Glaze <dionnaglaze@google.com>,
linux-kernel@vger.kernel.org, x86@kernel.org,
Ashish Kalra <ashish.kalra@amd.com>,
John Allen <john.allen@amd.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: linux-coco@lists.linux.dev,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Michael Roth <michael.roth@amd.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Russ Weight <russ.weight@linux.dev>,
Danilo Krummrich <dakr@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Tianfei zhang <tianfei.zhang@intel.com>,
Alexey Kardashevskiy <aik@amd.com>,
linux-crypto@vger.kernel.org
Subject: Re: [PATCH v5 07/10] crypto: ccp: Add preferred access checking method
Date: Mon, 11 Nov 2024 16:46:44 -0600 [thread overview]
Message-ID: <4ec6b73f-4707-c93a-f046-213ac4d4549d@amd.com> (raw)
In-Reply-To: <20241107232457.4059785-8-dionnaglaze@google.com>
On 11/7/24 17:24, Dionna Glaze wrote:
> sev_issue_cmd_external_user is the only function that checks permissions
> before performing its task. With the new GCTX API, it's important to
> establish permission once and have that determination dominate later API
> uses. This is implicitly how ccp has been used by dominating uses of
> sev_do_cmd by a successful sev_issue_cmd_external_user call.
>
> Consider sev_issue_cmd_external_user deprecated by
> checking if a held file descriptor passes file_is_sev, similar to the
> file_is_kvm function.
>
> This also fixes the header comment that the bad file error code is
> -%EINVAL when in fact it is -%EBADF.
Same comment as before. This commit merely creates a helper function, so
this commit message is not appropriate.
>
> CC: Sean Christopherson <seanjc@google.com>
> CC: Paolo Bonzini <pbonzini@redhat.com>
> CC: Thomas Gleixner <tglx@linutronix.de>
> CC: Ingo Molnar <mingo@redhat.com>
> CC: Borislav Petkov <bp@alien8.de>
> CC: Dave Hansen <dave.hansen@linux.intel.com>
> CC: Ashish Kalra <ashish.kalra@amd.com>
> CC: Tom Lendacky <thomas.lendacky@amd.com>
> CC: John Allen <john.allen@amd.com>
> CC: Herbert Xu <herbert@gondor.apana.org.au>
> CC: "David S. Miller" <davem@davemloft.net>
> CC: Michael Roth <michael.roth@amd.com>
> CC: Luis Chamberlain <mcgrof@kernel.org>
> CC: Russ Weight <russ.weight@linux.dev>
> CC: Danilo Krummrich <dakr@redhat.com>
> CC: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> CC: "Rafael J. Wysocki" <rafael@kernel.org>
> CC: Tianfei zhang <tianfei.zhang@intel.com>
> CC: Alexey Kardashevskiy <aik@amd.com>
>
> Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
> ---
> drivers/crypto/ccp/sev-dev.c | 13 +++++++++++--
> include/linux/psp-sev.h | 11 ++++++++++-
> 2 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 498ec8a0deeca..f92e6a222da8a 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -8,6 +8,7 @@
> */
>
> #include <linux/bitfield.h>
> +#include <linux/file.h>
> #include <linux/module.h>
> #include <linux/kernel.h>
> #include <linux/kthread.h>
> @@ -2486,11 +2487,19 @@ static struct notifier_block snp_panic_notifier = {
> .notifier_call = snp_shutdown_on_panic,
> };
>
> +bool file_is_sev(struct file *p)
> +{
> + return p && p->f_op == &sev_fops;
> +}
> +EXPORT_SYMBOL_GPL(file_is_sev);
> +
> int sev_issue_cmd_external_user(struct file *filep, unsigned int cmd,
> void *data, int *error)
> {
> - if (!filep || filep->f_op != &sev_fops)
> - return -EBADF;
> + int rc = file_is_sev(filep) ? 0 : -EBADF;
> +
> + if (rc)
> + return rc;
Get rid of rc and just do:
if (!file_is_sev(filep))
return -EBADF;
Thanks,
Tom
>
> return sev_do_cmd(cmd, data, error);
> }
> diff --git a/include/linux/psp-sev.h b/include/linux/psp-sev.h
> index b91cbdc208f49..ed85c0cfcfcbe 100644
> --- a/include/linux/psp-sev.h
> +++ b/include/linux/psp-sev.h
> @@ -879,11 +879,18 @@ int sev_platform_status(struct sev_user_data_status *status, int *error);
> * -%ENOTSUPP if the SEV does not support SEV
> * -%ETIMEDOUT if the SEV command timed out
> * -%EIO if the SEV returned a non-zero return code
> - * -%EINVAL if the SEV file descriptor is not valid
> + * -%EBADF if the file pointer is bad or does not grant access
> */
> int sev_issue_cmd_external_user(struct file *filep, unsigned int id,
> void *data, int *error);
>
> +/**
> + * file_is_sev - returns whether a file pointer is for the SEV device
> + *
> + * @filep - SEV device file pointer
> + */
> +bool file_is_sev(struct file *filep);
> +
> /**
> * sev_guest_deactivate - perform SEV DEACTIVATE command
> *
> @@ -1039,6 +1046,8 @@ static inline int sev_guest_df_flush(int *error) { return -ENODEV; }
> static inline int
> sev_issue_cmd_external_user(struct file *filep, unsigned int id, void *data, int *error) { return -ENODEV; }
>
> +static inline bool file_is_sev(struct file *filep) { return false; }
> +
> static inline void *psp_copy_user_blob(u64 __user uaddr, u32 len) { return ERR_PTR(-EINVAL); }
>
> static inline void *snp_alloc_firmware_page(gfp_t mask)
next prev parent reply other threads:[~2024-11-11 22:46 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20241107232457.4059785-1-dionnaglaze@google.com>
2024-11-07 23:24 ` [PATCH v5 04/10] crypto: ccp: Fix uapi definitions of PSP errors Dionna Glaze
2024-11-08 16:14 ` Tom Lendacky
2024-11-08 22:13 ` Dionna Amalie Glaze
2024-11-07 23:24 ` [PATCH v5 05/10] crypto: ccp: Add GCTX API to track ASID assignment Dionna Glaze
2024-11-08 17:24 ` Tom Lendacky
2024-11-08 22:13 ` Dionna Amalie Glaze
2024-11-11 17:13 ` Tom Lendacky
2024-11-11 21:16 ` Kalra, Ashish
2024-11-11 21:35 ` Dionna Amalie Glaze
2024-11-11 21:48 ` Kalra, Ashish
2024-11-07 23:24 ` [PATCH v5 06/10] crypto: ccp: Add DOWNLOAD_FIRMWARE_EX support Dionna Glaze
2024-11-08 15:42 ` Dionna Amalie Glaze
2024-11-08 17:44 ` Tom Lendacky
2024-11-08 22:13 ` Dionna Amalie Glaze
2024-11-11 22:10 ` Kalra, Ashish
2024-11-11 22:37 ` Dionna Amalie Glaze
2024-11-07 23:24 ` [PATCH v5 07/10] crypto: ccp: Add preferred access checking method Dionna Glaze
2024-11-11 22:46 ` Tom Lendacky [this message]
2024-11-12 19:47 ` Dionna Amalie Glaze
2024-11-12 21:08 ` Tom Lendacky
2024-11-07 23:24 ` [PATCH v5 08/10] KVM: SVM: move sev_issue_cmd_external_user to new API Dionna Glaze
2024-11-12 15:52 ` Tom Lendacky
2024-11-12 19:30 ` Dionna Amalie Glaze
2024-11-12 22:06 ` Tom Lendacky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4ec6b73f-4707-c93a-f046-213ac4d4549d@amd.com \
--to=thomas.lendacky@amd.com \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=bp@alien8.de \
--cc=dakr@redhat.com \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=dionnaglaze@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=john.allen@amd.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rafael@kernel.org \
--cc=russ.weight@linux.dev \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=tianfei.zhang@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox