Bug 646823 - any local user can do DoS attack for the system easily
Summary: any local user can do DoS attack for the system easily
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: setup
Version: 5.5
Hardware: All
OS: Linux
high
high
Target Milestone: rc
: ---
Assignee: Ondrej Vasik
QA Contact: qe-baseos-daemons
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2010-10-26 11:52 UTC by Masahiro Matsuya
Modified: 2018-11-14 17:05 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2011-08-18 06:32:56 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Proposed patch for lang.csh (420 bytes, patch)
2010-10-27 08:58 UTC, Norbert Nemeth
no flags Details | Diff
Proposed patch for lang.csh (824 bytes, patch)
2011-01-05 18:05 UTC, Norbert Nemeth
no flags Details | Diff
Proposing patch for "git apply" (1.23 KB, patch)
2011-01-11 14:30 UTC, Vojtech Vitek
no flags Details | Diff

Description Masahiro Matsuya 2010-10-26 11:52:22 UTC
Description of problem:

On a customer's system, a large amount of processes were created by a local user.
When the number of proceses reached the system limit, all NFS shares were unaccessible and anybody could not log in.

Version-Release number of selected component (if applicable):
RHEL 4, 5, and 6

How reproducible:
Always

Steps to Reproduce:
1. login with normal user
2. # tcsh
3. # touch grep
   # chmod +x grep
4. (Only case of RHEL6) # touch ~/.i18n
5. # setenv PATH ".:$PATH"
6. # tcsh

Actual results:
tcsh doesn't return and continue to create processes. A large amount of processes are created and the system becomes unusable.

Expected results:
A large amount of processes are not created.

Additional info:

## CAUSE of this problem
When tsch is executed, /etc/profile.d/lang.csh is executed as well.
Some command (like grep and sed) executed in /etc/profile.d/lang.csh doesn't have absolute path.

When there is the file which is not executable format in the directory specified in $PATH, after exec() for the file fails, a new tcsh process with the file is executed because it's possible the file is a script file. And, /etc/profile.d/lang.csh is executed again.

So, any commands in /etc/profile.d/lang.csh should have absolute path.
Please clone this bugzilla to RHEL6. If it's possible that this will be fixed on RHEL4, clone this bugizlla to RHEL4 as well.

Comment 1 Harald Hoyer 2010-10-26 12:18:59 UTC
any user could fork bomb the system... what's the point? nothing prevents anybody from doing this with any language..

Comment 2 Harald Hoyer 2010-10-26 12:36:06 UTC
better configure something like:

/etc/security/limits.conf:

*               hard    nproc           100
*               hard    rss             10000

Comment 3 Petr Lautrbach 2010-10-26 13:10:48 UTC
It is tcsh issue. Here is another reproducer unrelated to initscripts:

$ ls -l
-rwxrwxr-x. 1 plautrba plautrba 0 Oct 26 15:00 fakecmd

$ cat ~/.cshrc
fakecmd

$ setenv PATH ".:$PATH"

$ tcsh

Comment 4 Vincent Danen 2010-10-26 21:00:35 UTC
This is not something we would consider a security issue.  This is no different than a traditional "fork bomb" attack scenario.  While it could certainly be considered a bug in tcsh, there are so many other ways to fork bomb a system, and this just happens to be one of them.

