Skip to content

Commit 22ca15b

Browse files
iokillgregkh
authored andcommitted
KEYS: trusted: dcp: fix improper sg use with CONFIG_VMAP_STACK=y
commit e8d9fab upstream. 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: [email protected] # v6.10+ Fixes: 0e28bf6 ("KEYS: trusted: dcp: fix leak of blob encryption key") Signed-off-by: David Gstir <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 900923f commit 22ca15b

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

security/keys/trusted-keys/trusted_dcp.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,16 @@ static int trusted_dcp_seal(struct trusted_key_payload *p, char *datablob)
201201
{
202202
struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
203203
int blen, ret;
204-
u8 plain_blob_key[AES_KEYSIZE_128];
204+
u8 *plain_blob_key;
205205

206206
blen = calc_blob_len(p->key_len);
207207
if (blen > MAX_BLOB_SIZE)
208208
return -E2BIG;
209209

210+
plain_blob_key = kmalloc(AES_KEYSIZE_128, GFP_KERNEL);
211+
if (!plain_blob_key)
212+
return -ENOMEM;
213+
210214
b->fmt_version = DCP_BLOB_VERSION;
211215
get_random_bytes(b->nonce, AES_KEYSIZE_128);
212216
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)
229233
ret = 0;
230234

231235
out:
232-
memzero_explicit(plain_blob_key, sizeof(plain_blob_key));
236+
memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
237+
kfree(plain_blob_key);
233238

234239
return ret;
235240
}
@@ -238,7 +243,7 @@ static int trusted_dcp_unseal(struct trusted_key_payload *p, char *datablob)
238243
{
239244
struct dcp_blob_fmt *b = (struct dcp_blob_fmt *)p->blob;
240245
int blen, ret;
241-
u8 plain_blob_key[AES_KEYSIZE_128];
246+
u8 *plain_blob_key = NULL;
242247

243248
if (b->fmt_version != DCP_BLOB_VERSION) {
244249
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)
256261
goto out;
257262
}
258263

264+
plain_blob_key = kmalloc(AES_KEYSIZE_128, GFP_KERNEL);
265+
if (!plain_blob_key) {
266+
ret = -ENOMEM;
267+
goto out;
268+
}
269+
259270
ret = decrypt_blob_key(b->blob_key, plain_blob_key);
260271
if (ret) {
261272
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)
271282

272283
ret = 0;
273284
out:
274-
memzero_explicit(plain_blob_key, sizeof(plain_blob_key));
285+
if (plain_blob_key) {
286+
memzero_explicit(plain_blob_key, AES_KEYSIZE_128);
287+
kfree(plain_blob_key);
288+
}
275289

276290
return ret;
277291
}

0 commit comments

Comments
 (0)