xref: /linux/security/keys/compat_dh.c (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2f1c316a3SStephan Mueller /* 32-bit compatibility syscall for 64-bit systems for DH operations
3f1c316a3SStephan Mueller  *
4f1c316a3SStephan Mueller  * Copyright (C) 2016 Stephan Mueller <smueller@chronox.de>
5f1c316a3SStephan Mueller  */
6f1c316a3SStephan Mueller 
7f1c316a3SStephan Mueller #include <linux/uaccess.h>
8f1c316a3SStephan Mueller 
9f1c316a3SStephan Mueller #include "internal.h"
10f1c316a3SStephan Mueller 
11f1c316a3SStephan Mueller /*
12f1c316a3SStephan Mueller  * Perform the DH computation or DH based key derivation.
13f1c316a3SStephan Mueller  *
14f1c316a3SStephan Mueller  * If successful, 0 will be returned.
15f1c316a3SStephan Mueller  */
compat_keyctl_dh_compute(struct keyctl_dh_params __user * params,char __user * buffer,size_t buflen,struct compat_keyctl_kdf_params __user * kdf)16f1c316a3SStephan Mueller long compat_keyctl_dh_compute(struct keyctl_dh_params __user *params,
17f1c316a3SStephan Mueller 			      char __user *buffer, size_t buflen,
18f1c316a3SStephan Mueller 			      struct compat_keyctl_kdf_params __user *kdf)
19f1c316a3SStephan Mueller {
20f1c316a3SStephan Mueller 	struct keyctl_kdf_params kdfcopy;
21f1c316a3SStephan Mueller 	struct compat_keyctl_kdf_params compat_kdfcopy;
22f1c316a3SStephan Mueller 
23f1c316a3SStephan Mueller 	if (!kdf)
24f1c316a3SStephan Mueller 		return __keyctl_dh_compute(params, buffer, buflen, NULL);
25f1c316a3SStephan Mueller 
26f1c316a3SStephan Mueller 	if (copy_from_user(&compat_kdfcopy, kdf, sizeof(compat_kdfcopy)) != 0)
27f1c316a3SStephan Mueller 		return -EFAULT;
28f1c316a3SStephan Mueller 
29f1c316a3SStephan Mueller 	kdfcopy.hashname = compat_ptr(compat_kdfcopy.hashname);
30f1c316a3SStephan Mueller 	kdfcopy.otherinfo = compat_ptr(compat_kdfcopy.otherinfo);
31f1c316a3SStephan Mueller 	kdfcopy.otherinfolen = compat_kdfcopy.otherinfolen;
324f9dabfaSEric Biggers 	memcpy(kdfcopy.__spare, compat_kdfcopy.__spare,
334f9dabfaSEric Biggers 	       sizeof(kdfcopy.__spare));
34f1c316a3SStephan Mueller 
35f1c316a3SStephan Mueller 	return __keyctl_dh_compute(params, buffer, buflen, &kdfcopy);
36f1c316a3SStephan Mueller }
37