Skip to content

Commit

Permalink
s390/pkey: use memdup_user() to simplify code
Browse files Browse the repository at this point in the history
Generated by: scripts/coccinelle/api/memdup_user.cocci

Link: http://lkml.kernel.org/r/[email protected]
[[email protected]: use ==0 instead of <=0 for a size_t variable]
[[email protected]: split bugfix into separate patch; shorten changelog]
Signed-off-by: Markus Elfring <[email protected]>
Signed-off-by: Christian Borntraeger <[email protected]>
Signed-off-by: Heiko Carstens <[email protected]>
Signed-off-by: Vasily Gorbik <[email protected]>
  • Loading branch information
elfring authored and Vasily Gorbik committed Nov 12, 2019
1 parent f9cac4f commit 8b57e7c
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions drivers/s390/crypto/pkey_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,38 +715,18 @@ static int pkey_apqns4keytype(enum pkey_key_type ktype,

static void *_copy_key_from_user(void __user *ukey, size_t keylen)
{
void *kkey;

if (!ukey || keylen < MINKEYBLOBSIZE || keylen > KEYBLOBBUFSIZE)
return ERR_PTR(-EINVAL);
kkey = kmalloc(keylen, GFP_KERNEL);
if (!kkey)
return ERR_PTR(-ENOMEM);
if (copy_from_user(kkey, ukey, keylen)) {
kfree(kkey);
return ERR_PTR(-EFAULT);
}

return kkey;
return memdup_user(ukey, keylen);
}

static void *_copy_apqns_from_user(void __user *uapqns, size_t nr_apqns)
{
void *kapqns = NULL;
size_t nbytes;

if (uapqns && nr_apqns > 0) {
nbytes = nr_apqns * sizeof(struct pkey_apqn);
kapqns = kmalloc(nbytes, GFP_KERNEL);
if (!kapqns)
return ERR_PTR(-ENOMEM);
if (copy_from_user(kapqns, uapqns, nbytes)) {
kfree(kapqns);
return ERR_PTR(-EFAULT);
}
}
if (!uapqns || nr_apqns == 0)
return NULL;

return kapqns;
return memdup_user(uapqns, nr_apqns * sizeof(struct pkey_apqn));
}

static long pkey_unlocked_ioctl(struct file *filp, unsigned int cmd,
Expand Down

0 comments on commit 8b57e7c

Please sign in to comment.