From patchwork Mon Sep 12 19:35:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Markovic X-Patchwork-Id: 9327927 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 A429A6077F for ; Mon, 12 Sep 2016 19:41:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 968E728E9C for ; Mon, 12 Sep 2016 19:41:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B3DA28EA3; Mon, 12 Sep 2016 19:41:36 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 6BCA328EA1 for ; Mon, 12 Sep 2016 19:41:34 +0000 (UTC) Received: from localhost ([::1]:44802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjX6j-0006RD-GO for patchwork-qemu-devel@patchwork.kernel.org; Mon, 12 Sep 2016 15:41:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjX2K-0003LL-9r for qemu-devel@nongnu.org; Mon, 12 Sep 2016 15:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjX2F-0003G6-Vk for qemu-devel@nongnu.org; Mon, 12 Sep 2016 15:36:59 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:43890 helo=mail.rt-rk.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjX2F-0003Fr-Ox for qemu-devel@nongnu.org; Mon, 12 Sep 2016 15:36:55 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.rt-rk.com (Postfix) with ESMTP id 244161A463F; Mon, 12 Sep 2016 21:36:52 +0200 (CEST) X-Virus-Scanned: amavisd-new at rt-rk.com Received: from mcs19.domain.local (mcs19.domain.local [10.10.13.51]) by mail.rt-rk.com (Postfix) with ESMTPSA id 0B5BE1A240A; Mon, 12 Sep 2016 21:36:52 +0200 (CEST) From: Aleksandar Markovic To: qemu-devel@nongnu.org, riku.voipio@iki.fi, peter.maydell@linaro.org, petar.jovanovic@imgtec.com, miodrag.dinic@imgtec.com, aleksandar.markovic@imgtec.com Date: Mon, 12 Sep 2016 21:35:53 +0200 Message-Id: <20160912193602.106478-6-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160912193602.106478-1-aleksandar.markovic@rt-rk.com> References: <20160912193602.106478-1-aleksandar.markovic@rt-rk.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 89.216.37.149 Subject: [Qemu-devel] [PATCH v3 05/10] linux-user: Fix socketcall() syscall emulation 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: , 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 do_socketcall() function in Qemu's syscalls.c is implemented to mirror corespondant implementation of socketcall() in Linux kernel. (see kernel source file net/socket.c, definition of socketcall). However, error codes are wrong for the cases of invalid values of the first argument. This patch in this sense brings do_socketcall() closer to its kernel counterpart. Also, this patch fixes failure of LTP test socketcall02, if executed on some Qemu emulated sywstems (uer mode). Signed-off-by: Aleksandar Markovic --- linux-user/syscall.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 22a11f9..60a94e4 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -3845,15 +3845,18 @@ static abi_long do_socketcall(int num, abi_ulong vptr) [SOCKOP_getsockopt] = 5, /* sockfd, level, optname, optval, optlen */ }; 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 */ + if (num < 0 || num > ARRAY_SIZE(ac)) { + return -TARGET_EINVAL; + } + + /* collect the arguments in a[] according to ac[] */ + 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; } } @@ -3901,7 +3904,7 @@ static abi_long do_socketcall(int num, abi_ulong vptr) return do_getsockopt(a[0], a[1], a[2], a[3], a[4]); default: gemu_log("Unsupported socketcall: %d\n", num); - return -TARGET_ENOSYS; + return -TARGET_EINVAL; } } #endif