Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 282539 - Portage: add QA check for non-prefixed shebangs
Summary: Portage: add QA check for non-prefixed shebangs
Status: RESOLVED FIXED
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: Gentoo Prefix
URL: http://git.overlays.gentoo.org/gitweb...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-08-24 09:13 UTC by Fabian Groffen
Modified: 2011-12-15 18:14 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to ignore symlinks pointing to outside prefix. (bug282539-extsymlinks.patch,975 bytes, patch)
2011-02-28 16:20 UTC, Michael Haubenwallner (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Fabian Groffen gentoo-dev 2009-08-24 09:13:40 UTC
/bin/bash just doesn't exist on a number of systems, e.g. FreeBSD, Interix, IRIX.  We don't want to use it, but since most systems /do/ provide one, we don't notice if one slips through.

Add a QA check for non-prefixed shebangs.  This is not trivial, but some ideas:
- use hardcoded list, e.g. /usr/bin/perl, /usr/bin/bash (Solaris), /bin/bash, bin/sh, /usr/bin/awk
  * con: hard to manage the list (manual and needs portage update)
  * pro: probably matches 99% of the cases in a simple way
- search for "unprefixed" paths, e.g. /usr, /bin
  * con: are /usr and /bin sufficient?  Do we need /usr/local/?
  * pro: catches all, if it works
- find suspects, looking for $EPREFIX in shebang
  * con: symlinks can result in different paths (canonical issue), q: how often is this the case?
  * pro: should catch everything suspicious

IMO we can't die on this violation, because:
- some she-bangs we accept (/bin/sh for real bourne scripts, e.g. like configure)
- some scripts are really of the kind "I don't care, totally broken anyway, so don't patch"
Comment 1 Markus Duft (RETIRED) gentoo-dev 2009-08-24 09:37:21 UTC
i'd rather use a whitelist. i.e. /bin/env, /bin/sh, /usr/bin/env are ok, all others must have $EPREFIX. is there any other executable to be on the whitelist?
Comment 2 Markus Duft (RETIRED) gentoo-dev 2009-08-24 09:43:04 UTC
(In reply to comment #0)
> IMO we can't die on this violation, because:
IMO it would be better to die, because:

> - some she-bangs we accept (/bin/sh for real bourne scripts, e.g. like
> configure)
those would be on the whitelist anyway, right?

> - some scripts are really of the kind "I don't care, totally broken anyway, so
> don't patch"
those should be removed before merging, so the user doesn't accidently gets to think it is usable. if it's there, it's just a matter of time, until somebody tries to use it, and if it's just the typical "uh, what is this? let's try ... *boom*".
Comment 3 Fabian Groffen gentoo-dev 2009-08-24 09:51:56 UTC
hehe, you got me
Comment 4 Fabian Groffen gentoo-dev 2009-09-14 07:29:31 UTC
ok, I implemented a warnlist and whitelist.  /usr/bin/env is on the whitelist (note: /bin/env is not valid: it doesn't exist on many systems!), while /bin/sh is on the warnlist.  Reason is that some scripts assume /bin/sh to be POSIX sh, which is a wrong assumption for most of our systems.
Comment 5 Fabian Groffen gentoo-dev 2009-09-14 08:29:19 UTC
first runs show a quite dramatic landscape wrt shebangs :(
Comment 6 Fabian Groffen gentoo-dev 2009-09-14 09:38:53 UTC
/usr/share/doc stuff is now ignored
/etc/{init,conf}.d stuff is now removed (no longer installed, waiting for someone to take up bug #196294)
Comment 7 Fabian Groffen gentoo-dev 2009-09-14 10:39:22 UTC
should we do autofixing for things like e.g. /bin/bash, /usr/bin/python, ... ?
Comment 8 Fabian Groffen gentoo-dev 2009-09-14 10:52:04 UTC
given the gigantic amount of cases where this is a problem I skipped the WARNLIST, and now automatically convert everything that I see that would be valid (e.g. binary exists) at the time of installing, or right after it.  Portage /is/ noisy about it, so it will show up.  Left are the cases where stupid python packages use shebangs like this: "#!python"
Comment 9 Markus Duft (RETIRED) gentoo-dev 2009-09-14 11:23:06 UTC
sounds like _many_ future troubles on ~x86-winnt just went away :) thanks!
Comment 10 Markus Duft (RETIRED) gentoo-dev 2009-09-14 11:23:43 UTC
and on ~x86-interix mainly of course... man - keyword [kc]onfusion
Comment 11 Fabian Groffen gentoo-dev 2009-09-16 18:18:52 UTC
I just changed the code to only scan executable files.  This should reduce the number of "fixed" and offending files drastically, limiting to only what really matters
Comment 12 Fabian Groffen gentoo-dev 2009-09-21 18:26:07 UTC
this is going to hit the tree (hard) as version 2.2.00.14277
Comment 13 Michael Haubenwallner (RETIRED) gentoo-dev 2011-02-28 16:03:15 UTC
Since symlinks are checked for valid shebang too[1], native-cctools breaks on AIX, as there is a symlink to /usr/ccs/bin/ranlib, which is a /bin/ksh-script.

But I'm unsure how best to handle that:
Ignore symlinks pointing to outside prefix, or
explicitly ignore sys-devel/native-cctools?

[1] http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commitdiff;h=807fbb504a3edba375f31d6ca80eec36b88bb1aa

Also I want to keep the ld-wrapper for "-soname" support a /bin/ksh-script to be useable outside prefix too: this can be done with "#!/usr/bin/env /bin/ksh"
Comment 14 Michael Haubenwallner (RETIRED) gentoo-dev 2011-02-28 16:20:26 UTC
Created attachment 264183 [details, diff]
Patch to ignore symlinks pointing to outside prefix.

(In reply to comment #13)
> But I'm unsure how best to handle that:
> Ignore symlinks pointing to outside prefix,

This patch ignores symlinks pointing to outside prefix...
Comment 15 Fabian Groffen gentoo-dev 2011-02-28 16:22:00 UTC
I thought I already implemented something like that
Comment 16 Michael Haubenwallner (RETIRED) gentoo-dev 2011-04-01 09:46:30 UTC
After fixing baselayout this is the next showstopper for AIX bootstrap.
As there was a portage update recently - any chance to get this in too?

I could add a portage patch meanwhile - but also I could wrap ranlib like done for Darwin already (even for different reason), but don't like the latter...
Comment 17 Fabian Groffen gentoo-dev 2011-04-01 10:26:20 UTC
The patch just ignores files that happen to be symlinks, and that point to outside the prefix, right?

Although one would like to check that too, to a certain extent, I can agree with that.  As such the patch looks ok.  Modulo the forget-factor, I'll apply it ASAP.
Comment 18 Michael Haubenwallner (RETIRED) gentoo-dev 2011-04-01 11:52:15 UTC
(In reply to comment #17)
> The patch just ignores files that happen to be symlinks, and that point to
> outside the prefix, right?

This is the idea, yes.

But reading the patch again, eventually we should also $(canonicalize "${rf}"), in case there's a symlink pointing to sth. like //////the/../the/prefix/.

This additional diff seems to work:

-[[ ${rf} != ${EPREFIX}/* && ${rf} != ${eprefix}/* ]] && continue
+[[ ${rf} != ${EPREFIX}/* && $(canonicalize "${rf}") != ${eprefix}/* ]] && continue
Comment 19 Fabian Groffen gentoo-dev 2011-04-24 17:21:14 UTC
committed now, so next release includes it (at last)
Comment 20 Fabian Groffen gentoo-dev 2011-12-15 18:14:28 UTC
released for ages