36 Commits

Author SHA1 Message Date
David Kalnischkies
4e04cbafe7 Use https config on https proxies for http servers
The settings used for unwrapping TLS connections depend on the access
and hostname we connect to more than what we eventually unwrap. The
bugreport mentions CaInfo, but all other https-settings should also
apply (regardless of generic or hostname specific) to an https proxy,
even if the connection we proxy through it is http-only.

Closes: #990555
2021-09-13 16:09:19 +02:00
David Kalnischkies
96dc40b196 Replace PrintStatus with SendMessage usage
varg API is a nightmare as the symbols seems different on ever other
arch, but more importantly SendMessage does a few checks on the content
of the message and it is all outputted via C++ iostreams and not mixed
in FILE* which is handy for overriding the streams.
2021-02-04 11:00:00 +01:00
David Kalnischkies
97d6c3b2d0 Implement encoded URI handling in all methods
Every method opts in to getting the encoded URI passed along while
keeping compat in case we are operated by an older acquire system.

Effectively this is just a change for the http-based methods as the
others just decode the URI as they work with files directly.
2020-12-18 19:31:19 +01:00
Julian Andres Klode
e8016805b8 Remove code tagged APT_PKG_590, add some missing includes
Remove all code scheduled to be removed after 5.90, and fix
files to include files they previously got from hashes.h
including more headers.
2020-02-18 12:48:38 +01:00
Julian Andres Klode
7e445a5344 seccomp: Allow recvmmsg_time64() and futex_time64()
Saw those in libseccomp commit, figured should add them
too.
2020-02-10 09:02:12 +01:00
Julian Andres Klode
3b7c766275 seccomp: Allow time64 variants (>402,<415) of allowed syscalls
Went through the list of syscalls starting at 403 (and looked
one back) up to the next unknown syscalls, and added all those that
were present in their non-time64 variant.

Closes: #951012
2020-02-09 22:06:30 +01:00
Julian Andres Klode
a9916c3faa netrc: Add warning when ignoring entries for unencrypted protocols
Commit 93f33052de restricted auth.conf
entries to only apply to https by default, but this was silent - there
was no information why http sources with auth.conf entries suddenly
started failing. Add such information, and extend test case to cover
it.
2020-01-15 22:07:25 +01:00
David Kalnischkies
2b734a7ec4 Apply various suggestions by cppcheck
Reported-By: cppcheck
2019-07-08 15:51:17 +02:00
Julian Andres Klode
e435312f06 aptmethod.h: Do not have gcc warning about ignoring write() result
This is a special case here, a best effort write, so there's no
point in having warnings about it for every method.
2019-02-05 12:50:05 +01:00
Julian Andres Klode
bbfcc05c19 Add support for /etc/apt/auth.conf.d/*.conf (netrcparts)
This allows us to install matching auth files for sources.list.d
files, for example; very useful.

This converts aptmethod's authfd from one FileFd to a vector of
pointers to FileFd, as FileFd cannot be copied, and move operators
are hard.
2018-12-04 17:48:41 +01:00
Julian Andres Klode
da385be6c3 Allow restart_syscall() syscall in seccomp sandboxes
Closes: #891644
2018-04-06 14:18:25 +02:00
Julian Andres Klode
e688a4f489 Turn off seccomp sandboxing by default
LP: #1732030
Closes: #890489
Fixes meefik/linuxdeploy#869
2018-04-06 14:17:26 +02:00
David Kalnischkies
57fa854e4c reimplement and simplify mirror:// method
Embedding an entire acquire stack and HTTP logic in the mirror method
made it rather heavy weight and fragile. This reimplement goes the other
way by doing only the bare minimum in the method itself and instead
redirect the actual download of files to their proper methods.

The reimplementation drops the (in the real world) unused query-string
feature as it isn't really implementable in the new architecture.
2018-01-03 18:55:41 +01:00
David Kalnischkies
47c0bdc310 report transient errors as transient errors
The Fail method for acquire methods has a boolean parameter indicating
the transient-nature of a reported error. The problem with this is that
Fail is called very late at a point where it is no longer easily
identifiable if an error is indeed transient or not, so some calls were
and some weren't and the acquire system would later mostly ignore the
transient flag and guess by using the FailReason instead.

Introducing a tri-state enum we can pass the information about fatal or
transient errors through the callstack to generate the correct fails.
2017-12-13 23:56:29 +01:00
Julian Andres Klode
243acdee17 Do not attempt seccomp under qemu-user and drop EFAULT workaround
qemu-user passes prctl()-based seccomp through to the kernel,
umodified. That's bad, as it blocks the wrong syscalls.

We ignored EFAULT which fixed the problem for targets with different
pointer sizes from the host, but was a bad hack. In order to identify
qemu we can rely on the fact that qemu-user prints its version and
exits with 0 if QEMU_VERSION is set to an unsupported value. If we
run a command that should fail in such an environment, and it exits
with 0, then we are running in qemu-user.

apt-helper is an obvious command to run. The tests ensure it exits
with 1, and it only prints usage information. We also could not use
/bin/false because apt might just as well be from a foreign arch
while /bin/false is not.

Closes: #881519
2017-11-12 17:45:13 +01:00
Julian Andres Klode
cfb6061b82 seccomp: Allow clock_nanosleep() and nanosleep() syscalls
We sleep in http.cc, so we should allow the sleeping syscalls.
2017-10-27 21:58:27 +02:00
Julian Andres Klode
b514128890 seccomp: Allow ipc() for fakeroot, and allow sysinfo() for sort
Sorting apparently calls sysconf() which calls sysinfo() to get
free pages or whatever.

Closes: #879814, #879826
2017-10-26 20:54:28 +02:00
Julian Andres Klode
39656a6f79 Print syscall number and arch to stderr when trapped by seccomp
This should help debugging crashes. The signal handler is a C++11
lambda, yay! Special care has been taken to only use signal handler
-safe functions inside there.
2017-10-26 00:02:33 +02:00
Julian Andres Klode
230b057053 Only warn about seccomp() EINVAL (normal) and EFAULT (qemu) errors
If seccomp is disabled, we fallback to running without it. Qemu fails
in the seccomp() call, returning ENOSYS and libseccomp falls back to
prctl() without adjusting the pointer, causing the EFAULT. I hope
qemu gets fixed at some point to return EINVAL for seccomp via
prctl.

Bug-Qemu: https://bugs.launchpad.net/qemu/+bug/1726394
2017-10-25 22:16:24 +02:00
Julian Andres Klode
cf1a98baa5 methods: Enable additional syscalls (SYSV IPC) in fakeroot
If FAKED_MODE is set, enable SYSV IPC so we don't crash when
running in fakeroot.

Closes: #879662
2017-10-25 21:40:35 +02:00
Julian Andres Klode
669b310a66 seccomp: Conditionalize statx() whitelisting
statx was introduced in 4.11, so it fails to build in stretch if
we just unconditionally use it.
2017-10-23 02:17:31 +02:00
Julian Andres Klode
f5572ef1da seccomp: Add missing syscalls for ppc64el, i386, and others
These are a few overlooked syscalls. Also add readv(), writev(),
renameat2(), and statx() in case libc uses them.

Gbp-Dch: ignore
2017-10-23 01:51:19 +02:00
Julian Andres Klode
32bcbd73e0 Sandbox methods with seccomp-BPF; except cdrom, gpgv, rsh
This reduces the number of syscalls to about 140 from about
350 or so, significantly reducing security risks.

Also change prepare-release to ignore the architecture lists
in the build dependencies when generating the build-depends
package for travis.

We might want to clean up things a bit more and/or move it
somewhere else.
2017-10-22 23:38:31 +02:00
David Kalnischkies
881ec045b6 allow the auth.conf to be root:root owned
Opening the file before we drop privileges in the methods allows us to
avoid chowning in the acquire main process which can apply to the wrong
file (imagine Binary scoped settings) and surprises users as their
permission setup is overridden.

There are no security benefits as the file is open, so an evil method
could as before read the contents of the file, but it isn't worse than
before and we avoid permission problems in this setup.
2017-07-26 19:09:04 +02:00
David Kalnischkies
ea408c560e reimplement and document auth.conf
We have support for an netrc-like auth.conf file since 0.7.25 (closing
518473), but it was never documented in apt that it even exists and
netrc seems to have fallen out of usage as a manpage for it no longer
exists making the feature even more arcane.

On top of that the code was a bit of a mess (as it is written in c-style)
and as a result the matching of machine tokens to URIs also a bit
strange by checking for less specific matches (= without path) first.
We now do a single pass over the stanzas.

In practice early adopters of the undocumented implementation will not
really notice the differences and the 'new' behaviour is simpler to
document and more usual for an apt user.

Closes: #811181
2017-07-26 19:09:04 +02:00