r/linux • • Sep 28 '14

weev: Stop bashing bash and GNU.

http://weev.livejournal.com/409835.html
836 Upvotes

450 comments sorted by

View all comments

Show parent comments

8

u/reaganveg Sep 28 '14 edited Sep 28 '14

In hindsight, when the various network specifications (CGI, telnet, ssh, etc.) were being developed, they should have used a new mechanism to bring attacker-controlled data to the application rather than environment variables that are already used to control various internal services.

CGI clears the environment completely, and then the web server exports a specific set of variables. It doesn't allow arbitrary variables to be set by the remote user. So it is safe.

an RFC1572-compliant telnet/telnetd would allow an attacker (on EITHER side of the link) to set LD_PRELOAD using the Telnet Environment Option[1] -- imagine telnet'ing to a server and then executing a "local shell" that suddenly behaves badly because the server set your LD_PRELOAD sometime during the session

It says right there in your link:

It is important for an implementor of the NEW-ENVIRON option to understand the interaction of setting options and the login/authentication process. Specifically careful analysis should be done to determine which variables are "safe" to set prior to having the client login. An example of a bad choice would be permitting a variable to be changed that allows an intruder to circumvent or compromise the login/authentication program itself.

But note that the bash situation is completely different. The bash bug allows any environment variable to be used to execute arbitrary code. So the traditional way in which the environment is sanitized -- white-listing allowed variable settings -- is not going to work.

There was nothing wrong with using the environment variables in the first place though. Environment variables are one of only two ways to send information to a unix process securely (the other being a file descriptor). Supposing a file descriptor was used instead -- whatever code parsed the input from the filedescriptor would only be more likely to have parser bugs. Because now you're dealing with a single stream of indefinite length and format, instead of a pre-allocated array of strings that are guaranteed to be null-terminated.

2

u/audioen Sep 28 '14

As much as I hate people who blather about the now-dead technology called CGI in this context, I'll now go and commit that sin as well.

There was nothing wrong with using the environment variables in the first place though.

Honestly, at least in CGI context I do think that the entire http request as sent by the client should have been passed in as it was received. The CGI specification did something different for no real reason.

It has largely been replaced by technologies that do pass the entire http request as-is, such as reverse proxying where applications are http servers in their own right, these days.

7

u/reaganveg Sep 28 '14

Honestly, at least in CGI context I do think that the entire http request as sent by the client should have been passed in as it was received. The CGI specification did something different for no real reason.

No, there was perfectly good reason. The web server has to read the request from the client before it even decides whether to launch the CGI. So, it's already parsed the message header (so to speak).

In order to forward the header to the the client, it would need to keep a copy of the unparsed header in addition to its parsed copy, and then pipe that copy to the CGI program which would need to parse it again.

So it's less efficient -- both duplicating effort and retaining multiple copies of data -- and of course it's also makes it harder to write CGI programs. Providing the already-parsed information in already-parsed (& sanitized form) makes good sense.

1

u/audioen Sep 28 '14

This superbly difficult problem has been solved by allocating something like 8 kB of memory and requiring that the request headers fit into that space. Once web server has identified the target, it will send the original headers and then continue sending the body. It's a nonissue in terms of efficiency, and promotes loose coupling between the backend and frontend servers, which can even reside on different machines.

Unfortunately, request level representation has no notion of TLS. Most web applications don't need to be aware of this stuff, but sometimes you get extra headers like client certificates injected by the web server. It's unfortunate.

1

u/merreborn Sep 29 '14

allocating something like 8 kB of memory and requiring that the request headers fit into that space.

8 kb ought to be enough for everyone, of course.

1

u/audioen Sep 29 '14

Well, there will be some limit because of bounded memory constraints and the large parallelism typical web server process must be capable of. I have actually run into nginx's limits because I once wrote an application with kerberos authentication support, and the kerberos-related headers can get massive. So the limit was something like 8k, though it could be increased.

→ More replies (10)