Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <CADk+mPDqxw4_S___1F_+hk6r=SzhJMH_TDK_33hMmA3+k5wHgQ@mail.gmail.com>
Date: Tue, 1 Dec 2026 10:30:10 -0600
From: rgerhards@...scon.com
To: oss-security@...ts.openwall.com
Subject: rsyslog: 2 security advisories published 2026-12-01 (imklog)

Hello,

rsyslog has published the following security advisory(ies). The
distros list was notified in advance.

Fix: https://github.com/rsyslog/rsyslog/pull/8146

GHSA-pw82-9r22-hjqg: imklog passes control characters from kernel log
text unescaped: process names with terminal escape sequences reach log
files and terminals
Advisory: https://github.com/rsyslog/rsyslog/security/advisories/GHSA-pw82-9r22-hjqg

## Summary

rsyslog escapes control characters in received messages
(`$EscapeControlCharactersOnReceive`, on by default) in the message parser
(`SanitizeMsg()`). imklog builds its messages itself and does not mark them for
parsing, so this step never runs for kernel messages. Every byte the kernel
prints, except LF (line separator) and NUL (the kernel never emits it), goes
into the message text unchanged.

Through `/proc/kmsg` the kernel prints strings chosen by unprivileged
processes without escaping (only `/dev/kmsg` escapes them), above all the
task name (`comm`, 15 bytes, `prctl(PR_SET_NAME)` or the basename of the
executed file). A program named `ESC[31mRED CR` that crashes therefore puts a
raw ESC sequence and a carriage return into every rsyslog output that
receives kernel messages, for example `/var/log/kern.log` and
`/var/log/syslog`. Displaying such a file in a terminal executes the escape
sequences (colour, cursor movement, screen clearing, title changes, and
whatever else the terminal emulator interprets); CR lets the rest of a line
overwrite the start of the displayed line.

The same happens in every other output that writes `%msg%` raw, including
`:omusrmsg:` (wall) and forwarding.

## Affected configuration

- `module(load="imklog")` with default settings, reading `/proc/kmsg`.
  Loaded by default in Debian/Ubuntu-style configurations.
- Any action that writes `%msg%` without a template option such as
  `escape-cc`, `space-cc` or `drop-cc`; the built-in file, forward and wall
  templates do not escape.
- The kernel must print the attacker's string: for the segfault report
  `debug.exception-trace=1` (default), rate limited by the kernel
  (`printk_ratelimit`, by default 10 messages per 5 seconds).
- Attacker: any local user who can run a program. Writing to `/dev/kmsg` is not
  needed and not possible (mode 0644 root:root).

## Details

Source at a6c1f4023d (main, after 8.2610.0):

- `plugins/imklog/imklog.c:166-183` `enqMsg()`: `msgConstruct()` (flags 0,
  i.e. no `NEEDS_PARSING`), `MsgSetRawMsgWOSize(pMsg, msg)`,
  `MsgSetMSGoffs(pMsg, 0)`, tag and PRI set directly.
- `tools/rsyslogd.c:841`: `parser.ParseMsg()` only for messages with
  `NEEDS_PARSING`; `runtime/parser.c:729` `SanitizeMsg()` is only called from
  there. Kernel messages therefore never reach the escaping.
- `runtime/rsconf.c:222` `WallFmt` and `tools/omusrmsg.c:308`: the wall text is
  `"\r\n\7Message from syslogd@... \r\n %syslogtag%%msg%\n\r"` and is written
  to each terminal unchanged.

## Reproduction (performed 2026-11-14)

Environment: rsyslog main a6c1f4023d built twice (clang 18 with ASan/UBSan,
and gcc 13 `-O2 -D_FORTIFY_SOURCE=2`), WSL2 kernel 5.15.167.4.

