public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Gonda <pgonda@google.com>
To: herbert@gondor.apana.org.au
Cc: Peter Gonda <pgonda@google.com>, Andy Nguyen <theflow@google.com>,
	David Rientjes <rientjes@google.com>,
	stable@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-crypto@vger.kernel.org, John Allen <john.allen@amd.com>,
	"Thomas . Lendacky" <thomas.lendacky@amd.com>
Subject: [PATCH] crypto: ccp - Limit memory allocation in SEV_GET_ID2 ioctl
Date: Wed, 14 Dec 2022 12:20:46 -0800	[thread overview]
Message-ID: <20221214202046.719598-1-pgonda@google.com> (raw)

Currently userspace can ask for any uint32 size allocation for the
SEV_GET_ID2. Limit this allocation size to the max physically
contiguously allocation: MAX_ORDER.

Reported-by: Andy Nguyen <theflow@google.com>
Suggested-by: David Rientjes <rientjes@google.com>
Signed-off-by: Peter Gonda <pgonda@google.com>
Cc: stable@vger.kernel.org
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-kernel@vger.kernel.org
Cc: linux-crypto@vger.kernel.org
Cc: John Allen <john.allen@amd.com>
Cc: Thomas.Lendacky <thomas.lendacky@amd.com>

---
 drivers/crypto/ccp/sev-dev.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 06fc7156c04f..5c16c4406764 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -878,6 +878,10 @@ static int sev_ioctl_do_get_id2(struct sev_issue_cmd *argp)
 	if (copy_from_user(&input, (void __user *)argp->data, sizeof(input)))
 		return -EFAULT;
 
+	/* Max length that can be allocated physically contiguously */
+	if (get_order(input.length) >= MAX_ORDER)
+		return -ENOMEM;
+
 	input_address = (void __user *)input.address;
 
 	if (input.address && input.length) {
-- 
2.39.0.rc1.256.g54fd8350bd-goog


             reply	other threads:[~2022-12-14 20:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-14 20:20 Peter Gonda [this message]
2022-12-15 10:05 ` [PATCH] crypto: ccp - Limit memory allocation in SEV_GET_ID2 ioctl 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         ` [patch] crypto: ccp - Avoid page allocation failure warning for SEV_GET_ID2 David Rientjes
2023-01-03 14:39           ` 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=20221214202046.719598-1-pgonda@google.com \
    --to=pgonda@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=john.allen@amd.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rientjes@google.com \
    --cc=stable@vger.kernel.org \
    --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