<feed xmlns='http://www.w3.org/2005/Atom'>
<title>ubox/log, branch master</title>
<subtitle>OpenWrt core utilities</subtitle>
<id>https://git.openwrt.org/project/ubox/atom?h=master</id>
<link rel='self' href='https://git.openwrt.org/project/ubox/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/'/>
<updated>2026-11-15T17:30:59Z</updated>
<entry>
<title>logread: don't crash on a time with a five-digit year</title>
<updated>2026-11-15T17:30:59Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T15:58:34Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=b0635f4227bd12de3445bdfe69653723de300953'/>
<id>urn:sha1:b0635f4227bd12de3445bdfe69653723de300953</id>
<content type='text'>
log_notify() formats each message's time with ctime(). musl's
asctime_r() aborts on purpose when the result does not fit in its
26-byte buffer, which happens for any year after 9999. So one message
with a bogus time kills logread and cuts off the rest of its output.
That is how the ring buffer bug of FS#4118 showed up: logd handed out
stale entries, and logread died on their timestamps. ctime() can also
return NULL, which was not checked.

Skip a message whose time cannot be converted or has a year after
9999, as a message with a missing field is skipped. Linux cannot set
its clock past 2262, so only corrupt entries are skipped. All other
times are printed as before.

Assisted-by: Claude:claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 &lt;noreply@anthropic.com&gt;
Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/10
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: align the entries in the buffer for their header</title>
<updated>2026-11-15T11:37:38Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T17:12:15Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=9555709f00d5d148c2d51b19a6053cbf45360ea9'/>
<id>urn:sha1:9555709f00d5d148c2d51b19a6053cbf45360ea9</id>
<content type='text'>
Each entry starts right after the text of the one before, padded to 4
bytes. But the header holds a struct timespec, which needs 8-byte
alignment on 64-bit targets and on most 32-bit ones with a 64-bit
time_t, so about every second entry is misaligned. That is undefined
behaviour, which UBSan reports as

  runtime error: member access within misaligned address ... for type
  'struct log_head', which requires 8 byte alignment

and on 64-bit MIPS and RISC-V, the time is read and written with 8-byte
loads and stores, which trap on a misaligned address unless the CPU
handles it in hardware.

Pad the text of the entries to the alignment of their header. This
costs at most 4 more bytes per entry, about 2% fewer entries in the
buffer with messages of up to 100 characters, and nothing on 32-bit x86.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/11
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: keep "logread -l" working after 2^31 messages</title>
<updated>2026-11-15T11:37:38Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T17:10:58Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=1767e1d19f0a2ac60fd012354275f9e80457b509'/>
<id>urn:sha1:1767e1d19f0a2ac60fd012354275f9e80457b509</id>
<content type='text'>
The ids of the messages come from current_id, a signed int. After 2^31
messages, about eight months at 100 messages a second, incrementing it
is undefined behaviour, and in practice it goes negative. log_list()
then takes every entry for one of the last "count", so "logread -l 1"
prints the whole buffer until 2^31 more messages have come in. When the
counter is back at 0, the entries from before have the highest ids, and
the same happens until they are overwritten.

Make the counter unsigned, and tell the last "count" entries by how far
their id is behind it, which works across the wrap around.
The count is unsigned from the "lines" of the request on, so a value of
2^31 or more is a large count, not a negative one that gets no entries.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/11
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: don't hand out an entry from an empty buffer</title>
<updated>2026-11-15T11:37:38Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T17:09:38Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=8609c32b4f0f29b8d6893b463f42e31afe899638'/>
<id>urn:sha1:8609c32b4f0f29b8d6893b463f42e31afe899638</id>
<content type='text'>
Until the first message comes in, the ring buffer is all zeroes, and
log_list() still returns its first slot as the oldest entry. So
"logread" on a logd that has no message yet, e.g. right after
"/etc/init.d/log restart", prints

  Thu Jan  1 00:00:00 1970 kern.emerg kernel:

and "ubus call log read" returns that entry with a time of 0.

Return nothing while the buffer is empty: "oldest" and "newest" are
then both at its start, and they never meet again once an entry is in.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/11
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: don't read before a message of only whitespace</title>
<updated>2026-11-15T11:37:38Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T17:09:02Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=7ab668af44c21c4f1b0b3a2675672bf83ea55e72'/>
<id>urn:sha1:7ab668af44c21c4f1b0b3a2675672bf83ea55e72</id>
<content type='text'>
log_add() strips trailing whitespace by walking back from the end of
the message, and nothing stops it at the start. For a message that is
empty or only whitespace, such as a datagram of a single space or
newline on /dev/log, it reads the byte in front of the message, outside
the buffer it was received in. If that byte is whitespace too, the walk
goes on, logd writes the terminating NUL in front of the buffer and
stores an entry of size 0, which looks like the end of a round.

Stop at the first character. A message of only whitespace is still
stored as an empty one.

Fixes: 2c0d9cfe05e9 ("logd: move stripping of newlines to log_add()")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/11
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: don't overflow a ring buffer smaller than a message</title>
<updated>2026-11-15T11:37:38Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T17:07:59Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=eb2eb2fe60367caf425921103ab62349640ba3e5'/>
<id>urn:sha1:eb2eb2fe60367caf425921103ab62349640ba3e5</id>
<content type='text'>
log_add() copies each message with strcpy() after the header of its
entry, and relies on the entry fitting in the ring buffer with room for
the header after it. The size of the buffer comes from "logd -S", in
KiB (log_buffer_size or log_size in the system config, 64 by default),
and anything from 1 up is taken. With a 1 KiB buffer, an entry with a
message of more than 959 characters does not fit, and from 992
characters on strcpy() writes past the end of the buffer: a heap buffer
overflow in logd, which any local user can trigger, as /dev/log is
world-writable.

