1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-23 17:34:00 +03:00
Commit Graph

50237 Commits

Author SHA1 Message Date
Lennart Poettering
915ba31cfd resolved: rework CNAME logic a bit more
When following CNAME/DNAME redirects in the stub we currently first
iterate through the packet and pick up what we can use (in
dns_stub_collect_answer_by_question() and friends), following all
CNAMEs/DNAMEs, and would then issue dns_query_process_cname() to move
the DnsQuery object forward too, where we'd then possibly restart
the query and pick things up again, as above.

There's one thought error in this though: dns_query_process_cname()
tries to be smart and will internally follow not just a single
CNAME/DNAME redirect, but a chain of them if they are contained inside
the same packet until we reach the point where the answer is not
included in the packet anymore, where we'd restart the query. This was
great as long as we only focussed on the D-Bus and Varlink resolver
APIs, since there the CNAME/DNAME chain in the middle doesn't actually
matter, we just return information about the final name of the RR and
its content, and aren't interested in the chain to it. For the DNS stub
this is different however: there we need to place the full CNAME/DNAME
chain (and all the appropriate metadata RRs) in the stub reply.

Hence rework this so that we build on the fact that the previous commit
split dns_query_process_cname() in two:

1. dns_query_process_cname_one() will do exactly one CNAME/DNAME
   redirect step. This will be called by the stub, so that we can pick
   up matching RRs for every single step along the way.

2. dns_query_process_cname_many() will follow a chain as long as that's
   possible within the same packet. It's thus pretty much identical to
   the old dns_query_process_cname() call. This is what we now use in
   the D-Bus and Varlink APIs. dns_query_process_cname_many() is
   basically just a loop around dns_query_process_cname_one().

Any logic to follow and pick up RRs manually in the stub along the
CNAME/DNAME path is now dropped (i.e.
dns_stub_collect_answer_by_question() becomes trivially simple again),
we solely rely on dns_query_process_cname_one() to follow CNAME/DNAME
now: each step followed by a full call of dns_stub_assign_sections() to
copy out the RRs that matter.

Net result: things are a bit simpler again, as the only place we follow
CNAME/DNAME redirects is DnsQuery again, and stub answers are always
complete: they contain all CNAME/DNAME RRs on the way including all
their metadata we might pick up in the other sections.
2021-03-25 13:12:19 +01:00
Lennart Poettering
1db8e6d1db resolved: split dns_query_process_cname() into two separate functions
This does some refactoring: the dns_query_process_cname() function
becomes two: dns_query_process_cname_one() and
dns_query_process_cname_many(). The former will process exactly one
CNAME chain element, the latter will follow a chain for as long as
possible within the current packet.

dns_query_process_cname_many() is mostly identical to the old
dns_query_process_cname(), and all existing code is moved over to using
that.

This is mostly preparation for the next commit, where we make direct use
of dns_query_process_cname_one().

This also renames the DNS_QUERY_RESTARTED return value to
DNS_QUERY_CNAME. That's because in the dns_query_process_cname_many()
case as before if we return this we restarted the query in case we
reached the end of the chain without a conclusive answer, as before. But
in dns_query_process_cname_one() we'll only go one step anyway, and
leave restarting if needed to the caller. Hence DNS_QUERY_RESTARTED is a
bit of a misnomer in that case.

This also gets rid of the weird tail recursion in
dns_query_process_cname() and replaces it with an explicit loop in
dns_query_process_cname_many(). The old recursion wasn't a security
issue since we put a limit on the number of CNAMEs we follow anyway, but
it's still icky to scale stack use by that.
2021-03-25 13:12:19 +01:00
Lennart Poettering
d451f0e84b resolved: tweak sections we add answer RRs to
Previously we'd stick all answer sections RRs we acquired into
the authoritative section if we didn't find them directly answering our
question. Let's put them into additional instead. The authoritative
section should hence only include what comes from the upstream
authoritative section, and nothing else.
2021-03-25 11:42:39 +01:00
Lennart Poettering
8640566ac4 resolved: pass mDNS reply packets to each transaction exactly once
Previously we'd iterate through the RRs of an mDNS reply and then find
exactly one matching transaction on our scope for it, and pass it as
reply to that. If multiple RRs of the same packet match we'd pas the
packet multiple times to the transaction even.

This all doesn't really work anymore since there can be multiple open
transactions for the same key (with different flags), and it's kinda
ugly anywy. Hence let's turn this around: let's iterate through the
transactions and check if any of the included RRs match it, and if so
pass the packet to that transaction exactly once.

This speeds up mDNS a bit, since previously we'd oftentimes fail to find
all suitable transactions for an mDNS reply (because there can be
multiple transactions for the same RR key with different flags, and we
checked exactly one flag combination). Which would then mean the
transaction would time out, and be retried – at which point the cache
would be populated and thus it would still succeed, but only after this
timeout. With this fix this is corrected: every transaction that matches
will get the reply, instantly as we get it.
2021-03-25 11:37:30 +01:00
Lennart Poettering
9b564bbca5 resolved: upgrade log level to LOG_NOTICE if we switch to fallback server (or back)
This is inspired by a recent thread on fedora-devel: it's noteworthy
when we switch to the fallback servers, since it might (or might not)
indicate some configuration problem.

Fixes: #18788
2021-03-25 10:43:23 +01:00
simmon
390e67305d po: Translated using Weblate (Korean)
Currently translated at 100.0% (189 of 189 strings)

Co-authored-by: simmon <simmon@nplob.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/master/ko/
Translation: systemd/main
2021-03-25 10:42:02 +01:00
Lennart Poettering
729c5deb2e resolved: don't suppress OPT if we have no OPT
This is inspired by #18917. It suppresses a misleading log message about
suppressing OPT where we might not actually have OPT.
2021-03-25 11:38:53 +09:00
Luca Boccassi
a2c69debd9
Merge pull request #19076 from yuwata/firewall-util-modernizations
firewall-util: modernize code and improve test
2021-03-24 23:19:59 +00:00
David Tardon
d2f4a9488c local-addresses: fix use of uninitialized value
This can happen if ifi fails to be read from the netlink message and the
error is ENODATA.

Fixes the following valgrind message when running netstat:

==164141== Conditional jump or move depends on uninitialised value(s)
==164141==    at 0x524AE60: address_compare (local-addresses.c:29)
==164141==    by 0x48BCC78: msort_with_tmp.part.0 (msort.c:105)
==164141==    by 0x48BC9E4: msort_with_tmp (msort.c:45)
==164141==    by 0x48BC9E4: msort_with_tmp.part.0 (msort.c:53)
==164141==    by 0x48BCF85: msort_with_tmp (msort.c:45)
==164141==    by 0x48BCF85: qsort_r (msort.c:297)
==164141==    by 0x52500FC: UnknownInlinedFun (sort-util.h:47)
==164141==    by 0x52500FC: local_gateways.constprop.0 (local-addresses.c:310)
==164141==    by 0x5251C05: _nss_myhostname_gethostbyaddr2_r (nss-myhostname.c:456)
==164141==    by 0x5252006: _nss_myhostname_gethostbyaddr_r (nss-myhostname.c:500)
==164141==    by 0x498E7FE: gethostbyaddr_r@@GLIBC_2.2.5 (getXXbyYY_r.c:274)
==164141==    by 0x498E560: gethostbyaddr (getXXbyYY.c:135)
==164141==    by 0x121353: INET_rresolve.constprop.0 (inet.c:212)
==164141==    by 0x1135B9: INET_sprint (inet.c:261)
==164141==    by 0x121BFC: addr_do_one.constprop.0.isra.0 (netstat.c:1156)
2021-03-24 18:14:45 +01:00
Yu Watanabe
b5d2f4e757 test-firewall-util: use assert_se() at most places
Otherwise, we cannot notice any failures...
2021-03-25 01:05:54 +09:00
Pjotr Vertaalt
91a96a564f po: Translated using Weblate (Dutch)
Currently translated at 100.0% (189 of 189 strings)

Co-authored-by: Pjotr Vertaalt <pjotrvertaalt@gmail.com>
Translate-URL: https://translate.fedoraproject.org/projects/systemd/master/nl/
Translation: systemd/main
2021-03-24 18:26:52 +09:00
Anita Zhang
7b7a060e83 process-util: dont allocate max length to read /proc/PID/cmdline
Alternative title: Replace get_process_cmdline()'s fopen()/fread() with
read_full_virtual_file().

When RLIMIT_STACK is set to infinity:infinity, _SC_ARG_MAX will
return 4611686018427387903 (depending on the system, but definitely
something larger than most systems have). It's impractical to allocate this
in one go when most cmdlines are much shorter than that.

Instead use read_full_virtual_file() which seems to increase the buffer
depending on the size of the contents.
2021-03-24 16:46:45 +09:00
Lincoln Ramsay
7325a2b2d1
pid1: do not use generated strings as format strings (#19098)
The generated string may include %, which will confuse both the
xprintf call, and the VA_FORMAT_ADVANCE macro.

Pass the generated string as an argument to a "%s" format string
instead.
2021-03-24 16:37:25 +09:00
hide
6b1ed5e7e6
network: fix ipv6 tunnel encapsulation limit (#19087)
The encapsulation limit of IPv6 tunnel can not be set to 4, which is the default value of the encapsulation limit.
2021-03-24 01:05:25 +09:00
Lennart Poettering
f19384b43f repart: remove spurious empty double newlines 2021-03-23 15:52:59 +00:00
Lennart Poettering
86b8610794 blockdev-util: actually specify an access mode on open()
Linux is pretty lenient here, but we should specify the access mode.
2021-03-23 16:37:05 +01:00
Lennart Poettering
49bd547b38 update TODO 2021-03-23 14:43:07 +01:00
Pjotr Vertaalt
798c65cf1f po: Added translation using Weblate (Dutch)
Co-authored-by: Pjotr Vertaalt <pjotrvertaalt@gmail.com>
2021-03-23 11:06:02 +01:00
David Tardon
f055cf7786 man: document differences in clean exit status for Type=oneshot
See commit 1f0958f640 .
2021-03-23 09:33:23 +01:00
Christian Hesse
3babb81625 man: rate limited services can be restartet from timer or socket
If rate limiting kicks in for Restart= logic it is still possible for a
timer or socket to restart the service.
2021-03-23 09:16:30 +01:00
Zbigniew Jędrzejewski-Szmek
39f756d3ae sd-event: disable epoll_pwait2 for now
This reverts the gist of commit 798445ab84.

Unfortunately the new syscall causes test-event to hang. 32 bit architectures
seem affected: i686 and arm32 in fedora koji. 32 bit build of test-event hangs
reliably under valgrind:

$ PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig meson build-32 -Dc_args=-m32 -Dc_link_args=-m32 -Dcpp_args=-m32 -Dcpp_link_args=-m32 && ninja -C build-32 test-event && valgrind build/test-event

If I set epoll_pwait2_absent=true, so the new function is never called, then
the issue does not reproduce. It seems to be strictly tied to the syscall.

On amd64, the syscall is not used, at least with the kernel that Fedora
provides. The kernel patch 58169a52ebc9a733aeb5bea857bc5daa71a301bb says:

  For timespec, only support this new interface on 2038 aware platforms
  that define __kernel_timespec_t. So no CONFIG_COMPAT_32BIT_TIME.

And Fedora sets CONFIG_COMPAT_32BIT_TIME=y. I expect most other distros will too.

On amd64: epoll_wait_usec: epoll_pwait2: ret=-1 / errno=38
On i686 (same kernel): epoll_wait_usec: epoll_pwait2: ret=2 / errno=0

Is this some kind of emulation? Anyway, it seems that this is what is going wrong.

So let's disable the syscall until it becomes more widely available and the
kinks have been ironed out.

Fixes test-event issue in #19052.
2021-03-23 09:10:29 +01:00
Zbigniew Jędrzejewski-Szmek
ca83c7f88c
Merge pull request #19075 from keszybz/calendarspec-loop
Fix infinite loop in calendarspec calculation when timezone has negative DST save value
2021-03-23 09:06:16 +01:00
Yu Watanabe
0c4363a005 firewall-util: refuse IPv6 firewall rules when kernel does not support IPv6 2021-03-23 15:17:44 +09:00
Yu Watanabe
175bc86315 firewall-util: gracefully handle -EOVERFLOW returned from older kernel 2021-03-23 15:17:44 +09:00
Yu Watanabe
5ee7c719e1 firewall-util: do not use goto for retrying 2021-03-23 15:17:44 +09:00
Yu Watanabe
84af90ba5d firewall-util: add missing return value check 2021-03-23 15:17:44 +09:00
Yu Watanabe
dfb433f2a7 firewall-util: probe firewall backend in fw_ctx_new()
FirewallContext is used by networkd and nspawn. Both allocates the
context when it is really necessary. Hence, it is not necessary to delay
probing backend.

Moreover, if iptables backend is not enabled on build, and nftables is
not supported by kernel, previously `fw_nftables_init()` is called
everytime when we try to configure masquerade or dnat. It causes
significant performance loss.

Fixes test-firewall-util issue in #19052.
2021-03-23 15:17:34 +09:00
Yu Watanabe
4fb8a48ff0 network: allocate FirewallContext lazily 2021-03-23 14:41:13 +09:00
Yu Watanabe
da00b84087 firewall-util: logs which backend will be used
This also modernizes code a bit.
2021-03-23 14:40:50 +09:00
Zbigniew Jędrzejewski-Szmek
129cb6e249 shared/calendarspec: when mktime() moves us backwards, jump forward
When trying to calculate the next firing of 'Sun *-*-* 01:00:00', we'd fall
into an infinite loop, because mktime() moves us "backwards":

Before this patch:
tm_within_bounds: good=0 2021-03-29 01:00:00 → 2021-03-29 00:00:00
tm_within_bounds: good=0 2021-03-29 01:00:00 → 2021-03-29 00:00:00
tm_within_bounds: good=0 2021-03-29 01:00:00 → 2021-03-29 00:00:00
...

We rely on mktime() normalizing the time. The man page does not say that it'll
move the time forward, but our algorithm relies on this. So let's catch this
case explicitly.

With this patch:
$ TZ=Europe/Dublin faketime 2021-03-21 build/systemd-analyze calendar --iterations=5 'Sun *-*-* 01:00:00'
Normalized form: Sun *-*-* 01:00:00
    Next elapse: Sun 2021-03-21 01:00:00 GMT
       (in UTC): Sun 2021-03-21 01:00:00 UTC
       From now: 59min left
       Iter. #2: Sun 2021-04-04 01:00:00 IST
       (in UTC): Sun 2021-04-04 00:00:00 UTC
       From now: 1 weeks 6 days left           <---- note the 2 week jump here
       Iter. #3: Sun 2021-04-11 01:00:00 IST
       (in UTC): Sun 2021-04-11 00:00:00 UTC
       From now: 2 weeks 6 days left
       Iter. #4: Sun 2021-04-18 01:00:00 IST
       (in UTC): Sun 2021-04-18 00:00:00 UTC
       From now: 3 weeks 6 days left
       Iter. #5: Sun 2021-04-25 01:00:00 IST
       (in UTC): Sun 2021-04-25 00:00:00 UTC
       From now: 1 months 4 days left

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1941335.
2021-03-23 00:35:02 +01:00
Luca Boccassi
e6fda8f675
Merge pull request #19079 from poettering/resolved-ipv6-cache-fix
fix CNAME/DNAME following in combined A/AAAA replies
2021-03-22 23:20:11 +00:00
Luca Boccassi
d4bb2b0b4e
Merge pull request #19081 from keszybz/three-comment-updates
Three comment updates
2021-03-22 22:36:01 +00:00
Zbigniew Jędrzejewski-Szmek
ccd593a61c man: say that .device units need udev
This was implied by the need to tag them with "systemd", but let's make this
obvious, since it's rather easy to trip over this as a user.

Inspired by https://bugzilla.redhat.com/show_bug.cgi?id=1941458.
2021-03-22 21:48:45 +01:00
Zbigniew Jędrzejewski-Szmek
d229704743 Reword and reindent comment
Follow-up for 0e557eef37.
2021-03-22 21:48:17 +01:00
Zbigniew Jędrzejewski-Szmek
de0b89913c Partially revert "correct incorrect command in NEWS (#19048)"
This reverts commit 6d18c13e79.

The syntax like "0666" is very unclear. It only makes sense for some subset of
people who do C programming. Let's use the much more sensible modern python
syntax instead.
2021-03-22 21:33:03 +01:00
Zbigniew Jędrzejewski-Szmek
965984240e
Merge pull request #19058 from bugaevc/log-open-protect-errno
Save errno over log_open() calls
2021-03-22 21:28:28 +01:00
Yu Watanabe
c23bb96b38 shell-completion: systemd-run: add missing options
Closes #19044.
2021-03-22 21:20:17 +01:00
Lennart Poettering
24063ba16a update TODO 2021-03-22 21:17:58 +01:00
Zbigniew Jędrzejewski-Szmek
47b0b65766 test-calendarspec: do not convert timezone "" to ":"
I *think* it doesn't actually make any difference, because ":" will be ignored.
437f48a471 added prefixing with ":", but didn't
take into account the fact that we also use "" with a different meaning than
NULL here. But let's restore the original behaviour of specifying the empty
string.
2021-03-22 20:08:16 +01:00
Zbigniew Jędrzejewski-Szmek
f035bb1b7a test-calendarspec: print offending line in output
The output is rather long at this makes it easier to jump to the right place.
Also use normal output routines and set_unset_env() to make things more
compact.
2021-03-22 20:08:16 +01:00
Zbigniew Jędrzejewski-Szmek
462f15d92d shared/calendarspec: constify parameter and simplify assignments to variable
The scope of start & stop is narrowed down, and they are assigned only once.
No functional change, but I think the code is easier to read this way.
Also add a comment to make the code easier to read.
2021-03-22 20:08:16 +01:00
Lennart Poettering
7e7b0e2198 update TODO 2021-03-22 19:07:34 +01:00
Lennart Poettering
1a71fe4ee5 resolved: don't accept responses to query unless they completely answer our questions
When we checking if the responses we collected for a DnsQuery are
sufficient to complete it we previously only check if one of the
collected response RRs matches at least one of the question RR keys.

This changes the logic to require that there must be at least one
response RR matched *each* of the question RR keys before considering
the answer complete.

Otherwise we might end up accepting an A reply as complete answer for an
A/AAAA query and vice versa, but we want to make sure we wait until we
get a reply on both types before returning this to the user in all
cases.

This has been broken for basically forever, but didn't surface until
b1eea703e0 since until then we'd basically
ignore the auxiliary RRs included in CNAME/DNAME replies. Once that
commit was made we'd start using the auxiliary RRs included in
CNAME/DNAME replies but those typically included only A or only AAAA
which we then took for complete.

Fixe: #19049
2021-03-22 18:40:06 +01:00
Lennart Poettering
4cba52cc7a resolved: propagate correct error variable 2021-03-22 18:27:36 +01:00
Sergey Bugaev
fbdacd7268 homework: use FORK_CLOSE_ALL_FDS in a few more places
And make sure to reopen the log appropriately.
2021-03-22 19:34:07 +03:00
Sergey Bugaev
7e0ed2e9a2 tree-wide: reopen log after fork when needed
This follows up on 0b1f3c768c, adding more places
where we should reopen the log after forking with FORK_CLOSE_ALL_FDS.

When immediately calling exec in the child, prefer to explicitly reopen the log
after exec fails. In other cases, just use FORK_REOPEN_LOG.
2021-03-22 19:34:07 +03:00
Sergey Bugaev
0e557eef37 log: protect errno in log_open()
Commit 0b1f3c768c has introduced log_open()
calls after exec fails post-fork. However, the log_open() call itself could
change the value of errno, which, for me, manifested in:

$ coredumpctl gdb
...
Failed to invoke gdb: Success

Fix this by using PROTECT_ERRNO in log_open().
2021-03-22 19:34:03 +03:00
Yu Watanabe
dcb6061e1c meson: fix warning about comparison between different types
Follow-up for e39288193f.
2021-03-22 14:40:46 +01:00
Zbigniew Jędrzejewski-Szmek
169615c9a8 shared/calendarspec: abort calculation after 1000 iterations
We have a bug where we seem to enter an infinite loop when running in the
Europe/Dublin timezone. The timezone is "special" because it has negative SAVE
values. The handling of this should obviously be fixed, but let's use a
belt-and-suspenders approach, and gracefully fail if we fail to find an answer
within a specific number of attempts. The code in this function is rather
complex, and it's hard to rule out another bug in the future.
2021-03-22 13:44:57 +01:00
Antonio Terceiro
17e9000164 logs-show: add missing newline in warning message 2021-03-21 17:52:07 +00:00