From patchwork Mon May 14 18:19:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 913182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40l8C13MhTz9s1R for ; Tue, 15 May 2018 04:20:45 +1000 (AEST) Received: from localhost ([::1]:47588 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fII5T-0005Fe-1m for incoming@patchwork.ozlabs.org; Mon, 14 May 2018 14:20:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fII4Z-0005Du-19 for qemu-devel@nongnu.org; Mon, 14 May 2018 14:19:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fII4V-0005C6-0c for qemu-devel@nongnu.org; Mon, 14 May 2018 14:19:47 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:38607) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fII4U-00059W-NS for qemu-devel@nongnu.org; Mon, 14 May 2018 14:19:42 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue006 [212.227.15.167]) with ESMTPSA (Nemesis) id 0Lx0lJ-1eBdfz29vN-016emQ; Mon, 14 May 2018 20:19:34 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Mon, 14 May 2018 20:19:25 +0200 Message-Id: <20180514181928.18034-5-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180514181928.18034-1-laurent@vivier.eu> References: <20180514181928.18034-1-laurent@vivier.eu> X-Provags-ID: V03:K1:fzKKhx/sMc7+tBK1wWXTF1AmLXxQx6aux2Fa65PRax9TsIgI2ZT VUJH2PSHiHeaqGN7S1yuNL0/esBKhJC8EnuhpagFcChEQdUkt0JX4O9UVGNDFTYD8Q0GvEd 8g8esdojUfveA+HBg56NzG/YppEBB18FGm42/J/fgdGewL4N9KL7ULxpjKunsJ0yAiCQs8W UbVSfdlOte2bld5ZJn3sw== X-UI-Out-Filterresults: notjunk:1; V01:K0:nnulRSaLc8s=:VHQ9e3FWxF21+yNOzsmhQY bQva9PJYhq0EUc99+qZ82C2iflQnAfT8Sy4pQUxDJqO8114cvuHoSzeTm2Ejg0741USlZNIqL xpSeVknlhQOKFCVoTw/820os28LrQQVlvzaJZLBs/Eg429FDymVzeVM2ZR2yus6D/9BH+m69j 3oubo6dkATPxsaAXS2ZTtitMzdEEPktzRfUEOD4Q7lYtLB/SZgpWL0gEOom7K+w0FOOEXKMPz LvwAr/0V62tySQvN/iAPJxMhMF/FvddrMGetuOmkfc8/E7q0tsHR/9cKGMP2pfUq0lPF6Y8Si CUfL8l/UcbLTfE+2/cOAdm9oyxcfNE3FpnRX0MyYpRUJ9IAcKkzH3WJCyQQCmBX2LX5dvd3Ri uIyC5JK4XBYpwI1iMi/sKGkSDH/Ww4LFj67Q3XafQt+uBpZb/OEMGQfElaTC5OWiS91VPCS76 kax3udT/3jh/Do2dSJ3KcMBHih7G4ahvEunb2k5wpvl68OYf1eRKTWULwbTly5WpHRfcgFuxU EQghqop1dZzR2IX2aNkS5FrR5NHQ3N3SMzP4u+7eeukHrgPxBbZylfuNkFegNoZfRi+SNLxrs yivnnAw7VEUBclR9Hk3/BcAixI84oKfVcVYm7gJHtEbLStpjTKBrtB6l2FEIGcSFOD4E9wHAn Tl/c8LzkksHZhg1sMojm9Xe/JxPq6jSF6ak4uTmfp7EIvYNl/IFjjKQ+cKoU9clYnEPM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.126.131 Subject: [Qemu-devel] [PULL 4/7] linux-user: fix conversion of flock/flock64 l_type field 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: Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" As l_type values (F_RDLCK, F_WRLCK, F_UNLCK, F_EXLCK, F_SHLCK) are not bitmasks, we can't use target_to_host_bitmask() and host_to_target_bitmask() to convert them. Introduce target_to_host_flock() and host_to_target_flock() to convert values between host and target. Signed-off-by: Laurent Vivier Reviewed-by: Max Filippov Message-Id: <20180509231123.20864-5-laurent@vivier.eu> --- linux-user/syscall.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e4825747f9..af8603f1b7 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6546,28 +6546,50 @@ static int target_to_host_fcntl_cmd(int cmd) return -TARGET_EINVAL; } -#define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a } -static const bitmask_transtbl flock_tbl[] = { - TRANSTBL_CONVERT(F_RDLCK), - TRANSTBL_CONVERT(F_WRLCK), - TRANSTBL_CONVERT(F_UNLCK), - TRANSTBL_CONVERT(F_EXLCK), - TRANSTBL_CONVERT(F_SHLCK), - { 0, 0, 0, 0 } -}; +#define FLOCK_TRANSTBL \ + switch (type) { \ + TRANSTBL_CONVERT(F_RDLCK); \ + TRANSTBL_CONVERT(F_WRLCK); \ + TRANSTBL_CONVERT(F_UNLCK); \ + TRANSTBL_CONVERT(F_EXLCK); \ + TRANSTBL_CONVERT(F_SHLCK); \ + } + +static int target_to_host_flock(int type) +{ +#define TRANSTBL_CONVERT(a) case TARGET_##a: return a + FLOCK_TRANSTBL +#undef TRANSTBL_CONVERT + return -TARGET_EINVAL; +} + +static int host_to_target_flock(int type) +{ +#define TRANSTBL_CONVERT(a) case a: return TARGET_##a + FLOCK_TRANSTBL +#undef TRANSTBL_CONVERT + /* if we don't know how to convert the value coming + * from the host we copy to the target field as-is + */ + return type; +} static inline abi_long copy_from_user_flock(struct flock64 *fl, abi_ulong target_flock_addr) { struct target_flock *target_fl; - short l_type; + int l_type; if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { return -TARGET_EFAULT; } __get_user(l_type, &target_fl->l_type); - fl->l_type = target_to_host_bitmask(l_type, flock_tbl); + l_type = target_to_host_flock(l_type); + if (l_type < 0) { + return l_type; + } + fl->l_type = l_type; __get_user(fl->l_whence, &target_fl->l_whence); __get_user(fl->l_start, &target_fl->l_start); __get_user(fl->l_len, &target_fl->l_len); @@ -6586,7 +6608,7 @@ static inline abi_long copy_to_user_flock(abi_ulong target_flock_addr, return -TARGET_EFAULT; } - l_type = host_to_target_bitmask(fl->l_type, flock_tbl); + l_type = host_to_target_flock(fl->l_type); __put_user(l_type, &target_fl->l_type); __put_user(fl->l_whence, &target_fl->l_whence); __put_user(fl->l_start, &target_fl->l_start); @@ -6604,14 +6626,18 @@ static inline abi_long copy_from_user_oabi_flock64(struct flock64 *fl, abi_ulong target_flock_addr) { struct target_oabi_flock64 *target_fl; - short l_type; + int l_type; if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { return -TARGET_EFAULT; } __get_user(l_type, &target_fl->l_type); - fl->l_type = target_to_host_bitmask(l_type, flock_tbl); + l_type = target_to_host_flock(l_type); + if (l_type < 0) { + return l_type; + } + fl->l_type = l_type; __get_user(fl->l_whence, &target_fl->l_whence); __get_user(fl->l_start, &target_fl->l_start); __get_user(fl->l_len, &target_fl->l_len); @@ -6630,7 +6656,7 @@ static inline abi_long copy_to_user_oabi_flock64(abi_ulong target_flock_addr, return -TARGET_EFAULT; } - l_type = host_to_target_bitmask(fl->l_type, flock_tbl); + l_type = host_to_target_flock(fl->l_type); __put_user(l_type, &target_fl->l_type); __put_user(fl->l_whence, &target_fl->l_whence); __put_user(fl->l_start, &target_fl->l_start); @@ -6645,14 +6671,18 @@ static inline abi_long copy_from_user_flock64(struct flock64 *fl, abi_ulong target_flock_addr) { struct target_flock64 *target_fl; - short l_type; + int l_type; if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { return -TARGET_EFAULT; } __get_user(l_type, &target_fl->l_type); - fl->l_type = target_to_host_bitmask(l_type, flock_tbl); + l_type = target_to_host_flock(l_type); + if (l_type < 0) { + return l_type; + } + fl->l_type = l_type; __get_user(fl->l_whence, &target_fl->l_whence); __get_user(fl->l_start, &target_fl->l_start); __get_user(fl->l_len, &target_fl->l_len); @@ -6671,7 +6701,7 @@ static inline abi_long copy_to_user_flock64(abi_ulong target_flock_addr, return -TARGET_EFAULT; } - l_type = host_to_target_bitmask(fl->l_type, flock_tbl); + l_type = host_to_target_flock(fl->l_type); __put_user(l_type, &target_fl->l_type); __put_user(fl->l_whence, &target_fl->l_whence); __put_user(fl->l_start, &target_fl->l_start);