aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Tokarev <mjt@tls.msk.ru>2024-03-31 13:07:34 +0300
committerMichael Tokarev <mjt@tls.msk.ru>2024-04-25 22:19:25 +0300
commit51cc8762a0c2f8b08d1fc4957c0c309c73241812 (patch)
treeeefe8597bd95804ec9f6053ec2292138ca0ed794
parent6ea6863f215c7f1f3cf7756dc5876a67ba2b90fc (diff)
downloadqemu-51cc8762a0c2f8b08d1fc4957c0c309c73241812.zip
qemu-51cc8762a0c2f8b08d1fc4957c0c309c73241812.tar.gz
qemu-51cc8762a0c2f8b08d1fc4957c0c309c73241812.tar.bz2
linux-user: do_setsockopt: fix SOL_ALG.ALG_SET_KEY
This setsockopt accepts zero-lengh optlen (current qemu implementation does not allow this). Also, there's no need to make a copy of the key, it is enough to use lock_user() (which accepts zero length already). Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2197 Fixes: f31dddd2fc "linux-user: Add support for setsockopt() option SOL_ALG" Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Message-Id: <20240331100737.2724186-2-mjt@tls.msk.ru> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> (cherry picked from commit 04f6fb897a5aeb3e356a7b889869c9962f9c16c7) Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
-rw-r--r--linux-user/syscall.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 41017b0..74240f9 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2297,18 +2297,13 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
switch (optname) {
case ALG_SET_KEY:
{
- char *alg_key = g_malloc(optlen);
-
+ char *alg_key = lock_user(VERIFY_READ, optval_addr, optlen, 1);
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);
+ unlock_user(alg_key, optval_addr, optlen);
break;
}
case ALG_SET_AEAD_AUTHSIZE: