Skip to content

Add RPC for injecting messages in the system log - #1643

Merged
troglobit merged 5 commits into
mainfrom
rpc-log
Sep 23, 2026
Merged

troglobit merged 5 commits into
mainfrom
rpc-log

Conversation

@troglobit

@troglobit troglobit commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Test systems and scripts have had no clean way to leave a mark in a device's log, short of SSH and logger(1). This adds an RPC that hands a message to the local syslog daemon, exposing the full RFC 5424 header: severity, app-name, msgid, and structured data. Defaults follow logger, user.notice, with app-name defaulting to the calling user. Messages are time stamped on arrival and follow the configured /syslog filtering and forwarding rules, so the device decides where they end up, not the caller.

  • confd: new infix-syslog.yang revision with the log RPC
  • cli: admin-exec log [severity S] [msgid M] MESSAGE.
  • infamy: target.log() helper, four tests converted from SSH + logger
  • test: new syslog/rpc_log case verifying header fields and defaults

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

@troglobit
troglobit marked this pull request as draft September 15, 2026 15:27
@troglobit troglobit changed the title Rpc log Add infix-syslog:log RPC for injecting messages in the system log Sep 16, 2026
@troglobit troglobit changed the title Add infix-syslog:log RPC for injecting messages in the system log Add RPC for injecting messages in the system log Sep 16, 2026
@troglobit
troglobit marked this pull request as ready for review September 16, 2026 08:43
@troglobit troglobit linked an issue Sep 16, 2026 that may be closed by this pull request

@mattiaswal mattiaswal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Security review of the new log RPC. Verified against libyang (yanglint) with the exact type definitions from this PR, and against the sysklogd 2.7.2 sources Infix ships. Details inline; summary ranked by severity:

  1. High: format string injection via msgid. libsyslog's vsyslogp_r() concatenates msgid into the printf format it hands to vsnprintf(), and the pattern [!-~]+ allows %. Runs inside confd as root.
  2. Medium: log line forgery via structured-data/param/value. Control characters are not escaped, syslogd does not sanitize SD (only MSG), and fmt5424 writes it verbatim to RFC 5424 files and remote forwarding.
  3. Medium: unbounded SD is truncated in libsyslog's 2048-byte buffer, after which syslogd's RFC 5424 parser drops the whole message silently.
  4. Medium (design): any user with exec rights (factory NACM: exec-default permit) can forge entries tagged as any daemon, in auth/authpriv, or at emergency severity (walled to all ttys and /dev/console). Only kern is neutralized by syslogd.
  5. Low: no rate limiting; libsyslog's sendto() is blocking and confd's RPC callback is SR_SUBSCR_NO_THREAD.
  6. Low: default app-name from sr_session_get_orig_name() is client-controlled.

What I checked and found fine: the sd-name typedef matches RFC 5424 exactly (rejects =, ], ", SP); sd_build() length arithmetic is correct and sysrepo validates mandatory/key leaves before the callback; ASCII control characters in message are rejected by libyang (C0 except TAB/LF/CR) or neutralized by syslogd (LF to space, others to ^X); the klish script quoting and the rpc/copy changes are sound.

Note that -8 on syslogd disables C1 masking, so UTF-8 encoded C1 controls (U+0085, U+009B), U+2028 and bidi overrides in message reach log files and show log untouched. Low severity, mentioned for completeness.

Comment thread src/confd/yang/confd/infix-syslog.yang Resolved
Comment thread src/confd/src/syslog.c Resolved
Comment thread src/confd/yang/confd/infix-syslog.yang Resolved
Comment thread src/confd/src/syslog.c Resolved
Comment thread src/confd/yang/confd/infix-syslog.yang Resolved
Comment thread src/confd/yang/confd/infix-syslog.yang Resolved
Comment thread src/confd/src/syslog.c Resolved
Comment thread src/confd/src/syslog.c Resolved

@mattiaswal mattiaswal left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Duplicate of the review above, posted twice by mistake. Comments removed.

@mattiaswal

Copy link
Copy Markdown
Contributor

Didn't find anything when reviewing but i was scared about something like #1643 (comment) so i let claude get a round of this. This i feel is crutial, other it looks fine.

@troglobit

Copy link
Copy Markdown
Contributor Author

Didn't find anything when reviewing but i was scared about something like #1643 (comment) so i let claude get a round of this. This i feel is crutial, other it looks fine.

Agreed, will have a look at it over the weekend, thanks! 🙇‍♂️

Add an infix-syslog:log RPC that hands a message to the local syslog
daemon.  The full RFC 5424 header is exposed: severity, facility,
app-name, msgid, and structured data.  Defaults follow logger(1),
notice severity, with app-name defaulting to the user name reported
by the calling client.
The message is time stamped on arrival and goes through the regular
/syslog filtering and forwarding rules, so where it ends up is decided
by the device configuration, not the caller.

