• Kirill A. Shutemov's avatar
    Allow recursion in binfmt_script and binfmt_misc · bf2a9a39
    Kirill A. Shutemov authored
    binfmt_script and binfmt_misc disallow recursion to avoid stack overflow
    using sh_bang and misc_bang.  It causes problem in some cases:
    
    $ echo '#!/bin/ls' > /tmp/t0
    $ echo '#!/tmp/t0' > /tmp/t1
    $ echo '#!/tmp/t1' > /tmp/t2
    $ chmod +x /tmp/t*
    $ /tmp/t2
    zsh: exec format error: /tmp/t2
    
    Similar problem with binfmt_misc.
    
    This patch introduces field 'recursion_depth' into struct linux_binprm to
    track recursion level in binfmt_misc and binfmt_script.  If recursion
    level more then BINPRM_MAX_RECURSION it generates -ENOEXEC.
    
    [akpm@linux-foundation.org: make linux_binprm.recursion_depth a uint]
    Signed-off-by: default avatarKirill A. Shutemov <kirill@shutemov.name>
    Cc: Pavel Emelyanov <xemul@openvz.org>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    bf2a9a39
binfmt_misc.c 15.1 KB