{"id":"GHSA-pw82-9r22-hjqg","aliases":["DHI-3pnf-qbzr-p5mf-admz"],"status":"published","description":"## Summary\n\nrsyslog escapes control characters in received messages\n(`$EscapeControlCharactersOnReceive`, on by default) in the message parser\n(`SanitizeMsg()`). imklog builds its messages itself and does not mark them for\nparsing, so this step never runs for kernel messages. Every byte the kernel\nprints, except LF (line separator) and NUL (the kernel never emits it), goes\ninto the message text unchanged.\n\nThrough `/proc/kmsg` the kernel prints strings chosen by unprivileged\nprocesses without escaping (only `/dev/kmsg` escapes them), above all the\ntask name (`comm`, 15 bytes, `prctl(PR_SET_NAME)` or the basename of the\nexecuted file). A program named `ESC[31mRED CR` that crashes therefore puts a\nraw ESC sequence and a carriage return into every rsyslog output that\nreceives kernel messages, for example `/var/log/kern.log` and\n`/var/log/syslog`. Displaying such a file in a terminal executes the escape\nsequences (colour, cursor movement, screen clearing, title changes, and\nwhatever else the terminal emulator interprets); CR lets the rest of a line\noverwrite the start of the displayed line.\n\nThe same happens in every other output that writes `%msg%` raw, including\n`:omusrmsg:` (wall) and forwarding.\n\n## Affected configuration\n\n- `module(load=\"imklog\")` with default settings, reading `/proc/kmsg`.\n  Loaded by default in Debian/Ubuntu-style configurations.\n- Any action that writes `%msg%` without a template option such as\n  `escape-cc`, `space-cc` or `drop-cc`; the built-in file, forward and wall\n  templates do not escape.\n- The kernel must print the attacker's string: for the segfault report\n  `debug.exception-trace=1` (default), rate limited by the kernel\n  (`printk_ratelimit`, by default 10 messages per 5 seconds).\n- Attacker: any local user who can run a program. Writing to `/dev/kmsg` is not\n  needed and not possible (mode 0644 root:root).\n\n## Details\n\nSource at a6c1f4023d (main, after 8.2610.0):\n\n- `plugins/imklog/imklog.c:166-183` `enqMsg()`: `msgConstruct()` (flags 0,\n  i.e. no `NEEDS_PARSING`), `MsgSetRawMsgWOSize(pMsg, msg)`,\n  `MsgSetMSGoffs(pMsg, 0)`, tag and PRI set directly.\n- `tools/rsyslogd.c:841`: `parser.ParseMsg()` only for messages with\n  `NEEDS_PARSING`; `runtime/parser.c:729` `SanitizeMsg()` is only called from\n  there. Kernel messages therefore never reach the escaping.\n- `runtime/rsconf.c:222` `WallFmt` and `tools/omusrmsg.c:308`: the wall text is\n  `\"\\r\\n\\7Message from syslogd@... \\r\\n %syslogtag%%msg%\\n\\r\"` and is written\n  to each terminal unchanged.\n\n## Reproduction (performed 2026-11-14)\n\nEnvironment: rsyslog main a6c1f4023d built twice (clang 18 with ASan/UBSan,\nand gcc 13 `-O2 -D_FORTIFY_SOURCE=2`), WSL2 kernel 5.15.167.4.\n\n1. Kernel output: as an unprivileged user a small program sets its name with\n   `prctl(PR_SET_NAME)` to `ESC [31mRED CR` and dereferences NULL. The kernel\n   output was captured with `klogctl(SYSLOG_ACTION_READ_ALL)`, which uses the\n   same formatter as `/proc/kmsg` (reading `/proc/kmsg` needs CAP_SYSLOG).\n   Captured (shown with `cat -v`):\n\n   ```\n   \u003c6\u003e[213394.704515] ^[[31mRED^M[2527574]: segfault at 0 ip ... in segv[...]\n   ```\n2. Replay: rsyslogd with `module(load=\"imklog\" logpath=\"\u003cfifo\u003e\")`, upstream\n   default settings, omfile with a plain `%msg%` template. Output (`cat -v`):\n\n   ```\n   pri=kern.info tag=kernel: msg= ^[[31mRED^M[2527574]: segfault at 0 ...\n   ```\n\n   ESC and CR arrive byte for byte. Same with `permitnonkernelfacility=\"on\"`\n   and on both builds.\n3. Chain with V1 (`permitnonkernelfacility=\"on\"`): process name\n   `\u003c8\u003eESC[2JESC[HX` (clear screen, cursor home; 15 bytes). Captured kernel\n   line and result:\n\n   ```\n   \u003c6\u003e[213531.071662] \u003c8\u003e^[[2J^[[HX[2592902]: segfault at 0 ...\n   pri=user.emerg tag=kernel: msg=^[[2J^[[HX[2592902]: segfault at 0 ...\n   ```\n\n   The message matched a `*.emerg` action. That action was omfile standing in\n   for `:omusrmsg:*`; the write to real terminals was not executed.\n\n## Impact\n\nIntegrity of log files and of what administrators see when they display\nthem. A local unprivileged user can embed terminal control sequences and\ncarriage returns in kernel-tagged log lines: hide or rewrite displayed text,\nclear the screen, change terminal state, and reach any terminal-emulator\nhandling of escape sequences on the viewing side.\n\nChained with V1 (`permitnonkernelfacility=\"on\"` plus a `*.emerg :omusrmsg:*`\nrule), the sequences are written to every logged-in terminal without any\nuser action, similar to the util-linux `wall` escape-sequence issue. This\nrequires that rsyslogd can open the terminals. On stock Ubuntu it cannot:\nrsyslogd runs as user `syslog` (groups `syslog`, `adm`, no capabilities)\nand terminals are mode 0620 owner/tty, so the broadcast is not delivered\nthere. It applies where rsyslogd keeps root privileges (upstream default).\nWith a `maxMessageSize` below about 1-2 KiB the split-line variant in V1\ngives `kern.emerg` even with `permitnonkernelfacility=\"off\"`.\n\nLF cannot be injected into a single record through `/proc/kmsg`: the kernel\nstarts a new prefixed line, which rsyslog logs as a separate kernel message\n(see V1). No memory safety impact.\n\n## Fix direction\n\n1. `plugins/imklog/imklog.c` `enqMsg()`: escape control characters in the\n   message text, with the same semantics and global settings as\n   `SanitizeMsg()` (`parser.escapeControlCharactersOnReceive`, escape\n   prefix, 8-bit and tab handling). Preferably call the parser's\n   `SanitizeMsg()` (exported in the parser interface) on the message after\n   `MsgSetRawMsgWOSize()` instead of writing a second implementation. This is the only place where imklog creates\n   messages from kernel text, so it covers `/proc/kmsg`, `/dev/klog` (BSD)\n   and any configured LogPath.\n2. Apply the same to the split continuation fragments (they go through the\n   same `enqMsg()`, so point 1 covers them once V1's fix keeps them in the\n   normal path).\n3. Regression test: LogPath-based imklog test with ESC, CR, BEL and DEL in the\n   text; the output must contain the `#ooo` escapes.\n4. Optional defence in depth (separate decision, not needed for this\n   advisory): `WallFmt` / `StdUsrMsgFmt` could use `escape-cc` for\n   `%syslogtag%` and `%msg%`, since `:omusrmsg:` writes to terminals.\n\nWorkaround until a fix: use `%msg:::escape-cc%` (or `space-cc` / `drop-cc`)\ninstead of `%msg%` in the templates of actions that receive kernel messages,\nincluding a custom template for `:omusrmsg:`.","facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":false},"published":"2026-12-02T14:27:24Z","modified":"2026-12-04T16:45:25Z","affected":[{"source":"osv","ecosystem":"Docker Hardened Images:Debian:13","package":"ascender-25","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"25.6.3-0"}]}],"versions":["25.6.3-0","25.6.3-1","25.6.3-10","25.6.3-11","25.6.3-12","25.6.3-2","25.6.3-3","25.6.3-4","25.6.3-5","25.6.3-6","25.6.3-7","25.6.3-8","25.6.3-9"]}],"references":[{"url":"https://scout.docker.com/v/DHI-3pnf-qbzr-p5mf-admz","tags":["advisory"]},{"url":"https://github.com/rsyslog/rsyslog/security/advisories/GHSA-pw82-9r22-hjqg","tags":["advisory"]}],"sources":{"osv":[{"id":"DHI-3pnf-qbzr-p5mf-admz","upstream":["GHSA-pw82-9r22-hjqg"],"title":"## Summary","description":"## Summary\n\nrsyslog escapes control characters in received messages\n(`$EscapeControlCharactersOnReceive`, on by default) in the message parser\n(`SanitizeMsg()`). imklog builds its messages itself and does not mark them for\nparsing, so this step never runs for kernel messages. Every byte the kernel\nprints, except LF (line separator) and NUL (the kernel never emits it), goes\ninto the message text unchanged.\n\nThrough `/proc/kmsg` the kernel prints strings chosen by unprivileged\nprocesses without escaping (only `/dev/kmsg` escapes them), above all the\ntask name (`comm`, 15 bytes, `prctl(PR_SET_NAME)` or the basename of the\nexecuted file). A program named `ESC[31mRED CR` that crashes therefore puts a\nraw ESC sequence and a carriage return into every rsyslog output that\nreceives kernel messages, for example `/var/log/kern.log` and\n`/var/log/syslog`. Displaying such a file in a terminal executes the escape\nsequences (colour, cursor movement, screen clearing, title changes, and\nwhatever else the terminal emulator interprets); CR lets the rest of a line\noverwrite the start of the displayed line.\n\nThe same happens in every other output that writes `%msg%` raw, including\n`:omusrmsg:` (wall) and forwarding.\n\n## Affected configuration\n\n- `module(load=\"imklog\")` with default settings, reading `/proc/kmsg`.\n  Loaded by default in Debian/Ubuntu-style configurations.\n- Any action that writes `%msg%` without a template option such as\n  `escape-cc`, `space-cc` or `drop-cc`; the built-in file, forward and wall\n  templates do not escape.\n- The kernel must print the attacker's string: for the segfault report\n  `debug.exception-trace=1` (default), rate limited by the kernel\n  (`printk_ratelimit`, by default 10 messages per 5 seconds).\n- Attacker: any local user who can run a program. Writing to `/dev/kmsg` is not\n  needed and not possible (mode 0644 root:root).\n\n## Details\n\nSource at a6c1f4023d (main, after 8.2610.0):\n\n- `plugins/imklog/imklog.c:166-183` `enqMsg()`: `msgConstruct()` (flags 0,\n  i.e. no `NEEDS_PARSING`), `MsgSetRawMsgWOSize(pMsg, msg)`,\n  `MsgSetMSGoffs(pMsg, 0)`, tag and PRI set directly.\n- `tools/rsyslogd.c:841`: `parser.ParseMsg()` only for messages with\n  `NEEDS_PARSING`; `runtime/parser.c:729` `SanitizeMsg()` is only called from\n  there. Kernel messages therefore never reach the escaping.\n- `runtime/rsconf.c:222` `WallFmt` and `tools/omusrmsg.c:308`: the wall text is\n  `\"\\r\\n\\7Message from syslogd@... \\r\\n %syslogtag%%msg%\\n\\r\"` and is written\n  to each terminal unchanged.\n\n## Reproduction (performed 2026-11-14)\n\nEnvironment: rsyslog main a6c1f4023d built twice (clang 18 with ASan/UBSan,\nand gcc 13 `-O2 -D_FORTIFY_SOURCE=2`), WSL2 kernel 5.15.167.4.\n\n1. Kernel output: as an unprivileged user a small program sets its name with\n   `prctl(PR_SET_NAME)` to `ESC [31mRED CR` and dereferences NULL. The kernel\n   output was captured with `klogctl(SYSLOG_ACTION_READ_ALL)`, which uses the\n   same formatter as `/proc/kmsg` (reading `/proc/kmsg` needs CAP_SYSLOG).\n   Captured (shown with `cat -v`):\n\n   ```\n   \u003c6\u003e[213394.704515] ^[[31mRED^M[2527574]: segfault at 0 ip ... in segv[...]\n   ```\n2. Replay: rsyslogd with `module(load=\"imklog\" logpath=\"\u003cfifo\u003e\")`, upstream\n   default settings, omfile with a plain `%msg%` template. Output (`cat -v`):\n\n   ```\n   pri=kern.info tag=kernel: msg= ^[[31mRED^M[2527574]: segfault at 0 ...\n   ```\n\n   ESC and CR arrive byte for byte. Same with `permitnonkernelfacility=\"on\"`\n   and on both builds.\n3. Chain with V1 (`permitnonkernelfacility=\"on\"`): process name\n   `\u003c8\u003eESC[2JESC[HX` (clear screen, cursor home; 15 bytes). Captured kernel\n   line and result:\n\n   ```\n   \u003c6\u003e[213531.071662] \u003c8\u003e^[[2J^[[HX[2592902]: segfault at 0 ...\n   pri=user.emerg tag=kernel: msg=^[[2J^[[HX[2592902]: segfault at 0 ...\n   ```\n\n   The message matched a `*.emerg` action. That action was omfile standing in\n   for `:omusrmsg:*`; the write to real terminals was not executed.\n\n## Impact\n\nIntegrity of log files and of what administrators see when they display\nthem. A local unprivileged user can embed terminal control sequences and\ncarriage returns in kernel-tagged log lines: hide or rewrite displayed text,\nclear the screen, change terminal state, and reach any terminal-emulator\nhandling of escape sequences on the viewing side.\n\nChained with V1 (`permitnonkernelfacility=\"on\"` plus a `*.emerg :omusrmsg:*`\nrule), the sequences are written to every logged-in terminal without any\nuser action, similar to the util-linux `wall` escape-sequence issue. This\nrequires that rsyslogd can open the terminals. On stock Ubuntu it cannot:\nrsyslogd runs as user `syslog` (groups `syslog`, `adm`, no capabilities)\nand terminals are mode 0620 owner/tty, so the broadcast is not delivered\nthere. It applies where rsyslogd keeps root privileges (upstream default).\nWith a `maxMessageSize` below about 1-2 KiB the split-line variant in V1\ngives `kern.emerg` even with `permitnonkernelfacility=\"off\"`.\n\nLF cannot be injected into a single record through `/proc/kmsg`: the kernel\nstarts a new prefixed line, which rsyslog logs as a separate kernel message\n(see V1). No memory safety impact.\n\n## Fix direction\n\n1. `plugins/imklog/imklog.c` `enqMsg()`: escape control characters in the\n   message text, with the same semantics and global settings as\n   `SanitizeMsg()` (`parser.escapeControlCharactersOnReceive`, escape\n   prefix, 8-bit and tab handling). Preferably call the parser's\n   `SanitizeMsg()` (exported in the parser interface) on the message after\n   `MsgSetRawMsgWOSize()` instead of writing a second implementation. This is the only place where imklog creates\n   messages from kernel text, so it covers `/proc/kmsg`, `/dev/klog` (BSD)\n   and any configured LogPath.\n2. Apply the same to the split continuation fragments (they go through the\n   same `enqMsg()`, so point 1 covers them once V1's fix keeps them in the\n   normal path).\n3. Regression test: LogPath-based imklog test with ESC, CR, BEL and DEL in the\n   text; the output must contain the `#ooo` escapes.\n4. Optional defence in depth (separate decision, not needed for this\n   advisory): `WallFmt` / `StdUsrMsgFmt` could use `escape-cc` for\n   `%syslogtag%` and `%msg%`, since `:omusrmsg:` writes to terminals.\n\nWorkaround until a fix: use `%msg:::escape-cc%` (or `space-cc` / `drop-cc`)\ninstead of `%msg%` in the templates of actions that receive kernel messages,\nincluding a custom template for `:omusrmsg:`.\n","status":"published","published":"2026-12-02T14:27:24Z","modified":"2026-12-04T16:45:25.074569103Z","updated_at":"2026-12-04T17:18:58.764469Z"}]}}
