Live data from Hacker News

Glibc getaddrinfo stack-based buffer overflow

googleonlinesecurity.blogspot.com

211–220 of 480 posts

Re: Glibc getaddrinfo stack-based buffer overflow

#211

[flagged]

> Repeat after me: there is no silver bullet! There is no single silver bullet, but there exists silver bullets for a variety of problems. When was the last time you saw a pure Python or pure Java code segfaulting from invalid memory accesses? When was the last time you saw a C/C++ code doing the same? It is simply negligent to use a language or system that exposes you to that many more classes of vulnerabilities . I…

> When was the last time you saw a pure Python or pure Java code segfaulting from invalid memory accesses?

When was the last time you saw Python or pure Java being used to write an interface between applications and kernel?

Those are different languages made for different purposes. They have their own issues (from top of my head pickle module allows to execute code if served with untrusted input), and generally applications written in them are not as wildly deployed as glibc.

Also it's kind of ironic to compare them because both Python and Java are written in C and C++.

Re: Glibc getaddrinfo stack-based buffer overflow

#212
post #140

Earlier quoted context omitted.

You are missing the forest for the trees. Grandparent is saying "replace all C with Rust" and you replied with "but look, Rust programs rely on glibc! It's unsafe!" Yes, Rust programs can be affected by this. But only because they call into C at a lower level, for the libc layer. If glibc was in Rust it would provide security to all application, including ssh or curl which aren't in Rust. Also, extern "C" is for C FF…

