Re: Broken su in current - trying to fix myself, help needed!

From: Kostik Belousov <kostikbel_at_gmail.com>
Date: Wed, 17 Oct 2007 22:07:33 +0300
On Wed, Oct 17, 2007 at 10:32:16PM +0400, Artem Kuchin wrote:
> Hello!
> 
> 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.
> 
> If you don't know what is the problem i'll describe it shortly:
> 
> if you try to run a very simple perl script:
> 
> #!/usr/bin/perl
> $com="/usr/bin/su root -c 'echo heck'";
> system($com);
> print "done!\n";
> 
> it will print 
> heck
> 
> and then
> 
> Suspended (tty output)
> 
> and will hang in memory untill you type
> fg
> 
> then you get
> 
> done!
> 
> 
> I am working in csh, but i tested it in sh - result is
> the same. FreeBSD version is  7-PRERELEASE.
> 
> 
> 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.
> 
> There are such like in the default: dection of switch
> 
>                child_pgrp = getpgid(child_pid);
>                if (tcgetpgrp(STDERR_FILENO) == child_pgrp)
>                        tcsetpgrp(STDERR_FILENO, getpgrp());
> 
> 
> 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).
> 
> The weird thing is that if i just comment out those lines like this
> 
> /* child_pgrp = getpgid(child_pid);
>   if (tcgetpgrp(STDERR_FILENO) == child_pgrp) */
>   tcsetpgrp(STDERR_FILENO, getpgrp());
> 
> su starts working again just fine.
> 
> Any idea why getpgid fails and why tcgetpgrp return 100000 (always the same
> 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).

Received on Wed Oct 17 2007 - 17:07:42 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:19 UTC