From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JSojF-0000gt-M4 for qemu-devel@nongnu.org; Sat, 23 Feb 2008 02:23:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JSojA-0000fs-SK for qemu-devel@nongnu.org; Sat, 23 Feb 2008 02:23:24 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JSojA-0000fj-Mn for qemu-devel@nongnu.org; Sat, 23 Feb 2008 02:23:20 -0500 Received: from partizan.velesys.com ([213.184.230.195]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JSoj7-0000xv-NY for qemu-devel@nongnu.org; Sat, 23 Feb 2008 02:23:20 -0500 Received: from localhost (mail.velesys.com [10.0.5.31]) by partizan.velesys.com (partizan.velesys.com) with ESMTP id BCE62136B4E for ; Sat, 23 Feb 2008 07:22:22 +0000 (UTC) Received: from partizan.velesys.com ([10.0.5.31]) by localhost (mail.velesys.com [10.0.5.31]) (amavisd-new, port 10024) with ESMTP id V42PsIBh2TWP for ; Sat, 23 Feb 2008 07:22:20 +0000 (UTC) Received: from localhost.localdomain (unknown [86.57.194.252]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by partizan.velesys.com (partizan.velesys.com) with ESMTP id 03E94136AE0 for ; Sat, 23 Feb 2008 07:22:17 +0000 (UTC) Date: Sat, 23 Feb 2008 09:25:30 +0200 From: "Kirill A. Shutemov" Subject: Re: [Qemu-devel] [PATCH] linux-user, fix getgroups/getgroups32 when both args are zero. Message-ID: <20080223072529.GA4717@localhost.localdomain> References: <20080223120023.2ce6ed1e.takasi-y@ops.dti.ne.jp> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="bg08WKrSYDhXBjb5" Content-Disposition: inline In-Reply-To: <20080223120023.2ce6ed1e.takasi-y@ops.dti.ne.jp> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --bg08WKrSYDhXBjb5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On [Sat, 23.02.2008 12:00], Takashi Yoshii wrote: > getgroups() and getgroups32() returns NGROUPS_MAX when both its two args = are > zero. But because we pass a ptr to allocated space as 2nd arg, this funct= ion > are interfered. The patch attached fixed it. > /yoshii > --- > linux-user/syscall.c: fix getgroups{,32} when both args are zero. >=20 My version of patch to fix same problem: getgroups: return total number of supplementary group IDs for the process if size =3D=3D 0 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index ad97871..96a11a9 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5029,6 +5029,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, =20 grouplist =3D alloca(gidsetsize * sizeof(gid_t)); ret =3D get_errno(getgroups(gidsetsize, grouplist)); + if (gidsetsize =3D=3D 0) + break; if (!is_error(ret)) { target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidsets= ize * 2, 0); if (!target_grouplist) @@ -5179,6 +5181,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, =20 grouplist =3D alloca(gidsetsize * sizeof(gid_t)); ret =3D get_errno(getgroups(gidsetsize, grouplist)); + if (gidsetsize =3D=3D 0) + break; if (!is_error(ret)) { target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidsets= ize * 4, 0); if (!target_grouplist) { Another patch for getgroups: Trivial optimization of getgroups syscall implementation: swap only returned groups, not all group in list. diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 6f2872f..ad97871 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -5033,7 +5033,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, target_grouplist =3D lock_user(VERIFY_WRITE, arg2, gidsets= ize * 2, 0); if (!target_grouplist) goto efault; - for(i =3D 0;i < gidsetsize; i++) + for(i =3D 0;i < ret; i++) target_grouplist[i] =3D tswap16(grouplist[i]); unlock_user(target_grouplist, arg2, gidsetsize * 2); } @@ -5185,7 +5185,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long = arg1, ret =3D -TARGET_EFAULT; goto fail; } - for(i =3D 0;i < gidsetsize; i++) + for(i =3D 0;i < ret; i++) target_grouplist[i] =3D tswap32(grouplist[i]); unlock_user(target_grouplist, arg2, gidsetsize * 4); } It makes getgroups much faster in some cases. --=20 Regards, Kirill A. Shutemov + Belarus, Minsk + Velesys Ltd, http://www.velesys.com/ + ALT Linux Team, http://www.altlinux.com/ --bg08WKrSYDhXBjb5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (GNU/Linux) iEYEARECAAYFAke/ymkACgkQbWYnhzC5v6plqACeMfCqBvSl7fEv8Pd3L8boZ6fi NLwAnixbCS2F+cqyNfuXWY34/oTGGs+g =szRh -----END PGP SIGNATURE----- --bg08WKrSYDhXBjb5--