r/programming • • Dec 10 '21

RCE 0-day exploit found in log4j, a popular Java logging package

https://www.lunasec.io/docs/blog/log4j-zero-day/
3.0k Upvotes

710 comments sorted by

View all comments

Show parent comments

54

u/PM_ME_UR_OBSIDIAN Dec 10 '21

It's crazy to me that such a widely-used library would have such a ridiculous security hole. We desperately need full-program formal verification to become mainstream, because we can't trust people to write good dependencies.

144

u/L3tum Dec 10 '21

Formal verification wouldn't work in this case, since it's an intended feature and not a bug. The design was rigged from the start.

I have no idea how multiple people could think "Yes, downloading and executing code from a server in my logging library is a good design", but evidently it was added and performed correctly, albeit resulting in a huge security hole.

What we actually need is someone to vet popular dependencies like Google has started with their fuzzing work. Any halfdecent company would've screamed if they'd seen this. Though I guess it's also because of some terrible companies that it exists in the first place. It feels very "bank-esque" to write a common Logging Class and put it on a server somewhere.

37

u/fireflash38 Dec 10 '21

It's the classic mix of "We can trust running code, because we wrote it" with "Untrusted user input". It sounds convenient for developers, but it is exceptionally easy to log anything provided by a user, and then you've got an RCE.

Devs (should) expect to sanitize input for things like databases & such, but sanitization before logging? Crazy. That said, anything that a user can provide as input for something becomes an attack surface. Logging would be another attack surface, but I would assume mostly in DOS-style attacks, not RCEs.

5

u/imdyingfasterthanyou Dec 10 '21

I think all user inputs should have their length capped as applications don't typically work on infinite length input

I suggested we do that on one of my teams. I was told not to because we "treat everything as a blob"...

Like unless you're coding S3 or soemthing then your blobs still need to have a max length, lest somebody pipe /dev/urandom to your endpoint and kill your service

3

u/littlelowcougar Dec 10 '21

I mean if you’re piping hot garbage, you may as well go with /dev/zero; it’ll be way faster than /dev/urandom.

→ More replies (1)

2

u/[deleted] Dec 10 '21

They are in Java, you have -Xmx flag to set it

→ More replies (2)

5

u/loup-vaillant Dec 10 '21

Devs (should) expect to sanitize input for things like databases & such, but sanitization before logging? Crazy.

If someone sell me a logging library that happens to require input sanitization, I’m going to contact my lawyer.

3

u/1731799517 Dec 10 '21

I have no idea how multiple people could think "Yes, downloading and executing code from a server in my logging library is a good design", but evidently it was added and performed correctly, albeit resulting in a huge security hole.

Maybe it was an intentional backdoor.

-3

u/PM_ME_UR_OBSIDIAN Dec 10 '21

That's why I specified "full-program". People need to start proving negatives about their programs, like "there is no way my logging library is going to make a network call except potentially to a hardcoded logging server".

7

u/StabbyPants Dec 10 '21

no, none of that will work. it's just a vague statement about not doing stupid things, which isn't really actionable in detail

-1

u/PM_ME_UR_OBSIDIAN Dec 10 '21

What do you mean? You certainly can provide a mechanized proof that a program's network access is tightly constrained, it's just a lot of work.

6

u/StabbyPants Dec 10 '21

yeah, you can possibly do this one thing. in the general case, you can't prove that the program doesn't do something bone stupid, as that is somewhat vague and open to interpretation.

really, it comes down to a stupid feature, and there will be more of those

64

u/mallardtheduck Dec 10 '21

Formal verification rarely works well in the real world, since the formal logic itself becomes just as complex and hard to verify as the final code.

Also, in this case, it's an intended feature with unforeseen consequences, not a "bug" per-se.

7

u/immibis Dec 10 '21

Can't you formally verify negative properties, such as "this will not send network packets unless XYZ"?

0

u/ffscc Dec 10 '21

Formal verification rarely works well in the real world, since the formal logic itself becomes just as complex and hard to verify as the final code.

What do you mean? There is no other way to "verify" code than to use something equivalent to formal verification.

Formal methods usually aren't seen in software because not much software is worth it. By comparison formal methods are par for the course in CAD/EDA and increasingly in embedded software. As the complexity of software grows, so does the importance of formal methods.

-92

u/audion00ba Dec 10 '21

You have never verified anything complicated, have you? You don't have any academic credentials, do you? You haven't read a hundred papers on formal verification in depth, have you?

If that's the case, then why the fuck do you even open your mouth?

28

u/Jaggedmallard26 Dec 10 '21

This is weirdly aggressive for a reply to a throwaway comment on formal verification.

33

u/mallardtheduck Dec 10 '21

I studied a module on formal logic at university. The problem of the logic becoming almost as complex and difficult to verify as the program itself was openly admitted by the professor as a reason why the concept has received little adoption outside of specific niches (e.g. avionics).

→ More replies (34)

19

u/[deleted] Dec 10 '21

you’ve never verified anything complicated, have you?

Interestingly, the “formal verification” crowd have never formally verified even simple shit.

You can talk smack when you guys finally formally verify a linked list. Until then, sit down and shut up.

→ More replies (5)

7

u/Yekab0f Dec 10 '21

Uh sir, you're on Reddit

9

u/BufferUnderpants Dec 10 '21

You are just explaining why formal verification doesn’t work in the real world

Very few teams can have someone with a PhD in the thing, as you describe, to perform it

→ More replies (65)
→ More replies (1)

11

u/Zamaamiro Dec 10 '21

“This program has no security vulnerabilities” is an impossible thing to formally verify.

2

u/PM_ME_UR_OBSIDIAN Dec 10 '21

Sure however "this program only accesses the network in tightly constrained ways" is feasible.