systemd/.git
5 years agojournal: do not trigger assertion when journal_file_close() get NULL
Yu Watanabe [Tue, 28 May 2019 03:40:17 +0000 (12:40 +0900)]
journal: do not trigger assertion when journal_file_close() get NULL

We generally expect destructors to not complain if a NULL argument is passed.

Closes #12400.

(cherry picked from commit c377a6f3ad3d9bed4ce7e873e8e9ec6b1650c57d)
(cherry picked from commit dc4c3a5aa35a5e88adcf210471d9460262c8c0d9)
Resolves: #1807350

5 years agosd-bus: use "queue" message references for managing r/w message queues in connection... v239-18.4
Lennart Poettering [Thu, 17 Jan 2019 17:31:59 +0000 (18:31 +0100)]
sd-bus: use "queue" message references for managing r/w message queues in connection objects

Let's make use of the new concept the previous commit added.

See: #4846
(cherry picked from commit c1757a70eac0382c4837a3833d683919f6a48ed7)
Related: CVE-2020-1712

5 years agopolkit: when authorizing via PK let's re-resolve callback/userdata instead of caching it v239-18.3
Jan Synacek [Fri, 31 Jan 2020 14:17:25 +0000 (15:17 +0100)]
polkit: when authorizing via PK let's re-resolve callback/userdata instead of caching it

Previously, when doing an async PK query we'd store the original
callback/userdata pair and call it again after the PK request is
complete. This is problematic, since PK queries might be slow and in the
meantime the userdata might be released and re-acquired. Let's avoid
this by always traversing through the message handlers so that we always
re-resolve the callback and userdata pair and thus can be sure it's
up-to-date and properly valid.

Resolves: CVE-2020-1712

5 years agosd-event: add sd_event_source_disable_unref() helper
Zbigniew Jędrzejewski-Szmek [Wed, 8 May 2019 12:39:57 +0000 (14:39 +0200)]
sd-event: add sd_event_source_disable_unref() helper

(cherry picked from commit afd15bbb4b6414b9356799c63029e36642dae8e4)
Related: CVE-2020-1712

5 years agosd-bus: introduce API for re-enqueuing incoming messages
Jan Synacek [Fri, 31 Jan 2020 10:34:45 +0000 (11:34 +0100)]
sd-bus: introduce API for re-enqueuing incoming messages

When authorizing via PolicyKit we want to process incoming method calls
twice: once to process and figure out that we need PK authentication,
and a second time after we aquired PK authentication to actually execute
the operation. With this new call sd_bus_enqueue_for_read() we have a
way to put an incoming message back into the read queue for this
purpose.

This might have other uses too, for example debugging.
Related: CVE-2020-1712

5 years agobus-message: introduce two kinds of references to bus messages
Lennart Poettering [Thu, 17 Jan 2019 17:18:54 +0000 (18:18 +0100)]
bus-message: introduce two kinds of references to bus messages

Before this commit bus messages had a single reference count: when it
reached zero the message would be freed. This simple approach meant a
cyclic dependency was typically seen: a message that was enqueued in a
bus connection object would reference the bus connection object but also
itself be referenced by the bus connection object. So far out strategy
to avoid cases like this was: make sure to process the bus connection
regularly so that messages don#t stay queued, and at exit flush/close
the connection so that the message queued would be emptied, and thus the
cyclic dependencies resolved. Im many cases this isn't done properly
however.

With this change, let's address the issue more systematically: let's
break the reference cycle. Specifically, there are now two types of
references to a bus message:

1. A regular one, which keeps both the message and the bus object it is
   associated with pinned.

2. A "queue" reference, which is weaker: it pins the message, but not
   the bus object it is associated with.

The idea is then that regular user handling uses regular references, but
when a message is enqueued on its connection, then this takes a "queue"
reference instead. This then means that a queued message doesn't imply
the connection itself remains pinned, only regular references to the
connection or a message associated with it do. Thus, if we end up in the
situation where a user allocates a bus and a message and enqueues the
latter in the former and drops all refs to both, then this will detect
this case and free both.

Note that this scheme isn't perfect, it only covers references between
messages and the busses they are associated with. If OTOH a bus message
is enqueued on a different bus than it is associated with cyclic deps
cannot be recognized with this simple algorithm, and thus if you enqueue
a message associated with a bus A on a bus B, and another message
associated with bus B on a bus A, a cyclic ref will be in effect and not
be discovered. However, given that this is an exotic case (though one
that happens, consider systemd-bus-stdio-bridge), it should be OK not to
cover with this, and people have to explicit flush all queues on exit in
that case.

Note that this commit only establishes the separate reference counters
per message. A follow-up commit will start making use of this from the
bus connection object.

(cherry picked from commit 1b3f9dd759ca0ea215e7b89f8ce66d1b724497b9)
Related: CVE-2020-1712

5 years agosd-bus: always go through sd_bus_unref() to free messages
Lennart Poettering [Thu, 17 Jan 2019 20:07:42 +0000 (21:07 +0100)]
sd-bus: always go through sd_bus_unref() to free messages

Don't try to be smart, don't bypass the ref counting logic if there's no
real reason to.

This matters if we want to tweak the ref counting logic later.

(cherry picked from commit b41812d1e308de03c879cfca490105216d528c4b)
Related: CVE-2020-1712

5 years agosd-bus: initialize mutex after we allocated the wqueue
Lennart Poettering [Thu, 17 Jan 2019 20:06:30 +0000 (21:06 +0100)]
sd-bus: initialize mutex after we allocated the wqueue

That way the mutex doesn't have to be destroyed when we exit early due
to OOM.

(cherry picked from commit 2fe9a10d7695c4c3a748969a0d1662c624e50e5e)
Related: CVE-2020-1712

5 years agosd-bus: drop two inappropriate empty lines
Lennart Poettering [Thu, 17 Jan 2019 17:18:18 +0000 (18:18 +0100)]
sd-bus: drop two inappropriate empty lines

(cherry picked from commit 39feb2ce417e54cf9746e64b5dfd610cef6ac440)
Related: CVE-2020-1712

5 years agosd-bus: make sure dispatch_rqueue() initializes return parameter on all types of...
Lennart Poettering [Thu, 17 Jan 2019 17:15:37 +0000 (18:15 +0100)]
sd-bus: make sure dispatch_rqueue() initializes return parameter on all types of success

Let's make sure our own code follows coding style and initializes all
return values on all types of success (and leaves it uninitialized in
all types of failure).

(cherry picked from commit c0bc4ec5cc17ac61773d1e9362b0ffa8382c1ff1)
Related: CVE-2020-1712

5 years agosd-bus: reorder bus ref and bus message ref handling
Lennart Poettering [Thu, 17 Jan 2019 17:14:17 +0000 (18:14 +0100)]
sd-bus: reorder bus ref and bus message ref handling

Let's always place handling of these references together, so that all
reference counting during allocation is at a single place.

(cherry picked from commit e593b6a87a335267e5f7238b14683b7f840a01a3)
Related: CVE-2020-1712

5 years agosd-bus: make rqueue/wqueue sizes of type size_t
Lennart Poettering [Thu, 17 Jan 2019 17:13:03 +0000 (18:13 +0100)]
sd-bus: make rqueue/wqueue sizes of type size_t

Let's do this like we usually do and size arrays with size_t.

We already do this for the "allocated" counter correctly, and externally
we expose the queue sizes as uint64_t anyway, hence there's really no
point in usigned "unsigned" internally.

(cherry picked from commit 143d4e045a798ccc87889b2a8a60d7fbe44be441)
Related: CVE-2020-1712

5 years agotest: bump the second partition's size to 50M
Frantisek Sumsal [Mon, 21 Oct 2019 16:39:39 +0000 (18:39 +0200)]
test: bump the second partition's size to 50M