1. Kernel output: as an unprivileged user a small program sets its name with
   `prctl(PR_SET_NAME)` to `ESC [31mRED CR` and dereferences NULL. The kernel
   output was captured with `klogctl(SYSLOG_ACTION_READ_ALL)`, which uses the
   same formatter as `/proc/kmsg` (reading `/proc/kmsg` needs CAP_SYSLOG).
   Captured (shown with `cat -v`):

   ```
   <6>[213394.704515] ^[[31mRED^M[2527574]: segfault at 0 ip ... in segv[...]
   ```
2. Replay: rsyslogd with `module(load="imklog" logpath="<fifo>")`, upstream
   default settings, omfile with a plain `%msg%` template. Output (`cat -v`):

   ```
   pri=kern.info tag=kernel: msg= ^[[31mRED^M[2527574]: segfault at 0 ...
   ```

   ESC and CR arrive byte for byte. Same with `permitnonkernelfacility="on"`
   and on both builds.
3. Chain with V1 (`permitnonkernelfacility="on"`): process name
   `<8>ESC[2JESC[HX` (clear screen, cursor home; 15 bytes). Captured kernel
   line and result:

   ```
   <6>[213531.071662] <8>^[[2J^[[HX[2592902]: segfault at 0 ...
   pri=user.emerg tag=kernel: msg=^[[2J^[[HX[2592902]: segfault at 0 ...
   ```

   The message matched a `*.emerg` action. That action was omfile standing in
   for `:omusrmsg:*`; the write to real terminals was not executed.

## Impact

Integrity of log files and of what administrators see when they display
them. A local unprivileged user can embed terminal control sequences and
carriage returns in kernel-tagged log lines: hide or rewrite displayed text,
clear the screen, change terminal state, and reach any terminal-emulator
handling of escape sequences on the viewing side.

Chained with V1 (`permitnonkernelfacility="on"` plus a `*.emerg :omusrmsg:*`
rule), the sequences are written to every logged-in terminal without any
user action, similar to the util-linux `wall` escape-sequence issue. This
requires that rsyslogd can open the terminals. On stock Ubuntu it cannot:
rsyslogd runs as user `syslog` (groups `syslog`, `adm`, no capabilities)
and terminals are mode 0620 owner/tty, so the broadcast is not delivered
there. It applies where rsyslogd keeps root privileges (upstream default).
With a `maxMessageSize` below about 1-2 KiB the split-line variant in V1
gives `kern.emerg` even with `permitnonkernelfacility="off"`.

LF cannot be injected into a single record through `/proc/kmsg`: the kernel
starts a new prefixed line, which rsyslog logs as a separate kernel message
(see V1). No memory safety impact.

## Fix direction

1. `plugins/imklog/imklog.c` `enqMsg()`: escape control characters in the
   message text, with the same semantics and global settings as
   `SanitizeMsg()` (`parser.escapeControlCharactersOnReceive`, escape
   prefix, 8-bit and tab handling). Preferably call the parser's
   `SanitizeMsg()` (exported in the parser interface) on the message after
   `MsgSetRawMsgWOSize()` instead of writing a second implementation.
This is the only place where imklog creates
   messages from kernel text, so it covers `/proc/kmsg`, `/dev/klog` (BSD)
   and any configured LogPath.
2. Apply the same to the split continuation fragments (they go through the
   same `enqMsg()`, so point 1 covers them once V1's fix keeps them in the
   normal path).
3. Regression test: LogPath-based imklog test with ESC, CR, BEL and DEL in the
   text; the output must contain the `#ooo` escapes.
4. Optional defence in depth (separate decision, not needed for this
   advisory): `WallFmt` / `StdUsrMsgFmt` could use `escape-cc` for
   `%syslogtag%` and `%msg%`, since `:omusrmsg:` writes to terminals.

Workaround until a fix: use `%msg:::escape-cc%` (or `space-cc` / `drop-cc`)
instead of `%msg%` in the templates of actions that receive kernel messages,
including a custom template for `:omusrmsg:`.

