Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/jmorris/linux-security

Pull key handling update from James Morris:
 "This alters a new keyctl function added in the current merge window to
  allow for a future extension planned for the next merge window"

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security:
  KEYS: Add placeholder for KDF usage with DH
  • Loading branch information
Linus Torvalds committed Jun 5, 2016
2 parents eedf265 + 4693fc7 commit d834502
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Documentation/security/keys.txt
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,8 @@ The keyctl syscall functions are:
(*) Compute a Diffie-Hellman shared secret or public key

long keyctl(KEYCTL_DH_COMPUTE, struct keyctl_dh_params *params,
char *buffer, size_t buflen);
char *buffer, size_t buflen,
void *reserved);

The params struct contains serial numbers for three keys:

Expand All @@ -843,6 +844,8 @@ The keyctl syscall functions are:
public key. If the base is the remote public key, the result is
the shared secret.

The reserved argument must be set to NULL.

The buffer length must be at least the length of the prime, or zero.

If the buffer length is nonzero, the length of the result is
Expand Down
2 changes: 1 addition & 1 deletion security/keys/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,

case KEYCTL_DH_COMPUTE:
return keyctl_dh_compute(compat_ptr(arg2), compat_ptr(arg3),
arg4);
arg4, compat_ptr(arg5));

default:
return -EOPNOTSUPP;
Expand Down
8 changes: 7 additions & 1 deletion security/keys/dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ static ssize_t mpi_from_key(key_serial_t keyid, size_t maxlen, MPI *mpi)
}

long keyctl_dh_compute(struct keyctl_dh_params __user *params,
char __user *buffer, size_t buflen)
char __user *buffer, size_t buflen,
void __user *reserved)
{
long ret;
MPI base, private, prime, result;
Expand All @@ -97,6 +98,11 @@ long keyctl_dh_compute(struct keyctl_dh_params __user *params,
goto out;
}

if (reserved) {
ret = -EINVAL;
goto out;
}

keylen = mpi_from_key(pcopy.prime, buflen, &prime);
if (keylen < 0 || !prime) {
/* buflen == 0 may be used to query the required buffer size,
Expand Down
5 changes: 3 additions & 2 deletions security/keys/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ static inline long keyctl_get_persistent(uid_t uid, key_serial_t destring)

#ifdef CONFIG_KEY_DH_OPERATIONS
extern long keyctl_dh_compute(struct keyctl_dh_params __user *, char __user *,
size_t);
size_t, void __user *);
#else
static inline long keyctl_dh_compute(struct keyctl_dh_params __user *params,
char __user *buffer, size_t buflen)
char __user *buffer, size_t buflen,
void __user *reserved)
{
return -EOPNOTSUPP;
}
Expand Down
4 changes: 2 additions & 2 deletions security/keys/keyctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1688,8 +1688,8 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,

case KEYCTL_DH_COMPUTE:
return keyctl_dh_compute((struct keyctl_dh_params __user *) arg2,
(char __user *) arg3,
(size_t) arg4);
(char __user *) arg3, (size_t) arg4,
(void __user *) arg5);

default:
return -EOPNOTSUPP;
Expand Down

0 comments on commit d834502

Please sign in to comment.