From: Yunqiang Su <ysu@wavecomp.com>
Add support for options SOL_ALG of the syscall setsockopt(). This
option is used in relation to Linux kernel Crypto API, and allows
a user to set additional information for the cipher operation via
syscall setsockopt(). The field "optname" must be one of the
following:
- ALG_SET_KEY – seting the key
- ALG_SET_AEAD_AUTHSIZE – set the authentication tag size
SOL_ALG is relatively newer setsockopt() option. Therefore, the
code that handles SOL_ALG is enclosed in "ifdef" so that the build
does not fail for older kernels that do not contain support for
SOL_ALG. "ifdef" also contains check if ALG_SET_KEY and
ALG_SET_AEAD_AUTHSIZE are defined.
Signed-off-by: Yunqiang Su <ysu@wavecomp.com>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
---
linux-user/syscall.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index dde6889..82c08b6 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -103,6 +103,7 @@
#include <linux/blkpg.h>
#include <netpacket/packet.h>
#include <linux/netlink.h>
+#include <linux/if_alg.h>
#include "linux_loop.h"
#include "uname.h"
@@ -1998,6 +1999,36 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
goto unimplemented;
}
break;
+#if defined(SOL_ALG) && defined(ALG_SET_KEY) && defined(ALG_SET_AEAD_AUTHSIZE)
+ case SOL_ALG:
+ switch (optname) {
+ case ALG_SET_KEY:
+ {
+ char *alg_key = g_malloc(optlen);
+
+ if (!alg_key) {
+ return -TARGET_ENOMEM;
+ }
+ if (copy_from_user(alg_key, optval_addr, optlen)) {
+ g_free(alg_key);
+ return -TARGET_EFAULT;
+ }
+ ret = get_errno(setsockopt(sockfd, level, optname,
+ alg_key, optlen));
+ g_free(alg_key);
+ break;
+ }
+ case ALG_SET_AEAD_AUTHSIZE:
+ {
+ ret = get_errno(setsockopt(sockfd, level, optname,
+ NULL, optlen));
+ break;
+ }
+ default:
+ goto unimplemented;
+ }
+ break;
+#endif
case TARGET_SOL_SOCKET:
switch (optname) {
case TARGET_SO_RCVTIMEO:
--
2.7.4
Le 07/06/2019 à 12:35, Aleksandar Markovic a écrit :
> From: Yunqiang Su <ysu@wavecomp.com>
>
> Add support for options SOL_ALG of the syscall setsockopt(). This
> option is used in relation to Linux kernel Crypto API, and allows
> a user to set additional information for the cipher operation via
> syscall setsockopt(). The field "optname" must be one of the
> following:
>
> - ALG_SET_KEY – seting the key
> - ALG_SET_AEAD_AUTHSIZE – set the authentication tag size
>
> SOL_ALG is relatively newer setsockopt() option. Therefore, the
> code that handles SOL_ALG is enclosed in "ifdef" so that the build
> does not fail for older kernels that do not contain support for
> SOL_ALG. "ifdef" also contains check if ALG_SET_KEY and
> ALG_SET_AEAD_AUTHSIZE are defined.
>
> Signed-off-by: Yunqiang Su <ysu@wavecomp.com>
> Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
> ---
> linux-user/syscall.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index dde6889..82c08b6 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -103,6 +103,7 @@
> #include <linux/blkpg.h>
> #include <netpacket/packet.h>
> #include <linux/netlink.h>
> +#include <linux/if_alg.h>
> #include "linux_loop.h"
> #include "uname.h"
>
> @@ -1998,6 +1999,36 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
> goto unimplemented;
> }
> break;
> +#if defined(SOL_ALG) && defined(ALG_SET_KEY) && defined(ALG_SET_AEAD_AUTHSIZE)
> + case SOL_ALG:
> + switch (optname) {
> + case ALG_SET_KEY:
> + {
> + char *alg_key = g_malloc(optlen);
> +
> + if (!alg_key) {
> + return -TARGET_ENOMEM;
> + }
> + if (copy_from_user(alg_key, optval_addr, optlen)) {
> + g_free(alg_key);
> + return -TARGET_EFAULT;
> + }
> + ret = get_errno(setsockopt(sockfd, level, optname,
> + alg_key, optlen));
> + g_free(alg_key);
> + break;
> + }
> + case ALG_SET_AEAD_AUTHSIZE:
> + {
> + ret = get_errno(setsockopt(sockfd, level, optname,
> + NULL, optlen));
> + break;
> + }
> + default:
> + goto unimplemented;
> + }
> + break;
> +#endif
> case TARGET_SOL_SOCKET:
> switch (optname) {
> case TARGET_SO_RCVTIMEO:
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
© 2016 - 2025 Red Hat, Inc.