The former size (10M) caused systemd-journald to crash with SIGABRT when
used on a LUKS2 partition, as the LUKS2 metadata consume a significant
part of the 10M partition, thus leaving no space for the journal file
itself (relevant for TEST-02-CRYPTSETUP). This change has been present
in upstream for a while anyway.

rhel-only

(cherry picked from commit 27d1acaa1d4c9299db461f0f1922c573be6a52c0)
Related: #1781712

5 years agotest: mask several unnecessary services
Yu Watanabe [Thu, 1 Nov 2018 08:26:36 +0000 (17:26 +0900)]
test: mask several unnecessary services

This may make CIs run faster.

(cherry picked from commit 056ae88152a722bdbea54ff33db815d585c8b9c6)
(cherry picked from commit c748b95f5a00b6d9c46026c3d251c40437e6b64a)
Related: #1781712

5 years agotest: use PBKDF2 instead of Argon2 in cryptsetup...
Frantisek Sumsal [Fri, 15 Mar 2019 09:05:33 +0000 (10:05 +0100)]
test: use PBKDF2 instead of Argon2 in cryptsetup...

to reduce memory requirements for volume manipulation. Also,
to further improve the test performance, reduce number of PBKDF
iterations to 1000 (allowed minimum).

(cherry picked from commit 5b69d297c153478f6f5e74ba66e1f4e5b6422baf)
(cherry picked from commit a7f18f9ef4abc7e0732d1710ead2a18a38c3ec6d)
Related: #1781712

