๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

rsyslog Hardening Audit: Log Injection and TLS Peer Checks

rsyslog Hardening Audit: Log Injection and TLS Peer Checks

Ubuntu's USN-9527-1 covers several rsyslog issues at once, which makes it a good prompt for a proper rsyslog hardening pass instead of a bare apt upgrade. The notice lists log injection through unsanitized messages, control characters in kernel log messages, certificate common-name parsing that could let an attacker spoof a permitted peer, and handling of discarded rejected messages.

If you run a central collector that accepts TCP from dozens of hosts, you need three answers in one afternoon: am I patched, am I exposed, and what should the configuration look like regardless of the patch. The sections below take them in that order, starting with what the notice actually says.

What the rsyslog advisory actually covers

Four issues, four different attack surfaces

USN-9527-1 bundles four problems. Each one lands in a different part of the rsyslog configuration, which is why a single "is it patched" check is not enough.

  • Log injection through insufficient sanitizing of certain messages (GHSA-3w8v-2pjp-5r8p, reported by Rainer Gerhards). This touches the input modules, the code that turns received bytes into message text.
  • Control characters in kernel log messages (GHSA-pw82-9r22-hjqg), which could modify log files or possibly lead to code execution. This is the imklog path.
  • Common-name parsing that could allow spoofing as a permitted peer (GHSA-2j6x-gq6h-q426). This is the TLS permittedpeer matching on receivers and senders.
  • Handling of discarded rejected messages. This sits on the output and queue side. The notice is the authority on the details, so read it before drawing conclusions.

Which of your hosts are in scope

Ubuntu lists affected releases from 16.04 LTS to 26.10. Notices from Debian, Red Hat and other vendors may differ in wording, scope and fixed versions, so read the one for your distribution on its own terms. For Ubuntu, the Ubuntu security notices page has the USN, including the fixed package versions per release. Take version strings from there, not from a blog post.

Start with the collector, since it terminates TLS and takes network input. Then cover every host that loads imklog or imuxsock, which is nearly all of them. The configuration changes in the later sections are worth making even on fully patched machines.

Check whether the patched package is installed

Ubuntu and Debian: changelog and version check

Start with what is running and what is installed:

$ rsyslogd -v | head -1
rsyslogd  8.2312.0 (aka 2023.52) compiled with:

$ dpkg -l rsyslog | tail -1
ii  rsyslog  8.2312.0-3ubuntu9.1  amd64  reliable system and kernel logging daemon

$ apt list --upgradable 2>/dev/null | grep rsyslog
rsyslog/noble-updates,noble-security 8.2312.0-3ubuntu9.2 amd64 [upgradable from: 8.2312.0-3ubuntu9.1]

These version strings are illustrative. Compare yours with the fixed version in the notice. The changelog is a second check:

$ apt changelog rsyslog | head -40 | grep -E 'GHSA|USN|CVE'
$ sudo apt install --only-upgrade rsyslog

Ubuntu changelogs normally name the issue being fixed. If the grep returns nothing on an installed package, you are probably not on the fixed build.

RHEL, AlmaLinux and Rocky: errata check

$ rpm -q rsyslog
rsyslog-8.2102.0-117.el9.x86_64

$ dnf updateinfo list --security | grep rsyslog
$ rpm -q --changelog rsyslog | head -30
$ sudo dnf upgrade rsyslog

Red Hat backports fixes without bumping the upstream version, so the changelog and the vendor errata matter more than rsyslogd -v. Whether a given release is affected is Red Hat's call, not Ubuntu's.

Restarting the daemon after the update

A package upgrade usually restarts the service, but confirm it. A daemon still running the old binary is not patched.

$ ls -l /proc/$(pidof rsyslogd)/exe
lrwxrwxrwx 1 root root 0 ... /proc/812/exe -> /usr/sbin/rsyslogd (deleted)

$ systemctl show rsyslog -p ActiveEnterTimestamp
$ sudo systemctl restart rsyslog

A (deleted) suffix means the process predates the upgrade. needrestart reports the same thing across all services. For a fleet, ansible all -m command -a 'dpkg-query -W rsyslog' gives one line per host.