The handler uses syslogp_r() from the sysklogd libsyslog, which passes
msgid and structured data through and sets the tag per call without
touching confd's own openlog() identity.  The callback's event session
runs as confd, so the calling user is taken from the event originator:
netopeer2 pushes it as originator data, the CLI sets it as originator
name.  RESTCONF conveys no caller at all, since sysrepo keeps the NACM
user in the client process, so the tag is left at NILVALUE rather than
naming the daemon's own user.

Messages are logged with the user facility, the RPC offers no way to
select one: a caller-selected facility would let messages land among the
records written by system services, e.g., auth.  For the same reason
structured data is limited to private SD-IDs, the short form is reserved
for identifiers registered with IANA, like origin, which collectors read
as provenance.

The RPC is nacm:default-deny-all since the remaining header fields, the
tag included, are caller-supplied and unverified.  Input is bounded to
what libsyslog's 2048 byte packet buffer holds, oversized calls are
rejected rather than silently truncated, msgid may not contain '%',
which libsyslog would treat as a printf conversion, and control
characters are kept out of structured data, which syslogd does not
sanitize.

Fixes #1639

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Front-end to the infix-syslog:log RPC.  Optional severity, facility,
and msgid keywords precede the message, which is the rest of the line:

admin@example:/> log severity warning msgid test-start Test 42 starting

Two fixes to the rpc tool the command is built on.  It now sets the
session originator name to the calling user, like klish-plugin-sysrepo,
so the RPC can default app-name to the user.  And it only splits
comma-separated values for leaf-lists, previously any leaf value with
a comma became two instances and the RPC failed:

$ rpc /infix-syslog:log message "Kilroy was here, again"

Issue #1639

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Wrap the infix-syslog:log RPC so tests can leave markers in a DUT's
system log over the management API instead of SSH and logger(1).
Facility names are module-qualified in the helper, and structured
data is given as a dict of dicts to keep call sites short.

The RESTCONF backend's call_dict() only tracked coverage and returned
without sending anything, so RPCs with input silently did nothing over
RESTCONF.  POST to /restconf/operations/MODULE:NAME with the input
wrapped per RFC 8040, like call_action() does.

Convert the tests that logged via SSH.  The remote and hostname_filter
tests keep using logger(1), they deliberately exercise the remote
client path.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
Log to an RFC 5424 formatted file and check app-name, msgid, and
structured data land in the header, and that a bare message gets the
default app-name with empty msgid and structured data.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
The documented way to force a transport had no effect, the tests kept
picking one pseudo-randomly:

    make INFAMY_EXTRA_ARGS="--transport=restconf" TESTS=... test

The env script appended -o="$INFAMY_EXTRA_ARGS" to its command, which
reached 9pm while the make recipe called it directly.  Since the recipe
was wrapped in sh -c '...' to run the report tool in the container, the
appended argument became $0 of that shell script instead.

Fold the extra arguments into INFAMY_ARGS, which Infamy prepends to
every test's argv, so the override reaches the tests regardless of how
9pm is invoked.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
@troglobit

Copy link
Copy Markdown
Contributor Author

Ping @mattiaswal: rebased on latest main and facility is now removed, so not possible anymore to forge avahi-daemon, for example.

@mattiaswal

Copy link
Copy Markdown
Contributor

Verified fixed

  • Format string injection (High). The msgid pattern rejects %, confirmed with yanglint on the PR's module. The C side also doubles any % before libsyslog splices it into the printf format. Either fix alone is sufficient.
  • SD log line forgery (Medium). The value pattern rejects all Unicode control characters. yanglint rejects LF, CR, TAB, DEL and the C1 U+0085. The C escaper also maps anything below 0x20 to a space as a fallback.
  • Silent truncation (Medium). A pre-check computes the full RFC 5424 line before sending and rejects oversize input with an error. I traced the arithmetic against sysklogd 2.7.2. It over-estimates by ten bytes, so it is conservative in the safe direction.
  • Authorization (Medium). The RPC now carries default-deny-all. In the factory NACM only the admin permit-all rule matches it, and I confirmed sysrepo applies the extension at step 10 after no rule matches. NETCONF, RESTCONF and the CLI all set the NACM user, so the deny holds on every path. The facility leaf is gone and the code hard-wires user, so auth, authpriv and kern are unreachable.

Also closed: the literal "netopeer2" tag fallback now yields -.

Unchanged, acceptable with admin-only exec

  • No rate limiting, and the blocking send to the log socket still runs inside the no-thread callback.
  • emergency still walls to all ttys and the console.
  • The app-name pattern allows [, ] and :, so an admin can produce an RFC 3164 line that looks like sshd[123]:. The user facility keeps it out of the auth log.
  • U+2028 and bidi overrides pass both message and SD values. Cosmetic to viewers only.

Verdict: no open findings above Low. Safe to merge from the security side.

@troglobit
troglobit merged commit 2ea65ef into main Sep 23, 2026
9 checks passed
@troglobit
troglobit deleted the rpc-log branch September 23, 2026 14:05
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.

Add RPC for injecting log messages to a device

2 participants