From patchwork Mon Oct 17 13:24:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 9379281 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 808C9607D4 for ; Mon, 17 Oct 2016 13:29:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7076B29367 for ; Mon, 17 Oct 2016 13:29:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6547329373; Mon, 17 Oct 2016 13:29:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2168829367 for ; Mon, 17 Oct 2016 13:29:54 +0000 (UTC) Received: from localhost ([::1]:33072 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bw7zF-00075a-8V for patchwork-qemu-devel@patchwork.kernel.org; Mon, 17 Oct 2016 09:29:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bw7uQ-00037R-Tu for qemu-devel@nongnu.org; Mon, 17 Oct 2016 09:24:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bw7uO-0003Bn-Ua for qemu-devel@nongnu.org; Mon, 17 Oct 2016 09:24:54 -0400 Received: from mail-lf0-x22b.google.com ([2a00:1450:4010:c07::22b]:34391) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bw7uO-0003Ae-HX for qemu-devel@nongnu.org; Mon, 17 Oct 2016 09:24:52 -0400 Received: by mail-lf0-x22b.google.com with SMTP id b81so285332702lfe.1 for ; Mon, 17 Oct 2016 06:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rtlCo4GsrgM1WasIXDlA4d2vQFO2rcxB8cGz99UKnT8=; b=kwuEIWZY4wgF3+nSstw8uJ+4JzuiIeCy+pqjQgovLPCvtR4/9OcwHASNPahRygsJH8 ABdiE1+Q+Uo6/JJMiqixM6mUoltj9PuziC1+B7Vx6VrDVEjGvvQVvZakJ+5a+i8Q7jmg 95fMCKkTdG82aoAANxONbjOn1qKecJ78JcNBM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rtlCo4GsrgM1WasIXDlA4d2vQFO2rcxB8cGz99UKnT8=; b=dCZUh5rmRtymI7Kd812bhvpPvy8F7gneFtUoReTLlIrXyQ6haoA073UJExUan4CkuL WL4Zn30BKnekB6GQb8wJNb1J0DkF9frqcTNICzC2pU6QDzBU5bnmWipIa8rnEDM/kbsc TxhELsy4KTOyLbR8NZFTGjx4No9OdHZR44mj97jy5CdgJ4JGbIuYD/DpgYQArmnexXfm OVQf7MlE+8/6yABPZ2feXsLuEW1Dv0vaXjm7mlUgW5cn4ALasS3ESGe9trpX+DjVrQov P/mwHQeYx/6z3RIN1+cHT/n+bsbR+qPn5yD546Q1/3+WY42jUE+90GHwOWOHFg6zVlFi 1o2g== X-Gm-Message-State: AA6/9Rn8dvDUknKOwZzUKNG+xt6Pi+toyeGF9VgmTevXtLjBnQBkkDnVDZO/2TXb1LX16uQz X-Received: by 10.25.211.142 with SMTP id k136mr13010202lfg.45.1476710689018; Mon, 17 Oct 2016 06:24:49 -0700 (PDT) Received: from beaming.home (91-157-170-157.elisa-laajakaista.fi. [91.157.170.157]) by smtp.gmail.com with ESMTPSA id y81sm7782857lff.29.2016.10.17.06.24.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Oct 2016 06:24:48 -0700 (PDT) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 17 Oct 2016 16:24:23 +0300 Message-Id: X-Mailer: git-send-email 2.1.4 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22b Subject: [Qemu-devel] [PULL 05/22] linux-user: Fix socketcall() syscall support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Aleksandar Markovic Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Aleksandar Markovic Since not all Linux host platforms support socketcall() (most notably Intel), do_socketcall() function in Qemu's syscalls.c is implemented to mirror the corespondant implementation of socketcall() in Linux kernel, and to utilise individual socket operations that are supported on all Linux platforms. (see kernel source file net/socket.c, definition of socketcall). However, error codes produced by Qemu implementation are wrong for the cases of invalid values of the first argument. Also, naming of constants is not consistent with kernel one, and not consistant with Qemu convention of prefixing such constants with "TARGET_". This patch in that light brings do_socketcall() closer to its kernel counterpart, and in that way fixes the errors and yields more consisrtent Qemu code. There were also three missing cases (among 20) for strace support for socketcall(). The array that contains pointers for appropriate printing functions is updated with 3 elements, however pointers to functions are left NULL, and its implementation is left for future. Also, this patch fixes failure of LTP test socketcall02, if executed on some Qemu emulated sywstems (uer mode). Signed-off-by: Aleksandar Markovic Signed-off-by: Riku Voipio --- linux-user/strace.c | 39 ++++++++------- linux-user/syscall.c | 119 ++++++++++++++++++++++++---------------------- linux-user/syscall_defs.h | 42 ++++++++-------- 3 files changed, 105 insertions(+), 95 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index f37b386..a0e45b5 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -1675,29 +1675,32 @@ print_optint: } #define PRINT_SOCKOP(name, func) \ - [SOCKOP_##name] = { #name, func } + [TARGET_SYS_##name] = { #name, func } static struct { const char *name; void (*print)(const char *, abi_long); } scall[] = { - PRINT_SOCKOP(socket, do_print_socket), - PRINT_SOCKOP(bind, do_print_sockaddr), - PRINT_SOCKOP(connect, do_print_sockaddr), - PRINT_SOCKOP(listen, do_print_listen), - PRINT_SOCKOP(accept, do_print_sockaddr), - PRINT_SOCKOP(getsockname, do_print_sockaddr), - PRINT_SOCKOP(getpeername, do_print_sockaddr), - PRINT_SOCKOP(socketpair, do_print_socketpair), - PRINT_SOCKOP(send, do_print_sendrecv), - PRINT_SOCKOP(recv, do_print_sendrecv), - PRINT_SOCKOP(sendto, do_print_msgaddr), - PRINT_SOCKOP(recvfrom, do_print_msgaddr), - PRINT_SOCKOP(shutdown, do_print_shutdown), - PRINT_SOCKOP(sendmsg, do_print_msg), - PRINT_SOCKOP(recvmsg, do_print_msg), - PRINT_SOCKOP(setsockopt, do_print_sockopt), - PRINT_SOCKOP(getsockopt, do_print_sockopt), + PRINT_SOCKOP(SOCKET, do_print_socket), + PRINT_SOCKOP(BIND, do_print_sockaddr), + PRINT_SOCKOP(CONNECT, do_print_sockaddr), + PRINT_SOCKOP(LISTEN, do_print_listen), + PRINT_SOCKOP(ACCEPT, do_print_sockaddr), + PRINT_SOCKOP(GETSOCKNAME, do_print_sockaddr), + PRINT_SOCKOP(GETPEERNAME, do_print_sockaddr), + PRINT_SOCKOP(SOCKETPAIR, do_print_socketpair), + PRINT_SOCKOP(SEND, do_print_sendrecv), + PRINT_SOCKOP(RECV, do_print_sendrecv), + PRINT_SOCKOP(SENDTO, do_print_msgaddr), + PRINT_SOCKOP(RECVFROM, do_print_msgaddr), + PRINT_SOCKOP(SHUTDOWN, do_print_shutdown), + PRINT_SOCKOP(SETSOCKOPT, do_print_sockopt), + PRINT_SOCKOP(GETSOCKOPT, do_print_sockopt), + PRINT_SOCKOP(SENDMSG, do_print_msg), + PRINT_SOCKOP(RECVMSG, do_print_msg), + PRINT_SOCKOP(ACCEPT4, NULL), + PRINT_SOCKOP(RECVMMSG, NULL), + PRINT_SOCKOP(SENDMMSG, NULL), }; static void diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 032cb76..05b4c41 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3898,89 +3898,94 @@ fail: } #ifdef TARGET_NR_socketcall -/* do_socketcall() Must return target values and target errnos. */ +/* do_socketcall() must return target values and target errnos. */ static abi_long do_socketcall(int num, abi_ulong vptr) { - static const unsigned ac[] = { /* number of arguments per call */ - [SOCKOP_socket] = 3, /* domain, type, protocol */ - [SOCKOP_bind] = 3, /* sockfd, addr, addrlen */ - [SOCKOP_connect] = 3, /* sockfd, addr, addrlen */ - [SOCKOP_listen] = 2, /* sockfd, backlog */ - [SOCKOP_accept] = 3, /* sockfd, addr, addrlen */ - [SOCKOP_accept4] = 4, /* sockfd, addr, addrlen, flags */ - [SOCKOP_getsockname] = 3, /* sockfd, addr, addrlen */ - [SOCKOP_getpeername] = 3, /* sockfd, addr, addrlen */ - [SOCKOP_socketpair] = 4, /* domain, type, protocol, tab */ - [SOCKOP_send] = 4, /* sockfd, msg, len, flags */ - [SOCKOP_recv] = 4, /* sockfd, msg, len, flags */ - [SOCKOP_sendto] = 6, /* sockfd, msg, len, flags, addr, addrlen */ - [SOCKOP_recvfrom] = 6, /* sockfd, msg, len, flags, addr, addrlen */ - [SOCKOP_shutdown] = 2, /* sockfd, how */ - [SOCKOP_sendmsg] = 3, /* sockfd, msg, flags */ - [SOCKOP_recvmsg] = 3, /* sockfd, msg, flags */ - [SOCKOP_sendmmsg] = 4, /* sockfd, msgvec, vlen, flags */ - [SOCKOP_recvmmsg] = 4, /* sockfd, msgvec, vlen, flags */ - [SOCKOP_setsockopt] = 5, /* sockfd, level, optname, optval, optlen */ - [SOCKOP_getsockopt] = 5, /* sockfd, level, optname, optval, optlen */ + static const unsigned nargs[] = { /* number of arguments per operation */ + [TARGET_SYS_SOCKET] = 3, /* domain, type, protocol */ + [TARGET_SYS_BIND] = 3, /* fd, addr, addrlen */ + [TARGET_SYS_CONNECT] = 3, /* fd, addr, addrlen */ + [TARGET_SYS_LISTEN] = 2, /* fd, backlog */ + [TARGET_SYS_ACCEPT] = 3, /* fd, addr, addrlen */ + [TARGET_SYS_GETSOCKNAME] = 3, /* fd, addr, addrlen */ + [TARGET_SYS_GETPEERNAME] = 3, /* fd, addr, addrlen */ + [TARGET_SYS_SOCKETPAIR] = 4, /* domain, type, protocol, tab */ + [TARGET_SYS_SEND] = 4, /* fd, msg, len, flags */ + [TARGET_SYS_RECV] = 4, /* fd, msg, len, flags */ + [TARGET_SYS_SENDTO] = 6, /* fd, msg, len, flags, addr, addrlen */ + [TARGET_SYS_RECVFROM] = 6, /* fd, msg, len, flags, addr, addrlen */ + [TARGET_SYS_SHUTDOWN] = 2, /* fd, how */ + [TARGET_SYS_SETSOCKOPT] = 5, /* fd, level, optname, optval, optlen */ + [TARGET_SYS_GETSOCKOPT] = 5, /* fd, level, optname, optval, optlen */ + [TARGET_SYS_SENDMSG] = 3, /* fd, msg, flags */ + [TARGET_SYS_RECVMSG] = 3, /* fd, msg, flags */ + [TARGET_SYS_ACCEPT4] = 4, /* fd, addr, addrlen, flags */ + [TARGET_SYS_RECVMMSG] = 4, /* fd, msgvec, vlen, flags */ + [TARGET_SYS_SENDMMSG] = 4, /* fd, msgvec, vlen, flags */ }; abi_long a[6]; /* max 6 args */ + unsigned i; - /* first, collect the arguments in a[] according to ac[] */ - if (num >= 0 && num < ARRAY_SIZE(ac)) { - unsigned i; - assert(ARRAY_SIZE(a) >= ac[num]); /* ensure we have space for args */ - for (i = 0; i < ac[num]; ++i) { - if (get_user_ual(a[i], vptr + i * sizeof(abi_long)) != 0) { - return -TARGET_EFAULT; - } + /* check the range of the first argument num */ + /* (TARGET_SYS_SENDMMSG is the highest among TARGET_SYS_xxx) */ + if (num < 1 || num > TARGET_SYS_SENDMMSG) { + return -TARGET_EINVAL; + } + /* ensure we have space for args */ + if (nargs[num] > ARRAY_SIZE(a)) { + return -TARGET_EINVAL; + } + /* collect the arguments in a[] according to nargs[] */ + for (i = 0; i < nargs[num]; ++i) { + if (get_user_ual(a[i], vptr + i * sizeof(abi_long)) != 0) { + return -TARGET_EFAULT; } } - - /* now when we have the args, actually handle the call */ + /* now when we have the args, invoke the appropriate underlying function */ switch (num) { - case SOCKOP_socket: /* domain, type, protocol */ + case TARGET_SYS_SOCKET: /* domain, type, protocol */ return do_socket(a[0], a[1], a[2]); - case SOCKOP_bind: /* sockfd, addr, addrlen */ + case TARGET_SYS_BIND: /* sockfd, addr, addrlen */ return do_bind(a[0], a[1], a[2]); - case SOCKOP_connect: /* sockfd, addr, addrlen */ + case TARGET_SYS_CONNECT: /* sockfd, addr, addrlen */ return do_connect(a[0], a[1], a[2]); - case SOCKOP_listen: /* sockfd, backlog */ + case TARGET_SYS_LISTEN: /* sockfd, backlog */ return get_errno(listen(a[0], a[1])); - case SOCKOP_accept: /* sockfd, addr, addrlen */ + case TARGET_SYS_ACCEPT: /* sockfd, addr, addrlen */ return do_accept4(a[0], a[1], a[2], 0); - case SOCKOP_accept4: /* sockfd, addr, addrlen, flags */ - return do_accept4(a[0], a[1], a[2], a[3]); - case SOCKOP_getsockname: /* sockfd, addr, addrlen */ + case TARGET_SYS_GETSOCKNAME: /* sockfd, addr, addrlen */ return do_getsockname(a[0], a[1], a[2]); - case SOCKOP_getpeername: /* sockfd, addr, addrlen */ + case TARGET_SYS_GETPEERNAME: /* sockfd, addr, addrlen */ return do_getpeername(a[0], a[1], a[2]); - case SOCKOP_socketpair: /* domain, type, protocol, tab */ + case TARGET_SYS_SOCKETPAIR: /* domain, type, protocol, tab */ return do_socketpair(a[0], a[1], a[2], a[3]); - case SOCKOP_send: /* sockfd, msg, len, flags */ + case TARGET_SYS_SEND: /* sockfd, msg, len, flags */ return do_sendto(a[0], a[1], a[2], a[3], 0, 0); - case SOCKOP_recv: /* sockfd, msg, len, flags */ + case TARGET_SYS_RECV: /* sockfd, msg, len, flags */ return do_recvfrom(a[0], a[1], a[2], a[3], 0, 0); - case SOCKOP_sendto: /* sockfd, msg, len, flags, addr, addrlen */ + case TARGET_SYS_SENDTO: /* sockfd, msg, len, flags, addr, addrlen */ return do_sendto(a[0], a[1], a[2], a[3], a[4], a[5]); - case SOCKOP_recvfrom: /* sockfd, msg, len, flags, addr, addrlen */ + case TARGET_SYS_RECVFROM: /* sockfd, msg, len, flags, addr, addrlen */ return do_recvfrom(a[0], a[1], a[2], a[3], a[4], a[5]); - case SOCKOP_shutdown: /* sockfd, how */ + case TARGET_SYS_SHUTDOWN: /* sockfd, how */ return get_errno(shutdown(a[0], a[1])); - case SOCKOP_sendmsg: /* sockfd, msg, flags */ + case TARGET_SYS_SETSOCKOPT: /* sockfd, level, optname, optval, optlen */ + return do_setsockopt(a[0], a[1], a[2], a[3], a[4]); + case TARGET_SYS_GETSOCKOPT: /* sockfd, level, optname, optval, optlen */ + return do_getsockopt(a[0], a[1], a[2], a[3], a[4]); + case TARGET_SYS_SENDMSG: /* sockfd, msg, flags */ return do_sendrecvmsg(a[0], a[1], a[2], 1); - case SOCKOP_recvmsg: /* sockfd, msg, flags */ + case TARGET_SYS_RECVMSG: /* sockfd, msg, flags */ return do_sendrecvmsg(a[0], a[1], a[2], 0); - case SOCKOP_sendmmsg: /* sockfd, msgvec, vlen, flags */ - return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 1); - case SOCKOP_recvmmsg: /* sockfd, msgvec, vlen, flags */ + case TARGET_SYS_ACCEPT4: /* sockfd, addr, addrlen, flags */ + return do_accept4(a[0], a[1], a[2], a[3]); + case TARGET_SYS_RECVMMSG: /* sockfd, msgvec, vlen, flags */ return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 0); - case SOCKOP_setsockopt: /* sockfd, level, optname, optval, optlen */ - return do_setsockopt(a[0], a[1], a[2], a[3], a[4]); - case SOCKOP_getsockopt: /* sockfd, level, optname, optval, optlen */ - return do_getsockopt(a[0], a[1], a[2], a[3], a[4]); + case TARGET_SYS_SENDMMSG: /* sockfd, msgvec, vlen, flags */ + return do_sendrecvmmsg(a[0], a[1], a[2], a[3], 1); default: gemu_log("Unsupported socketcall: %d\n", num); - return -TARGET_ENOSYS; + return -TARGET_EINVAL; } } #endif diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 7872b9d..adb7153 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -9,26 +9,28 @@ #include "syscall_nr.h" -#define SOCKOP_socket 1 -#define SOCKOP_bind 2 -#define SOCKOP_connect 3 -#define SOCKOP_listen 4 -#define SOCKOP_accept 5 -#define SOCKOP_getsockname 6 -#define SOCKOP_getpeername 7 -#define SOCKOP_socketpair 8 -#define SOCKOP_send 9 -#define SOCKOP_recv 10 -#define SOCKOP_sendto 11 -#define SOCKOP_recvfrom 12 -#define SOCKOP_shutdown 13 -#define SOCKOP_setsockopt 14 -#define SOCKOP_getsockopt 15 -#define SOCKOP_sendmsg 16 -#define SOCKOP_recvmsg 17 -#define SOCKOP_accept4 18 -#define SOCKOP_recvmmsg 19 -#define SOCKOP_sendmmsg 20 + +/* socket operations for socketcall() */ +#define TARGET_SYS_SOCKET 1 /* socket() */ +#define TARGET_SYS_BIND 2 /* bind() */ +#define TARGET_SYS_CONNECT 3 /* connect() */ +#define TARGET_SYS_LISTEN 4 /* listen() */ +#define TARGET_SYS_ACCEPT 5 /* accept() */ +#define TARGET_SYS_GETSOCKNAME 6 /* getsockname() */ +#define TARGET_SYS_GETPEERNAME 7 /* getpeername() */ +#define TARGET_SYS_SOCKETPAIR 8 /* socketpair() */ +#define TARGET_SYS_SEND 9 /* send() */ +#define TARGET_SYS_RECV 10 /* recv() */ +#define TARGET_SYS_SENDTO 11 /* sendto() */ +#define TARGET_SYS_RECVFROM 12 /* recvfrom() */ +#define TARGET_SYS_SHUTDOWN 13 /* shutdown() */ +#define TARGET_SYS_SETSOCKOPT 14 /* setsockopt() */ +#define TARGET_SYS_GETSOCKOPT 15 /* getsockopt() */ +#define TARGET_SYS_SENDMSG 16 /* sendmsg() */ +#define TARGET_SYS_RECVMSG 17 /* recvmsg() */ +#define TARGET_SYS_ACCEPT4 18 /* accept4() */ +#define TARGET_SYS_RECVMMSG 19 /* recvmmsg() */ +#define TARGET_SYS_SENDMMSG 20 /* sendmmsg() */ #define IPCOP_semop 1 #define IPCOP_semget 2