Skip to content

Commit 4693fc7

Browse files
smuellerDDJames Morris
authored andcommitted
KEYS: Add placeholder for KDF usage with DH
The values computed during Diffie-Hellman key exchange are often used in combination with key derivation functions to create cryptographic keys. Add a placeholder for a later implementation to configure a key derivation function that will transform the Diffie-Hellman result returned by the KEYCTL_DH_COMPUTE command. [This patch was stripped down from a patch produced by Mat Martineau that had a bug in the compat code - so for the moment Stephan's patch simply requires that the placeholder argument must be NULL] Original-signed-off-by: Mat Martineau <mathew.j.martineau@linux.intel.com> Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: James Morris <james.l.morris@oracle.com>
1 parent 4340fa5 commit 4693fc7

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎Documentation/security/keys.txt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ The keyctl syscall functions are:
826826
(*) Compute a Diffie-Hellman shared secret or public key
827827

828828
long keyctl(KEYCTL_DH_COMPUTE, struct keyctl_dh_params *params,
829-
char *buffer, size_t buflen);
829+
char *buffer, size_t buflen,
830+
void *reserved);
830831

831832
The params struct contains serial numbers for three keys:
832833

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

847+
The reserved argument must be set to NULL.
848+
846849
The buffer length must be at least the length of the prime, or zero.
847850

848851
If the buffer length is nonzero, the length of the result is

‎security/keys/compat.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ COMPAT_SYSCALL_DEFINE5(keyctl, u32, option,
134134

135135
case KEYCTL_DH_COMPUTE:
136136
return keyctl_dh_compute(compat_ptr(arg2), compat_ptr(arg3),
137-
arg4);
137+
arg4, compat_ptr(arg5));
138138

139139
default:
140140
return -EOPNOTSUPP;

‎security/keys/dh.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ static ssize_t mpi_from_key(key_serial_t keyid, size_t maxlen, MPI *mpi)
7878
}
7979

8080
long keyctl_dh_compute(struct keyctl_dh_params __user *params,
81-
char __user *buffer, size_t buflen)
81+
char __user *buffer, size_t buflen,
82+
void __user *reserved)
8283
{
8384
long ret;
8485
MPI base, private, prime, result;
@@ -97,6 +98,11 @@ long keyctl_dh_compute(struct keyctl_dh_params __user *params,
9798
goto out;
9899
}
99100

101+
if (reserved) {
102+
ret = -EINVAL;
103+
goto out;
104+
}
105+
100106
keylen = mpi_from_key(pcopy.prime, buflen, &prime);
101107
if (keylen < 0 || !prime) {
102108
/* buflen == 0 may be used to query the required buffer size,

‎security/keys/internal.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ static inline long keyctl_get_persistent(uid_t uid, key_serial_t destring)
260260

261261
#ifdef CONFIG_KEY_DH_OPERATIONS
262262
extern long keyctl_dh_compute(struct keyctl_dh_params __user *, char __user *,
263-
size_t);
263+
size_t, void __user *);
264264
#else
265265
static inline long keyctl_dh_compute(struct keyctl_dh_params __user *params,
266-
char __user *buffer, size_t buflen)
266+
char __user *buffer, size_t buflen,
267+
void __user *reserved)
267268
{
268269
return -EOPNOTSUPP;
269270
}

‎security/keys/keyctl.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,8 +1688,8 @@ SYSCALL_DEFINE5(keyctl, int, option, unsigned long, arg2, unsigned long, arg3,
16881688

16891689
case KEYCTL_DH_COMPUTE:
16901690
return keyctl_dh_compute((struct keyctl_dh_params __user *) arg2,
1691-
(char __user *) arg3,
1692-
(size_t) arg4);
1691+
(char __user *) arg3, (size_t) arg4,
1692+
(void __user *) arg5);
16931693

16941694
default:
16951695
return -EOPNOTSUPP;

0 commit comments

Comments
 (0)