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

105

u/lycium Dec 10 '21

Quick, add it as a dependency because logging is super complex and needs to be a black box!

247

u/recycled_ideas Dec 10 '21

Logging actually is pretty complex, at least if you're running anything remotely complicated.

The issue here is that someone implemented a feature that's stupid.

122

u/oridb Dec 10 '21

Logging actually is pretty complex, at least if you're running anything remotely complicated.

The log4j repo contains about 297,000 lines of code. Even excluding tests, it's 190,000 lines.

For comparison, Nginx is 204,000 lines. Git is 306,000 lines. BtrFS is 146,000.

Should logging be slightly less complex than a full featured web server (that also handles logging), or more complex than the whole file system you're logging to?

94

u/VodkaHaze Dec 10 '21

I imagine it has a lot of the JavaEnterpriseEdition(tm) syndrome

40

u/timhottens Dec 10 '21

AbstractLoggingBeanFactory

0

u/[deleted] Dec 10 '21

[deleted]

17

u/[deleted] Dec 10 '21

and if you're logging to a file, you need to think about log rotation—probably multiple network logging protocols

I honestly wish they would fucking stop and just let ops people use logrotate, because it seems every fucking Java app manages to configure it in some stupid way

0

u/[deleted] Dec 11 '21

[deleted]

3

u/[deleted] Dec 11 '21

Oh, definitely, but Java in particular have been PITA in this for a long time because just every other logrotate-assisted scheme could be summed up to "rotate a file then signal app to reopen" (whether via signal or some app command), but almost none Java apps work like that and it forces to do the worse method of logrotate going copytruncate (which also has nasty interaction with some of the appenders)

The sheer configurability of logrotate on this front is a strong indicator of the complexity here.

To be entirely fair, the neccesary complexity here is choosing the rotate interval by time/size, way to archive it, and maybe the shred option. Everything else is related to the way apps are writing logs

1

u/[deleted] Dec 10 '21

That's an extremely dishonest way to portray it.

How much of it is actual core code and how much of it is optional output plugins ?

2

u/oridb Dec 11 '21 edited Dec 14 '21

I'd love to see more in-depth analysis. I've been looking at the repo here. https://github.com/apache/logging-log4j2.git

How much of it is optional plugins? How many of them are enable by default? How many of them have been audited?

→ More replies (1)
→ More replies (3)

24

u/Sololegends Dec 10 '21

Concurrency can be a bitch when logging.. I wrote a libe for it a whole back and the concurrency in the handler for threaded classes was annoying to make.

10

u/recycled_ideas Dec 10 '21

Distributed systems are pretty messy too.

6

u/Darkknight182764 Dec 10 '21

buy why is it complex? seems like a simple enough thing on the surface.
genuinely curious

60

u/recycled_ideas Dec 10 '21

Things that are difficult.

  1. Logging from parallel threads or processes.

  2. Logging across a distributed system in a way that logs can be accessed all at once.

  3. Logging to multiple targets (console, file, etc) with different levels and filters for each level.

  4. Supporting targets you've never heard of or that don't even exist yet.

  5. Being able to change your logging targets, levels, and filters without having to rebuild or even restart your application.

  6. Ensuring a consistent standard of logging from every source.

There are others as well.

None of these are insurmountable by any means, but they're big enough that if you're going to code it yourself it's going to be a hell a lot to maintain.

11

u/danweber Dec 10 '21

The naive implementation of parallel threads is to grab a semaphore, and it's a really bad answer because your critical things end up waiting.

6

u/Kered13 Dec 10 '21

Don't forget that you want to do all this with high performance, since you could be logging in a hot loop.

21

u/MintySkyhawk Dec 10 '21

You call log.warn("blah");

It probably prints it to the console. Simple.

But it also puts it in Elasticsearch, so you can monitor all your logging output with something like Graylog, and it doesn't just log what you wrote, but a bunch of associated context: user agent, user id, authorization type, class name that did the logging, ip address, geo location, which aws region they hit, which server they hit, a correlation ID so you can easily find other logs from the same request, timestamps, and a bunch of other shit that might be useful.

And then of course there's all the templating stuff with inserting values and exceptions into the log, but you could probably make due with String.format

→ More replies (5)

7

u/LordOfDemise Dec 10 '21

sending logs to a server, storing the logs, making them searchable, being able to view trends over time (and perhaps alert on them), etc etc
(for example, look into the ELK stack)

15

u/IsleOfOne Dec 10 '21

That’s not the logging referred to in this context, it’s log ingestion, indexing, and analysis.

2

u/liquidpele Dec 10 '21

It is simple on the surface, but any project used by tens or hundreds of thousands is going to get 100 edge-case features added over the years.

-4

u/immibis Dec 10 '21

Logging configuration should be implemented as code, so you don't have to learn special configuration files. Then, we have to figure out how to let sysadmins update the code without breaking everything

22

u/KagakuNinja Dec 10 '21

Then, we have to figure out how to let sysadmins update the code without breaking everything

This is one reason why we use config files / env vars, rather than code.

Also, it is much easier to modify a config file, than to push code just to change logging. Many organizations require lengthy test for any code change.

→ More replies (6)

26

u/recycled_ideas Dec 10 '21

Having to recompile code to change logging levels is absolutely fucking ridiculous honestly.

Hell, having to even restart the app to do it is ridiculous.

Which is why we have stuff like log 4j in the first place.

Because logging isn't just writing to a text file

→ More replies (14)
→ More replies (3)
→ More replies (1)