From owner-freebsd-current@FreeBSD.ORG Wed Oct 17 19:07:42 2007 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9819D16A417 for ; Wed, 17 Oct 2007 19:07:42 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from gnome.kiev.sovam.com (gnome.kiev.sovam.com [212.109.32.24]) by mx1.freebsd.org (Postfix) with ESMTP id 2FEDB13C447 for ; Wed, 17 Oct 2007 19:07:41 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from relay02.kiev.sovam.com ([62.64.120.197]) by gnome.kiev.sovam.com with esmtp (Exim 4.67 (FreeBSD)) (envelope-from ) id 1IiEF1-000Knt-PP for freebsd-current@freebsd.org; Wed, 17 Oct 2007 22:07:40 +0300 Received: from [212.82.216.226] (helo=deviant.kiev.zoral.com.ua) by relay02.kiev.sovam.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1IiEF0-0008jV-1y for freebsd-current@freebsd.org; Wed, 17 Oct 2007 22:07:39 +0300 Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1) with ESMTP id l9HJ7Y3U080221; Wed, 17 Oct 2007 22:07:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.1/8.14.1/Submit) id l9HJ7Yql080220; Wed, 17 Oct 2007 22:07:34 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 17 Oct 2007 22:07:33 +0300 From: Kostik Belousov To: Artem Kuchin Message-ID: <20071017190733.GI6511@deviant.kiev.zoral.com.ua> References: <00bd01c810ec$10371230$0c00a8c0@Artem> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZY5CS28jBCfb727c" Content-Disposition: inline In-Reply-To: <00bd01c810ec$10371230$0c00a8c0@Artem> User-Agent: Mutt/1.4.2.3i X-Scanner-Signature: 44556c58cf61beb49de4494ee559d59c X-DrWeb-checked: yes X-SpamTest-Envelope-From: kostikbel@gmail.com X-SpamTest-Group-ID: 00000000 X-SpamTest-Info: Profiles 1631 [Oct 17 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {received from trusted relay: not dialup} X-SpamTest-Method: none X-SpamTest-Method: Local Lists X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release Cc: freebsd-current@freebsd.org Subject: Re: Broken su in current - trying to fix myself, help needed! X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Oct 2007 19:07:42 -0000 --ZY5CS28jBCfb727c Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 17, 2007 at 10:32:16PM +0400, Artem Kuchin wrote: > Hello! >=20 > I really not at all good at any kind of system programming > in FreeBSD or Un*x, but since my contacts with last commited > of su could not be establish i decided to look at it myself. >=20 > If you don't know what is the problem i'll describe it shortly: >=20 > if you try to run a very simple perl script: >=20 > #!/usr/bin/perl > $com=3D"/usr/bin/su root -c 'echo heck'"; > system($com); > print "done!\n"; >=20 > it will print=20 > heck >=20 > and then >=20 > Suspended (tty output) >=20 > and will hang in memory untill you type > fg >=20 > then you get >=20 > done! >=20 >=20 > I am working in csh, but i tested it in sh - result is > the same. FreeBSD version is 7-PRERELEASE. >=20 >=20 > So, I fetched su v. 1.76 from 6.2-STABLE and compiled it - it works > like a charm. SO, i decided to figure what fails in 1.86. >=20 > There are such like in the default: dection of switch >=20 > child_pgrp =3D getpgid(child_pid); > if (tcgetpgrp(STDERR_FILENO) =3D=3D child_pgrp) > tcsetpgrp(STDERR_FILENO, getpgrp()); >=20 >=20 > The problem is here. > getpgid(child_pid) simply fails with errno 3 (process doesn't exist) > and tcgetpgrp(STDERR_FILENO) return 100000 (can it be THAT high? i though > it is only in 0-65535 range). >=20 > The weird thing is that if i just comment out those lines like this >=20 > /* child_pgrp =3D getpgid(child_pid); > if (tcgetpgrp(STDERR_FILENO) =3D=3D child_pgrp) */ > tcsetpgrp(STDERR_FILENO, getpgrp()); >=20 > su starts working again just fine. >=20 > Any idea why getpgid fails and why tcgetpgrp return 100000 (always the sa= me > number)? What will brak if i leave these lines commented? I tried the same perl script on RELENG_7 machine, and it did work as expected. This suggests that the issue could be the race condition of some kind. Could you provide the ktrace (or kdump) output of the script run where the problem shows up ? Please, ktrace both perl and all it descendants (this is, probably, somewhat nontrivial due to suid-ness of the su). --ZY5CS28jBCfb727c Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4 (FreeBSD) iD8DBQFHFl11C3+MBN1Mb4gRAu0HAKCd1l0c193GIRKxskCXh0pttUdB7gCg6ciW n6yyxuKHkXaJlVQnTfRc4Ls= =nubY -----END PGP SIGNATURE----- --ZY5CS28jBCfb727c--