From: Tom Lendacky <thomas.lendacky@amd.com>
To: Jacky Li <jackyli@google.com>,
Brijesh Singh <brijesh.singh@amd.com>,
John Allen <john.allen@amd.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Marc Orr <marcorr@google.com>, Alper Gun <alpergun@google.com>,
Peter Gonda <pgonda@google.com>,
linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] crypto: ccp - Fix the INIT_EX data file open failure
Date: Mon, 11 Apr 2022 13:58:00 -0500 [thread overview]
Message-ID: <4278ae8b-eb87-06ac-43af-41a1c741f9a9@amd.com> (raw)
In-Reply-To: <20220411180006.4187548-1-jackyli@google.com>
On 4/11/22 13:00, Jacky Li wrote:
> There are 2 common cases when INIT_EX data file might not be
> opened successfully and fail the sev initialization:
>
> 1. In user namespaces, normal user tasks (e.g. VMM) can change their
> current->fs->root to point to arbitrary directories. While
> init_ex_path is provided as a module param related to root file
> system. Solution: use the root directory of init_task to avoid
> accessing the wrong file.
>
> 2. Normal user tasks (e.g. VMM) don't have the privilege to access
> the INIT_EX data file. Solution: open the file as root and
> restore permissions immediately.
>
> Signed-off-by: Jacky Li <jackyli@google.com>
Should this have a Fixes: tag?
Thanks,
Tom
> ---
> drivers/crypto/ccp/sev-dev.c | 30 ++++++++++++++++++++++++++++--
> 1 file changed, 28 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 6ab93dfd478a..3aefb177715e 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -23,6 +23,7 @@
> #include <linux/gfp.h>
> #include <linux/cpufeature.h>
> #include <linux/fs.h>
> +#include <linux/fs_struct.h>
>
> #include <asm/smp.h>
>
> @@ -170,6 +171,31 @@ static void *sev_fw_alloc(unsigned long len)
> return page_address(page);
> }
>
> +static struct file *open_file_as_root(const char *filename, int flags, umode_t mode)
> +{
> + struct file *fp;
> + struct path root;
> + struct cred *cred;
> + const struct cred *old_cred;
> +
> + task_lock(&init_task);
> + get_fs_root(init_task.fs, &root);
> + task_unlock(&init_task);
> +
> + cred = prepare_creds();
> + if (!cred)
> + return ERR_PTR(-ENOMEM);
> + cred->fsuid = GLOBAL_ROOT_UID;
> + old_cred = override_creds(cred);
> +
> + fp = file_open_root(&root, filename, flags, mode);
> + path_put(&root);
> +
> + revert_creds(old_cred);
> +
> + return fp;
> +}
> +
> static int sev_read_init_ex_file(void)
> {
> struct sev_device *sev = psp_master->sev_data;
> @@ -181,7 +207,7 @@ static int sev_read_init_ex_file(void)
> if (!sev_init_ex_buffer)
> return -EOPNOTSUPP;
>
> - fp = filp_open(init_ex_path, O_RDONLY, 0);
> + fp = open_file_as_root(init_ex_path, O_RDONLY, 0);
> if (IS_ERR(fp)) {
> int ret = PTR_ERR(fp);
>
> @@ -217,7 +243,7 @@ static void sev_write_init_ex_file(void)
> if (!sev_init_ex_buffer)
> return;
>
> - fp = filp_open(init_ex_path, O_CREAT | O_WRONLY, 0600);
> + fp = open_file_as_root(init_ex_path, O_CREAT | O_WRONLY, 0600);
> if (IS_ERR(fp)) {
> dev_err(sev->dev,
> "SEV: could not open file for write, error %ld\n",
next prev parent reply other threads:[~2022-04-11 18:58 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-11 18:00 [PATCH] crypto: ccp - Fix the INIT_EX data file open failure Jacky Li
2022-04-11 18:58 ` Tom Lendacky [this message]
2022-04-11 19:35 ` Jacky Li
2022-04-13 15:40 ` Peter Gonda
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=4278ae8b-eb87-06ac-43af-41a1c741f9a9@amd.com \
--to=thomas.lendacky@amd.com \
--cc=alpergun@google.com \
--cc=brijesh.singh@amd.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=jackyli@google.com \
--cc=john.allen@amd.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcorr@google.com \
--cc=pgonda@google.com \
/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