Affected: rsyslog >= 3.17.1, <= 8.2610.0
Fixed in: 2026-12-01 daily stable
Severity: Low, CVSS 3.1 2.8 (CVSS:3.1/AV:L/AC:L/PR:L/UI:R/S:U/C:N/I:L/A:N)

GHSA-vj8g-x55g-mp3x: imklog trusts a second `<PRI>` inside kernel log
text: a local user can choose the facility and severity of
kernel-tagged messages, or have them dropped
Advisory: https://github.com/rsyslog/rsyslog/security/advisories/GHSA-vj8g-x55g-mp3x

## Summary

imklog reads kernel log lines of the form `<d>[ seconds.micros] text`. After
removing the timestamp (default), `Syslog()` checks whether the remaining text
starts with a second `<NN>` and, if `NN` is a valid PRI of 8 or more, uses it
as the message's facility and severity instead of the kernel's own `<d>`. This
was added in 2011 for systemd writing `<NN>`-prefixed records into
`/dev/kmsg` on kernels that did not yet parse that prefix themselves; current
kernels do.

The text after the kernel prefix is not kernel-controlled in general. The
kernel prints strings chosen by unprivileged processes, most notably the task
name (`comm`, 15 bytes, set with `prctl(PR_SET_NAME)` or by the basename of
the executed file). A process that crashes produces, by default on x86 and
arm64, a line that starts with its name:

```
<6>[213394.693709] <33>forged[2527549]: segfault at 0 ip ... in segv[...]
```

imklog turns this into `auth.alert` with tag `kernel:`. Because `/proc/kmsg`
starts every line of a record with the record's prefix, a line feed inside
the name gives the attacker the start of a new line inside any kernel message
that prints `comm`, not only at the start of the segfault line.

Consequences depend on `permitnonkernelfacility`:

- `on` (Ubuntu's distribution default): the attacker chooses any non-kernel
  facility and any severity. Forged `auth.*`, `authpriv.*`, `mail.*`,
  `user.emerg` etc. records are routed by the facility/severity filters, for
  example into `/var/log/auth.log`, to remote collectors, or to `*.emerg`
  actions.
- `off` (upstream default): the line is silently discarded, because its
  facility is no longer `kern`. The attacker can suppress its own segfault
  line and the remainder of any kernel line after an LF in its name.

Only the facility can be chosen freely with a value of 8 or more; `kern.*`
cannot be forged through this branch. The tag stays `kernel:`, so a forged
record is visibly attributed to the kernel. Writing to `/dev/kmsg` is not
part of the attack: it is mode 0644 root:root and not writable by
unprivileged users.

## Affected configuration

- `module(load="imklog")` reading `/proc/kmsg` (Linux default path).
- Default `keepkerneltimestamp="off"` (or a kernel that prints no printk
  timestamps). With `keepkerneltimestamp="on"` on a timestamping kernel the
  branch does not match.
- Forgery: `permitnonkernelfacility="on"`. Ubuntu ships
  `module(load="imklog" permitnonkernelfacility="on")` in `/etc/rsyslog.conf`
  (verified on Ubuntu 24.04, rsyslog 8.2312.0-3ubuntu9.4) and
  `*.emerg :omusrmsg:*` in `50-default.conf`.
- Suppression only: upstream default `permitnonkernelfacility="off"`.
- The kernel must print the attacker's string: the segfault report requires
  `debug.exception-trace=1` (default) and is rate limited by the kernel
  (`printk_ratelimit`, by default 10 messages per 5 seconds).
- Attacker: any local user who can run a program.
- Note for Ubuntu: rsyslogd drops privileges to user `syslog` (groups
  `syslog`, `adm`, no capabilities). Terminal devices are mode 0620 owner/tty,
  so `:omusrmsg:*` cannot open them and the wall broadcast of a forged
  `user.emerg` does not reach terminals there. It does where rsyslogd runs as
  root (upstream default, no privilege drop) and `permitnonkernelfacility` is
  on.
- BSD (`/dev/klog`): a related residual exists and is not fixed by the patch
  for this advisory; see Fix direction point 4 (static analysis only).

## Details

Source at a6c1f4023d (main, after 8.2610.0):

- `plugins/imklog/bsd.c:246-269` `readklog()`: `read()` from `/proc/kmsg`,
  split on `\n`, each line to `submitSyslog()`; an unterminated tail of
  `maxMessageSize - 1` bytes is submitted on its own and the rest of that line
  becomes the next "line".
- `bsd.c:85-123` `submitSyslog()`: detects `<d>[ secs.usecs]` and, unless
  `keepkerneltimestamp` is on, `memmove`s the text over the timestamp, giving
  `<d> text`.
- `plugins/imklog/imklog.c:256-266` `Syslog()`: if `pMsg[3] == '<'` or
  `pMsg[3] == ' ' && pMsg[4] == '<'`, `parsePRI()` at that position; a value
  `>= 8 && <= 191` replaces `priority`, and the message text starts after it.
- `imklog.c:274`: non-`kern` facility -> discarded unless
  `permitnonkernelfacility` is on.
- `imklog.c:176-183` `enqMsg()`: text, tag `kernel:` and the chosen PRI go to
  the message unchanged.

Second path to an attacker-controlled PRI (independent of the branch above):
a line longer than `maxMessageSize - 1` is split, and the continuation is
passed through the primary `parsePRI()` as if it were a new kernel line. Text
`<0>` at the split offset becomes `kern.emerg`, also with
`permitnonkernelfacility="off"`. This only applies when `maxMessageSize` is
smaller than the kernel's per-record size (about 1 KiB on 5.15, 2 KiB on
newer kernels); the default of 8096 is not affected. The attacker controls
long kernel lines mainly through file names (for example the mapping name in
the segfault report).