Never make the buffer smaller than an entry with the longest message,
LOG_LINE_SIZE bytes with the NUL, and the header after it: 1088 bytes
with the 32-byte header of a 64-bit time_t, which is what "logd -S 1"
now gets. Messages from /dev/log and ubus are cut to LOG_LINE_SIZE
already, but a line from /proc/kmsg can be a little longer (up to 1023
characters from the kernel, plus the timestamp), so cut those too.

A buffer this small relies on the previous commit: there, a long
message often covers all of the previous round.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/11
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: don't walk past the end marker when the ring wraps</title>
<updated>2026-11-15T11:37:38Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-11-07T17:05:45Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=79f0910ec1f8e315adc26ea4049bc19e13d25e47'/>
<id>urn:sha1:79f0910ec1f8e315adc26ea4049bc19e13d25e47</id>
<content type='text'>
When a message does not fit before the end of the ring buffer,
log_add() writes an end marker (an entry of size 0) where the current
round ends, puts the message at the start of the buffer and looks for
the new oldest entry: it walks the entries of the round that just ended
from the start of the buffer, and stops at the first one that begins
after the new message.

With a buffer of 2 or 3 KiB (log_size 2 or 3), a round can be so short
that all of its entries begin within the new message. The walk then
stops at the end marker, which log_list() hands out as the oldest entry
with a stale header, or it steps over the end marker into stale data of
an earlier round. So logread gets entries with random sizes and
timestamps, and on a 32-bit target a stale size can even wrap a pointer
around, and logd can crash on it. Or the stale data sends the walk back
to the start of the buffer, where it starts over and never ends: logd
hangs in log_add() and stops reading /dev/log, and everything that logs
blocks.

Stop the walk at the end marker. When it gets there, nothing is left of
the previous round, and the new message is the oldest entry.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/11
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: don't hand out stale entries after the ring wraps</title>
<updated>2026-11-15T11:07:32Z</updated>
<author>
<name>Pierre-Yves Le Borgne</name>
</author>
<published>2026-10-07T14:09:03Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=46f702b7f8af523a780a54e30c9de941001cadfd'/>
<id>urn:sha1:46f702b7f8af523a780a54e30c9de941001cadfd</id>
<content type='text'>
logd keeps the messages in a ring buffer. When a message does not fit
before the end of the buffer, log_add() writes an end marker (an entry
of size 0) where the current round ends and starts over at the
beginning, and "oldest" then points into the entries of the previous
round. As the new round grows, log_add() pushes "oldest" forward
through those entries, but nothing stops it at the end marker: the
entry after a zero-sized one is its header's own end, which is stale
data of an earlier round. From then on log_list() starts from garbage,
so "logread" gets entries with random sizes and timestamps, and logd
can read past the end of the buffer. musl's asctime_r() aborts on such
a timestamp, which shows up as

  traps: logread[...] general protection fault ... in libc.so

Messages of varying length make it likely, e.g. "logger" with 1 to 100
characters in a loop next to "logread -l 1" in a loop (FS#4118).

Stop at the end marker: when "oldest" reaches it, the oldest entry is
the first one of the new round, at the start of the buffer.

Also start over at the beginning when the header of the next entry does
not fit before the end of the buffer, not only when its first byte does
not: an entry that starts in the last bytes of the buffer has its header
cut, and log_list() reads past the end of the buffer there.

Assisted-by: Claude Code (Claude Opus 5.5)
Signed-off-by: Pierre-Yves Le Borgne &lt;pylaterreur@gmail.com&gt;
Link: https://github.com/openwrt/ubox/pull/9
Signed-off-by: Robert Marko &lt;robimarko@gmail.com&gt;
</content>
</entry>
<entry>
<title>logd: add udebug support</title>
<updated>2023-11-30T12:42:09Z</updated>
<author>
<name>Felix Fietkau</name>
</author>
<published>2023-11-30T12:42:09Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=c08709cceb554cba02c935d1442f6a042fe6b2a8'/>
<id>urn:sha1:c08709cceb554cba02c935d1442f6a042fe6b2a8</id>
<content type='text'>
Signed-off-by: Felix Fietkau &lt;nbd@nbd.name&gt;
</content>
</entry>
<entry>
<title>logd: add support for subscribing to the log object</title>
<updated>2023-01-19T12:06:21Z</updated>
<author>
<name>Felix Fietkau</name>
</author>
<published>2023-01-19T12:06:19Z</published>
<link rel='alternate' type='text/html' href='https://git.openwrt.org/project/ubox/commit/?id=cc34fb7b922f183e6ece5fa0fec31d4eb95c5823'/>
<id>urn:sha1:cc34fb7b922f183e6ece5fa0fec31d4eb95c5823</id>
<content type='text'>
Provides easier access to log messages

Signed-off-by: Felix Fietkau &lt;nbd@nbd.name&gt;
</content>
</entry>
</feed>
