Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qubes.Syslog #321

Closed
wants to merge 6 commits into from
Closed

qubes.Syslog #321

wants to merge 6 commits into from

Conversation

3hhh
Copy link
Contributor

@3hhh 3hhh commented Aug 6, 2021

This is a qrexec service to receive logs.

Fixes QubesOS/qubes-issues#830

All the doc is in the file header.

The packaging should work. I don't see the point of providing a default RPC policy for this qrexec service as it requires user intervention anyway.

This is a qrexec service to receive logs.

Fixes QubesOS/qubes-issues#830
@3hhh
Copy link
Contributor Author

3hhh commented Aug 6, 2021

KISS ftw!

if cat[0] == "C":
ret += "_"
else:
ret += ch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be more strict about it: just printable ASCII only. Rendering unicode is a complex thing, especially as you can combine various characters etc. Lets not expose whatever you use for viewing the logs...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like to exclude all non-American non-European logs.

What a receiving application should do: Don't assume anything about the encoding, consider it a byte stream and store it somewhere. Whatever viewer then will attempt to render that byte stream (probably less, vim or whatever pager journalctl uses). rsyslog seems to do it that way.

RFC5424 even clearly states:
"The character set used in MSG SHOULD be UNICODE, encoded using UTF-8
as specified in [RFC3629]. If the syslog application cannot encode
the MSG in Unicode, it MAY use any other encoding." RFC3164 doesn't have such encoding statements which probably resulted in the aforementioned rsyslog finding ("I have now simply taken the message as is and stuffed it into the MSG part").

I also think that users can understand the implications of working with potentially untrustworthy logs.

Btw if such a bug via non-ASCII characters existed, all Linux distributions would be affected by privilege escalation whenever a root user would view system logs via e.g. journalctl -b0. A user would just have to do something like logger "exploit here"... Not impossible, but rather unlikely from my point of view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that for a first version and until we are sure there is no security implication or side effect, I would suggest to restrict to what @marmarek said.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this limitation would affect some people more than others, but also, the main focus of Qubes is to provide reasonably secure system, and rendering unicode does have significant attack surface. This is not purely theoretical, see CVE-2019-18397 for example or almost yearly incident of an unicode wifi name or message crashing iPhones.
Excluding control characters reduces that risk significantly, but IMO not enough to have it allowed by default. That's also why we are not allowing unicode characters in window titles by default.

I also think that users can understand the implications of working with potentially untrustworthy logs.

No, I don't think so. Many (most?) can't understand that doing "curl | bash" is a horrible idea, or pasting something copied from a website directly to a shell (even if the command looks harmless: https://thejh.net/misc/website-terminal-copy-paste). So I definitely wouldn't expect people to understand that reading logs (which is seemingly much safer operation) may be risky if they come from untrusted place. When reading logs in a logvm, it may even not be obvious that they do come from untrusted place in the first place.

Btw if such a bug via non-ASCII characters existed, all Linux distributions would be affected by privilege escalation whenever a root user would view system logs via e.g. journalctl -b0. A user would just have to do something like logger "exploit here"... Not impossible, but rather unlikely from my point of view.

Here you go: https://seclists.org/fulldisclosure/2021/May/51
This one relies on control characters that you excluded, but just a proof that printing untrusted data in a terminal is still (in 2021) not safe yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that proves you right.

I made it ASCII by default now, but provided an option for unicode support.

If that approach is acceptable, I'd adjust my other PR accordingly.

Btw wrt security considerations:
The logs are written via the libc syslog routine, which then writes to the /dev/log unix socket, which usually journald listens to. rsyslog - if installed & configured - then obtains the logs via its imjournal module from journald and does whatever it's configured to do with them. Some distros (e.g. debian) don't use imjournal, but imuxsock instead.

@codecov
Copy link

codecov bot commented Aug 7, 2021

Codecov Report

Merging #321 (09ccd40) into master (f24ca2c) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #321   +/-   ##
=======================================
  Coverage   73.41%   73.41%           
=======================================
  Files           3        3           
  Lines         553      553           
=======================================
  Hits          406      406           
  Misses        147      147           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f24ca2c...09ccd40. Read the comment docs.

3hhh added 2 commits August 7, 2021 19:08
Better not rely on the OS encoding to include ASCII as subset.
@3hhh 3hhh requested a review from marmarek August 8, 2021 06:25
Comment on lines +43 to +44
`True`. This infers security risks with unicode parsing bugs in log
viewers.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option would be to losslessly escape them, so that no information is lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a sender may e.g. encode all logs in base64 and then decode it in his super trusted log viewer. ^^

Until such a log viewer exists however I'll assume that automatic escaping/unescaping only provides more bug opportunities in realistic viewers.

Btw a Qubes OS-like solution to this viewer distrust would be to accept unicode and then allow viewing the logs only in a dispVM.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw a Qubes OS-like solution to this viewer distrust would be to accept unicode and then allow viewing the logs only in a dispVM.

I love this solution!

syslog.openlog(ident=f"qubes.Syslog|{vm}[{pid}]", facility=syslog.LOG_USER)

input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding="utf-8")
for untrusted_line in input_stream:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows a trivial DoS by sending a very very very long line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I didn't bother about DoS as there's many opportunities in Qubes to do something like that (e.g. use the CPU a lot, I/O a lot, send tons of useless logs making journald rotate out the relevant ones, ...). Since it's easy to fix, I fixed it though.

@ddevz
Copy link
Contributor

ddevz commented Sep 22, 2021

Hey, I just wanted to say that this is very exciting and thank you for doing this!

@3hhh
Copy link
Contributor Author

3hhh commented Mar 18, 2023

@marmarek Does this PR still have a chance to go upstream or should I close it down?

@3hhh 3hhh closed this May 8, 2023
@er4z0r
Copy link

er4z0r commented May 17, 2023

Just found this. Too bad it is dead :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

logvm(s)
6 participants