From: David Rientjes <rientjes@google.com>
To: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>
Cc: Peter Gonda <pgonda@google.com>, Andy Nguyen <theflow@google.com>,
linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
John Allen <john.allen@amd.com>,
Tom Lendacky <thomas.lendacky@amd.com>
Subject: [patch] crypto: ccp - Avoid page allocation failure warning for SEV_GET_ID2
Date: Fri, 30 Dec 2022 14:18:46 -0800 (PST) [thread overview]
Message-ID: <833b4dd0-7f85-b336-0786-965f3f573f74@google.com> (raw)
In-Reply-To: <826b3dda-5b48-2d42-96b8-c49ccebfdfed@google.com>
For SEV_GET_ID2, the user provided length does not have a specified
limitation because the length of the ID may change in the future. The
kernel memory allocation, however, is implicitly limited to 4MB on x86 by
the page allocator, otherwise the kzalloc() will fail.
When this happens, it is best not to spam the kernel log with the warning.
Simply fail the allocation and return ENOMEM to the user.
Fixes: d6112ea0cb34 ("crypto: ccp - introduce SEV_GET_ID2 command")
Reported-by: Andy Nguyen <theflow@google.com>
Reported-by: Peter Gonda <pgonda@google.com>
Suggested-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David Rientjes <rientjes@google.com>
---
drivers/crypto/ccp/sev-dev.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -881,7 +881,14 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
input_address = (void __user *)input.address;
if (input.address && input.length) {
- id_blob = kzalloc(input.length, GFP_KERNEL);
+ /*
+ * The length of the ID shouldn't be assumed by software since
+ * it may change in the future. The allocation size is limited
+ * to 1 << (PAGE_SHIFT + MAX_ORDER - 1) by the page allocator.
+ * If the allocation fails, simply return ENOMEM rather than
+ * warning in the kernel log.
+ */
+ id_blob = kzalloc(input.length, GFP_KERNEL | __GFP_NOWARN);
if (!id_blob)
return -ENOMEM;
next prev parent reply other threads:[~2022-12-30 22:19 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 20:20 [PATCH] crypto: ccp - Limit memory allocation in SEV_GET_ID2 ioctl Peter Gonda
2022-12-15 10:05 ` Herbert Xu
2022-12-28 1:42 ` David Rientjes
2022-12-28 8:49 ` Herbert Xu
2022-12-30 22:01 ` David Rientjes
2022-12-30 22:18 ` David Rientjes [this message]
2023-01-03 14:39 ` [patch] crypto: ccp - Avoid page allocation failure warning for SEV_GET_ID2 Tom Lendacky
2023-01-03 23:18 ` David Rientjes
2023-01-04 14:40 ` Tom Lendacky
2023-01-05 1:49 ` David Rientjes
2023-01-05 15:37 ` Tom Lendacky
2023-01-06 15:18 ` Herbert Xu
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=833b4dd0-7f85-b336-0786-965f3f573f74@google.com \
--to=rientjes@google.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=john.allen@amd.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pgonda@google.com \
--cc=theflow@google.com \
--cc=thomas.lendacky@amd.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
all inboxes | Powered by JetHome®