Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 17 Oct 2007 22:07:33 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Artem Kuchin <matrix@itlegion.ru>
Cc:        freebsd-current@freebsd.org
Subject:   Re: Broken su in current - trying to fix myself, help needed!
Message-ID:  <20071017190733.GI6511@deviant.kiev.zoral.com.ua>
In-Reply-To: <00bd01c810ec$10371230$0c00a8c0@Artem>
References:  <00bd01c810ec$10371230$0c00a8c0@Artem>

next in thread | previous in thread | raw e-mail | index | archive | help

--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--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071017190733.GI6511>