Bug 459466

Summary: kernel: binfmt_misc.c: avoid potential kernel stack overflow [rhel-4.8]
Product: Red Hat Enterprise Linux 4 Reporter: Eugene Teo (Security Response) <eteo>
Component: kernelAssignee: Vitaly Mayatskikh <vmayatsk>
Status: CLOSED ERRATA QA Contact: Mike Gahagan <mgahagan>
Severity: medium Docs Contact:
Priority: medium    
Version: 4.8CC: dhoward, jtluka, lwang, vgoyal, vmayatsk
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-02-16 16:03:15 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 459462    
Bug Blocks: 459467, 461304    

Description Eugene Teo (Security Response) 2008-08-19 07:32:05 UTC
+++ This bug was initially created as a clone of Bug #459462 +++

Description of problem:
Register the ":text:E::txt::/root/cat.txt:' rule in binfmt_misc (by root) and try launching the cat.txt file (by anyone) :) The result is - the endless recursion in the load_misc_binary -> open_exec -> load_misc_binary chain and stack overflow.

There's a similar problem with binfmt_script, and there's a sh_bang memner on linux_binprm structure to handle this, but simply raising this in binfmt_misc may break some setups when the interpreter of some misc binaries is a script.

So the proposal is to turn sh_bang into a bit, add a new one (the misc_bang) and raise it in load_misc_binary.  After this, even if we set up the misc -> script -> misc loop for binfmts one of them will step on its own bang and exit.

Note that this can be triggered with root help only.

http://lkml.org/lkml/2008/3/13/245

--- Additional comment from eteo on 2008-08-19 03:17:02 EDT ---

Proposed upstream patch:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3a2e7f47d71e1df86acc1dda6826890b6546a4e1

--- Additional comment from eteo on 2008-08-19 03:17:35 EDT ---

(In reply to comment #1)
> Proposed upstream patch:
> http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3a2e7f47d71e1df86acc1dda6826890b6546a4e1

Note that there is a regression. See http://lkml.org/lkml/2008/8/18/544. The patch is not in upstream yet AFAIK.

Comment 1 Eugene Teo (Security Response) 2008-08-19 07:50:05 UTC
Steps to Reproduce:
1. as root user, run echo ":text:E::txt::/cat.txt:" >
/proc/sys/fs/binfmt_misc/register; touch /cat.txt; chmod +x /cat.txt
2) as normal user, run /cat.txt

Comment 2 Eugene Teo (Security Response) 2008-08-21 02:41:24 UTC
(In reply to comment #2)
> (In reply to comment #1)
> > Proposed upstream patch:
> > http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=3a2e7f47d71e1df86acc1dda6826890b6546a4e1
> 
> Note that there is a regression. See http://lkml.org/lkml/2008/8/18/544. The
> patch is not in upstream yet AFAIK.

This is ff9bc512f198eb47204f55b24c6fe3d36ed89592

Comment 3 RHEL Program Management 2008-09-03 13:09:40 UTC
Updating PM score.

Comment 9 RHEL Program Management 2009-02-09 11:28:58 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 14 RHEL Program Management 2009-06-05 13:46:25 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 15 Vivek Goyal 2010-10-14 14:39:09 UTC
Committed in 89.43.EL . RPMS are available at http://people.redhat.com/vgoyal/rhel4/

Comment 19 Mike Gahagan 2010-12-21 19:49:53 UTC
confirmed this bug is fixed on the -94.EL kernel.

Comment 20 errata-xmlrpc 2011-02-16 16:03:15 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHSA-2011-0263.html