Map your rsyslog attack surface before changing anything

Which inputs are loaded and which ports listen

Find what is actually listening first, then which config lines put it there:

$ sudo ss -tulpn | grep rsyslogd
udp UNCONN 0 0 0.0.0.0:514  0.0.0.0:* users:(("rsyslogd",pid=812,fd=6))
tcp LISTEN 0 25 0.0.0.0:6514 0.0.0.0:* users:(("rsyslogd",pid=812,fd=8))

A UDP 514 listener on a collector you believed was TLS-only is a common finding. Now trace each listener to its source:

$ sudo grep -rnE 'module\(load|input\(type|\$ModLoad|\$InputTCP|\$UDPServer' \
    /etc/rsyslog.conf /etc/rsyslog.d/

The table shows who can feed each input and what to do about it.

InputWho can writeRiskMitigation
imuxsockAny local user via /dev/logForged or multi-line messagesEscape control characters, rate-limit
imklogKernel; /dev/kmsg is root-only to writeControl characters from kernel-logged textPatch, escape, restrict facilities
imudpAny reachable host, spoofable sourceNo peer identity at allRemove, or firewall to known senders
imtcpAny reachable host, or TLS-authenticated peersPeer spoofing if matching is weakTLS with strict peer checks
imjournal (RHEL)Whatever reaches journaldInherits journald's trustTreat journald as the front door

On RHEL-family systems, imjournal reads from journald, so anything a local service writes there reaches rsyslog. Audit what journald accepts as well.

Dump the effective configuration

Validate syntax with sudo rsyslogd -N1, which ends with End of config validation run. Bye. when clean. Do not rely on it to print a merged configuration. Instead, read the files in the order rsyslog includes them. Files in /etc/rsyslog.d/ are processed in lexical order, so 10- comes before 50-, and a rule in an early file can discard messages before a later file sees them.

