From nobody Tue Oct 28 12:17:40 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 151447035028071.44483642179694; Thu, 28 Dec 2017 06:12:30 -0800 (PST) Received: from localhost ([::1]:52516 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUYv1-0007Hp-Hr for importer@patchew.org; Thu, 28 Dec 2017 09:12:23 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eUYu4-0006tU-D2 for qemu-devel@nongnu.org; Thu, 28 Dec 2017 09:11:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eUYu1-0005Ez-8W for qemu-devel@nongnu.org; Thu, 28 Dec 2017 09:11:24 -0500 Received: from [2a01:474::1] (port=58252 helo=hera.aquilenet.fr) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eUYu0-0005BU-TG for qemu-devel@nongnu.org; Thu, 28 Dec 2017 09:11:21 -0500 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id EEC3F10630; Thu, 28 Dec 2017 15:11:18 +0100 (CET) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L4D5hoYJfKlY; Thu, 28 Dec 2017 15:11:18 +0100 (CET) Received: from var.youpi.perso.aquilenet.fr (LFbn-ORL-1-236-13.w92-152.abo.wanadoo.fr [92.152.80.13]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 489FF1062F; Thu, 28 Dec 2017 15:11:15 +0100 (CET) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.90_RC4) (envelope-from ) id 1eUYtu-0003yN-Sw; Thu, 28 Dec 2017 15:11:14 +0100 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, Riku Voipio , Laurent Vivier Date: Thu, 28 Dec 2017 15:11:04 +0100 Message-Id: <20171228141104.15198-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.15.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:474::1 Subject: [Qemu-devel] [PATCH] linux-user: Fix sched_get/setaffinity conversion 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: Samuel Thibault 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" sched_get/setaffinity linux-user syscalls were missing conversions for little/big endian, which is hairy since longs may not be the same size either. For simplicity, this just introduces loops to convert bit by bit like is done for select. Signed-off-by: Samuel Thibault --- linux-user/syscall.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 11c9116c4a..8ec7de96ce 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -10341,6 +10341,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, { unsigned int mask_size; unsigned long *mask; + abi_ulong *abimask; + unsigned i, j; =20 /* * sched_getaffinity needs multiples of ulong, so need to take @@ -10353,6 +10355,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, mask_size =3D (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) -= 1); =20 mask =3D alloca(mask_size); + memset(mask, 0, mask_size); ret =3D get_errno(sys_sched_getaffinity(arg1, mask_size, mask)= ); =20 if (!is_error(ret)) { @@ -10372,9 +10375,27 @@ abi_long do_syscall(void *cpu_env, int num, abi_lo= ng arg1, ret =3D arg2; } =20 - if (copy_to_user(arg3, mask, ret)) { + abimask =3D lock_user(VERIFY_WRITE, arg3, arg2, 0); + if (!abimask) { goto efault; } + + for (i =3D 0 ; i < arg2 / sizeof(abi_ulong); i++) { + unsigned abi_ubits =3D sizeof(abi_ulong) * 8; + unsigned ubits =3D sizeof(*mask) * 8; + unsigned bit =3D i * abi_ubits; + abi_ulong val =3D 0; + + for (j =3D 0; j < abi_ubits; j++, bit++) { + if (mask[bit / ubits] & (1UL << (bit % ubits))) { + val |=3D 1UL << j; + } + } + __put_user(val, &abimask[i]); + } + + unlock_user(abimask, arg3, arg2); + } } break; @@ -10382,6 +10403,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_lon= g arg1, { unsigned int mask_size; unsigned long *mask; + abi_ulong *abimask; + unsigned i, j; =20 /* * sched_setaffinity needs multiples of ulong, so need to take @@ -10394,11 +10417,28 @@ abi_long do_syscall(void *cpu_env, int num, abi_l= ong arg1, mask_size =3D (arg2 + (sizeof(*mask) - 1)) & ~(sizeof(*mask) -= 1); =20 mask =3D alloca(mask_size); - if (!lock_user_struct(VERIFY_READ, p, arg3, 1)) { + memset(mask, 0, mask_size); + + abimask =3D lock_user(VERIFY_READ, arg3, arg2, 1); + if (!abimask) { goto efault; } - memcpy(mask, p, arg2); - unlock_user_struct(p, arg2, 0); + + for (i =3D 0 ; i < arg2 / sizeof(abi_ulong); i++) { + unsigned abi_ubits =3D sizeof(abi_ulong) * 8; + unsigned ubits =3D sizeof(*mask) * 8; + unsigned bit =3D i * abi_ubits; + abi_ulong val; + + __get_user(val, &abimask[i]); + for (j =3D 0; j < abi_ubits; j++, bit++) { + if (val & (1UL << j)) { + mask[bit / ubits] |=3D 1UL << (bit % ubits); + } + } + } + + unlock_user(abimask, arg3, 0); =20 ret =3D get_errno(sys_sched_setaffinity(arg1, mask_size, mask)= ); } --=20 2.15.1