## Reproduction (performed 2026-11-14)

Environment: rsyslog main a6c1f4023d built twice (clang 18 with ASan/UBSan,
and gcc 13 `-O2 -D_FORTIFY_SOURCE=2`), WSL2 kernel 5.15.167.4.

1. Kernel output: as an unprivileged user (uid 1000) a small program sets its
   name with `prctl(PR_SET_NAME)` and dereferences NULL. Names used:
   `<33>forged`, `\n<8>EMERG`. The kernel output was captured with
   `klogctl(SYSLOG_ACTION_READ_ALL)`, which uses the same formatter as
   `/proc/kmsg` (reading `/proc/kmsg` itself needs CAP_SYSLOG, which the test
   account does not have). Captured lines:

   ```
   <6>[213394.693709] <33>forged[2527549]: segfault at 0 ip ... in segv[...]
   <6>[213394.698465]
   <6>[213394.698465] <8>EMERG[2527557]: segfault at 0 ip ... in segv[...]
   <4>[213394.698495] CPU: 14 PID: 2527557 Comm:
   <4>[213394.698495] <8>EMERG Not tainted 5.15.167.4-microsoft-standard-WSL2 #1
   ```

   The last two lines show the LF effect inside a register dump line printed
   by this kernel.
2. Replay: rsyslogd with `module(load="imklog" logpath="<fifo>")`, the captured
   lines written into the FIFO, output through omfile with template
   `pri=%syslogfacility-text%.%syslogseverity-text% tag=%syslogtag% msg=%msg%`.
3. Results with `permitnonkernelfacility="on"`:

   ```
   pri=auth.alert tag=kernel: msg=forged[2527549]: segfault at 0 ...
   pri=user.emerg tag=kernel: msg=EMERG[2527557]: segfault at 0 ...
   pri=user.emerg tag=kernel: msg=EMERG Not tainted 5.15.167.4-...
   ```

   Both `user.emerg` lines also matched a `*.emerg` action (omfile standing in
   for `:omusrmsg:*`). With the upstream default the same three lines are
   absent from the output; the surrounding kernel lines are logged normally.
   Identical results on both builds.