$ sudo grep -nE '^\s*(module|input|include|\$IncludeConfig|\$ModLoad)' \
    /etc/rsyslog.conf /etc/rsyslog.d/*.conf

The shell expands the glob in sorted order, matching the include order. Watch for old $ModLoad lines mixed with the newer module(load=...) syntax. Both load modules, and the old ones are easy to miss.

Neutralise control characters and newlines in incoming messages

Global parser settings to set explicitly

Escaping of control characters on receive is on by default in current rsyslog, but set it explicitly so a later include file cannot change it quietly. Then audit for the opposite. Admins sometimes turn it off to keep multi-line output such as stack traces in one record.

$ sudo grep -rniE 'escapeControlCharacter|EscapeControlCharactersOnReceive|dropTrailingLF' \
    /etc/rsyslog.conf /etc/rsyslog.d/

Any match set to off is a finding. The better fix for multi-line logs is structured output (JSON) or imfile multi-line handling, not raw line feeds in the stream.

global(
  parser.escapeControlCharactersOnReceive="on"
  parser.controlCharacterEscapePrefix="#"
  parser.escapeControlCharacterTab="on"
  parser.dropTrailingLFOnReception="on"
)

The prefix defaults to #, so an LF is written as #012 and ESC as #033. The legacy form $EscapeControlCharactersOnReceive on still exists and may appear in older configs. A line feed matters because file output uses it as the record separator. A TCP frame with an embedded LF becomes two lines in the file, and the second one can imitate any host or program.

Testing injection with a crafted message

Run this against a lab collector, never production. The frame is octet-counted (58 bytes), so the LF sits inside a single message. This assumes an imtcp listener on the lab port.

$ printf '58 <14>1 2026-01-01T00:00:00Z host app - - - real\nFORGED line' \
    | nc -w1 lab-collector 10514

With escaping off you get two lines. With it on you get one. The exact line layout depends on your template, so treat this output as illustrative:

# escaping off
Jan  1 00:00:00 host app real
Jan  1 00:00:00 host app FORGED line

# escaping on
Jan  1 00:00:00 host app real#012FORGED line

Test the local path the same way:

$ logger $'a\x1b[31mred'
$ tail -1 /var/log/syslog
Jan  1 00:00:05 web01 user: a#033[31mred

Behaviour depends on rsyslog version and input module, so run both tests on your own build. Escaping protects the file on disk only. SIEM pipelines, Logstash filters and log viewers must also treat log content as untrusted input.

Lock down kernel log ingestion with imklog

Why kernel messages are a special case

The advisory lists control characters in kernel log messages as a separate issue. Kernel messages often embed text that someone else influences: hostnames, filenames, USB device strings, network interface names, and iptables LOG prefixes. That text reaches rsyslog through imklog, which sits outside the network and /dev/log paths you have already reviewed.

Containers widen the exposure. A container with write access to /dev/kmsg, such as a privileged one, can put its own lines into the kernel ring buffer. See Docker Security & Production Hardening for restricting device access.

Settings to review in imklog and the kernel

First, check how the module is loaded:

$ sudo grep -rn 'imklog' /etc/rsyslog.conf /etc/rsyslog.d/
module(load="imklog" permitnonkernelfacility="off")

When permitnonkernelfacility is on, messages written to /dev/kmsg with a non-kernel facility are passed on with that facility. Some stock configs set it to on, so check yours and set off unless you need it.

$ ls -l /dev/kmsg
crw-rw---- 1 root adm 1, 11 ... /dev/kmsg
$ sysctl kernel.dmesg_restrict
kernel.dmesg_restrict = 1

The mode varies by distribution, but it should never be world-writable. Persist the sysctl in /etc/sysctl.d/, for example kernel.dmesg_restrict = 1 in a 60-dmesg.conf. This setting restricts reading by unprivileged users, not writing to the ring buffer. The sysctl audit tool can check it across a fleet.

Finally, check who runs the daemon and who can read its output:

$ ps -o user,cmd -C rsyslogd
USER     CMD
syslog   /usr/sbin/rsyslogd -n -iNONE

$ sudo grep -rnE 'PrivDropTo|FileOwner|FileGroup|FileCreateMode' /etc/rsyslog.conf /etc/rsyslog.d/

Debian-family packages normally drop to syslog with $PrivDropToUser and $PrivDropToGroup, and RHEL-family systems often run as root. Look for $FileCreateMode 0640 so log files are not world-readable.

Fix TLS peer authentication on a central collector

Why anonymous and fingerprint-less TLS is not authentication

The gtls driver supports four authentication modes, and only some of them identify the peer.

  • anon: encryption only. Anyone who connects is accepted.
  • x509/certvalid: the certificate must chain to your CA, but any holder of such a certificate is accepted.
  • x509/name: the certificate must be valid and its name must match a permitted peer.
  • x509/fingerprint: the certificate must match a pinned fingerprint.

Only the last two answer "which host is this". For a small fleet, pin SHA-256 fingerprints, since they avoid name matching altogether. For a larger one, use x509/name with a private CA that issues certificates only to your log clients. That way, spoofing a name requires getting a certificate issued, as RFC 5425 expects for TLS transport for syslog.

A collector config with x509/name and explicit peers

global(
  DefaultNetstreamDriver="gtls"
  DefaultNetstreamDriverCAFile="/etc/rsyslog.d/tls/ca.pem"
  DefaultNetstreamDriverCertFile="/etc/rsyslog.d/tls/collector.pem"
  DefaultNetstreamDriverKeyFile="/etc/rsyslog.d/tls/collector.key"
)
module(load="imtcp" StreamDriver.Name="gtls" StreamDriver.Mode="1"
       StreamDriver.AuthMode="x509/name"
       PermittedPeer=["*.logs.example.net"])
input(type="imtcp" port="6514")

Keep patterns narrow. Never use a bare *, and never a wildcard wider than the domain your CA issues for. Given the common-name parsing issue in the notice, prefer certificates that carry proper subject alternative names, and check what your patched build matches. The client side pins the collector's name the same way:

action(type="omfwd" target="collector" port="6514" protocol="tcp"
       StreamDriver="gtls" StreamDriverMode="1"
       StreamDriverAuthMode="x509/name"
       StreamDriverPermittedPeers="collector.logs.example.net")

Verifying that an unlisted client is rejected

Check the server certificate first, then present a client certificate from your CA whose name is not permitted:

$ openssl s_client -connect collector:6514 -CAfile ca.pem </dev/null | grep -E 'Verify|subject'
$ openssl s_client -connect collector:6514 -CAfile ca.pem \
    -cert other.pem -key other.key </dev/null

The handshake may complete, because rsyslog checks the peer name after it. The proof is in the collector log:

$ journalctl -u rsyslog -n 5
rsyslogd: peer name not authorized - not permitted to talk to it. Names: other.example.org

That wording is only an example of the form, so confirm the exact message on your version. Also confirm that no messages from the test client reach the destination file.

Contain floods and rejected messages

Queue limits and rate limiting on network inputs

The advisory mentions handling of discarded rejected messages, so assume that the drop paths deserve a look. Set limits on each listener so one noisy or hostile sender cannot starve the rest. The values below are starting points, not recommendations for your volume.

global(maxMessageSize="8k")
module(load="imuxsock" SysSock.RateLimit.Interval="5" SysSock.RateLimit.Burst="500")
input(type="imtcp" port="6514" ratelimit.interval="5" ratelimit.burst="2000")

action(type="omfwd" target="siem.example.net" port="6514" protocol="tcp"
       action.resumeRetryCount="-1"
       queue.type="LinkedList" queue.filename="fwd_siem"
       queue.size="100000" queue.maxdiskspace="1g")

Setting queue.filename makes the queue disk-assisted, and queue.maxdiskspace caps it so a dead destination cannot fill /var. imudp takes the same ratelimit.* parameters, but if nothing needs UDP, delete its module(load="imudp") line instead. maxMessageSize already defaults to 8k, so state it explicitly to catch drift. Parameter names differ slightly between versions, so check the rsyslog documentation for yours.

Then restrict who can reach the port. Adjust the table and chain names to your ruleset:

nft add rule inet filter input ip saddr 10.20.0.0/24 tcp dport 6514 accept
nft add rule inet filter input tcp dport { 514, 6514 } drop

Discarded messages: make drops visible

Rate limits and full queues drop messages silently unless you count them. Enable impstats and write to its own file:

module(load="impstats" interval="60" severity="7"
       log.syslog="off" log.file="/var/log/rsyslog-stats.log")

Watch the discard counters, which should stay at zero. Counter names vary by module and version, so verify them against your own output. An illustrative excerpt:

imuxsock: origin=imuxsock submitted=412 ratelimit.discarded=37
action 1 queue: origin=core.queue size=0 enqueued=9120 full=0 discarded.full=0 discarded.nf=0 maxqsize=214

A rising ratelimit.discarded means a sender hit its limit, and a non-zero discarded.full means the queue overflowed. Alert on either.

Post-patch verification and a repeatable audit script

A small shell audit you can run across the fleet

Run it as root through Ansible or SSH and diff the output between hosts.

#!/usr/bin/env bash
C="/etc/rsyslog.conf /etc/rsyslog.d"
echo "== version";    rsyslogd -v | head -1
echo "== package";    dpkg-query -W rsyslog 2>/dev/null || rpm -q rsyslog
echo "== listeners";  ss -tulpn | grep rsyslogd
echo "== anon TLS";   grep -rniE 'AuthMode="?anon' $C
echo "== escaping";   grep -rniE 'EscapeControlCharactersOnReceive.*off' $C
echo "== imklog";     grep -rniE 'permitnonkernelfacility' $C
echo "== validation"; rsyslogd -N1 2>&1 | tail -1
echo "== user";       ps -o user= -C rsyslogd
== version
rsyslogd  8.2312.0 (aka 2023.52) compiled with:
== listeners
tcp LISTEN 0 25 0.0.0.0:6514 ... users:(("rsyslogd",pid=812,fd=8))
== anon TLS
== escaping
== imklog
/etc/rsyslog.conf:12:module(load="imklog" permitnonkernelfacility="off")
== validation
rsyslogd: End of config validation run. Bye.
== user
syslog

Empty sections under anon TLS and escaping are the good result. A missing permitnonkernelfacility line means the default applies.

What to do if you suspect past log tampering

Nothing in the advisory says exploitation has been seen, so treat this as due diligence. Local files on a host that accepted untrusted input are weak evidence. Compare them with the copy on the collector or SIEM, and look for:

  • Unexpected #012 or #033 sequences, which show escaping caught something.
  • Timestamps out of order within one file.
  • Identical message text arriving under different hostnames.
  • Connections in the collector log from peers you do not recognise.

Going forward, ship logs off-host to storage the sending host cannot rewrite. Pair that with auditd for a record of who touched the files.

rsyslog hardening checklist for this week

Work through these in order. Each one is a command or a one-line config change.

  1. Compare dpkg -l rsyslog or rpm -q rsyslog on every host with your vendor's notice, starting with collectors.
  2. Restart rsyslog wherever /proc/PID/exe shows (deleted).
  3. Run ss -tulpn | grep rsyslogd and remove every listener you cannot justify, especially UDP 514.
  4. Set parser.escapeControlCharactersOnReceive="on" explicitly, and remove any off setting.
  5. Set permitnonkernelfacility="off" on imklog and confirm kernel.dmesg_restrict = 1.
  6. Replace anon TLS with x509/name or x509/fingerprint, and prove an unlisted client is rejected.
  7. Add rate limits, bounded action queues and impstats, then alert on discard counters.
  8. Firewall 6514 to client subnets only.
  9. Schedule the audit script and keep its output.

If you want this as part of a wider baseline, the Linux security audit checklist covers the rest of the host, and Linux Security Hardening goes deeper on logging, auditd and kernel settings.

Frequently Asked Questions

How do I check which rsyslog version is installed and whether it includes the security fix?

Run rsyslogd -v | head -1 and dpkg -l rsyslog or rpm -q rsyslog. Compare the package version with the fixed version in your vendor's notice. On Ubuntu, apt changelog rsyslog should name the fix. On RHEL-family systems, check the changelog and errata, since backports keep the upstream version number.

Does rsyslog escape control characters and newlines by default?

Current versions escape control characters on receive by default, so an LF is written as #012. Do not rely on that alone. Set parser.escapeControlCharactersOnReceive="on" explicitly and grep for any off setting in included files. Behaviour can differ by version and input module, so test it on your build.

What is the difference between anon, x509/fingerprint and x509/name in rsyslog TLS?

anon encrypts but accepts any peer. x509/fingerprint accepts only certificates whose fingerprint you listed. x509/name requires a valid certificate whose name matches a permitted peer pattern. Only the last two identify the peer. Use fingerprints for small fleets and names with a private CA for larger ones.

Can a local user inject fake entries into my syslog files?

Yes, by design. Any local user can write to /dev/log with logger and choose the tag and message text. Escaping stops them from forging extra lines with newlines, but one fake line is still possible. Treat local logs as untrusted evidence, rate-limit imuxsock, and keep an off-host copy.

Should I replace rsyslog with journald-only logging to avoid these issues?

Not for this reason. Journald has its own parser, its own trust model and its own advisories. Dropping rsyslog also removes the TLS forwarding and filtering most collectors depend on. Patch, tighten the configuration, and remove inputs you do not use. Consolidate on journald only if you have no central collector and no rsyslog-specific needs.

Share this article:
Dorian Thorne
About the Author

Dorian Thorne

Cloud Infrastructure, Cloud Architecture, Infrastructure Automation, Technical Documentation

Dorian Thorne is a cloud infrastructure specialist and technical author focused on the design, deployment, and operation of scalable cloud-based systems.

He has extensive experience working with cloud platforms and modern infrastructure practices, including virtualized environments, cloud networking, identity and acces...

Cloud Computing Cloud Networking Identity and Access Management Infrastructure as Code System Reliability

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.