Skip to content

Commit 29936d3

Browse files
holger-denglermehmetb0
authored andcommitted
s390/pkey: Wipe copies of clear-key structures on failure
[ Upstream commit d65d76a ] Wipe all sensitive data from stack for all IOCTLs, which convert a clear-key into a protected- or secure-key. Reviewed-by: Harald Freudenberger <[email protected]> Reviewed-by: Ingo Franzki <[email protected]> Acked-by: Heiko Carstens <[email protected]> Signed-off-by: Holger Dengler <[email protected]> Signed-off-by: Alexander Gordeev <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (backported from commit 7f6243edd901b75aaece326c90a1cc0dcb60cc3d linux-6.9.y) [mpellizzer: backported solving merge conflicts due to surrounding instructions which do not affect the patch] CVE-2024-42156 Signed-off-by: Massimiliano Pellizzer <[email protected]> Acked-by: Ivan Hu <[email protected]> Acked-by: Manuel Diewald <[email protected]> Signed-off-by: Roxana Nicolescu <[email protected]>
1 parent d6b3fc3 commit 29936d3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

drivers/s390/crypto/pkey_api.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,7 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
11671167
rc = cca_clr2seckey(kcs.cardnr, kcs.domain, kcs.keytype,
11681168
kcs.clrkey.clrkey, kcs.seckey.seckey);
11691169
DEBUG_DBG("%s cca_clr2seckey()=%d\n", __func__, rc);
1170-
if (rc)
1171-
break;
1172-
if (copy_to_user(ucs, &kcs, sizeof(kcs)))
1170+
if (!rc && copy_to_user(ucs, &kcs, sizeof(kcs)))
11731171
rc = -EFAULT;
11741172
memzero_explicit(&kcs, sizeof(kcs));
11751173
break;
@@ -1199,9 +1197,7 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
11991197
rc = pkey_clr2protkey(kcp.keytype,
12001198
&kcp.clrkey, &kcp.protkey);
12011199
DEBUG_DBG("%s pkey_clr2protkey()=%d\n", __func__, rc);
1202-
if (rc)
1203-
break;
1204-
if (copy_to_user(ucp, &kcp, sizeof(kcp)))
1200+
if (!rc && copy_to_user(ucp, &kcp, sizeof(kcp)))
12051201
rc = -EFAULT;
12061202
memzero_explicit(&kcp, sizeof(kcp));
12071203
break;
@@ -1345,11 +1341,14 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
13451341
if (copy_from_user(&kcs, ucs, sizeof(kcs)))
13461342
return -EFAULT;
13471343
apqns = _copy_apqns_from_user(kcs.apqns, kcs.apqn_entries);
1348-
if (IS_ERR(apqns))
1344+
if (IS_ERR(apqns)) {
1345+
memzero_explicit(&kcs, sizeof(kcs));
13491346
return PTR_ERR(apqns);
1347+
}
13501348
kkey = kmalloc(klen, GFP_KERNEL);
13511349
if (!kkey) {
13521350
kfree(apqns);
1351+
memzero_explicit(&kcs, sizeof(kcs));
13531352
return -ENOMEM;
13541353
}
13551354
rc = pkey_clr2seckey2(apqns, kcs.apqn_entries,
@@ -1359,15 +1358,18 @@ static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
13591358
kfree(apqns);
13601359
if (rc) {
13611360
kfree(kkey);
1361+
memzero_explicit(&kcs, sizeof(kcs));
13621362
break;
13631363
}
13641364
if (kcs.key) {
13651365
if (kcs.keylen < klen) {
13661366
kfree(kkey);
1367+
memzero_explicit(&kcs, sizeof(kcs));
13671368
return -EINVAL;
13681369
}
13691370
if (copy_to_user(kcs.key, kkey, klen)) {
13701371
kfree(kkey);
1372+
memzero_explicit(&kcs, sizeof(kcs));
13711373
return -EFAULT;
13721374
}
13731375
}

0 commit comments

Comments
 (0)