Skip to content

Commit 7404ce5

Browse files
committed
Merge tag 's390-7.2-3' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
Pull s390 fixes from Vasily Gorbik: - Fix PKEY_VERIFYPROTK ioctl key type handling by removing the generic key-length based type check with its wrong bit-size calculation, and leaving protected key verification to the pkey handler - Fix monwriter buffer reuse by rejecting records that change the data length, preventing out of bounds user copy into the kernel buffer * tag 's390-7.2-3' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux: s390/monwriter: Reject buffer reuse with different data length pkey: Move keytype check from pkey api to handler
2 parents 410430b + 2995cce commit 7404ce5

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

drivers/s390/char/monwriter.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ static int monwrite_new_hdr(struct mon_private *monpriv)
122122
kfree(monbuf->data);
123123
kfree(monbuf);
124124
monbuf = NULL;
125+
} else if (monbuf->hdr.datalen != monhdr->datalen) {
126+
/* Data with buffer reuse must not change its length */
127+
return -EINVAL;
125128
}
126129
} else if (monhdr->mon_function != MONWRITE_STOP_INTERVAL) {
127130
if (mon_buf_count >= mon_max_bufs)

drivers/s390/crypto/pkey_api.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ static int pkey_ioctl_verifyprotk(struct pkey_verifyprotk __user *uvp)
327327
{
328328
struct pkey_verifyprotk kvp;
329329
struct protaeskeytoken *t;
330-
u32 keytype;
331330
u8 *tmpbuf;
332331
int rc;
333332

@@ -341,14 +340,6 @@ static int pkey_ioctl_verifyprotk(struct pkey_verifyprotk __user *uvp)
341340
return -EINVAL;
342341
}
343342

344-
keytype = pkey_aes_bitsize_to_keytype(8 * kvp.protkey.len);
345-
if (!keytype) {
346-
PKEY_DBF_ERR("%s unknown/unsupported protkey length %u\n",
347-
__func__, kvp.protkey.len);
348-
memzero_explicit(&kvp, sizeof(kvp));
349-
return -EINVAL;
350-
}
351-
352343
/* build a 'protected key token' from the raw protected key */
353344
tmpbuf = kzalloc(sizeof(*t), GFP_KERNEL);
354345
if (!tmpbuf) {
@@ -358,7 +349,7 @@ static int pkey_ioctl_verifyprotk(struct pkey_verifyprotk __user *uvp)
358349
t = (struct protaeskeytoken *)tmpbuf;
359350
t->type = TOKTYPE_NON_CCA;
360351
t->version = TOKVER_PROTECTED_KEY;
361-
t->keytype = keytype;
352+
t->keytype = kvp.protkey.type;
362353
t->len = kvp.protkey.len;
363354
memcpy(t->protkey, kvp.protkey.protkey, kvp.protkey.len);
364355

0 commit comments

Comments
 (0)