You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As can be seen in in #1424, there are occasional problems caused by the /bin/sh impurity. While removing it from the chroot or system completely would be a lot of work because of shebang scripts, it should be doable to at least make system(3) not rely on /bin/sh. I'll come up with an implementation and hopefully it will be acceptable to merge.
[17:52] <shlevy> Eh I'm not sure there's really an issue with just looking up in $PATH for glibc final
[17:53] <civodul> shlevy: well, that's at least a problem for setuid binaries
[17:54] <shlevy> civodul: isn't it already gospel that system and popen shouldn't be used in setuid binaries?
[17:54] <shlevy> Do not use system() from a program with set-user-ID or set-group-ID privileges, because strange
[17:54] <shlevy> values for some environment variables might be used to subvert system integrity. Use the exec(3)
[17:54] <shlevy> family of functions instead, but not execlp(3) or execvp(3). system() will not, in fact, work
[17:54] <shlevy> properly from programs with set-user-ID or set-group-ID privileges on systems on which /bin/sh is
[17:55] <shlevy> bash version 2, since bash 2 drops privileges on startup. (Debian uses a modified bash which
[17:55] <shlevy> does not do this when invoked as sh.)
[17:55] <shlevy> from man 3 system :)
[17:56] <viric> setuid is chosen by users, not programmers
[17:56] <civodul> right
[17:56] <civodul> i would be very conservative here
Well, I thought the scheme is to hardcode sh, except for some bootstrapping glibc versions.
As for libc's system', change Awk to look forsh' in $PATH. This patch is only meant to be used during bootstrapping, where we don't know in advance the absolute file name of `sh'.
Hmm, I have WIP for hardcoding shell in glibc, but it introduces a chicken-egg problem: currently the final glibc is linked from the final bash. Any ideas?
(cont.) This results in the state that bash in glibc gets hardcoded to a bootstrap version of bash.
The easiest way to resolve this 2-cycle seems (to me) to have both final versions in one derivation output. I would do that e.g. by building bash separately, and then when building glibc copy bash and change its linking section to use libc from the common $out (linking section is the only reference of bash to glibc).
My idea was: Buildglibc with a link to bootstrap sh in $out/bin, then when building bash move the glibc build (with hash-rewriting) into bash's $out before the build, then before make install unlink $out/bin/sh if needed.
An alternative idea would be to provide a 'config file' for glibc found in an env var that points it to bash and anything else it might need.
That sounds the same way of breaking the 2-cycle, just the other way around :-) IMO it's a more difficult one, as it isn't enough to re-write hash -- name+length change too (bootstrap-utils vs. bash, I think).
No, you wouldn't rewrite the hash of the sh symlink, you'd leave it pointing to bootstrap-utils then it would be replaced by the currently building bash's sh program during make install. You'd have to make the glibc and bash names the same length though.
I like this way better because bash should ideally be compiled against the same exact version of the library it will run against. Note that you'll have to fix the hashes in the other direction too, as bash will surely have self-references.
Yeah, having a static bash just for system and popen is another idea but there's the problem you pointed out plus the additional bother of needing two versions of bash at all. I think separate derivations are preferable, but YMMV of course.
Relying on an environment variable inside a build is never an impurity... and in any case, #1870 is about a shebang reference to /bin/sh, which this issue doesn't address.
I was referring to run-time glibc -- the one that all packages depend on. For bootstrapping versions this approach seems fine (and it was supported by me in the first comment on this issue).
I am in favor of hard-coding the path. For the final glibc I see no better way. I even have some WIP on it, but that's been stalled for a week, as I see that much simpler and less controversial changes have "problems" getting into master (#1840).
@edolstra perhaps I misunderstand what you expect of stdenv-changing updates. Do you expect me to merge that branch now (discussed at the end of #1840)? I thought it was preferable to have a full Hydra rebuild before merging.
Is there any hope in getting rid of /bin/sh? I see several old and closed issues on this subject,
but no agreed upon solution yet.
Background: I wanted to set up some reproducible builds and got into trouble when running libfaketime + perl because it invokes host /bin/sh. The build crashed. I'm looking into using proot -b $(command -v sh):/bin/sh buildscript as workaround.
Right. I forgot to say that this is on non-NixOS. Setting up sandbox / multi-user builds on non-NixOS currently requires more setup, so I've opted for single-user mode and fixing all impurities in the builds instead. (I have one NixOS machine with sanboxing as reference. The other machines run Ubuntu and I don't control them.) Now the builds are pure, except for Nix itself!
Even if sandboxing setup becomes trivial, it will only affect builds, not runtime. So /bin/sh is still an issue.
Activity
edolstra commentedon Dec 30, 2013
Before you reinvent the wheel: https://gitorious.org/guix/guix/commit/5d4fd2671aaadc5b0b7e0c331fa5e2a1d7e5c4d8
7c6f434c commentedon Dec 31, 2013
I vote in favour of cloning the C part of the patch into NixPkgs glibc build.
shlevy commentedon Dec 31, 2013
From IRC yesterday ( @civodul @viric ):
vcunat commentedon Jan 1, 2014
Well, I thought the scheme is to hardcode
sh, except for some bootstrapping glibc versions.shlevy commentedon Feb 3, 2014
Updated the milestone to
14.yyas I'm not sure I'll be able to get to this this month.vcunat commentedon Mar 2, 2014
Hmm, I have WIP for hardcoding shell in glibc, but it introduces a chicken-egg problem: currently the final glibc is linked from the final bash. Any ideas?
vcunat commentedon Mar 2, 2014
(cont.) This results in the state that bash in glibc gets hardcoded to a bootstrap version of bash.
The easiest way to resolve this 2-cycle seems (to me) to have both final versions in one derivation output. I would do that e.g. by building bash separately, and then when building glibc copy bash and change its linking section to use libc from the common $out (linking section is the only reference of bash to glibc).
vcunat commentedon Mar 2, 2014
If you agree, I can implement that to catch the glibc-2.19 merge.
shlevy commentedon Mar 2, 2014
My idea was: Build
glibcwith a link to bootstrap sh in$out/bin, then when buildingbashmove theglibcbuild (with hash-rewriting) intobash's$outbefore the build, then beforemake installunlink$out/bin/shif needed.An alternative idea would be to provide a 'config file' for glibc found in an env var that points it to
bashand anything else it might need.vcunat commentedon Mar 2, 2014
That sounds the same way of breaking the 2-cycle, just the other way around :-) IMO it's a more difficult one, as it isn't enough to re-write hash -- name+length change too (bootstrap-utils vs. bash, I think).
shlevy commentedon Mar 2, 2014
No, you wouldn't rewrite the hash of the
shsymlink, you'd leave it pointing to bootstrap-utils then it would be replaced by the currently buildingbash'sshprogram duringmake install. You'd have to make theglibcandbashnames the same length though.I like this way better because
bashshould ideally be compiled against the same exact version of the library it will run against. Note that you'll have to fix the hashes in the other direction too, asbashwill surely have self-references.civodul commentedon Mar 3, 2014
Howdy!
FWIW, the approach taken in Guix is described at:
https://lists.gnu.org/archive/html/bug-guix/2013-01/msg00041.html
We found out about limitations though:
https://lists.gnu.org/archive/html/guix-devel/2014-02/msg00141.html
Presumably we’ll end up building Bash from within the glibc derivation.
Ludo’.
shlevy commentedon Mar 3, 2014
Yeah, having a static bash just for
systemandpopenis another idea but there's the problem you pointed out plus the additional bother of needing two versions of bash at all. I think separate derivations are preferable, but YMMV of course.shlevy commentedon Mar 3, 2014
Taking a crack this afternoon
4 remaining items
civodul commentedon Mar 4, 2014
Eelco Dolstra [email protected] skribis:
We purposefully limited that approach to the bootstrap glibc, on the
grounds that it may break expectations, and/or lead to security issues.
For instance, if a program or library fiddles with $PATH, then
subsequent calls to system(3) or popen(3) could behave differently.
Ludo’.
vcunat commentedon Mar 5, 2014
Having final glibc find sh in $PATH seems like an impurity that could bite people, e.g. #1870.
edolstra commentedon Mar 5, 2014
Relying on an environment variable inside a build is never an impurity... and in any case, #1870 is about a shebang reference to /bin/sh, which this issue doesn't address.
vcunat commentedon Mar 5, 2014
I was referring to run-time glibc -- the one that all packages depend on. For bootstrapping versions this approach seems fine (and it was supported by me in the first comment on this issue).
shlevy commentedon Mar 13, 2014
I'm in favor of hard-coding the path to
sh, so if you don't want to go that route I'll close this.vcunat commentedon Mar 13, 2014
I am in favor of hard-coding the path. For the final glibc I see no better way. I even have some WIP on it, but that's been stalled for a week, as I see that much simpler and less controversial changes have "problems" getting into master (#1840).
shlevy commentedon Mar 13, 2014
I pretty much have a working impl of this already locally, but @edolstra seems to prefer the other way.
edolstra commentedon Mar 14, 2014
@vcunat What changes have problems getting into master?
vcunat commentedon Mar 14, 2014
@edolstra perhaps I misunderstand what you expect of stdenv-changing updates. Do you expect me to merge that branch now (discussed at the end of #1840)? I thought it was preferable to have a full Hydra rebuild before merging.
offlinehacker commentedon Mar 15, 2014
/bin/shis also a security concern. If you remove it, most of the exploits will just fail, and nixos will suddenly become super secure :Dbjornfor commentedon Jan 10, 2018
Is there any hope in getting rid of /bin/sh? I see several old and closed issues on this subject,
but no agreed upon solution yet.
Background: I wanted to set up some reproducible builds and got into trouble when running libfaketime + perl because it invokes host /bin/sh. The build crashed. I'm looking into using
proot -b $(command -v sh):/bin/sh buildscriptas workaround.7c6f434c commentedon Jan 10, 2018
@bjornfor in context of Nix builds, sandbox builds can mount Nix-built Bash package's
bin/shto/bin/shbjornfor commentedon Jan 11, 2018
Right. I forgot to say that this is on non-NixOS. Setting up sandbox / multi-user builds on non-NixOS currently requires more setup, so I've opted for single-user mode and fixing all impurities in the builds instead. (I have one NixOS machine with sanboxing as reference. The other machines run Ubuntu and I don't control them.) Now the builds are pure, except for Nix itself!
Even if sandboxing setup becomes trivial, it will only affect builds, not runtime. So /bin/sh is still an issue.
civodul commentedon Jan 11, 2018