Or perhaps he made a more subtle point: you can't replace all C with Rust. Even if you rewrite the libc (you'll need some assembly), even if you rewrite the kernel (you'll need a lot of assembly and "unsafe"), there will still be lots of closed-source C running on undocumented components of your computer as firmware. C is just representative of computers as they really are today, for a bunch of reasons (mostly pragma…

Agree.

"C" to OS, Kernel, Computer Language, applications is like oxygen is to life on earth.

Yes, O2 causes fire from time to time, but you can't live without it.

Re: Glibc getaddrinfo stack-based buffer overflow

#213
post #90

Earlier quoted context omitted.

> Written properly, C++ is not unsafe. This is abusing what "unsafe" means. As a language, C++ is inherently unsafe. However, some C++ programs ("written properly") are correct. If written properly C++ is not unsafe, then written properly C is not unsafe.

I don't subscribe to the "properly written Modern C++ is safe" meme, but still it must be recognized that there are degrees of unsafety [1] between languages. [1] not talking about memory safety, but as a general "probability of having a defect".

I really dislike the "safe"/"unsafe" terminology, there isn't a commonly-agreed upon definition of "safe". But I think it's safe to say that it's a combination of type and memory safety, not "low probability of having a defect".

There certainly is a spectrum.

Re: Glibc getaddrinfo stack-based buffer overflow

#214
post #107

Earlier quoted context omitted.

Why can't it be linked statically?

Glibs uses /etc/nsswitch.conf to decide at runtime which libraries has to be loaded dynamically to implement DNS resolver, user lookup etc. One in principle can compile those libraries statically, but it is rather complicated for no gains, so almost nobody is doing that.

Interesting, thanks!

Re: Glibc getaddrinfo stack-based buffer overflow

#215
post #22

Earlier quoted context omitted.

I'm still unsure why people start projects with C, or C++ (or other unsafe languages), that do not need it. I totally understand that there are use cases where C++ and C make sense. In my mind, these use cases are quite limited though - integration into 3rd party libraries, legacy codebases, and working in embedded environments. I also agree that performance can be a reason, but see Knuth's opinion on premature optim…

> Can people tell me why they start projects in broad C++, and C still? I may be completely missing some piece of the puzzle. Sure. --- Compelling features: - Unrivaled portability (yes, contrary to folklore C - and to a lesser extent C++ - is more portable than Java) - Excellent libraries - Excellent documentation and learning resources - Unrivaled tooling - perfect mapping to how the computer works - Unrivaled perf…

  > a kernel in Rust/Nim/whatever would be under a big unsafe block anyways?
Only portions of it do. The whole point of unsafe is that you can encapsulate it, and then go from there.

Re: Glibc getaddrinfo stack-based buffer overflow

#216
post #72

Earlier quoted context omitted.

Yes, UNIX was adopted by the corporations and brought C with it. Some people don't get it that before it happened we were happily using other systems programming languages way safer than C.

>Some people don't get it that before it happened we were happily using other systems programming languages way safer than C. Maybe some people, but most systems programming was done is Assembly before C.

If targeting home computers, the so called mini-computers and home micros, yes. C was just yet another "managed language".

If targeting real computers, what is nowadays left as mainframes, then no.

Extended Algol was already being used by Burroughs in 1961 for writing Assembly free OSes.

There are lots of other examples, which C advocates tend to ignore, so that they can sell the story that before C there was only Assembly to those that don't bother with history of computing.

Re: Glibc getaddrinfo stack-based buffer overflow

#217
post #117
post #85

Earlier quoted context omitted.

> Anything that's using glibc (directly) is written in C ... and together with stuff using glibc (indirectly) constitutes 99.99% of your software. How much software/languages implement their own DNS resolver instead of just calling libc? How about syscall wrappers?

The JVM looks to have its own implementation. I imagine .net would be the same. There's ocaml-dns for unikernel-deployed OCaml. A managed language generally doesn't give you direct access to syscalls at all. In rust you can perform them without having to go via C.

With Redtamarin (based on AVM2), there is a native library which sole purpose is to give direct access to C and other syscalls.

For ex with getaddrinfo: https://gist.github.com/zwetan/0c047d36542cc6979652

I know because I did it on purpose, even if it managed code written in AS3 you don't want to reinvent getaddrinfo, you want to reuse it "as is" as much as possible.

Re: Glibc getaddrinfo stack-based buffer overflow

#218
post #66

[flagged]

There absolutely are some silver bullets. ALL of these buffer overflows in C happen because the C stack grows backward, and old space is after new space. If anyone have enough of a crap just to standardize a calling convention that went the other way, stack buffer overwrites would ALWAYS go into unused memory. Then security-minded people would switch to this calling convention for secure programs, and many problems w…

Um, what?

    char too_small_buffer[256];
    function_that_expects_a_big_buffer(too_small_buffer);
There's even a paragraph on Wikipedia debunking this idea: https://en.wikipedia.org/wiki/Stack_buffer_overflow#Stacks_t...

Re: Glibc getaddrinfo stack-based buffer overflow

#219
post #29

Earlier quoted context omitted.

Apparently until the UNIX culture that worships C exist, it won't happen. C only became a thing in computing after UNIX workstations became popular. Before it, there were quite a few safer systems programming languages to choose from, that got steam rolled by C adoption in OS SDKs. Due to its relation with UNIX, it will most likely happen with Apple (Swift), Microsoft (.NET Native, System C#, C++/GSL), Google (Java F…

I wouldn't say that UNIX workstations became truly popular until after Mac OS X took off sometime in the 2000s. C and C++ were enormously popular in the 90s, if not earlier. They were really common for Mac and Windows programming, and I don't think that had anything to do with the UNIX connection.

I was there.

The only reason to get a C compiler for CP/M, MS-DOS or Amiga was to be able to bring work home from those expensive workstations at work or university.

Re: Glibc getaddrinfo stack-based buffer overflow

#220
post #65

Earlier quoted context omitted.

Rust can have the same ABI as C - rewriting NSS in Rust should not pose ABI problems.

It's still completely pointless. How would mmap be any different if it was implemented in Rust rather than in C? You need unsafe to implement it! The safety mechanisms are practically useless at such a low level. Wrap existing C with safe Rust, not the other way around! We don't rewrite unsafe C code in Unsafe Rust so that it can be called from all the unsafe C code in UNIX. Such a translation is so pointless and err…

> How would mmap be any different if it was implemented in Rust rather than in C? You need unsafe to implement it! The safety mechanisms are practically useless at such a low level.

They're definitely not. The power of Rust is not avoiding all `unsafe` ever, but wrapping that unsafe into finite-scope, safe wrappers. Something like mmap would presumably interface with the OS's internal memory management routines, which would definitely have to have `unsafe` somewhere since they're hitting the hardware, but it seems very reasonable for the amount of unsafe exposed to much reduced (possibly even to zero). See, for instance, http://os.phil-opp.com/modifying-page-tables.html . Basically, as soon as you're above the absolute raw hardware level, you can start introducing extra help to reduce unsafety/catch bugs.

In any case, code inside `unsafe` still benefits from all the conventional Rust checks, e.g. iterating over a slice won't go out of bounds due to a typo in the loop even inside `unsafe`, nor will references accidentally become dangling. (Of course, the `unsafe` block may do something explicitly that causes either of these problems, but this exact same risk is pervasive in all C code, rather than just around explicitly marked areas.)

> Wrap existing C with safe Rust, not the other way around! We don't rewrite unsafe C code in Unsafe Rust so that it can be called from all the unsafe C code in UNIX. Such a translation is so pointless and error prone.

Note that this is exactly what is done now, the features of Rust for making safe interfaces makes Rust often a far nicer way to use C interfaces than C itself, without overhead (IMO, of course). See http://blog.rust-lang.org/2015/04/24/Rust-Once-Run-Everywher... , for example. Of course, zero-overhead Rust is only as safe as the C code it wraps, it can't (in general) protect against the C code not correctly implementing its stated contract(s).

Post reply on HN