From nobody Thu Oct 30 15:20:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525907623276950.9247576324852; Wed, 9 May 2018 16:13:43 -0700 (PDT) Received: from localhost ([::1]:59394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGYH7-0000NA-DH for importer@patchew.org; Wed, 09 May 2018 19:13:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34918) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGYFY-0007z5-Jk for qemu-devel@nongnu.org; Wed, 09 May 2018 19:11:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGYFV-0002gR-B6 for qemu-devel@nongnu.org; Wed, 09 May 2018 19:11:56 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:50289) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGYFV-0002dz-26 for qemu-devel@nongnu.org; Wed, 09 May 2018 19:11:53 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MXovv-1em9kq2OsJ-00WoUT; Thu, 10 May 2018 01:11:39 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 01:11:21 +0200 Message-Id: <20180509231123.20864-5-laurent@vivier.eu> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180509231123.20864-1-laurent@vivier.eu> References: <20180509231123.20864-1-laurent@vivier.eu> X-Provags-ID: V03:K1:qSpJCSLtRcyAAGFTYG7jZM24vozLR3/CbFpwNUgQJeM3WA3/PVB 4ZLq5t/pZLwKcoKOERGHnBCmPAMtQmjZanvB3Ffrt5SU/+xGGVecYMDpBBeqW9uG1YMlUb4 szambG3Pc4vtfkQJ+rf4oQkFLUJwcw/XvREjGkiUtV0u83zQ5y6wJdQSerL/CfVElTIReaU f2A+U1LYCO0uzNBY+0lwA== X-UI-Out-Filterresults: notjunk:1;V01:K0:0mmocp2ne+g=:8wECR9kCeso6pAddRG4ysC afAdnOaVUG4qM64g2u+A2X3NtB8p/fvmpaUu4nvcEkSVKmxPETSDX0CH3e5v2JTwA+hMZi4KC PKJUw+M1CAogR3rA14P7n/fpPi0x+jmlw7IYYiqa83B2hPqhWwjXlp2fiNj5fl121D87rg2ma ifCiQ8ZYRpvf4m+Np03wknWrg/HhLxKucy85ZWCmE1UA4GR/gg7brBUk7ERyyOBRKAiKvb3w2 bBs21+mwi6w2Jc5HdZ4FIwVI+tsnXJCQYxTQSMocgbmho664Hb5VhKwrhEE2wU6cg27JUbfES aBx4F6m34Zdi/zorgKTfmDY8tgCTLltqJ41UB7obhNSgz4z0x1iRNvxCNRJ47Xp4v5pAdi47G Mlv8WNEUh++VunZSKPS6cdV9JoFZfY5N0UmBWEfq2koRf7F3aR7WC7vgTDdvijiF9WYlLIP9c LYD/BXY3c5A5KmRta0UR7shG6uTHdTYyZ2cAyTvCoHVqopjtofiWccW2UPw4M3vC2Z6s0PzH3 Us3PT1eF3JnHkGHPIP/PU7gjFrPZS1xakiJGOt2ViDISd8z2iApecKKCE21NLJw8i5goxCMDU QgOecSbVSlbia3F0nmOfRv8EU91HkjtawShdSqOE2LVKUOVntxsgTXGQizLlcBb44S4k5iGVg 1uZ3O7RAFRPv8JCT+ivvRrf4DGYWEZ7fJdjrfNKqwvCiootW6ztvVCnbIalMaKZ+ANIw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 217.72.192.73 Subject: [Qemu-devel] [PATCH v2 4/6] 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: Max Filippov , Riku Voipio , Laurent Vivier Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- Notes: v2: - add common switch macro to convert to/from target to/from host - return -TARGET_EINVAL is l_type cannot be converted 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; } =20 -#define TRANSTBL_CONVERT(a) { -1, TARGET_##a, -1, a } -static const bitmask_transtbl flock_tbl[] =3D { - 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; +} =20 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; =20 if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { return -TARGET_EFAULT; } =20 __get_user(l_type, &target_fl->l_type); - fl->l_type =3D target_to_host_bitmask(l_type, flock_tbl); + l_type =3D target_to_host_flock(l_type); + if (l_type < 0) { + return l_type; + } + fl->l_type =3D 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 t= arget_flock_addr, return -TARGET_EFAULT; } =20 - l_type =3D host_to_target_bitmask(fl->l_type, flock_tbl); + l_type =3D 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; =20 if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { return -TARGET_EFAULT; } =20 __get_user(l_type, &target_fl->l_type); - fl->l_type =3D target_to_host_bitmask(l_type, flock_tbl); + l_type =3D target_to_host_flock(l_type); + if (l_type < 0) { + return l_type; + } + fl->l_type =3D 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; } =20 - l_type =3D host_to_target_bitmask(fl->l_type, flock_tbl); + l_type =3D 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(struc= t flock64 *fl, abi_ulong target_flock_addr) { struct target_flock64 *target_fl; - short l_type; + int l_type; =20 if (!lock_user_struct(VERIFY_READ, target_fl, target_flock_addr, 1)) { return -TARGET_EFAULT; } =20 __get_user(l_type, &target_fl->l_type); - fl->l_type =3D target_to_host_bitmask(l_type, flock_tbl); + l_type =3D target_to_host_flock(l_type); + if (l_type < 0) { + return l_type; + } + fl->l_type =3D 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; } =20 - l_type =3D host_to_target_bitmask(fl->l_type, flock_tbl); + l_type =3D 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); --=20 2.14.3