In recent Fedora and RHEL6, this is addressed by the default /etc/security/limits.d/90-nproc.conf (as a result of bug #432903) which contains:

# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     1024

On older RHEL releases it can be set as noted in comment #2.

Also adding the reporter to this bug (we have had discussion with him outside of the bug already so he is aware of our view on this issue).

Comment 5 Norbert Nemeth 2010-10-27 08:57:17 UTC
I am the original reporter of this bug.

Reasons I consider this is a bug:
- you may think that reproducing steps are unlikely to happen on any system please consider that my users did it unintentionally thus caused serious production downtimes.
- nproc setting is good to save the machine, but it still causes outage to the "malicious" user who is in this case absolutely not malicious.
- The fix for this in /etc/profile.d/lang.csh looks easy I proposed a patch for it. The benefit of it is not high but eliminates this accidental fork bomb scenario. (This still leaves lot of other fork bomb possibilities tough)
- Petr example is good how to shoot yourself on foot with a fork bomb, but the difference between that and the original reproducing steps are that original steps does not require any (tcsh) configuration change and  using an original system configuration file to cause this behaviour.
- You should not trust in PATH variable in any csh profile file. If you check all .csh under /etc/profile.d/ all other scripts use absolute path for executables.

Comment 6 Norbert Nemeth 2010-10-27 08:58:27 UTC
Created attachment 455921 [details]
Proposed patch for lang.csh

Proposed patch from the requestor.

Comment 7 Petr Lautrbach 2010-11-01 13:29:18 UTC
(In reply to comment #5)
> - The fix for this in /etc/profile.d/lang.csh looks easy I proposed a patch for
> it. The benefit of it is not high but eliminates this accidental fork bomb
> scenario. (This still leaves lot of other fork bomb possibilities tough)
> - Petr example is good how to shoot yourself on foot with a fork bomb, but the
> difference between that and the original reproducing steps are that original
> steps does not require any (tcsh) configuration change and  using an original
> system configuration file to cause this behaviour.

In my case the problem script is not /etc/profile.d/lang.csh but /etc/profile.d/kde.csh which is executed before lang.csh. So this could be fixed in various scripts across whole distribution or fixed directly in tcsh since it doesn't affect other shells like bash. That's why I changed component.

Comment 8 Norbert Nemeth 2010-11-08 21:32:17 UTC
It maybe not a tcsh bug, but a misuse of a tcsh feature :). I am not a tcsh expert, but both bash and ksh having login shell/normal shell concept while tcsh runs the profile for each subshell. This needs to be verified by a tcsh expert. Since it is a known behaviour of tchs I suggest chceking all .csh profile script for command not using absolute path.

Comment 9 Vojtech Vitek 2011-01-05 15:02:17 UTC
I don't think there is anything wrong with those .csh scripts.
Imho, it's completely fine for user to run his own versions of /usr/binaries (eg. his own optimized grep/sed).

The only problem I see is in user who changed PATH variable and thus changed grep's functionality to something completely different that doesn't do the right job.

I can't even say it's a bug in tcsh. It's just the default behaviour - trying to run non-binary executable files in a subshell as a script. We can try to optimize tcsh by running those scripts in current context without loading any configuration files. But we should propose this to upstream more likely as a "feature" than a "bugfix".

Comment 10 Norbert Nemeth 2011-01-05 18:02:24 UTC
I still think it is bug in lang.csh and possibly in many other /etc/profile.d/*.csh scripts. If you check lang.csh closer you can see for example following code:

if ( -x /bin/unicode_start ) then
    if { /sbin/consoletype fg } then
        if ( $?SYSFONT ) then
            if ( $?SYSFONTACM ) then
                unicode_start $SYSFONT $SYSFONTACM
            else
                unicode_start $SYSFONT
            endif
        endif
    endif
endif

If your idea is true why the code checks for /bin/unicode_start while it is invoke it from PATH? Possibly another unicode_start will run, or do a fork bomb :) (Do you think users want to use their own unicode_start implementation???)

Let's see another example from lang.cs:

if ( -x /bin/unicode_stop ) then
  if { /sbin/consoletype fg } then
    /bin/unicode_stop
  endif
endif

Let's see how the first code looks like in lang.sh

[ -x /bin/unicode_start ] && /sbin/consoletype fg && /bin/unicode_start $SYSFONT $SYSFONTACM

Here it is /bin/unicode_start and not unicode_start!

This is correct IMHO and all should look like this. Please correct it. I upload the updated patch.

Comment 11 Norbert Nemeth 2011-01-05 18:03:14 UTC
I still think it is bug in lang.csh and possibly in many other /etc/profile.d/*.csh scripts. If you check lang.csh closer you can see for example following code:

if ( -x /bin/unicode_start ) then
    if { /sbin/consoletype fg } then
        if ( $?SYSFONT ) then
            if ( $?SYSFONTACM ) then
                unicode_start $SYSFONT $SYSFONTACM
            else
                unicode_start $SYSFONT
            endif
        endif
    endif
endif

If your idea is true why the code checks for /bin/unicode_start while it is invoke it from PATH? Possibly another unicode_start will run, or do a fork bomb :) (Do you think users want to use their own unicode_start implementation???)

Let's see another example from lang.cs:

if ( -x /bin/unicode_stop ) then
  if { /sbin/consoletype fg } then
    /bin/unicode_stop
  endif
endif

Let's see how the first code looks like in lang.sh

[ -x /bin/unicode_start ] && /sbin/consoletype fg && /bin/unicode_start $SYSFONT $SYSFONTACM

Here it is /bin/unicode_start and not unicode_start!

This is correct IMHO and all should look like this. Please correct it. I upload the updated patch.

Comment 12 Norbert Nemeth 2011-01-05 18:05:47 UTC
Created attachment 471917 [details]
Proposed patch for lang.csh

Comment 13 Vojtech Vitek 2011-01-05 19:18:29 UTC
Well, I was looking into many /etc/profile.d/*.[c]sh scripts and you are right that in most cases there are absolute paths used to point binaries. And it makes sense to me as well - but just in case we are sure the binaries are not relocatable.

Several /etc/profile.d/*.[c]sh scripts (including lang.csh and kde.csh) are pointing to some binaries relatively. The thing is, that most of them are usually installed from different packages, so I can't track them all instantly.

* NOTE: If we want to "fix" all these scripts, then we have to rely on their "absolute-paths".
- sed - not relocatable (/bin/sed in sed.spec)
- grep - not relocatable (/bin/grep in grep.spec)
- cut - probably not relocatable (/usr/bin/cut in coreutils.spec ?)
- tty - __probably relocatable__ (%_bindir/* in coreutils.spec)
- udisks - __relocatable__ (%_bindir/* in udisks.spec)
- ?others?

Adding Ondrej Vasik to CC, as he is maintainer of coreutils.
Ondrej, what do you think?

Comment 14 Ondrej Vasik 2011-01-06 07:02:37 UTC
For reference - cut is now in /bin/cut (hardcoded in spec) as well - /usr/bin/cut is just compat symlink... such moves do happen from time to time - if some tool is considered to be required even with disconnected /usr (could be separate partition and disconnected at start up or shutdown).

As you already said, these scripts are from various packages - and it will be quite long run to change them all to rely on absolute paths where possible. It's not only in .csh scripts, bash/ksh/... .sh profile.d scripts use in many cases basic tool names without absolute paths as well. 

However - absolute paths has one drawback - sometimes the absolute path changes - e.g. move from /usr/bin to /bin/ ... like the case of already mentioned /bin/cut - although this usually means symlink which stays in /usr/bin for quite a while, these scripts could get broken one day. 

So I think it's up to you - if you want to create a tracker and bugzillas with requests for .sh/.csh scripts changes in profile.d to use absolute paths - why not. But as was already said, this will not prevent user's from fork bomb ability and imho it brings very low benefit.

Comment 15 Vojtech Vitek 2011-01-11 13:39:18 UTC
Single command execution in tcsh (eg. executing our fake "grep"):
- fork to a subshell
- find a command file (search for it's absolute path using PATH variable)
- try to execute the file using execv()
- if can't execute the file (ENOEXEC - not a binary executable), run it as a script using execv($SHELL, [$SHELL, command, arguments..]), where $SHELL is "/bin/tcsh", "/bin/csh" or other shell alias)

The default behaviour of tcsh is to run executable files in forked subshell because of context issues - the program must not change the environment of the current shell.

So I can't suggest any changes in tcsh source code, unless we want to change the above described fork-execv design (which would lead to massive patches).

Comment 16 Vojtech Vitek 2011-01-11 14:29:20 UTC
There is another solution which should be clean and much more simple: Prevent user's paths while sourcing profile scripts in /etc/csh.cshrc.

Changing component to setup.

Comment 17 Vojtech Vitek 2011-01-11 14:30:50 UTC
Created attachment 472826 [details]
Proposing patch for "git apply"

Comment 18 Ondrej Vasik 2011-01-11 14:51:15 UTC
This can't be used, as some (e.g. qt.csh but I'm sure others as well) modify PATH envvar intentionally - and you will throw away this with this concept (and you will limit the user to use absolute paths in his own profile.d scripts - he can't rely on his intentionally set $PATH envvar).
Maybe with some merge after the profile.d scripts... or with just filtering cwd from the PATH (and possibly restoring it later) ... anyway, nasty hacks :) ...

Comment 19 RHEL Program Management 2011-05-31 15:41:59 UTC
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated in the
current release, Red Hat is unfortunately unable to address this
request at this time. Red Hat invites you to ask your support
representative to propose this request, if appropriate and relevant,
in the next release of Red Hat Enterprise Linux.

Comment 20 Ondrej Vasik 2011-08-18 06:32:56 UTC
Closing that WONTFIX (as in setup there is no good solution - and in Fedora/RHEL-6 it was solved in PAM as result of https://bugzilla.redhat.com/show_bug.cgi?id=432903 fix. Workaround mentioned in comment #2 ...

If you believe that this has to be addressed in RHEL-5, please reopen it against pam.


Note You need to log in before you can comment on or make changes to this bug.