* [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y
@ 2024-11-13 21:27 David Gstir
2025-01-07 12:56 ` David Gstir
0 siblings, 1 reply; 4+ messages in thread
From: David Gstir @ 2024-11-13 21:27 UTC (permalink / raw)
To: sigma star Kernel Team, James Bottomley, Jarkko Sakkinen,
Mimi Zohar, David Howells, Paul Moore, James Morris,
Serge E. Hallyn
Cc: linux-integrity, keyrings, linux-security-module, linux-kernel,
David Gstir, stable
With vmalloc stack addresses enabled (CONFIG_VMAP_STACK=y) DCP trusted
keys can crash during en- and decryption of the blob encryption key via
the DCP crypto driver. This is caused by improperly using sg_init_one()
with vmalloc'd stack buffers (plain_key_blob).
Fix this by always using kmalloc() for buffers we give to the DCP crypto
driver.
Cc: stable@vger.kernel.org # v6.10+
Fixes: 0e28bf61a5f9 ("KEYS: trusted: dcp: fix leak of blob encryption key")
Signed-off-by: David Gstir <david@sigma-star.at>
---
security/keys/trusted-keys/trusted_dcp.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/security/keys/trusted-keys/trusted_dcp.c b/security/keys/trusted-keys/trusted_dcp.c
index e908c53a803c..7b6eb655df0c 100644
--- a/security/keys/trusted-keys/trusted_dcp.c
+++ b/security/keys/trusted-keys/trusted_dcp.c
@@ -201,12 +201,16 @@ static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
{
struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
int blen, ret;
- u8 plain_blob_key[AES_KEYSIZE_128];
+ u8 *plain_blob_key;
blen = calc_blob_len(p->key_len);
if (blen > MAX_BLOB_SIZE)
return -E2BIG;
+ plain_blob_key = kmalloc(AES_KEYSIZE_128, GFP_KERNEL);
+ if (!plain_blob_key)
+ return -ENOMEM;
+
b->fmt_version = DCP_BLOB_VERSION;
get_random_bytes(b->nonce, AES_KEYSIZE_128);
get_random_bytes(plain_blob_key, AES_KEYSIZE_128);
@@ -229,7 +233,8 @@ static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
ret = 0;
out:
- memzero_explicit(plain_blob_key, sizeof(plain_blob_key));
+ memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
+ kfree(plain_blob_key);
return ret;
}
@@ -238,7 +243,7 @@ static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
{
struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
int blen, ret;
- u8 plain_blob_key[AES_KEYSIZE_128];
+ u8 *plain_blob_key = NULL;
if (b->fmt_version != DCP_BLOB_VERSION) {
pr_err("DCP blob has bad version: %i, expected %i\n",
@@ -256,6 +261,12 @@ static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
goto out;
}
+ plain_blob_key = kmalloc(AES_KEYSIZE_128, GFP_KERNEL);
+ if (!plain_blob_key) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
ret = decrypt_blob_key(b->blob_key, plain_blob_key);
if (ret) {
pr_err("Unable to decrypt blob key: %i\n", ret);
@@ -271,7 +282,10 @@ static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
ret = 0;
out:
- memzero_explicit(plain_blob_key, sizeof(plain_blob_key));
+ if (plain_blob_key) {
+ memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
+ kfree(plain_blob_key);
+ }
return ret;
}
--
2.47.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y
2024-11-13 21:27 [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y David Gstir
@ 2025-01-07 12:56 ` David Gstir
2025-01-07 19:05 ` Jarkko Sakkinen
0 siblings, 1 reply; 4+ messages in thread
From: David Gstir @ 2025-01-07 12:56 UTC (permalink / raw)
To: sigma star Kernel Team, James Bottomley, Jarkko Sakkinen,
Mimi Zohar, David Howells, Paul Moore, James Morris,
Serge E. Hallyn
Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, stable
> On 13.11.2024, at 22:27, David Gstir <david@sigma-star.at> wrote:
>
> With vmalloc stack addresses enabled (CONFIG_VMAP_STACK=y) DCP trusted
> keys can crash during en- and decryption of the blob encryption key via
> the DCP crypto driver. This is caused by improperly using sg_init_one()
> with vmalloc'd stack buffers (plain_key_blob).
>
> Fix this by always using kmalloc() for buffers we give to the DCP crypto
> driver.
>
> Cc: stable@vger.kernel.org # v6.10+
> Fixes: 0e28bf61a5f9 ("KEYS: trusted: dcp: fix leak of blob encryption key")
> Signed-off-by: David Gstir <david@sigma-star.at>
gentle ping.
Thanks!
- David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y
2025-01-07 12:56 ` David Gstir
@ 2025-01-07 19:05 ` Jarkko Sakkinen
2025-01-07 19:05 ` Jarkko Sakkinen
0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Sakkinen @ 2025-01-07 19:05 UTC (permalink / raw)
To: David Gstir, sigma star Kernel Team, James Bottomley, Mimi Zohar,
David Howells, Paul Moore, James Morris, Serge E. Hallyn
Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, stable
On Tue Jan 7, 2025 at 2:56 PM EET, David Gstir wrote:
>
> > On 13.11.2024, at 22:27, David Gstir <david@sigma-star.at> wrote:
> >
> > With vmalloc stack addresses enabled (CONFIG_VMAP_STACK=y) DCP trusted
> > keys can crash during en- and decryption of the blob encryption key via
> > the DCP crypto driver. This is caused by improperly using sg_init_one()
> > with vmalloc'd stack buffers (plain_key_blob).
> >
> > Fix this by always using kmalloc() for buffers we give to the DCP crypto
> > driver.
> >
> > Cc: stable@vger.kernel.org # v6.10+
> > Fixes: 0e28bf61a5f9 ("KEYS: trusted: dcp: fix leak of blob encryption key")
> > Signed-off-by: David Gstir <david@sigma-star.at>
>
> gentle ping.
It's done, thanks for reminding, and don't hesitate to do it earlier
if this ever happens again.
>
> Thanks!
> - David
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y
2025-01-07 19:05 ` Jarkko Sakkinen
@ 2025-01-07 19:05 ` Jarkko Sakkinen
0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Sakkinen @ 2025-01-07 19:05 UTC (permalink / raw)
To: Jarkko Sakkinen, David Gstir, sigma star Kernel Team,
James Bottomley, Mimi Zohar, David Howells, Paul Moore,
James Morris, Serge E. Hallyn
Cc: linux-integrity@vger.kernel.org, keyrings@vger.kernel.org,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, stable
On Tue Jan 7, 2025 at 9:05 PM EET, Jarkko Sakkinen wrote:
> On Tue Jan 7, 2025 at 2:56 PM EET, David Gstir wrote:
> >
> > > On 13.11.2024, at 22:27, David Gstir <david@sigma-star.at> wrote:
> > >
> > > With vmalloc stack addresses enabled (CONFIG_VMAP_STACK=y) DCP trusted
> > > keys can crash during en- and decryption of the blob encryption key via
> > > the DCP crypto driver. This is caused by improperly using sg_init_one()
> > > with vmalloc'd stack buffers (plain_key_blob).
> > >
> > > Fix this by always using kmalloc() for buffers we give to the DCP crypto
> > > driver.
> > >
> > > Cc: stable@vger.kernel.org # v6.10+
> > > Fixes: 0e28bf61a5f9 ("KEYS: trusted: dcp: fix leak of blob encryption key")
> > > Signed-off-by: David Gstir <david@sigma-star.at>
> >
> > gentle ping.
>
> It's done, thanks for reminding, and don't hesitate to do it earlier
> if this ever happens again.
I.e. I applied and will put to my PR.
BR, Jarkko
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-01-07 19:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-13 21:27 [PATCH] KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y David Gstir
2025-01-07 12:56 ` David Gstir
2025-01-07 19:05 ` Jarkko Sakkinen
2025-01-07 19:05 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).