4. Split continuation: `maxMessageSize="1024"`, upstream default imklog
   settings, one line with `<0>FORGED kernel emergency` at byte offset 1024:
   second message `pri=kern.emerg msg=FORGED kernel emergency`, matched by
   `*.emerg`. This was fed from a file, not from a real kernel record.

Not executed: reading the live `/proc/kmsg`; the terminal write of
`:omusrmsg:*`; BSD (`/dev/klog`), where the same `Syslog()` code is used.

## Impact

Integrity of log records. A local unprivileged user can

- with `permitnonkernelfacility="on"`: create kernel-tagged records with an
  arbitrary non-kernel facility and any severity, so that they land in
  facility-specific files (for example auth.log), trigger severity-based
  actions (`*.emerg`, alerting, forwarding rules) or are excluded from
  `kern.*` destinations;
- with the upstream default: have kernel lines (its own segfault report, and
  the part after an LF in its name in other kernel messages) silently
  dropped.

The text of the forged record is limited by what the kernel prints around
the name; the attacker controls 15 bytes of it. Not new: a local user can
already log with any facility and severity through `/dev/log`, but those
records carry the user's own tag and pass through the regular parser; the new
part is that kernel-input records, which rulesets often treat as trusted, get
an attacker-chosen PRI. No memory safety impact.

## Fix direction

All points in `plugins/imklog/`:

1. `imklog.c` `Syslog()`: remove the secondary-PRI branch, or make it an
   opt-in parameter that is off by default and documented as unsafe with
   `/proc/kmsg`. Its use case (systemd on kernels older than 3.5 writing
   `<NN>` into `/dev/kmsg`) is obsolete. Covers both shapes `<d><NN>` and
   `<d> <NN>`.
2. `bsd.c` `submitSyslog()`: the timestamp strip creates the `<d> <NN>`
   shape; after point 1 it is harmless, but any remaining PRI logic must run
   before the strip or ignore its result.
3. `bsd.c` `readklog()`: never PRI-parse a continuation fragment. When a line
   is split at `maxMessageSize - 1`, or a partial line is flushed on
   EINTR/EAGAIN/EOF, the following fragment must be submitted with the
   previous line's PRI (or `kern.info`) and without `parsePRI()`.
4. BSD (`/dev/klog`): points 1 and 3 apply there too, because the BSD shim
   uses the same `Syslog()` and `readklog()`. They do not close the whole
   issue on BSD. On FreeBSD, lines from kernel `printf()` (msgbuf priority
   -1) carry no `<N>` prefix, so imklog still parses a leading PRI from the
   text itself. The process name (`p_comm`, the basename of the executed
   file) may contain a line feed, so a kernel `printf()` that includes it can
   start a new line with an attacker-chosen `<0>`: `kern.emerg`, or a dropped
   line for a non-kernel facility with `permitnonkernelfacility="off"`. This
   is a known residual that the current patch does not fix. It was found by
   static analysis only and was not tested.
5. Regression tests: LogPath-based imklog tests (FIFO or file) for
   `<6> <8>x` and `<6><8>x` (must stay `kern.info`), for a line longer than
   `maxMessageSize` with `<0>` at the split offset (must not become
   `kern.emerg`), with both values of `permitnonkernelfacility`.
6. Documentation: note in the imklog docs that `/proc/kmsg` text after the
   kernel prefix may contain user-chosen strings.

Workarounds until a fix: `keepkerneltimestamp="on"` (closes the branch on
timestamping kernels); keep `permitnonkernelfacility="off"` (turns forgery
into suppression); keep `maxMessageSize` at or above 8 KiB.

Affected: rsyslog >= 5.9.0, <= 8.2610.0
Fixed in: 2026-12-01 daily stable
Severity: Low, CVSS 3.1 3.3 (CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:L/A:N)

Regards,
the rsyslog security team
(sent automatically by the rsyslog release system)

Powered by blists - more mailing lists

Please check out the Open Source Software Security Wiki, which is counterpart to this mailing list.

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.