5 years agojournald: fixed assertion failure when system journal rotation fails (#9893)
Renaud Métrich [Mon, 3 Sep 2018 03:42:39 +0000 (05:42 +0200)]
journald: fixed assertion failure when system journal rotation fails (#9893)

(cherry picked from commit fd790d6f09b10a87b007b71403cb018f18ff91c9)
(cherry picked from commit 33aa231f5bf3335cdacfb38ffba757865019ce4d)
Related: #1781712

5 years agosyslog: fix segfault in syslog_parse_priority()
Yu Watanabe [Wed, 8 Aug 2018 09:27:15 +0000 (18:27 +0900)]
syslog: fix segfault in syslog_parse_priority()

(cherry picked from commit a5ee33b951cfa22db53d0274c9c6c0d9d4dae39d)
(cherry picked from commit 8bd791fb3a8e85063e297204bdef8004aacd22b1)
Related: #1781712

5 years agocore, job: fix breakage of ordering dependencies by systemctl reload command
HATAYAMA Daisuke [Mon, 28 Oct 2019 10:35:24 +0000 (19:35 +0900)]
core, job: fix breakage of ordering dependencies by systemctl reload command

Currently, systemctl reload command breaks ordering dependencies if it's
executed when its target service unit is in activating state.

For example, prepare A.service, B.service and C.target as follows:

    # systemctl cat A.service B.service C.target
    # /etc/systemd/system/A.service
    [Unit]
    Description=A

    [Service]
    Type=oneshot
    ExecStart=/usr/bin/echo A1
    ExecStart=/usr/bin/sleep 60
    ExecStart=/usr/bin/echo A2
    ExecReload=/usr/bin/echo A reloaded
    RemainAfterExit=yes

    # /etc/systemd/system/B.service
    [Unit]
    Description=B
    After=A.service

    [Service]
    Type=oneshot
    ExecStart=/usr/bin/echo B
    RemainAfterExit=yes

    # /etc/systemd/system/C.target
    [Unit]
    Description=C
    Wants=A.service B.service

Start them.

    # systemctl daemon-reload
    # systemctl start C.target

Then, we have:

    # LANG=C journalctl --no-pager -u A.service -u B.service -u C.target -b
    -- Logs begin at Mon 2019-09-09 00:25:06 EDT, end at Thu 2019-10-24 22:28:47 EDT. --
    Oct 24 22:27:47 localhost.localdomain systemd[1]: Starting A...
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Child 967 belongs to A.service.
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Running next main command for state start.
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Passing 0 fds to service
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: About to execute: /usr/bin/sleep 60
    Oct 24 22:27:47 localhost.localdomain systemd[1]: A.service: Forked /usr/bin/sleep as 968
    Oct 24 22:27:47 localhost.localdomain systemd[968]: A.service: Executing: /usr/bin/sleep 60
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Trying to enqueue job A.service/reload/replace
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Merged into running job, re-running: A.service/reload as 1288
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Enqueued job A.service/reload as 1288
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Unit cannot be reloaded because it is inactive.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: A.service: Job 1288 A.service/reload finished, result=invalid
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Passing 0 fds to service
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: About to execute: /usr/bin/echo B
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Forked /usr/bin/echo as 970
    Oct 24 22:27:52 localhost.localdomain systemd[970]: B.service: Executing: /usr/bin/echo B
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Failed to send unit change signal for B.service: Connection reset by peer
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Changed dead -> start
    Oct 24 22:27:52 localhost.localdomain systemd[1]: Starting B...
    Oct 24 22:27:52 localhost.localdomain echo[970]: B
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Child 970 belongs to B.service.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Changed start -> exited
    Oct 24 22:27:52 localhost.localdomain systemd[1]: B.service: Job 1371 B.service/start finished, result=done
    Oct 24 22:27:52 localhost.localdomain systemd[1]: Started B.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: C.target: Job 1287 C.target/start finished, result=done
    Oct 24 22:27:52 localhost.localdomain systemd[1]: Reached target C.
    Oct 24 22:27:52 localhost.localdomain systemd[1]: C.target: Failed to send unit change signal for C.target: Connection reset by peer
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Child 968 belongs to A.service.
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Running next main command for state start.
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Passing 0 fds to service
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: About to execute: /usr/bin/echo A2
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Forked /usr/bin/echo as 972
    Oct 24 22:28:47 localhost.localdomain systemd[972]: A.service: Executing: /usr/bin/echo A2
    Oct 24 22:28:47 localhost.localdomain echo[972]: A2
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Child 972 belongs to A.service.
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Main process exited, code=exited, status=0/SUCCESS
    Oct 24 22:28:47 localhost.localdomain systemd[1]: A.service: Changed start -> exited

The issue occurs not only in reload command, i.e.:

  - reload
  - try-restart
  - reload-or-restart
  - reload-or-try-restart commands

The cause of this issue is that job_type_collapse() doesn't take care of the
activating state.

Fixes: #10464
(cherry picked from commit d1559793df555212271e490a4a72f55826caf5b4)
(cherry picked from commit cb084637ba1c8558f1538ce300c5520a6764dc76)
Resolves: #1781712

6 years agoask-password: prevent buffer overrow when reading from keyring v239-18.2
Thadeu Lima de Souza Cascardo [Mon, 13 May 2019 19:58:01 +0000 (16:58 -0300)]
ask-password: prevent buffer overrow when reading from keyring

When we read from keyring, a temporary buffer is allocated in order to
determine the size needed for the entire data. However, when zeroing that area,
we use the data size returned by the read instead of the lesser size allocate
for the buffer.

That will cause memory corruption that causes systemd-cryptsetup to crash
either when a single large password is used or when multiple passwords have
already been pushed to the keyring.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
(cherry picked from commit 59c55e73eaee345e1ee67c23eace8895ed499693)
(cherry picked from commit c6c8e0d097d6ba12471c6112c3fd339ea40329d5)

Resolves: #1777037

6 years agoresolved: query polkit only after parsing the data v239-18.1
Zbigniew Jędrzejewski-Szmek [Tue, 27 Aug 2019 17:28:19 +0000 (19:28 +0200)]
resolved: query polkit only after parsing the data

That's what we do everywhere else because it leads to nicer user experience.

Related: #1746857

6 years agoresolved: allow access to Set*Link and Revert methods through polkit
Zbigniew Jędrzejewski-Szmek [Tue, 27 Aug 2019 17:25:05 +0000 (19:25 +0200)]
resolved: allow access to Set*Link and Revert methods through polkit

This matches what is done in networkd very closely. In fact even the
policy descriptions are all identical (with s/network/resolve), except
for the last one:
resolved has org.freedesktop.resolve1.revert while
networkd has org.freedesktop.network1.revert-ntp and
org.freedesktop.network1.revert-dns so the description is a bit different.

Conflicts:
src/resolve/resolved-bus.c
src/resolve/resolved-link-bus.c

Related: #1746857

6 years agoresolved: do not run loop twice
Zbigniew Jędrzejewski-Szmek [Tue, 27 Aug 2019 17:02:53 +0000 (19:02 +0200)]
resolved: do not run loop twice

This doesn't matter much, but let's just do the loop once and allocate
the populate the result set on the fly. If we find an error, it'll get
cleaned up automatically.

Related: #1746857

6 years agosd-bus: adjust indentation of comments
Zbigniew Jędrzejewski-Szmek [Tue, 27 Aug 2019 17:00:50 +0000 (19:00 +0200)]
sd-bus: adjust indentation of comments

Related: #1746857

6 years agoshared/but-util: drop trusted annotation from bus_open_system_watch_bind_with_descrip...
Zbigniew Jędrzejewski-Szmek [Tue, 27 Aug 2019 17:00:34 +0000 (19:00 +0200)]
shared/but-util: drop trusted annotation from bus_open_system_watch_bind_with_description()

https://bugzilla.redhat.com/show_bug.cgi?id=1746057

This only affects systemd-resolved. bus_open_system_watch_bind_with_description()
is also used in timesyncd, but it has no methods, only read-only properties, and
in networkd, but it annotates all methods with SD_BUS_VTABLE_UNPRIVILEGED and does
polkit checks.

Resolves: #1746857

6 years agojournal: rely on _cleanup_free_ to free a temporary string used in client_context_rea...
Evgeny Vereshchagin [Sun, 23 Dec 2018 23:29:56 +0000 (00:29 +0100)]
journal: rely on _cleanup_free_ to free a temporary string used in client_context_read_cgroup

Closes https://github.com/systemd/systemd/issues/11253.

(cherry picked from commit ef30f7cac18a810814ada7e6a68a31d48cc9fccd)
(cherry picked from commit 3513426adcecc322937635c11ebb89f174f849ed)

Resolves: #1767716

6 years agoanalyze-security: fix potential division by zero v239-17 v239-18
Jan Synacek [Wed, 31 Jul 2019 07:13:41 +0000 (09:13 +0200)]
analyze-security: fix potential division by zero

Upstream PR: https://github.com/systemd/systemd/pull/13238

Resolves: #1734400

6 years agoswap: scan /proc/swaps before processing waitid() results
Lennart Poettering [Wed, 17 Jul 2019 16:58:44 +0000 (18:58 +0200)]
swap: scan /proc/swaps before processing waitid() results

Similar to the previous commit, but for /proc/swaps, where the same
logic and rationale applies.

(cherry picked from commit bcce581d65de68cca01c73e1c890e261e72d20af)

Related: #1696178

6 years agomount: rescan /proc/self/mountinfo before processing waitid() results
Lennart Poettering [Wed, 17 Jul 2019 16:57:13 +0000 (18:57 +0200)]
mount: rescan /proc/self/mountinfo before processing waitid() results

(The interesting bits about the what and why are in a comment in the
patch, please have a look there instead of looking here in the commit
msg).

Fixes: #10872
(cherry picked from commit 350804867dbcc9b7ccabae1187d730d37e2d8a21)

Conflicts:
src/core/mount.c

Resolves: #1696178

6 years agomount: simplify /proc/self/mountinfo handler
Lennart Poettering [Wed, 17 Jul 2019 12:53:07 +0000 (14:53 +0200)]
mount: simplify /proc/self/mountinfo handler

Our IO handler is only installed for one fd, hence there's no reason to
conditionalize on it again.

Also, split out the draining into a helper function of its own.

(cherry picked from commit fcd8e119c28be19ffbc5227089cf4d3b8ba60238)

Conflicts:
src/core/mount.c

Related: #1696178

6 years agorules: skip memory hotplug on ppc64 v239-16
Jan Synacek [Thu, 6 Jun 2019 07:35:27 +0000 (09:35 +0200)]
rules: skip memory hotplug on ppc64

Resolves (#1713159)

6 years agoman: note that journal does not validate syslog fields
Jan Synacek [Tue, 14 May 2019 08:45:08 +0000 (10:45 +0200)]
man: note that journal does not validate syslog fields

(cherry picked from commit 63ea8032f28052f7cda860e5324c0a83dee7ed23)

Resolves: #1707175

6 years agobash-completion: analyze: support 'security'
Yu Watanabe [Thu, 6 Dec 2018 17:51:56 +0000 (18:51 +0100)]
bash-completion: analyze: support 'security'

(cherry picked from commit 83da42c3bf86e8787cfec2c7fb6ca379dfec3632)

Resolves: #1733395

6 years agoChange job mode of manager triggered restarts to JOB_REPLACE
Jonathon Kowalski [Thu, 17 Jan 2019 17:08:00 +0000 (17:08 +0000)]
Change job mode of manager triggered restarts to JOB_REPLACE

Fixes: #11305
Fixes: #3260
Related: #11456

So, here's what happens in the described scenario in #11305. A unit goes
down, and that triggeres stop jobs for the other two units as they were
bound to it. Now, the timer for manager triggered restarts kicks in and
schedules a restart job with the JOB_FAIL job mode. This means there is
a stop job installed on those units, and now due to them being bound to
us they also get a restart job enqueued. This however is a conflicts, as
neither stop can merge into restart, nor restart into stop. However,
restart should be able to replace stop in any case. If the stop
procedure is ongoing, it can cancel the stop job, install itself, and
then after reaching dead finish and convert itself to a start job.
However, if we increase the timer, then it can always take those units
from inactive -> auto-restart.

We change the job mode to JOB_REPLACE so the restart job cancels the
stop job and installs itself.

Also, the original bug could be worked around by bumping RestartSec= to
avoid the conflicting.

This doesn't seem to be something that is going to break uses. That is
because for those who already had it working, there must have never been
conflicting jobs, as that would result in a desctructive transaction by
virtue of the job mode used.

After this change, the test case is able to work nicely without issues.

(cherry picked from commit 03ff2dc71ecb09272d728d458498b44f7f132f51)

Resolves: #1712524

6 years agoudev/scsi_id: fix incorrect page length when get device identification VPD page
Zhang Xianwei [Mon, 13 May 2019 10:41:55 +0000 (18:41 +0800)]
udev/scsi_id: fix incorrect page length when get device identification VPD page

The length of device identification VPD page is filled with two bytes,
but scsi_id only gets the low byte. Fix it.

Signed-off-by: Zhang Xianwei <zhang.xianwei8@zte.com.cn>
(cherry picked from commit 1f7b6872dbe8ccae1f3bda9aa6aeb87c9b42e01e)

Resolves: #1713227

6 years agocryptsetup: Add LUKS2 token support.
Milan Broz [Mon, 27 May 2019 07:44:14 +0000 (09:44 +0200)]
cryptsetup: Add LUKS2 token support.

LUKS2 supports so-called tokens. The libcryptsetup internally
support keyring token (it tries to open device using specified
keyring entry).
Only if all token fails (or are not available), it uses a passphrase.

This patch aligns the functionality with the cryptsetup utility
(cryptsetup luksOpen tries tokens first) but does not replace
the systemd native ask-password function (can be used the same in
combination with this patch).

(cherry picked from commit 894bb3ca4c730cc9e9d46ef5004ba4ca5e201d8d)

Resolves: #1719153

6 years agocryptsetup: call crypt_load() for LUKS only once
Milan Broz [Mon, 27 May 2019 07:43:03 +0000 (09:43 +0200)]
cryptsetup: call crypt_load() for LUKS only once

The crypt_load() for LUKS2 can read a quite big area of disk
(metadata area size is configurable and can increase up to megabytes).

This initialization is not needed to be repeated, just use the existing context.

(This patch is also required for the following change.)

(cherry picked from commit ea9a9d49e4af31c49e5c216e7e5e2f533e727579)

Related: #1719153

6 years agocryptsetup: Do not fallback to PLAIN mapping if LUKS data device set fails.
Milan Broz [Mon, 27 May 2019 07:27:54 +0000 (09:27 +0200)]
cryptsetup: Do not fallback to PLAIN mapping if LUKS data device set fails.

If crypt_load() for LUKS succeeds, we know that it is a LUKS device.
Failure of data device setting should fail in this case; remapping
as a PLAIN device late could mean data corruption.

(If a user wants to map PLAIN device over a device with LUKS header,
it should be said explicitly with "plain" argument type.)

Also, if there is no explicit PLAIN type requested and crypt device
is already initialized (crypt_data_type() is set), do not run
the initialization again.

(cherry picked from commit 2e4beb875bcb24e7d7d4339cc202b0b3f2953f71)

Related: #1719153

6 years agojournal: do not remove multiple spaces after identifier in syslog message
Yu Watanabe [Fri, 10 Aug 2018 02:07:54 +0000 (11:07 +0900)]
journal: do not remove multiple spaces after identifier in syslog message

Single space is used as separator.
C.f. discussions in #156.

Fixes #9839 introduced by a6aadf4ae0bae185dc4c414d492a4a781c80ffe5.

(cherry picked from commit 8595102d3ddde6d25c282f965573a6de34ab4421)

Resolves: #1691817

6 years agojournal-remote: do not request Content-Length if Transfer-Encoding is chunked
Yu Watanabe [Mon, 11 Mar 2019 03:27:18 +0000 (12:27 +0900)]
journal-remote: do not request Content-Length if Transfer-Encoding is chunked

This fixes a bug introduced by 7fdb237f5473cb8fc2129e57e8a0039526dcb4fd.

Closes #11571.

(cherry picked from commit a289dfd69b3ff4bccdde93e84b67c947bafa27e1)

Resolves: #1708849

6 years agosd-bus: deal with cookie overruns
Lennart Poettering [Mon, 25 Feb 2019 10:02:46 +0000 (11:02 +0100)]
sd-bus: deal with cookie overruns

Apparently this happens IRL. Let's carefully deal with issues like this:
when we overrun, let's not go back to zero but instead leave the highest
cookie bit set. We use that as indication that we are in "overrun
territory", and then are particularly careful with checking cookies,
i.e. that they haven't been used for still outstanding replies yet. This
should retain the quick cookie generation behaviour we used to have, but
permits dealing with overruns.

Replaces: #11804
Fixes: #11809
(cherry picked from commit 1f82f5bb4237ed5f015daf93f818e9db95e764b8)

Resolves: #1694999

6 years agojournal-gateway: use localStorage["cursor"] only when it has valid value v239-15
Yu Watanabe [Wed, 27 Jun 2018 05:50:19 +0000 (14:50 +0900)]
journal-gateway: use localStorage["cursor"] only when it has valid value

Discovered by LGTM.

(cherry picked from commit 944072feddb73333023d0a98bf87fd2a17f894d3)

Resolves: #1705971

6 years agotools: drop unused variable
Yu Watanabe [Sat, 8 Dec 2018 10:33:37 +0000 (19:33 +0900)]
tools: drop unused variable

(cherry picked from commit 2f6c9b6f3fb0128cee7f74985c143b4850feff6d)

Resolves: #1705971

6 years agojournal-gateway: explicitly declare local variables
Yu Watanabe [Wed, 27 Jun 2018 05:22:24 +0000 (14:22 +0900)]
journal-gateway: explicitly declare local variables

Suggested by LGTM.

(cherry picked from commit c497e449f41774a36e01ae2cc2abade6133dffe1)

Resolves: #1705971

6 years agotest: add test for Type=exec
Lennart Poettering [Tue, 17 Jul 2018 10:35:12 +0000 (12:35 +0200)]
test: add test for Type=exec

(cherry picked from commit 0e1f17561f5f6061ec5503de044298372ed7ca37)

Resolves: #1683334

6 years agosd-login: let's also make sd-login understand ".host"
Lennart Poettering [Tue, 17 Jul 2018 10:24:50 +0000 (12:24 +0200)]
sd-login: let's also make sd-login understand ".host"

if sd-bus and machined grok it, then sd-login should grok it too.

(cherry picked from commit a8c9b7a0fc0aa02666042543ff9a652aae3c9499)

Resolves: #1683334

6 years agosd-bus: allow connecting to the pseudo-container ".host"
Lennart Poettering [Tue, 17 Jul 2018 10:23:26 +0000 (12:23 +0200)]
sd-bus: allow connecting to the pseudo-container ".host"

machined exposes the pseudo-container ".host" as a reference to the host
system, and this means "machinectl login .host" and "machinectl shell
.host" get your a login/shell on the host. systemd-run currently doesn't
allow that. Let's fix that, and make sd-bus understand ".host" as an
alias for connecting to the host system.

(cherry picked from commit 1e5057b904473696ae0d591d7555233adcb51fa4)

Resolves: #1683334

6 years agoman: document the new Type=exec type
Lennart Poettering [Tue, 17 Jul 2018 10:01:26 +0000 (12:01 +0200)]
man: document the new Type=exec type

And while we are at it, let's rearrange and extend the Type=
documentation a bit. Let's make it an itemized list, and let's add a
paragraph explaining which type best to use.

(cherry picked from commit 79905a246d645d21633f09f564b3672d5085a85c)

Resolves: #1683334

6 years agocore: introduce new Type=exec service type
Lennart Poettering [Tue, 17 Jul 2018 09:47:14 +0000 (11:47 +0200)]
core: introduce new Type=exec service type

Users are often surprised that "systemd-run" command lines like
"systemd-run -p User=idontexist /bin/true" will return successfully,
even though the logs show that the process couldn't be invoked, as the
user "idontexist" doesn't exist. This is because Type=simple will only
wait until fork() succeeded before returning start-up success.

This patch adds a new service type Type=exec, which is very similar to
Type=simple, but waits until the child process completed the execve()
before returning success. It uses a pipe that has O_CLOEXEC set for this
logic, so that the kernel automatically sends POLLHUP on it when the
execve() succeeded but leaves the pipe open if not. This means PID 1
waits exactly until the execve() succeeded in the child, and not longer
and not shorter, which is the desired functionality.

Making use of this new functionality, the command line
"systemd-run -p User=idontexist -p Type=exec /bin/true" will now fail,
as expected.

(cherry picked from commit 5686391b006ee82d8a4559067ad9818e3e631247)

Resolves: #1683334

6 years agoexecute: use our usual syntax for defining bit masks
Lennart Poettering [Thu, 5 Jul 2018 08:00:52 +0000 (10:00 +0200)]
execute: use our usual syntax for defining bit masks

(cherry picked from commit ce0d60a7c4e07c5bdfed9f076bd48752287f0777)

Resolves: #1683334

6 years agocore: swap order of "n_storage_fds" and "n_socket_fds" parameters
Lennart Poettering [Thu, 5 Jul 2018 07:56:54 +0000 (09:56 +0200)]
core: swap order of "n_storage_fds" and "n_socket_fds" parameters

When process fd lists to pass to activated programs we always place the
socket activation fds first, and the storage fds last. Irritatingly in
almost all calls the "n_storage_fds" parameter (i.e. the number of
storage fds to pass) came first so far, and the "n_socket_fds" parameter
second. Let's clean this up, and specify the number of fds in the order
the fds themselves are passed.

(Also, let's fix one more case where "unsigned" was used to size an
array, while we should use "size_t" instead.)

(cherry picked from commit 25b583d7ffd699384435eba8e49f6ce927a83af0)

Resolves: #1683334

6 years agosocket-util: Introduce send_one_fd_iov() and receive_one_fd_iov()
Filipe Brandenburger [Wed, 25 Jul 2018 01:46:01 +0000 (18:46 -0700)]
socket-util: Introduce send_one_fd_iov() and receive_one_fd_iov()

These take a struct iovec to send data together with the passed FD.

The receive function returns the FD through an output argument. In case data is
received, but no FD is passed, the receive function will set the output
argument to -1 explicitly.

Update code in dynamic-user to use the new helpers.

(cherry picked from commit d34673ecb825aa9ecf6958b0caab792f5061c56a)

Resolves: #1683319

6 years agotest-socket-util: Add tests for receive_fd_iov() and friends.
Filipe Brandenburger [Wed, 25 Jul 2018 03:15:55 +0000 (20:15 -0700)]
test-socket-util: Add tests for receive_fd_iov() and friends.

Test it when sending an FD without any contents, or an FD and some contents,
or only contents and no FD (using a bare send().)

Also fix the previous test which forked but was missing an _exit() at the
end of the child execution code.

(cherry picked from commit 8a3386ab4fea9c4efa9c72e7c149cf510a46f03e)

Resolves: #1683319

6 years agotravis: switch from trusty to xenial
Frantisek Sumsal [Sat, 23 Feb 2019 21:28:05 +0000 (22:28 +0100)]
travis: switch from trusty to xenial

This should fix the timeout in test-event

Taken from: b635e4ef6b2f35f07111bb66a68fe850a2ccab72

Resolves: #1683319

6 years agomount-point: honour AT_SYMLINK_FOLLOW correctly
Lennart Poettering [Sat, 8 Dec 2018 19:21:43 +0000 (20:21 +0100)]
mount-point: honour AT_SYMLINK_FOLLOW correctly

Fixes: #11092
(cherry picked from commit be24321f3dae91a166166b239954032727439942)

Resolves: #1683319

6 years agosd-bus: call cap_last_cap() only once in has_cap()
Lennart Poettering [Wed, 10 Oct 2018 09:12:54 +0000 (11:12 +0200)]
sd-bus: call cap_last_cap() only once in has_cap()

Also, use the same type everywhere for dealing with it.

(cherry picked from commit 92a40e20bf970c3ded8a50fbeeae882a7b970c9a)

Resolves: #1683319

6 years agosd-bus: use size_t when dealing with memory offsets
Lennart Poettering [Wed, 10 Oct 2018 09:12:22 +0000 (11:12 +0200)]
sd-bus: use size_t when dealing with memory offsets

(cherry picked from commit 3cae6c21e732fd46ff024d6625243d88ef6377ed)

Resolves: #1683319

6 years agocapability: introduce CAP_TO_MASK_CORRECTED() macro replacing CAP_TO_MASK()
Lennart Poettering [Wed, 10 Oct 2018 09:07:54 +0000 (11:07 +0200)]
capability: introduce CAP_TO_MASK_CORRECTED() macro replacing CAP_TO_MASK()

linux/capability.h's CAP_TO_MASK potentially shifts a signed int "1"
(i.e. 32bit wide) left by 31 which means it becomes negative. That's
just weird, and ubsan complains about it. Let's introduce our own macro
CAP_TO_MASK_CORRECTED which doesn't fall into this trap, and make use of
it.

Fixes: #10347
(cherry picked from commit 5f00c5684f96c93a22840f7241ee444b9a632b1e)

Resolves: #1683319

6 years agosd-journal: escape binary data in match_make_string()
Evgeny Vereshchagin [Fri, 12 Oct 2018 12:17:04 +0000 (12:17 +0000)]
sd-journal: escape binary data in match_make_string()

Fixes: #10383
(cherry picked from commit 9e8b1ec08e8eb0b4611b7caf6adb8828feb32312)

Resolves: #1683319

6 years agotest-socket-util: avoid "memleak" reported by valgrind
Zbigniew Jędrzejewski-Szmek [Tue, 21 Aug 2018 17:44:48 +0000 (19:44 +0200)]
test-socket-util: avoid "memleak" reported by valgrind

valgrind reports the allocation done in the short-lived child as a leak.
Let's restructure the code to avoid this.

(cherry picked from commit 181c4ba750770b54a54b5abbe8ae8ff4f6db59b5)

Resolves: #1683319

6 years agoutil: introduce memcmp_safe()
Yu Watanabe [Wed, 8 Aug 2018 07:22:55 +0000 (16:22 +0900)]
util: introduce memcmp_safe()

(cherry picked from commit f30faf854b9bf01da294547a1bc3660506d750db)

Resolves: #1683319

6 years agotree-wide: various ubsan zero size memory fixes
Lennart Poettering [Wed, 10 Oct 2018 09:34:30 +0000 (11:34 +0200)]
tree-wide: various ubsan zero size memory fixes

Fixes: #10346
(cherry picked from commit 65f95765d05ddcd9e5849b68c379afa7e87d1248)

Resolves: #1683319

6 years agotests: keep SYS_PTRACE when running under ASan
Frantisek Sumsal [Fri, 9 Nov 2018 11:47:30 +0000 (12:47 +0100)]
tests: keep SYS_PTRACE when running under ASan

(cherry picked from commit 7a3025658836c536f81fdd742fa338545294f5bf)

Resolves: #1683319

6 years agotravis: enable ASan and UBSan on RHEL8
Frantisek Sumsal [Sat, 23 Feb 2019 16:10:55 +0000 (17:10 +0100)]
travis: enable ASan and UBSan on RHEL8

Resolves: #1683319
rhel-only

6 years agoutil: do not use stack frame for parsing arbitrary inputs
Yu Watanabe [Wed, 22 Aug 2018 03:33:27 +0000 (12:33 +0900)]
util: do not use stack frame for parsing arbitrary inputs

This replaces strndupa() by strndup() in socket_address_parse(),
as input string may be too long.

Fixes issue 10007 by ClusterFuzz-External:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10007

(cherry picked from commit 8d30fcb9b51b1d102a589171b6e28f5f370236f6)

Resolves: #1696224

6 years agobus-message: avoid wrap-around when using length read from message
Zbigniew Jędrzejewski-Szmek [Thu, 23 Aug 2018 12:48:40 +0000 (14:48 +0200)]
bus-message: avoid wrap-around when using length read from message

We would read (-1), and then add 1 to it, call message_peek_body(..., 0, ...),
and when trying to make use of the data.

The fuzzer test case is just for one site, but they all look similar.

v2: fix two UINT8_MAX/UINT32_MAX mismatches founds by LGTM
(cherry picked from commit 902000c19830f5e5a96e8948d691b42e91ecb1e7)

Resolves: #1696224

6 years agobus-message: return -EBADMSG not -EINVAL on invalid !gvariant messages
Zbigniew Jędrzejewski-Szmek [Sat, 11 Aug 2018 09:43:09 +0000 (11:43 +0200)]
bus-message: return -EBADMSG not -EINVAL on invalid !gvariant messages

(cherry picked from commit d831fb6f2bde829f9309aea242f502587662d1cc)

Resolves: #1696224

6 years agofuzz-bus-message: add two test cases that pass now
Zbigniew Jędrzejewski-Szmek [Sat, 11 Aug 2018 09:31:45 +0000 (11:31 +0200)]
fuzz-bus-message: add two test cases that pass now

It seems that they got fixed by one of the patches. Let's add them
just in case.

(cherry picked from commit edde66ffc2404de58e8b19810951f376efb344da)

Resolves: #1696224

6 years agobus-message: also properly copy struct signature when skipping
Zbigniew Jędrzejewski-Szmek [Sat, 11 Aug 2018 07:02:48 +0000 (09:02 +0200)]
bus-message: also properly copy struct signature when skipping

The change is similar to that in the previous commit, but I don't have
a reproducer / test case case for this one, so I'm keeping it seperate.

(cherry picked from commit 3d338a302f56c0ef0445660d9856794abe1af8b5)

Resolves: #1696224

6 years agobus-message: fix skipping of array fields in !gvariant messages
Zbigniew Jędrzejewski-Szmek [Sat, 11 Aug 2018 06:32:20 +0000 (08:32 +0200)]
bus-message: fix skipping of array fields in !gvariant messages

We copied part of the string into a buffer that was off by two.
If the element signature had length one, we'd copy 0 bytes and crash when
looking at the "first" byte. Otherwise, we would crash because strncpy would
not terminate the string.

(cherry picked from commit 73777ddba5100fe6c0791cd37a91f24a515f3202)

Resolves: #1696224

6 years agobus-message: output debug information about offset troubles
Zbigniew Jędrzejewski-Szmek [Fri, 3 Aug 2018 16:05:27 +0000 (18:05 +0200)]
bus-message: output debug information about offset troubles

(cherry picked from commit 0b4775b52747bebf7ecb62062798475629767044)

Resolves: #1696224

6 years agobus-message: drop asserts in functions which are wrappers for varargs version
Zbigniew Jędrzejewski-Szmek [Fri, 3 Aug 2018 14:36:51 +0000 (16:36 +0200)]
bus-message: drop asserts in functions which are wrappers for varargs version

The function does no processing on it's own, and just forwards arguments
to the other function. Let's just use the asserts there.

(cherry picked from commit 8792bdf8a3311f9e629daa0ec592c97c1cfb2a7c)

Resolves: #1696224

6 years agobus-message: fix calculation of offsets table for arrays
Zbigniew Jędrzejewski-Szmek [Fri, 3 Aug 2018 12:46:57 +0000 (14:46 +0200)]
bus-message: fix calculation of offsets table for arrays

This is similar to the grandparent commit 'fix calculation of offsets table',
except that now the change is for array elements. Same story as before: we need
to make sure that the offsets increase enough taking alignment into account.

While at it, rename 'p' to 'previous' to match similar code in other places.

(cherry picked from commit f88214cf9d66c93f4d22c4c8980de9ee3ff45bab)

Resolves: #1696224

6 years agobus-message: remove duplicate assignment
Zbigniew Jędrzejewski-Szmek [Thu, 2 Aug 2018 12:25:31 +0000 (14:25 +0200)]
bus-message: remove duplicate assignment

(cherry picked from commit 4d82a8d5052fce8c1ea51f8bdec3476fb8cc4747)

Resolves: #1696224

6 years agobus-message: fix calculation of offsets table
Zbigniew Jędrzejewski-Szmek [Thu, 2 Aug 2018 12:25:11 +0000 (14:25 +0200)]
bus-message: fix calculation of offsets table

The offsets specify the ends of variable length data. We would trust the
incoming data, putting the offsets specified in our message
into the offsets tables after doing some superficial verification.
But when actually reading the data we apply alignment, so we would take
the previous offset, align it, making it bigger then current offset, and
then we'd try to read data of negative length.

In the attached example, the message specifies the following offsets:
[1, 4]
but the alignment of those items is
[1, 8]
so we'd calculate the second item as starting at 8 and ending at 4.

(cherry picked from commit 12603b84d2fb07603e2ea94b240c6b78ad17510e)

Resolves: #1696224

6 years agobus: do not print (null) if the message has unknown type
Zbigniew Jędrzejewski-Szmek [Wed, 1 Aug 2018 22:46:20 +0000 (00:46 +0200)]
bus: do not print (null) if the message has unknown type

(cherry picked from commit e8fd7e4b5b5269377efc641a7da43850822c1250)

Resolves: #1696224

6 years agobus-message: use define
Zbigniew Jędrzejewski-Szmek [Tue, 24 Jul 2018 19:24:53 +0000 (21:24 +0200)]
bus-message: use define

(cherry picked from commit f22c308aff556bf5c6599ffcb61e637e366ab232)

Resolves: #1696224

6 years agobus-message: rename function for clarity
Zbigniew Jędrzejewski-Szmek [Tue, 24 Jul 2018 18:14:39 +0000 (20:14 +0200)]
bus-message: rename function for clarity

There's already message_free_last_container(), so rename to match.

(cherry picked from commit 9c65778d614588d21645163dea97a5fe2c1c4ca5)

Resolves: #1696224

6 years agobus-message: let's always use -EBADMSG when the message is bad
Zbigniew Jędrzejewski-Szmek [Mon, 9 Jul 2018 09:12:33 +0000 (11:12 +0200)]
bus-message: let's always use -EBADMSG when the message is bad

-EINVAL means the arguments were somehow wrong, so translate the code we get
internally into -EBADMSG when returning.

(cherry picked from commit 69bd42ca072dfb2f7603b1f82053063293ab54b5)

Resolves: #1696224

6 years agobus-message: avoid an infinite loop on empty structures
Zbigniew Jędrzejewski-Szmek [Mon, 9 Jul 2018 08:52:51 +0000 (10:52 +0200)]
bus-message: avoid an infinite loop on empty structures

The alternative would be to treat gvariant and !gvariant messages differently.
But this is a problem because we check signatures is variuos places before we
have an actual message, for example in sd_bus_add_object_vtable(). It seems
better to treat things consistent (i.e. follow the lowest common denominator)
and disallow empty structures everywhere.

(cherry picked from commit ec6bda56cbca9509b1abde1122645630caca877c)

Resolves: #1696224

6 years agobus-message: use structured initialization to avoid use of unitialized memory
Zbigniew Jędrzejewski-Szmek [Mon, 9 Jul 2018 05:38:10 +0000 (07:38 +0200)]
bus-message: use structured initialization to avoid use of unitialized memory

As far as I can see, we would either reuse some values from a previously exited
container or just random bytes from the heap.

Should fix #10127.

(cherry picked from commit cf81c68e96aa29d0c28b5d3a26d1de9aa1b53b85)

Resolves: #1696224

6 years agofuzz-bus-message: add fuzzer for message parsing
Zbigniew Jędrzejewski-Szmek [Sat, 7 Jul 2018 17:30:25 +0000 (19:30 +0200)]
fuzz-bus-message: add fuzzer for message parsing

As with other fuzzers, SYSTEMD_FUZZ_OUTPUT=1 and SYSTEMD_LOG_LEVEL=debug can be
used for debugging.

(cherry picked from commit 56b560c26339c4b282c06038316a91509eae75fd)

Resolves: #1696224

6 years agomeson: treat all fuzz cases as unit tests
Zbigniew Jędrzejewski-Szmek [Fri, 10 Aug 2018 15:15:05 +0000 (17:15 +0200)]
meson: treat all fuzz cases as unit tests

318/365 fuzz-bus-message:crash-26bba7182dedc8848939931d9fcefcb7922f2e56:address  OK       0.03 s
319/365 fuzz-bus-message:crash-29ed3c202e0ffade3cad42c8bbeb6cc68a21eb8e:address  OK       0.03 s
320/365 fuzz-bus-message:crash-b88ad9ecf4aacf4a0caca5b5543953265367f084:address  OK       0.03 s
321/365 fuzz-bus-message:crash-c1b37b4729b42c0c05b23cba4eed5d8102498a1e:address  OK       0.03 s
322/365 fuzz-bus-message:crash-d8f3941c74219b4c03532c9b244d5ea539c61af5:address  OK       0.03 s
323/365 fuzz-bus-message:crash-e1b811da5ca494e494b77c6bd8e1c2f2989425c5:address  OK       0.03 s
324/365 fuzz-bus-message:leak-c09c0e2256d43bc5e2d02748c8d8760e7bc25d20:address  OK       0.04 s
325/365 fuzz-bus-message:message1:address       OK       0.03 s
326/365 fuzz-bus-message:timeout-08ee8f6446a4064db064e8e0b3d220147f7d0b5b:address  OK       0.03 s
327/365 fuzz-dhcp-server:discover-existing:address  OK       0.04 s
328/365 fuzz-dhcp-server:discover-new:address   OK       0.03 s
329/365 fuzz-dhcp-server:release:address        OK       0.04 s
330/365 fuzz-dhcp-server:request-existing:address  OK       0.03 s
331/365 fuzz-dhcp-server:request-new:address    OK       0.03 s
332/365 fuzz-dhcp-server:request-reboot:address  OK       0.03 s
333/365 fuzz-dhcp-server:request-renew:address  OK       0.03 s
334/365 fuzz-dns-packet:issue-7888:address      OK       0.03 s
335/365 fuzz-dns-packet:oss-fuzz-5465:address   OK       0.03 s
336/365 fuzz-journal-remote:crash-5a8f03d4c3a46fcded39527084f437e8e4b54b76:address  OK       0.06 s
337/365 fuzz-journal-remote:crash-96dee870ea66d03e89ac321eee28ea63a9b9aa45:address  OK       0.04 s
338/365 fuzz-journal-remote:invalid-ts.txt:address  OK       0.04 s
339/365 fuzz-journal-remote:oss-fuzz-8659:address  OK       0.06 s
340/365 fuzz-journal-remote:oss-fuzz-8686:address  OK       0.04 s
341/365 fuzz-journal-remote:sample.txt:address  OK       0.07 s
342/365 fuzz-unit-file:directives.service:address  OK       0.03 s
343/365 fuzz-unit-file:empty.scope:address      OK       0.04 s
344/365 fuzz-unit-file:machine.slice:address    OK       0.03 s
345/365 fuzz-unit-file:oss-fuzz-6884:address    OK       0.05 s
346/365 fuzz-unit-file:oss-fuzz-6885:address    OK       0.03 s
347/365 fuzz-unit-file:oss-fuzz-6886:address    OK       0.04 s
348/365 fuzz-unit-file:oss-fuzz-6892:address    OK       0.03 s
349/365 fuzz-unit-file:oss-fuzz-6897:address    OK       0.05 s
350/365 fuzz-unit-file:oss-fuzz-6897-evverx:address  OK       0.04 s
351/365 fuzz-unit-file:oss-fuzz-6908:address    OK       0.05 s
352/365 fuzz-unit-file:oss-fuzz-6917:address    OK       0.06 s
353/365 fuzz-unit-file:oss-fuzz-6977:address    OK       0.08 s
354/365 fuzz-unit-file:oss-fuzz-6977-unminimized:address  OK       0.10 s
355/365 fuzz-unit-file:oss-fuzz-7004:address    OK       0.03 s
356/365 fuzz-unit-file:oss-fuzz-8064:address    OK       0.03 s
357/365 fuzz-unit-file:oss-fuzz-8827:address    OK       0.50 s
358/365 fuzz-unit-file:proc-sys-fs-binfmt_misc.automount:address  OK       0.03 s
359/365 fuzz-unit-file:syslog.socket:address    OK       0.03 s
360/365 fuzz-unit-file:systemd-ask-password-console.path:address  OK       0.03 s
361/365 fuzz-unit-file:systemd-machined.service:address  OK       0.03 s
362/365 fuzz-unit-file:systemd-resolved.service:address  OK       0.03 s
363/365 fuzz-unit-file:systemd-tmpfiles-clean.timer:address  OK       0.03 s
364/365 fuzz-unit-file:timers.target:address    OK       0.03 s
365/365 fuzz-unit-file:var-lib-machines.mount:address  OK       0.04 s

This gives us slightly nicer coverage in the normal test run.

When in a git repo, git ls-files is used to get a list of files known to git.
This mirrors what update-man-rules does for man files. Only looking at files
known to git makes it easier to not forget to commit the test file to git,
and also makes bisecting easier if some files are left in repo.

When outside of a git repo, we expect to be unpacked from a tarball, so just
using all files reported by ls is OK.

(cherry picked from commit e6bad6746151c79a5f408e95714ffa5cea290ab0)

Resolves: #1696224

6 years agomeson: use .source_root() in more places
Zbigniew Jędrzejewski-Szmek [Fri, 10 Aug 2018 14:50:07 +0000 (16:50 +0200)]
meson: use .source_root() in more places

In the main meson.build file, .source_root() and .current_source_dir() are
equivalent, but it seems more appropriate to use .source_root() when we are appending
a path which is by design relative to repo root.

(cherry picked from commit 243e5cecc3a211519544ccba01c44edc827ac517)

Resolves: #1696224

6 years agomeson: drop duplicated condition
Zbigniew Jędrzejewski-Szmek [Tue, 7 Aug 2018 16:10:53 +0000 (18:10 +0200)]
meson: drop duplicated condition

The generic check suffices for those four.

(cherry picked from commit 6bd2bc8e16a6d515f8a21c47fd6b833d7fcfdd1c)

Resolves: #1696224

6 years agomeson: allow building resolved and machined without nss modules
Yu Watanabe [Wed, 18 Jul 2018 00:25:57 +0000 (09:25 +0900)]
meson: allow building resolved and machined without nss modules

This adds -Dnss-resolve= and -Dnss-mymachines= meson options.
By using this option, e.g., resolved can be built without nss-resolve.
When no nss modules are built, then test-nss is neither built.

Also, This changes the option name -Dmyhostname= to -Dnss-myhostname=
for consistency to other nss related options.

Closes #9596.

(cherry picked from commit 08540a9591efe105439be81fc43d6dc65b715978)

Resolves: #1696224

6 years agomeson: add -Dlog-trace to set LOG_TRACE
Zbigniew Jędrzejewski-Szmek [Tue, 7 Aug 2018 15:34:47 +0000 (17:34 +0200)]
meson: add -Dlog-trace to set LOG_TRACE

The justification is the same as for -Dvalgrind: setting config in
meson in this way is easier, because when the value is changed stuff
that should be rebuilt is rebuilt.

(cherry picked from commit fd5dec9adf76591d713f163d43d04e3beb76893e)

Resolves: #1696224

6 years agotest-bus-marshal: use cescaping instead of hexmem
Zbigniew Jędrzejewski-Szmek [Sat, 7 Jul 2018 17:08:52 +0000 (19:08 +0200)]
test-bus-marshal: use cescaping instead of hexmem

It is easier to see the contents this way by eye.

(cherry picked from commit 3ddf3d439463ab2c76391a4d22b54166be2dbe94)

Resolves: #1696224

6 years agofuzz: unify the "fuzz-regressions" directory with the main corpus
Zbigniew Jędrzejewski-Szmek [Sat, 7 Jul 2018 16:09:21 +0000 (18:09 +0200)]
fuzz: unify the "fuzz-regressions" directory with the main corpus

There isn't really much need to keep them separate. Anything which is a good
corpus entry can be used as a smoke test, and anything which which is a
regression test can just as well be inserted into the corpus.

The only functional difference from this patch (apart from different paths in
output) is that the regression tests are now zipped together with the rest of
the corpus.

$ meson configure build -Dslow-tests=true && ninja -C build test
...
307/325 fuzz-dns-packet:issue-7888:address      OK       0.06 s
308/325 fuzz-dns-packet:oss-fuzz-5465:address   OK       0.04 s
309/325 fuzz-journal-remote:crash-5a8f03d4c3a46fcded39527084f437e8e4b54b76:address  OK       0.07 s
310/325 fuzz-journal-remote:crash-96dee870ea66d03e89ac321eee28ea63a9b9aa45:address  OK       0.05 s
311/325 fuzz-journal-remote:oss-fuzz-8659:address  OK       0.05 s
312/325 fuzz-journal-remote:oss-fuzz-8686:address  OK       0.07 s
313/325 fuzz-unit-file:oss-fuzz-6884:address    OK       0.06 s
314/325 fuzz-unit-file:oss-fuzz-6885:address    OK       0.05 s
315/325 fuzz-unit-file:oss-fuzz-6886:address    OK       0.05 s
316/325 fuzz-unit-file:oss-fuzz-6892:address    OK       0.05 s
317/325 fuzz-unit-file:oss-fuzz-6897:address    OK       0.05 s
318/325 fuzz-unit-file:oss-fuzz-6897-evverx:address  OK       0.06 s
319/325 fuzz-unit-file:oss-fuzz-6908:address    OK       0.07 s
320/325 fuzz-unit-file:oss-fuzz-6917:address    OK       0.07 s
321/325 fuzz-unit-file:oss-fuzz-6977:address    OK       0.13 s
322/325 fuzz-unit-file:oss-fuzz-6977-unminimized:address  OK       0.12 s
323/325 fuzz-unit-file:oss-fuzz-7004:address    OK       0.05 s
324/325 fuzz-unit-file:oss-fuzz-8064:address    OK       0.05 s
325/325 fuzz-unit-file:oss-fuzz-8827:address    OK       0.52 s

(cherry picked from commit c74a3f973e3e0bac13d66a28728a47f10046b71f)

Resolves: #1696224

6 years agotest: add testcase for issue 10007 by oss-fuzz
Yu Watanabe [Wed, 22 Aug 2018 03:39:40 +0000 (12:39 +0900)]
test: add testcase for issue 10007 by oss-fuzz

(cherry picked from commit a1a605f144e5635fdae57125a92032b3e5ebeca9)

Resolves: #1696224

6 years agofuzz: rename "fuzz-corpus" directory to just "fuzz"
Zbigniew Jędrzejewski-Szmek [Sat, 7 Jul 2018 15:43:40 +0000 (17:43 +0200)]
fuzz: rename "fuzz-corpus" directory to just "fuzz"

Also, all corpus subdirectories are named exactly the same as the fuzzer they
are for. This makes the paths a bit longer, but easier.

(cherry picked from commit 93b575b26605c347a717b2aa24ddf9cad08b8080)

Resolves: #1696224

6 years agotests: add a reproducer for another infinite loop in ndisc_handle_datagram
Evgeny Vereshchagin [Wed, 26 Sep 2018 18:09:09 +0000 (18:09 +0000)]
tests: add a reproducer for another infinite loop in ndisc_handle_datagram

(cherry picked from commit bbb393877b2cfcbe2f205c902ca7d9f7ce91f1a1)

Resolves: #1696224

6 years agotests: add a reproducer for an infinite loop in ndisc_handle_datagram
Evgeny Vereshchagin [Wed, 26 Sep 2018 15:10:21 +0000 (15:10 +0000)]
tests: add a reproducer for an infinite loop in ndisc_handle_datagram

=0  ndisc_router_parse (rt=0x60d000000110) at ../src/libsystemd-network/ndisc-router.c:126
=1  0x000055555558dc67 in ndisc_handle_datagram (nd=0x608000000020, rt=0x60d000000110) at ../src/libsystemd-network/sd-ndisc.c:170
=2  0x000055555558e65d in ndisc_recv (s=0x611000000040, fd=4, revents=1, userdata=0x608000000020) at ../src/libsystemd-network/sd-ndisc.c:233
=3  0x00007ffff63913a8 in source_dispatch (s=0x611000000040) at ../src/libsystemd/sd-event/sd-event.c:3042
=4  0x00007ffff6395eab in sd_event_dispatch (e=0x617000000080) at ../src/libsystemd/sd-event/sd-event.c:3455
=5  0x00007ffff6396b12 in sd_event_run (e=0x617000000080, timeout=18446744073709551615) at ../src/libsystemd/sd-event/sd-event.c:3512
=6  0x0000555555583f5c in LLVMFuzzerTestOneInput (data=0x6060000000e0 "\206", size=53) at ../src/fuzz/fuzz-ndisc-rs.c:422
=7  0x0000555555586356 in main (argc=2, argv=0x7fffffffe3d8) at ../src/fuzz/fuzz-main.c:33

(cherry picked from commit df30e78e02f653c9e6ee6677b7ccaea21d3dcd7d)

Resolves: #1696224

6 years agotests: add reproducers for several issues uncovered with fuzz-journald-syslog
Evgeny Vereshchagin [Sun, 2 Sep 2018 18:13:31 +0000 (18:13 +0000)]
tests: add reproducers for several issues uncovered with fuzz-journald-syslog

This is a follow-up to a70f343cacf03ac51cdefb0d2e.

(cherry picked from commit 3311c74d0560e4aa6a223f5e288a5fbf2404d3fa)

Resolves: #1696224

6 years agondisc: fix two infinite loops
Yu Watanabe [Fri, 28 Sep 2018 10:28:05 +0000 (19:28 +0900)]
ndisc: fix two infinite loops

(cherry picked from commit f3241c61f12dbd8f0ed37419ae272e291d09461d)

Resolves: #1696224

6 years agotests: add a fuzzer for sd-ndisc
Evgeny Vereshchagin [Wed, 26 Sep 2018 15:04:26 +0000 (15:04 +0000)]
tests: add a fuzzer for sd-ndisc

(cherry picked from commit 0f0a1dad7d69802a7e6c7fc9aba350f0e87c1952)

Resolves: #1696224

6 years agotests: add a fuzzer for server_process_native_message
Evgeny Vereshchagin [Mon, 3 Sep 2018 07:05:48 +0000 (07:05 +0000)]
tests: add a fuzzer for server_process_native_message

(cherry picked from commit 9cdea02db57a36442ad9e9afcd67760ca319173a)

Resolves: #1696224

6 years agojournald: make server_process_native_message compatible with fuzz_journald_processing...
Evgeny Vereshchagin [Mon, 3 Sep 2018 07:03:10 +0000 (07:03 +0000)]
journald: make server_process_native_message compatible with fuzz_journald_processing_function

(cherry picked from commit 21acb27b71f6284a57e4e9f3ac5f0d38721ef4eb)

Resolves: #1696224

6 years agotests: rework the code fuzzing journald
Evgeny Vereshchagin [Mon, 3 Sep 2018 06:46:24 +0000 (06:46 +0000)]
tests: rework the code fuzzing journald

This should make it easier to add a new fuzzer without a lot of
duplication.

(cherry picked from commit b1bd453f36b9428b6bf9feba31fa0a2b36143e9c)

Resolves: #1696224

6 years agojournald: free the allocated memory before returning from dev_kmsg_record
Evgeny Vereshchagin [Fri, 10 Aug 2018 12:52:07 +0000 (12:52 +0000)]
journald: free the allocated memory before returning from dev_kmsg_record

This fixes a minor memory leak.

(cherry picked from commit 30eddcd51b8a472e05d3b8d1f0b89fbd3e094d71)

Resolves: #1696224

6 years agojournald: make it clear that dev_kmsg_record modifies the string passed to it
Evgeny Vereshchagin [Fri, 10 Aug 2018 12:45:42 +0000 (12:45 +0000)]
journald: make it clear that dev_kmsg_record modifies the string passed to it

The function replaces a couple commas, a semicolon and the final newline with
zero bytes in the string passed to it. The 'const' seems to have been added
by accident during a bulk edit (more specifically 3b3154df7e2773332bb814).

(cherry picked from commit 1e0c5fc2a76e4f3d508331f410899c50493e1fc9)

Resolves: #1696224