* Interesting race condition...
@ 2004-07-23 3:04 Rob Landley
2004-07-23 7:33 ` Barry K. Nathan
` (3 more replies)
0 siblings, 4 replies; 26+ messages in thread
From: Rob Landley @ 2004-07-23 3:04 UTC (permalink / raw)
To: linux-kernel
I just saw a funky thing. Here's the cut and past from the xterm...
[root@(none) root]# ps ax | grep hack
9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm HISTSIZE=1000 USER=root LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=
[root@(none) root]# ps ax | grep hack
9966 pts/1 S 0:00 grep hack
Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
or the 2.6.7 kernel or what...
Rob
--
www.linucon.org: Linux Expo and Science Fiction Convention
October 8-10, 2004 in Austin Texas. (I'm the con chair.)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 3:04 Interesting race condition Rob Landley
@ 2004-07-23 7:33 ` Barry K. Nathan
2004-07-23 7:56 ` Hugo Mills
2004-07-24 8:13 ` Rob Landley
2004-07-23 10:01 ` P. Benie
` (2 subsequent siblings)
3 siblings, 2 replies; 26+ messages in thread
From: Barry K. Nathan @ 2004-07-23 7:33 UTC (permalink / raw)
To: Rob Landley; +Cc: linux-kernel
On Thu, Jul 22, 2004 at 10:04:46PM -0500, Rob Landley wrote:
> Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
> or the 2.6.7 kernel or what...
I've seen this too, on Fedora Core 2 and pretty recent (within the last
2 weeks) fc-devel. Hard enough to reproduce (and not enough of a bother
IMO) that I haven't filed it in Bugzilla though.
(Now that you mention Fedora Core, I can't remember seeing this with any
other distributions.)
-Barry K. Nathan <barryn@pobox.com>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 7:33 ` Barry K. Nathan
@ 2004-07-23 7:56 ` Hugo Mills
2004-07-24 8:13 ` Rob Landley
1 sibling, 0 replies; 26+ messages in thread
From: Hugo Mills @ 2004-07-23 7:56 UTC (permalink / raw)
To: Barry K. Nathan; +Cc: Rob Landley, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 965 bytes --]
On Fri, Jul 23, 2004 at 12:33:00AM -0700, Barry K. Nathan wrote:
> On Thu, Jul 22, 2004 at 10:04:46PM -0500, Rob Landley wrote:
> > Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
> > or the 2.6.7 kernel or what...
>
> I've seen this too, on Fedora Core 2 and pretty recent (within the last
> 2 weeks) fc-devel. Hard enough to reproduce (and not enough of a bother
> IMO) that I haven't filed it in Bugzilla though.
>
> (Now that you mention Fedora Core, I can't remember seeing this with any
> other distributions.)
I've seen it on Debian unstable/sid, running a 32-bit userspace on
a 64-bit amd64 2.6.6 from kernel.org.
Hugo.
--
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
PGP key: 1C335860 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
--- There is no dark side to the Moon, really. As a matter of ---
fact, it's all dark.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 3:04 Interesting race condition Rob Landley
2004-07-23 7:33 ` Barry K. Nathan
@ 2004-07-23 10:01 ` P. Benie
2004-07-24 8:17 ` Rob Landley
2004-07-28 8:05 ` Paul Jackson
2004-07-29 23:56 ` Roger Luethi
3 siblings, 1 reply; 26+ messages in thread
From: P. Benie @ 2004-07-23 10:01 UTC (permalink / raw)
To: Rob Landley; +Cc: linux-kernel
On Fri, 23 Jul 2004, Rob Landley wrote:
> I just saw a funky thing. Here's the cut and past from the xterm...
>
> [root@(none) root]# ps ax | grep hack
> 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm HISTSIZE=1000 USER=root LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=
> [root@(none) root]# ps ax | grep hack
> 9966 pts/1 S 0:00 grep hack
>
> Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
> or the 2.6.7 kernel or what...
The race is in the shell's pipeline - the processes don't start at exactly
the same time, and sometimes ps has completed before the shell has
started grep. This is the expected behaviour.
Peter
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 7:33 ` Barry K. Nathan
2004-07-23 7:56 ` Hugo Mills
@ 2004-07-24 8:13 ` Rob Landley
2004-07-24 13:40 ` Marc Ballarin
1 sibling, 1 reply; 26+ messages in thread
From: Rob Landley @ 2004-07-24 8:13 UTC (permalink / raw)
To: Barry K. Nathan; +Cc: linux-kernel
On Friday 23 July 2004 02:33, Barry K. Nathan wrote:
> On Thu, Jul 22, 2004 at 10:04:46PM -0500, Rob Landley wrote:
> > Seems like some kind of race condition, dunno if it's in Fedore Core 1's
> > ps or the 2.6.7 kernel or what...
>
> I've seen this too, on Fedora Core 2 and pretty recent (within the last
> 2 weeks) fc-devel. Hard enough to reproduce (and not enough of a bother
> IMO) that I haven't filed it in Bugzilla though.
>
> (Now that you mention Fedora Core, I can't remember seeing this with any
> other distributions.)
>
> -Barry K. Nathan <barryn@pobox.com>
Oh I can't reproduce it either. (Maybe if I set some kind of loop and left it
running for a few days...)
I just thought it was really odd. There should be a null terminator before
the environment variables, and it's getting stomped somehow. Maybe it was
right as the process was starting...?
Rob
--
www.linucon.org: Linux Expo and Science Fiction Convention
October 8-10, 2004 in Austin Texas. (I'm the con chair.)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 10:01 ` P. Benie
@ 2004-07-24 8:17 ` Rob Landley
2004-07-24 9:08 ` P. Benie
2004-07-27 20:40 ` Bill Davidsen
0 siblings, 2 replies; 26+ messages in thread
From: Rob Landley @ 2004-07-24 8:17 UTC (permalink / raw)
To: P. Benie; +Cc: linux-kernel
On Friday 23 July 2004 05:01, P. Benie wrote:
> On Fri, 23 Jul 2004, Rob Landley wrote:
> > I just saw a funky thing. Here's the cut and past from the xterm...
> >
> > [root@(none) root]# ps ax | grep hack
> > 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm
> > HISTSIZE=1000 USER=root
> > LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=
> >40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.
> >com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz
> >= [root@(none) root]# ps ax | grep hack
> > 9966 pts/1 S 0:00 grep hack
> >
> > Seems like some kind of race condition, dunno if it's in Fedore Core 1's
> > ps or the 2.6.7 kernel or what...
>
> The race is in the shell's pipeline - the processes don't start at exactly
> the same time, and sometimes ps has completed before the shell has
> started grep. This is the expected behaviour.
It's expected behavior for PS to show a process's environment variables as
part of its command line?
> Peter
Rob
--
www.linucon.org: Linux Expo and Science Fiction Convention
October 8-10, 2004 in Austin Texas. (I'm the con chair.)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-24 8:17 ` Rob Landley
@ 2004-07-24 9:08 ` P. Benie
2004-07-27 20:40 ` Bill Davidsen
1 sibling, 0 replies; 26+ messages in thread
From: P. Benie @ 2004-07-24 9:08 UTC (permalink / raw)
To: Rob Landley; +Cc: linux-kernel
On Sat, 24 Jul 2004, Rob Landley wrote:
> It's expected behavior for PS to show a process's environment variables as
> part of its command line?
Duh! Need more coffee...
Peter
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-24 8:13 ` Rob Landley
@ 2004-07-24 13:40 ` Marc Ballarin
2004-07-26 16:04 ` David Weinehall
2004-07-26 17:20 ` Marc Ballarin
0 siblings, 2 replies; 26+ messages in thread
From: Marc Ballarin @ 2004-07-24 13:40 UTC (permalink / raw)
To: linux-kernel
Rob Landley <rob <at> landley.net> writes:
> Oh I can't reproduce it either. (Maybe if I set some kind of loop and left
> it running for a few days...)
I could reproduce it on an otherwise idle system (2 GHz Athlon, kernel 2.6.7).
On a loaded system the bug did not occur, which certainly indicates a race
condition.
Using the following Bash script, the bug appeared 23 times in 122,221
iterations:
while [ 1 ];do
ps ax | grep hack >> TEST
done
The bug *seems* to be in bash, since an equivalent script in tcsh had no
problems:
while ( 1 )
ps ax | grep hack >> TEST2
end
This issue has the potential to break a lot of shell scripts in an almost
undebugable way. Should someone file a bug report via 'bashbug'?
Marc
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-24 13:40 ` Marc Ballarin
@ 2004-07-26 16:04 ` David Weinehall
2004-07-26 17:20 ` Marc Ballarin
1 sibling, 0 replies; 26+ messages in thread
From: David Weinehall @ 2004-07-26 16:04 UTC (permalink / raw)
To: Marc Ballarin; +Cc: linux-kernel
On Sat, Jul 24, 2004 at 01:40:59PM +0000, Marc Ballarin wrote:
> Rob Landley <rob <at> landley.net> writes:
>
> > Oh I can't reproduce it either. (Maybe if I set some kind of loop and left
> > it running for a few days...)
>
> I could reproduce it on an otherwise idle system (2 GHz Athlon, kernel 2.6.7).
> On a loaded system the bug did not occur, which certainly indicates a race
> condition.
>
> Using the following Bash script, the bug appeared 23 times in 122,221
> iterations:
> while [ 1 ];do
> ps ax | grep hack >> TEST
> done
>
> The bug *seems* to be in bash, since an equivalent script in tcsh had no
> problems:
> while ( 1 )
> ps ax | grep hack >> TEST2
> end
>
> This issue has the potential to break a lot of shell scripts in an almost
> undebugable way. Should someone file a bug report via 'bashbug'?
I get this using posh as well, so it doesn't seem to be bash-specific.
Regards: David Weinehall
--
/) David Weinehall <tao@acc.umu.se> /) Northern lights wander (\
// Maintainer of the v2.0 kernel // Dance across the winter sky //
\) http://www.acc.umu.se/~tao/ (/ Full colour fire (/
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-24 13:40 ` Marc Ballarin
2004-07-26 16:04 ` David Weinehall
@ 2004-07-26 17:20 ` Marc Ballarin
1 sibling, 0 replies; 26+ messages in thread
From: Marc Ballarin @ 2004-07-26 17:20 UTC (permalink / raw)
To: linux-kernel
Marc Ballarin <Ballarin.Marc <at> gmx.de> writes:
Ok, I could repruduce this issue in bash and tcsh, using both, procps
3.1.5/3.2.2 from procps.sourceforge.net and procps 2.0.16 from
tech9.net/rml/procps.
So, the bug is not in the shell (which is obvious, on second thought), but in
the kernel, glibc or procps - or the combination thereof.
I'm using kernel 2.6.7, gcc-3.3.3, and glibc-2.3.3 with NPTL on Gentoo.
Regards
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-24 8:17 ` Rob Landley
2004-07-24 9:08 ` P. Benie
@ 2004-07-27 20:40 ` Bill Davidsen
2004-07-28 8:00 ` Paul Jackson
2004-08-04 20:03 ` Robert White
1 sibling, 2 replies; 26+ messages in thread
From: Bill Davidsen @ 2004-07-27 20:40 UTC (permalink / raw)
To: linux-kernel
Rob Landley wrote:
> On Friday 23 July 2004 05:01, P. Benie wrote:
>
>>On Fri, 23 Jul 2004, Rob Landley wrote:
>>
>>>I just saw a funky thing. Here's the cut and past from the xterm...
>>>
>>>[root@(none) root]# ps ax | grep hack
>>> 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm
>>>HISTSIZE=1000 USER=root
>>>LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=
>>>40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.
>>>com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz
>>>= [root@(none) root]# ps ax | grep hack
>>> 9966 pts/1 S 0:00 grep hack
>>>
>>>Seems like some kind of race condition, dunno if it's in Fedore Core 1's
>>>ps or the 2.6.7 kernel or what...
>>
>>The race is in the shell's pipeline - the processes don't start at exactly
>>the same time, and sometimes ps has completed before the shell has
>>started grep. This is the expected behaviour.
>
>
> It's expected behavior for PS to show a process's environment variables as
> part of its command line?
When piped. For instance
ps eaxf
does not, while
ps eaxf | cat
does, at least on my systems. I tried on RHEL AS3.0 thru a four year old
version of Slackware, all did the same thing.
--
-bill davidsen (davidsen@tmr.com)
"The secret to procrastination is to put things off until the
last possible moment - but no longer" -me
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-27 20:40 ` Bill Davidsen
@ 2004-07-28 8:00 ` Paul Jackson
2004-08-04 20:03 ` Robert White
1 sibling, 0 replies; 26+ messages in thread
From: Paul Jackson @ 2004-07-28 8:00 UTC (permalink / raw)
To: Bill Davidsen; +Cc: linux-kernel
Bill writes:
> When piped. For instance
> ps eaxf
> does not [show environ], while
> ps eaxf | cat
> does
Neither the behaviour I'm seeing on my SuSE 8.2 box, and the code I see
in some random procps-3.2.1 I happened to have laying around, agree with
your description.
Rather, both behaviour and code have the 'e' option as a BSD option
(applicable if no '-' option flag) requesting that the environment be
shown, and I get the environment so shown, regardless of whether the
output is a pipe or a tty.
... This subthread is of course off-topic to Rob Landley's
original post - he wasn't using the 'e' option.
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.650.933.1373
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 3:04 Interesting race condition Rob Landley
2004-07-23 7:33 ` Barry K. Nathan
2004-07-23 10:01 ` P. Benie
@ 2004-07-28 8:05 ` Paul Jackson
2004-07-28 11:54 ` Marc Ballarin
2004-07-28 16:42 ` Rob Landley
2004-07-29 23:56 ` Roger Luethi
3 siblings, 2 replies; 26+ messages in thread
From: Paul Jackson @ 2004-07-28 8:05 UTC (permalink / raw)
To: Rob Landley; +Cc: linux-kernel
Rob wrote:
> I just saw a funky thing. Here's the cut and past from the xterm...
Can you reproduce this by cat'ing /proc/<pid>/cmdline? Can you get a
dump of the proc cmdline file to leak the environment sometimes?
It is this file that 'ps' is dumping for these options. Adding the
'e' option would also dump the /proc/<pid>/environ file (if readable).
But you aren't adding 'e', so presumably the environment is "leaking"
into the the cmdline file.
I suspect a kernel bug here - the ps code seems rather obvious and
unimpeachable.
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.650.933.1373
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-28 8:05 ` Paul Jackson
@ 2004-07-28 11:54 ` Marc Ballarin
2004-07-28 16:46 ` Rob Landley
2004-07-28 16:42 ` Rob Landley
1 sibling, 1 reply; 26+ messages in thread
From: Marc Ballarin @ 2004-07-28 11:54 UTC (permalink / raw)
To: Paul Jackson; +Cc: rob, linux-kernel
On Wed, 28 Jul 2004 01:05:46 -0700
Paul Jackson <pj@sgi.com> wrote:
> Rob wrote:
> > I just saw a funky thing. Here's the cut and past from the xterm...
>
> Can you reproduce this by cat'ing /proc/<pid>/cmdline? Can you get a
> dump of the proc cmdline file to leak the environment sometimes?
>
> It is this file that 'ps' is dumping for these options. Adding the
> 'e' option would also dump the /proc/<pid>/environ file (if readable).
>
> But you aren't adding 'e', so presumably the environment is "leaking"
> into the the cmdline file.
>
> I suspect a kernel bug here - the ps code seems rather obvious and
> unimpeachable.
>
I ran the following loop for a while (> 9 million times) and could not
reproduce the bug, but that might just be coincidence.
Conditions were the same as in my other, succesful test.
while [ 1 ];do
cat /proc/self/cmdline >> TEST
done
Marc
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-28 8:05 ` Paul Jackson
2004-07-28 11:54 ` Marc Ballarin
@ 2004-07-28 16:42 ` Rob Landley
2004-07-28 17:08 ` Tristan Wibberley
1 sibling, 1 reply; 26+ messages in thread
From: Rob Landley @ 2004-07-28 16:42 UTC (permalink / raw)
To: Paul Jackson; +Cc: linux-kernel
On Wednesday 28 July 2004 03:05, Paul Jackson wrote:
> Rob wrote:
> > I just saw a funky thing. Here's the cut and past from the xterm...
>
> Can you reproduce this by cat'ing /proc/<pid>/cmdline? Can you get a
> dump of the proc cmdline file to leak the environment sometimes?
I saw it exactly once, I'm afraid. Somebody else said they also saw it...
once. It smelled to me like a race condition, with the process
starting/exiting right as ps looked at it, but I haven't seen it again. (I
could run the command in a loop overnight...)
Rob
--
www.linucon.org: Linux Expo and Science Fiction Convention
October 8-10, 2004 in Austin Texas. (I'm the con chair.)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-28 11:54 ` Marc Ballarin
@ 2004-07-28 16:46 ` Rob Landley
0 siblings, 0 replies; 26+ messages in thread
From: Rob Landley @ 2004-07-28 16:46 UTC (permalink / raw)
To: Marc Ballarin, Paul Jackson; +Cc: linux-kernel
On Wednesday 28 July 2004 06:54, Marc Ballarin wrote:
> On Wed, 28 Jul 2004 01:05:46 -0700
>
> Paul Jackson <pj@sgi.com> wrote:
> > Rob wrote:
> > > I just saw a funky thing. Here's the cut and past from the xterm...
> >
> > Can you reproduce this by cat'ing /proc/<pid>/cmdline? Can you get a
> > dump of the proc cmdline file to leak the environment sometimes?
> >
> > It is this file that 'ps' is dumping for these options. Adding the
> > 'e' option would also dump the /proc/<pid>/environ file (if readable).
> >
> > But you aren't adding 'e', so presumably the environment is "leaking"
> > into the the cmdline file.
> >
> > I suspect a kernel bug here - the ps code seems rather obvious and
> > unimpeachable.
>
> I ran the following loop for a while (> 9 million times) and could not
> reproduce the bug, but that might just be coincidence.
> Conditions were the same as in my other, succesful test.
>
> while [ 1 ];do
> cat /proc/self/cmdline >> TEST
> done
>
> Marc
I might have actually just killed the process I was grepping for (I was
grepping to see if it had actually gone away yet). Dunno if that helps...
I haven't been able to reproduce it either. I think the pipe to grep (or
something similar) is important because your test isn't doing what mine did:
one process was looking at another process at the instant of process creation
(or perhaps exit). Maybe the appropriate null terminator is written out
after the process goes live?
This is a UP system, but I have preemption on...
Rob
--
www.linucon.org: Linux Expo and Science Fiction Convention
October 8-10, 2004 in Austin Texas. (I'm the con chair.)
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-28 16:42 ` Rob Landley
@ 2004-07-28 17:08 ` Tristan Wibberley
0 siblings, 0 replies; 26+ messages in thread
From: Tristan Wibberley @ 2004-07-28 17:08 UTC (permalink / raw)
To: linux-kernel
On Wed, 28 Jul 2004 11:42:37 -0500, Rob Landley wrote:
> On Wednesday 28 July 2004 03:05, Paul Jackson wrote:
>> Rob wrote:
>> > I just saw a funky thing. Here's the cut and past from the xterm...
>>
>> Can you reproduce this by cat'ing /proc/<pid>/cmdline? Can you get a
>> dump of the proc cmdline file to leak the environment sometimes?
>
> I saw it exactly once, I'm afraid. Somebody else said they also saw it...
> once. It smelled to me like a race condition, with the process
> starting/exiting right as ps looked at it, but I haven't seen it again. (I
> could run the command in a loop overnight...)
I think I have seen this exactly once. I ran helixplayer from a bash
command line and it quit, immediately spouting something about how it
couldn't find a file whose name looked remarkably similar to
some environment variables. I had put it down to screwed terminal settings
so I couldn't see I had pasted something in, and I immediately issued a
reset, so I have no more information I'm afraid.
--
I have a little sig...
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-23 3:04 Interesting race condition Rob Landley
` (2 preceding siblings ...)
2004-07-28 8:05 ` Paul Jackson
@ 2004-07-29 23:56 ` Roger Luethi
2004-07-30 0:18 ` Jesper Juhl
` (2 more replies)
3 siblings, 3 replies; 26+ messages in thread
From: Roger Luethi @ 2004-07-29 23:56 UTC (permalink / raw)
To: Rob Landley; +Cc: linux-kernel
On Thu, 22 Jul 2004 22:04:46 -0500, Rob Landley wrote:
> I just saw a funky thing. Here's the cut and past from the xterm...
>
> [root@(none) root]# ps ax | grep hack
> 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm HISTSIZE=1000 USER=root LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=
> [root@(none) root]# ps ax | grep hack
> 9966 pts/1 S 0:00 grep hack
>
> Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
> or the 2.6.7 kernel or what...
If somebody posted a solution for this, I didn't see it. There's a race in
the kernel, and considering the permissions on /proc/PID/{cmdline,environ}
a security bug as well: If you win the race with a starting process, you
can read its environment.
This should plug the hole. Can you give it a spin?
Roger
--- linux-2.6.8-rc2-bk1/fs/proc/base.c.orig 2004-07-30 01:43:23.535967505 +0200
+++ linux-2.6.8-rc2-bk1/fs/proc/base.c 2004-07-30 01:43:27.428303752 +0200
@@ -329,6 +329,8 @@ static int proc_pid_cmdline(struct task_
struct mm_struct *mm = get_task_mm(task);
if (!mm)
goto out;
+ if (!mm->arg_end)
+ goto out; /* Shh! No looking before we're done */
len = mm->arg_end - mm->arg_start;
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-29 23:56 ` Roger Luethi
@ 2004-07-30 0:18 ` Jesper Juhl
2004-07-30 0:22 ` Jesper Juhl
2004-07-30 8:27 ` Marc Ballarin
2004-08-20 10:15 ` Lee Revell
2 siblings, 1 reply; 26+ messages in thread
From: Jesper Juhl @ 2004-07-30 0:18 UTC (permalink / raw)
To: Roger Luethi; +Cc: Rob Landley, linux-kernel
On Fri, 30 Jul 2004, Roger Luethi wrote:
> On Thu, 22 Jul 2004 22:04:46 -0500, Rob Landley wrote:
>> I just saw a funky thing. Here's the cut and past from the xterm...
>>
>> [root@(none) root]# ps ax | grep hack
>> 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm HISTSIZE=1000 USER=root LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=
>> [root@(none) root]# ps ax | grep hack
>> 9966 pts/1 S 0:00 grep hack
>>
>> Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
>> or the 2.6.7 kernel or what...
>
> If somebody posted a solution for this, I didn't see it. There's a race in
> the kernel, and considering the permissions on /proc/PID/{cmdline,environ}
> a security bug as well: If you win the race with a starting process, you
> can read its environment.
>
> This should plug the hole. Can you give it a spin?
>
> Roger
>
> --- linux-2.6.8-rc2-bk1/fs/proc/base.c.orig 2004-07-30 01:43:23.535967505 +0200
> +++ linux-2.6.8-rc2-bk1/fs/proc/base.c 2004-07-30 01:43:27.428303752 +0200
> @@ -329,6 +329,8 @@ static int proc_pid_cmdline(struct task_
> struct mm_struct *mm = get_task_mm(task);
> if (!mm)
> goto out;
> + if (!mm->arg_end)
> + goto out; /* Shh! No looking before we're done */
>
> len = mm->arg_end - mm->arg_start;
>
I might be reading the code wrong or not be fully aware of the
circumstances here, so please bear with me, but I took a look at
get_task_mm() and it can return NULL. If it does you'd end up
dereferencing a NULL pointer with "if (!mm->arg_end)" - or is that
garanteed not to happen here?
Wouldn't something like
if (!mm || !mm->arg_end)
goto out;
be safer?
Just my two pennies..
- Jesper Juhl <juhl-lkml@dif.dk>
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-30 0:18 ` Jesper Juhl
@ 2004-07-30 0:22 ` Jesper Juhl
0 siblings, 0 replies; 26+ messages in thread
From: Jesper Juhl @ 2004-07-30 0:22 UTC (permalink / raw)
To: Jesper Juhl; +Cc: Roger Luethi, Rob Landley, linux-kernel
On Fri, 30 Jul 2004, Jesper Juhl wrote:
> On Fri, 30 Jul 2004, Roger Luethi wrote:
>
>> On Thu, 22 Jul 2004 22:04:46 -0500, Rob Landley wrote:
>>> I just saw a funky thing. Here's the cut and past from the xterm...
>>>
>>> [root@(none) root]# ps ax | grep hack
>>> 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash
>>> TERM=xterm HISTSIZE=1000 USER=root
>>> LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=
>>> [root@(none) root]# ps ax | grep hack
>>> 9966 pts/1 S 0:00 grep hack
>>>
>>> Seems like some kind of race condition, dunno if it's in Fedore Core 1's
>>> ps
>>> or the 2.6.7 kernel or what...
>>
>> If somebody posted a solution for this, I didn't see it. There's a race in
>> the kernel, and considering the permissions on /proc/PID/{cmdline,environ}
>> a security bug as well: If you win the race with a starting process, you
>> can read its environment.
>>
>> This should plug the hole. Can you give it a spin?
>>
>> Roger
>>
>> --- linux-2.6.8-rc2-bk1/fs/proc/base.c.orig 2004-07-30 01:43:23.535967505
>> +0200
>> +++ linux-2.6.8-rc2-bk1/fs/proc/base.c 2004-07-30 01:43:27.428303752
>> +0200
>> @@ -329,6 +329,8 @@ static int proc_pid_cmdline(struct task_
>> struct mm_struct *mm = get_task_mm(task);
>> if (!mm)
>> goto out;
>> + if (!mm->arg_end)
>> + goto out; /* Shh! No looking before we're done */
>>
>> len = mm->arg_end - mm->arg_start;
>>
>
> I might be reading the code wrong or not be fully aware of the circumstances
> here, so please bear with me, but I took a look at get_task_mm() and it can
> return NULL. If it does you'd end up dereferencing a NULL pointer with "if
> (!mm->arg_end)" - or is that garanteed not to happen here?
>
> Wouldn't something like
>
> if (!mm || !mm->arg_end)
> goto out;
>
> be safer?
>
Arrgh, that's what happens when you try to read patches at 02:25
For some reason my eyes read the patch as
- if (!mm)
- goto out;
+ if (!mm->arg_end)
+ goto out; /* Shh! No looking before we're done */
but that's not what it looks like :( Sorry about that. There's no problem
except for me being too sleepy.
/Jesper Juhl
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-29 23:56 ` Roger Luethi
2004-07-30 0:18 ` Jesper Juhl
@ 2004-07-30 8:27 ` Marc Ballarin
2004-07-30 8:38 ` Roger Luethi
2004-08-20 10:15 ` Lee Revell
2 siblings, 1 reply; 26+ messages in thread
From: Marc Ballarin @ 2004-07-30 8:27 UTC (permalink / raw)
To: Roger Luethi; +Cc: rob, linux-kernel
On Fri, 30 Jul 2004 01:56:54 +0200
Roger Luethi <rl@hellgate.ch> wrote:
> If somebody posted a solution for this, I didn't see it. There's a race
> in the kernel, and considering the permissions on
> /proc/PID/{cmdline,environ} a security bug as well: If you win the race
> with a starting process, you can read its environment.
>
> This should plug the hole. Can you give it a spin?
>
> Roger
>
> --- linux-2.6.8-rc2-bk1/fs/proc/base.c.orig 2004-07-30 01:43:23.535967505 +0200
> +++ linux-2.6.8-rc2-bk1/fs/proc/base.c 2004-07-30 01:43:27.428303752 +0200
> @@ -329,6 +329,8 @@ static int proc_pid_cmdline(struct task_
> struct mm_struct *mm = get_task_mm(task);
> if (!mm)
> goto out;
> + if (!mm->arg_end)
> + goto out; /* Shh! No looking before we're done */
>
> len = mm->arg_end - mm->arg_start;
>
Yes, this seems to fix it. First I replaced "goto out" with a printk, and
the printks matched the occurence of the bug.
However, I got multiple printks per bug (between 2 and 7). Is that
supposed to happen?
Anyway, I've added back the "goto out" (after printk), and the bug no
longer
occurs. The printk still happens, so this code path does get hit.
Regards, and thanks for the fix
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-30 8:27 ` Marc Ballarin
@ 2004-07-30 8:38 ` Roger Luethi
0 siblings, 0 replies; 26+ messages in thread
From: Roger Luethi @ 2004-07-30 8:38 UTC (permalink / raw)
To: Marc Ballarin; +Cc: rob, linux-kernel
On Fri, 30 Jul 2004 10:27:26 +0200, Marc Ballarin wrote:
> > --- linux-2.6.8-rc2-bk1/fs/proc/base.c.orig 2004-07-30 01:43:23.535967505 +0200
> > +++ linux-2.6.8-rc2-bk1/fs/proc/base.c 2004-07-30 01:43:27.428303752 +0200
> > @@ -329,6 +329,8 @@ static int proc_pid_cmdline(struct task_
> > struct mm_struct *mm = get_task_mm(task);
> > if (!mm)
> > goto out;
> > + if (!mm->arg_end)
> > + goto out; /* Shh! No looking before we're done */
> >
> > len = mm->arg_end - mm->arg_start;
> >
>
> Yes, this seems to fix it. First I replaced "goto out" with a printk, and
> the printks matched the occurence of the bug.
> However, I got multiple printks per bug (between 2 and 7). Is that
> supposed to happen?
Every time we proceed through proc_pid_cmdline with mm->arg_end == 0 is a
bug. AFAICT anyway. Whether you see an "occurence of the bug" depends on
how you measure it. Of course you are wecome to add more printks following
the code path to see how and when it propagates to where you are catching
it.
Roger
^ permalink raw reply [flat|nested] 26+ messages in thread
* RE: Interesting race condition...
2004-07-27 20:40 ` Bill Davidsen
2004-07-28 8:00 ` Paul Jackson
@ 2004-08-04 20:03 ` Robert White
2004-08-04 20:42 ` Roger Luethi
1 sibling, 1 reply; 26+ messages in thread
From: Robert White @ 2004-08-04 20:03 UTC (permalink / raw)
To: 'Bill Davidsen', linux-kernel
Using procps version 2.0.7 the inclusion of "e" in the arguments is documented to
return environment of the process.
So the below issues with "ps eaxf" are only surprising in that you claim the pipe is
necessary to see the environment. Ps has "always" done slightly different things
when used at the head of a pipe. In particular it will trim it's right side when not
in a pipe to keep the display readable, while in a pipe the lines will be "as long as
necessary."
The question of why the original poster was getting the environment when only using
"ps ax" is interesting. I'd look for PS_PERSONALITY (etc) in the ps-executing
environment. [consult your manual.]
And so on...
Rob.
-----Original Message-----
From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-owner@vger.kernel.org]
On Behalf Of Bill Davidsen
Sent: Tuesday, July 27, 2004 1:40 PM
To: linux-kernel@vger.kernel.org
Subject: Re: Interesting race condition...
Rob Landley wrote:
> On Friday 23 July 2004 05:01, P. Benie wrote:
>
>>On Fri, 23 Jul 2004, Rob Landley wrote:
>>
>>>I just saw a funky thing. Here's the cut and past from the xterm...
>>>
>>>[root@(none) root]# ps ax | grep hack
>>> 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm
>>>HISTSIZE=1000 USER=root
>>>LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=
>>>40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.
>>>com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz
>>>= [root@(none) root]# ps ax | grep hack
>>> 9966 pts/1 S 0:00 grep hack
>>>
>>>Seems like some kind of race condition, dunno if it's in Fedore Core 1's
>>>ps or the 2.6.7 kernel or what...
>>
>>The race is in the shell's pipeline - the processes don't start at exactly
>>the same time, and sometimes ps has completed before the shell has
>>started grep. This is the expected behaviour.
>
>
> It's expected behavior for PS to show a process's environment variables as
> part of its command line?
When piped. For instance
ps eaxf
does not, while
ps eaxf | cat
does, at least on my systems. I tried on RHEL AS3.0 thru a four year old
version of Slackware, all did the same thing.
--
-bill davidsen (davidsen@tmr.com)
"The secret to procrastination is to put things off until the
last possible moment - but no longer" -me
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-08-04 20:03 ` Robert White
@ 2004-08-04 20:42 ` Roger Luethi
0 siblings, 0 replies; 26+ messages in thread
From: Roger Luethi @ 2004-08-04 20:42 UTC (permalink / raw)
To: Robert White; +Cc: 'Bill Davidsen', linux-kernel
On Wed, 04 Aug 2004 13:03:50 -0700, Robert White wrote:
> Using procps version 2.0.7 the inclusion of "e" in the arguments is
> documented to return environment of the process.
Not the environment of somebody else's process, though. But that is
currently possible in mainline, the problem is not with ps but with
the kernel.
> The question of why the original poster was getting the environment when
> only using "ps ax" is interesting. I'd look for PS_PERSONALITY (etc) in
Basically, if anyone reads /proc/pid/cmdline early enough, when
mm->arg_end is still 0, the kernel will blast out the process environment
through that interface. Thus, you get the data of /proc/pid/environ
without the access restrictions of that file. Not good if you happen
to pass sensitive information using environment variables.
Check out the patch I posted earlier in this thread.
Roger
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-07-29 23:56 ` Roger Luethi
2004-07-30 0:18 ` Jesper Juhl
2004-07-30 8:27 ` Marc Ballarin
@ 2004-08-20 10:15 ` Lee Revell
2004-08-20 12:51 ` Marc Ballarin
2 siblings, 1 reply; 26+ messages in thread
From: Lee Revell @ 2004-08-20 10:15 UTC (permalink / raw)
To: Roger Luethi; +Cc: Rob Landley, linux-kernel
On Thu, 2004-07-29 at 19:56, Roger Luethi wrote:
> On Thu, 22 Jul 2004 22:04:46 -0500, Rob Landley wrote:
> > I just saw a funky thing. Here's the cut and past from the xterm...
> >
> > [root@(none) root]# ps ax | grep hack
> > 9964 pts/1 R 0:00 grep hack HOSTNAME= SHELL=/bin/bash TERM=xterm HISTSIZE=1000 USER=root LS_COLORS=no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;32:*.csh=00;32:*.tar=00;31:*.tgz=
> > [root@(none) root]# ps ax | grep hack
> > 9966 pts/1 S 0:00 grep hack
> >
> > Seems like some kind of race condition, dunno if it's in Fedore Core 1's ps
> > or the 2.6.7 kernel or what...
>
> If somebody posted a solution for this, I didn't see it. There's a race in
> the kernel, and considering the permissions on /proc/PID/{cmdline,environ}
> a security bug as well: If you win the race with a starting process, you
> can read its environment.
>
> This should plug the hole. Can you give it a spin?
>
Was this ever merged? I just hit this bug with 2.6.8.1:
rlrevell@mindpipe:~$ ps auxww | grep jack
rlrevell 10498 0.1 5.9 28656 28624 pts/0 SLl+ 06:07 0:00 jackd -n 1000000 --realtime -d alsa --rate 48000 -D -P hw:0,0 -C hw:0,2 -p 32 -S
rlrevell 10502 0.1 2.3 11432 11432 pts/2 SLl+ 06:07 0:00 jack_simple_client foo
rlrevell 10509 0.0 0.0 4 4 pts/1 R+ 06:09 0:00 grep jack SSH_AGENT_PID=667 TERM=rxvt SHELL=/bin/bash CVSROOT=:pserver:anonymous@cvs.alsa-project.org:/cvsroot/alsa GTK_RC_FILES=/etc/gtk/gtkrc:/home/rlrevell/.gtkrc-1.2-gnome2 WINDOWID=33554437 USER=rlrevell LS_COLORS=no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35: GNOME_KEYRING_SOCKET=/tmp/keyring-oFgJ2h/socket SSH_AUTH_SOCK=/tmp/ssh-JvFuVGV623/agent.623 SESSION_MANAGER=local/mindpipe:/tmp/.ICE-unix/623 USERNAME=rlrevell DESKTOP_SESSION=default PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games PWD=/home/rlrevell GDMSESSION=default HISTCONTROL=ignoredups HOME=/home/rlrevell SHLVL=1 GNOME_DESKTOP_SESSION_ID=Default LOGNAME=rlrevell DISPLAY=:0.0 COLORTERM=rxvt XAUTHORITY=/home/rlrevell/.Xauthority _=/bin/grep /bin/grep
rlrevell@mindpipe:~$ ps auxww | grep jack
rlrevell 10498 0.1 5.9 28656 28624 pts/0 SLl+ 06:07 0:00 jackd -n 1000000 --realtime -d alsa --rate 48000 -D -P hw:0,0 -C hw:0,2 -p 32 -S
rlrevell 10502 0.1 2.3 11432 11432 pts/2 SLl+ 06:07 0:00 jack_simple_client foo
rlrevell 10511 0.0 0.0 1576 464 pts/1 S+ 06:09 0:00 grep jack
rlrevell@mindpipe:~$ ps auxww | grep jack
rlrevell 10498 0.1 5.9 28656 28624 pts/0 SLl+ 06:07 0:00 jackd -n 1000000 --realtime -d alsa --rate 48000 -D -P hw:0,0 -C hw:0,2 -p 32 -S
rlrevell 10502 0.1 2.3 11432 11432 pts/2 SLl+ 06:07 0:00 jack_simple_client foo
rlrevell 10513 0.0 0.0 240 124 pts/1 R+ 06:09 0:00 grep jack
rlrevell@mindpipe:~$ ps auxww | grep jack
rlrevell 10498 0.1 5.9 28656 28624 pts/0 SLl+ 06:07 0:00 jackd -n 1000000 --realtime -d alsa --rate 48000 -D -P hw:0,0 -C hw:0,2 -p 32 -S
rlrevell 10502 0.1 2.3 11432 11432 pts/2 SLl+ 06:07 0:00 jack_simple_client foo
rlrevell 10515 0.0 0.0 1576 464 pts/1 S+ 06:09 0:00 grep jack
rlrevell@mindpipe:~$ ps auxww | grep jack
Lee
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: Interesting race condition...
2004-08-20 10:15 ` Lee Revell
@ 2004-08-20 12:51 ` Marc Ballarin
0 siblings, 0 replies; 26+ messages in thread
From: Marc Ballarin @ 2004-08-20 12:51 UTC (permalink / raw)
To: Lee Revell; +Cc: linux-kernel
On Fri, 20 Aug 2004 06:15:09 -0400
Lee Revell <rlrevell@joe-job.com> wrote:
>
> Was this ever merged? I just hit this bug with 2.6.8.1:
>
It's only in -mm series so far.
Regards
^ permalink raw reply [flat|nested] 26+ messages in thread
end of thread, other threads:[~2004-08-20 12:41 UTC | newest]
Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-23 3:04 Interesting race condition Rob Landley
2004-07-23 7:33 ` Barry K. Nathan
2004-07-23 7:56 ` Hugo Mills
2004-07-24 8:13 ` Rob Landley
2004-07-24 13:40 ` Marc Ballarin
2004-07-26 16:04 ` David Weinehall
2004-07-26 17:20 ` Marc Ballarin
2004-07-23 10:01 ` P. Benie
2004-07-24 8:17 ` Rob Landley
2004-07-24 9:08 ` P. Benie
2004-07-27 20:40 ` Bill Davidsen
2004-07-28 8:00 ` Paul Jackson
2004-08-04 20:03 ` Robert White
2004-08-04 20:42 ` Roger Luethi
2004-07-28 8:05 ` Paul Jackson
2004-07-28 11:54 ` Marc Ballarin
2004-07-28 16:46 ` Rob Landley
2004-07-28 16:42 ` Rob Landley
2004-07-28 17:08 ` Tristan Wibberley
2004-07-29 23:56 ` Roger Luethi
2004-07-30 0:18 ` Jesper Juhl
2004-07-30 0:22 ` Jesper Juhl
2004-07-30 8:27 ` Marc Ballarin
2004-07-30 8:38 ` Roger Luethi
2004-08-20 10:15 ` Lee Revell
2004-08-20 12:51 ` Marc Ballarin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox