tmpfiles: reject unused argument fields

Line types which do not use the argument field used to warn and ignore
a non-empty field. Treat that as invalid configuration instead, so typos
are not silently accepted.

Follow-up for: 614cc34f3a
This commit is contained in:
dongshengyuan
2026-07-29 15:29:54 +08:00
parent d47b07d05f
commit e347f63b0f
6 changed files with 24 additions and 7 deletions
+6
View File
@@ -73,6 +73,12 @@ CHANGES WITH 262:
* bootctl, systemd-oomd, systemd-repart, systemd-sysusers, and
systemd-tmpfiles now accept -n as a short option for --dry-run.
Changes in systemd-tmpfiles:
* systemd-tmpfiles now rejects non-empty argument fields for tmpfiles.d
line types that do not use the argument field. Previously, such
fields were silently ignored after a warning.
Changes in the TPM Subsystem:
* The way that NvPCRs are anchored has been improved. They are now
-1
View File
@@ -2730,7 +2730,6 @@ SPDX-License-Identifier: LGPL-2.1-or-later
- **tmpfiles:**
- allow time-based cleanup in r and R too
- instead of ignoring unknown fields, reject them.
- creating new directories/subvolumes/fifos/device nodes
should not follow symlinks. None of the other adjustment or creation
calls follow symlinks.
+5 -2
View File
@@ -164,7 +164,9 @@ L /tmp/foobar - - - - /dev/null</programlisting>
<para>Fields may contain C-style escapes. With the exception of the seventh field (the "argument") all
fields may be enclosed in quotes. Note that any whitespace found in the line after the beginning of the
argument field will be considered part of the argument field. To begin the argument field with a
whitespace character, use C-style escapes (e.g. <literal>\x20</literal>).</para>
whitespace character, use C-style escapes (e.g. <literal>\x20</literal>). Line types which do not
document use of the argument field reject a non-empty argument field; use <literal>-</literal> to leave
the argument field empty.</para>
<refsect2>
<title>Type</title>
@@ -743,7 +745,8 @@ d /tmp/foo/bar - - - bmA:1h -</programlisting></para>
and <varname>T</varname>, determines extended attributes to be set. For <varname>a</varname> and
<varname>A</varname>, determines ACL attributes to be set. For <varname>h</varname> and <varname>H</varname>,
determines the file attributes to set. For <varname>k</varname> and <varname>K</varname>, determines
file capabilities to be set. Ignored for all other lines.</para>
file capabilities to be set. For line types that do not document use of this field, a non-empty
argument is rejected; use <literal>-</literal> to leave it unset.</para>
<para>This field can contain specifiers, see below.</para>
</refsect2>
+5 -3
View File
@@ -4043,9 +4043,11 @@ static int parse_line(
case ADJUST_MODE:
case RELABEL_PATH:
case RECURSIVE_RELABEL_PATH:
if (i.argument)
log_syntax(NULL, LOG_WARNING, fname, line, 0,
"%c lines don't take argument fields, ignoring.", (char) i.type);
if (i.argument) {
*invalid_config = true;
return log_syntax(NULL, LOG_ERR, fname, line, SYNTHETIC_ERRNO(EBADMSG),
"%c lines don't take argument fields.", (char) i.type);
}
break;
case CREATE_FILE:
+7
View File
@@ -21,12 +21,19 @@ test ! -e /tmp/fifo
test ! -e /tmp/test
# Test invalid config
ret=0
systemd-tmpfiles --inline --remove 'garbage' || ret=$?
test "$ret" -eq 65 # EX_DATAERR
ret=0
systemd-tmpfiles --inline --create 'd /tmp/test - - - - unexpected' || ret=$?
test "$ret" -eq 65 # EX_DATAERR
echo 'garbage' >/tmp/config.conf
ret=0
systemd-tmpfiles --remove /tmp/config.conf || ret=$?
test "$ret" -eq 65 # EX_DATAERR
ret=0
systemd-tmpfiles --remove /tmp/config-missing.conf || ret=$?
test "$ret" -eq 1
+1 -1
View File
@@ -84,7 +84,7 @@ else
fi
# Check for an invalid "age" and "age-by" arguments.
for a in ':' ':1s' '2:1h' 'nope:42h' '" :7m"' 'm:' '::' '"+r^w-x:2/h"' 'b ar::64'; do
for a in ':' ':1s' '2:1h' 'nope:42h' '" :7m"' 'm:' '::' '"+r^w-x:2/h"' '"b ar::64"'; do
systemd-tmpfiles --clean - <<EOF 2>&1 | grep -F 'Invalid age' >/dev/null
d /tmp/ageby - - - ${a} -
EOF