Commit Graph

11557 Commits

Author SHA1 Message Date
Tycho Andersen
f7f15b20a3 make setproctitle()'s /proc/pid/stat parsing safe
it turns out that our parsing of /proc/pid/stat was not safe in general
(though probably safe for lxc, since our executable names do not contain
spaces).

Let's fix this by looking backwards through the file for ), and then
continuing on from there.

This was reported to me by Solar Designer, who pointed me to this thread:
https://twitter.com/solardiz/status/1634204168545001473

Indeed, this is a lot of tap dancing to work around the kernel's 16
character executable limit. Perhaps I'll send a kernel patch to raise that
limit next.

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
2023-04-10 17:20:47 -06:00
Serge Hallyn
52326514c6
Merge pull request #4287 from hallyn/2023-03-10/dbus
switch from libsystemd's dbus to dbus-1
2023-03-19 17:05:06 -05:00
Serge Hallyn
5894cf3101 console-log test: make sure container is stopped before restarting
Closes #4237

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-03-19 16:04:46 -05:00
Serge Hallyn
820d2a2b3a switch from libsystemd's dbus to dbus-1
This is purely so that we can do static linking.  Linking against
libsystemd makes that a challenge because while it's perfectly simple
to do, distros tend not to provide a libsystemd.a.

Tools that want to (a) link against liblxc and (b) have a statically
linked binary to bind into a minimal container are ill served by
this.  So link against libdbus-1.

.github/workflows/build.yml: switch to dbus-1.
src/lxc/cgroups/cgfsng.c: replace the unpriv_systemd_create_scope(),
   start_scope, and enter_scope() systemd code with dbus-1 code.
src/tests/oss-fuzz.sh: update from libsystemd-dev to libdbus-1-dev
src/tests/oss-fuzz.sh: disable dbus
.github/workflows/*: update from libsystemd-dev to libdbus-1-dev
meson.build and meson_options.txt: switch from sd_bus to dbus
lxc.spec.in: add dbus-1 to BuildRequires

Signed-off-by: Serge Hallyn <serge@hallyn.com>

Changelog: 03/13: use custom iter type so we can cleanup more easily...
Changelog: 03/13: initialize each dbus_iter to { 0 } as mihalicyn suggested.
2023-03-19 15:30:56 -05:00
Stéphane Graber
12887ebcc6
Merge pull request #4290 from mihalicyn/sk_cloexec
tree-wide: convert fcntl(FD_CLOEXEC) to SOCK_CLOEXEC
2023-03-17 11:20:54 -04:00
Alexander Mikhalitsyn
3c1453a38d
tree-wide: convert fcntl(FD_CLOEXEC) to SOCK_CLOEXEC
- replace accept() + fcntl(FD_CLOEXEC) with accept4(..., SOCK_CLOEXEC)
- remove fcntl(FD_CLOEXEC) in lxc_server_init() as we already set
SOCK_CLOEXEC in lxc_abstract_unix_open().

See also: ad9429e52 ("tree-wide: make socket SOCK_CLOEXEC")
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2023-03-17 13:43:34 +01:00
Serge Hallyn
838221c111
Merge pull request #4281 from smoser/feature/oci-squashfs
Add support for squashfs images in oci via atomfs
2023-02-27 13:57:45 -06:00
Scott Moser
4ea0b361f1 Allow fuse mounts in apparmor start-container.
Unprivledged user should be able to do fuse mounts during start-container.
Specifically this solves the problem for un-priv fuse mounting via
pre-hook.

Signed-off-by: Scott Moser <smoser@brickies.net>
2023-02-27 09:07:38 -05:00
Scott Moser
1a2da75b6e Add support for squashfs images in oci via atomfs
This adds support to the oci template for squashfs images.
It uses 'atomfs' from [1] to accomplish this.

Squashfs images (media type
application/vnd.stacker.image.layer.squashfs+zstd+verity) have several
benefits compared to tar+gz:

 * immediately mountable
 * read-only filesystem
 * verity data present in oci manifest.

I presented this at Fosdem 2023 at [2].

The 'atomfs' program can be replaced by passing '--mount-helper'
argument to the oci template.

    mount-helper mount oci:<oci_dir>:<oci_name> <mountpoint>
    mount-helper umount <mountpoint>

[1] https://github.com/project-machine/atomfs
[2] https://fosdem.org/2023/schedule/event/container_secure_storage/

Signed-off-by: Scott Moser <smoser@brickies.net>
2023-02-27 09:06:37 -05:00
Christian Brauner
71f7e788d9
Merge pull request #4284 from Blub/2023-02-27/empty-apparmor-files
apparmor: don't try to mmap empty files
2023-02-27 13:23:13 +01:00
Wolfgang Bumiller
db3cbfa75c apparmor: don't try to mmap empty files
In case empty profile files linger somehow (eg. powerloss or
oom killer etc. between creating and writing the file) we
tried to use mmap() with a length of 0 which is invalid.
Let's treat this as if it did not exist.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2023-02-27 11:08:46 +01:00
Stéphane Graber
0b286bde88
Merge pull request #4279 from mihalicyn/setproctitle_fix_fmt_spec
initutils: use PRIu64 for uint64_t in setproctitle
2023-02-16 11:15:00 -05:00
Alexander Mikhalitsyn
304bf58fa1
initutils: use PRIu64 for uint64_t in setproctitle
Kernel UAPI provides as with the following declaration:
/*
 * This structure provides new memory descriptor
 * map which mostly modifies /proc/pid/stat[m]
 * output for a task. This mostly done in a
 * sake of checkpoint/restore functionality.
 */
struct prctl_mm_map {
	__u64	start_code;		/* code section bounds */
	__u64	end_code;
	__u64	start_data;		/* data section bounds */
	__u64	end_data;
	__u64	start_brk;		/* heap for brk() syscall */
	__u64	brk;
	__u64	start_stack;		/* stack starts at */
	__u64	arg_start;		/* command line arguments bounds */
	__u64	arg_end;
	__u64	env_start;		/* environment variables bounds */
	__u64	env_end;
	__u64	*auxv;			/* auxiliary vector */
	__u32	auxv_size;		/* vector size */
	__u32	exe_fd;			/* /proc/$pid/exe link file */
};

Let's use appropriate types/format specifiers everywhere.

Issue #4268

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2023-02-16 13:38:28 +01:00
Stéphane Graber
2d3dab782d
Merge pull request #4277 from n0p90/fix-nft-ip6-nat
lxc-net.in: fix nftables syntax for IPv6 NAT
2023-02-13 16:36:09 -05:00
Quentin Lyons
4de047f513 lxc-net.in: fix nftables syntax for IPv6 NAT
The nftables masquarade rule for IPv6 was using the IPv4 syntax. This
resulted in the following error when starting the lxc-net.service with
LXC_IPV6_NAT="true" and nftables:

    Feb 11 18:54:54 pc lxc-net[4936]: Error: conflicting protocols specified: ip6 vs. ip
    Feb 11 18:54:54 pc lxc-net[4936]:                              ^^^^^^^^
    Feb 11 18:54:54 pc lxc-net[4917]: Failed to setup lxc-net.
    Feb 11 18:54:54 pc systemd[1]: lxc-net.service: Main process exited, code=exited, status=1/FAILURE
    Feb 11 18:54:54 pc systemd[1]: lxc-net.service: Failed with result 'exit-code'.
    Feb 11 18:54:54 pc systemd[1]: Failed to start LXC network bridge setup.

Signed-off-by: Quentin Lyons <36303164+n0p90@users.noreply.github.com>
2023-02-12 02:24:22 +00:00
Christian Brauner
08f0e76965
Merge pull request #4275 from ariel-miculas/fix_strl_rc_checks
Fix strlcat's return value checks
2023-02-07 14:16:27 +01:00
Ariel Miculas
311bb8c53e Fix strlcat's return value checks
Alternatively we could have used safe_strlcat, but it's not used
anywhere and there's also no safe_strlcpy

Signed-off-by: Ariel Miculas <amiculas@cisco.com>
2023-02-07 13:52:31 +02:00
Christian Brauner
042d8165a1
Merge pull request #4270 from ariel-miculas/fix_typo
Fix typo: bev_type -> bdev_type
2023-01-30 17:45:12 +01:00
Ariel Miculas
588b53b198 Fix typo: bev_type -> bdev_type
Signed-off-by: Ariel Miculas <amiculas@cisco.com>
2023-01-30 18:25:55 +02:00
Christian Brauner
4a1ec6086c
Merge pull request #4263 from hallyn/2023-01-18/drop-fuzz-test
drop broken lxc-test-fuzzers
2023-01-23 23:59:12 +01:00
Serge Hallyn
7914c259f2 drop broken lxc-test-fuzzers
Closes #4261

Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-01-20 15:19:03 -06:00
Stéphane Graber
a1874c80dc
Merge pull request #4255 from gibmat/fix-sparc64-link-error
Fix build error on sparc64 caused by using the gold linker
2023-01-10 20:08:00 -05:00
Mathias Gibbens
849d808779
Fix build error on sparc64 caused by using the gold linker
Signed-off-by: Mathias Gibbens <gibmat@debian.org>
2023-01-10 23:20:14 +00:00
Stéphane Graber
e343a16122
Merge pull request #4253 from hallyn/2023-01-09/overlay
lxc-default-cgns apparmor profile: allow overlay mounts
2023-01-09 17:30:28 -05:00
Serge Hallyn
43ad7816d8 lxc-default-cgns apparmor profile: allow overlay mounts
Signed-off-by: Serge Hallyn <serge@hallyn.com>
2023-01-09 13:36:45 -06:00
Christian Brauner
2097da81da
Merge pull request #4252 from mihalicyn/create_nic_fix
lxc_user_nic: fix get_mtu() error handling
2023-01-06 20:40:34 +01:00
Serge Hallyn
1b25a401b7
Merge pull request #4245 from MaherAzzouzi/master
Patching an incoming CVE (CVE-2022-47952)
2023-01-06 12:59:21 -06:00
Alexander Mikhalitsyn
4fa83282b5
lxc_user_nic: fix get_mtu() error handling
get_mtu() returns int, but "mtu" variable has unsigned int type.
It leads to logical error in error handling, which can end up
with strange -EINVAL error in lxc_veth_create(), cause (mtu > 0)
condition is met, but negative "mtu" value is too large when set
as mtu for network device.

Issue #4232

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2023-01-06 17:05:07 +01:00
Maher Azzouzi
1b0469530d Patching an incoming CVE (CVE-2022-47952)
lxc-user-nic in lxc through 5.0.1 is installed setuid root, and may
allow local users to infer whether any file exists, even within a
protected directory tree, because "Failed to open" often indicates
that a file does not exist, whereas "does not refer to a network
namespace path" often indicates that a file exists. NOTE: this is
different from CVE-2018-6556 because the CVE-2018-6556 fix design was
based on the premise that "we will report back to the user that the
open() failed but the user has no way of knowing why it failed";
however, in many realistic cases, there are no plausible reasons for
failing except that the file does not exist.

PoC:
> % ls /l
> ls: cannot open directory '/l': Permission denied
> % /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic delete lol lol /l/h/tt h h
> cmd/lxc_user_nic.c: 1096: main: Failed to open "/l/h/tt" <----- file does not exist.
> % /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic delete lol lol /l/h/t h h
> cmd/lxc_user_nic.c: 1101: main: Path "/l/h/t" does not refer to a network namespace path <---- file exist!

Signed-off-by: MaherAzzouzi <maherazz04@gmail.com>
Acked-by: Serge Hallyn <serge@hallyn.com>
2023-01-06 08:47:43 -06:00
Christian Brauner
440727ea38
Merge pull request #4246 from ffontaine/master
src/lxc/meson.build: fix build without apparmor
2023-01-05 10:30:33 +01:00
Stéphane Graber
1641f4576b
Merge pull request #4250 from brauner/build.shared.library
build: force linking against liblxc
2023-01-04 12:22:12 -05:00
Christian Brauner
a8e1070c61
build: force linking against liblxc
We really need to split up our code into better chunks so we avoid all of this
duplicated compilation.

Fixes: https://github.com/lxc/lxc/issues/4249
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
2023-01-04 16:45:03 +01:00
Christian Brauner
6564e6ccb2
Merge pull request #4248 from stgraber/master
Tweak checkconfig output
2023-01-04 00:08:24 +01:00
Stéphane Graber
c27ea96f7f
checkconfig: Fix filesystem capability check
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:55 -05:00
Stéphane Graber
3f361da618
checkconfig: Tweak cgroup handling
Only run the Cgroup V1 checks if we're not on a fully functional CGroup
V2 system.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:54 -05:00
Stéphane Graber
3ab04999d8
checkconfig: Tweak layout
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:54 -05:00
Stéphane Graber
e027ca7119
checkconfig: Hide version if no lxc-start
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:53 -05:00
Stéphane Graber
914fec51b0
checkconfig: Fix mixed tabs/spaces
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2023-01-03 18:02:52 -05:00
Fabrice Fontaine
70b176b0d1 src/lxc/meson.build: fix build without apparmor
Don't build lsm/apparmor.c if apparmor is explicitly disabled by the
user to avoid the following build failure with gcc 4.8:

/home/buildroot/autobuild/run/instance-3/output-1/host/arm-buildroot-linux-gnueabi/sysroot/usr/include/bits/fcntl2.h: In function '__apparmor_process_label_open.isra.0':
/home/buildroot/autobuild/run/instance-3/output-1/host/arm-buildroot-linux-gnueabi/sysroot/usr/include/bits/fcntl2.h:50:24: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments
    __open_missing_mode ();
                        ^

Fixes:
 - http://autobuild.buildroot.org/results/c9f05ad264543adf429badb99310905427092772

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-12-29 14:47:50 +01:00
Stéphane Graber
0b83d71c2c
Merge pull request #4242 from mihalicyn/fixes_after_coverity
Fixes after coverity scan
2022-12-12 11:39:17 -05:00
Alexander Mikhalitsyn
42b22da6d1 cgroups: fix cgroup layout detection in __initialize_cgroups
It looks like we made a mistake while detecting cgroup layout,
we are always set CGFSNG_LAYOUT_UNIFIED bit.

Reported-by: coverity (CID #1497115)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 12:28:31 +01:00
Alexander Mikhalitsyn
0072919ddc state: additional check in lxc_wait to prevent OOB
I can't see a real problem here, but let's just add a check
just in case.

Reported-by: coverity (CID #1517314)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 11:26:21 +01:00
Alexander Mikhalitsyn
62b94d3ec3 cgroups: check snprintf retval in unpriv_systemd_create_scope
Reported-by: coverity (CID #1517315)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 10:35:21 +01:00
Alexander Mikhalitsyn
93d545e378 cgroups: fix buffer out-of-bounds access in enable_controllers_delegation
Reported-by: coverity (CID #1517317)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 10:35:02 +01:00
Alexander Mikhalitsyn
f8aa61f97f network: always initialize struct nl_handler
Despite the fact that struct nl_handler is filled zeros
in netlink_open() there are two cases where we have possible
exit paths from the function before netlink_open() is called.

At the same time we have cleaner registered:
call_cleaner(netlink_close)

Two cases:
- netdev_get_flag
- lxc_ipvlan_create

If we are exiting from these functions before netlink_open()
is called we will close random file descriptor by reading
it from (struct nl_handler)->fd.

Let's just properly initialize this structure in all cases
to prevent this bug in the future.

Reported-by: coverity (CID #1517319 and #1517316)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 10:34:18 +01:00
Alexander Mikhalitsyn
6ea4a6c06b apparmor: properly check lxc_strmmap ret value
Reported-by: coverity (CID #1517320)
Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-12 10:33:12 +01:00
Christian Brauner
667292ad89
Merge pull request #4239 from mihalicyn/github_coverity_fix
github: fix coverity (add libpam-dev)
2022-12-08 22:01:48 +01:00
Alexander Mikhalitsyn
b37cce95b6 github: fix coverity (add libpam-dev)
Should fix
meson.build:494:0: ERROR: C header 'security/pam_modules.h' not found

Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
2022-12-08 16:12:14 +01:00
Stéphane Graber
e85c649c25
Merge pull request #4236 from mihalicyn/github_check_fixes
github: fix coverity build
2022-12-08 08:32:15 -05:00
Serge Hallyn
6ab3551615
Merge pull request #4209 from DuratarskeyK/master
Simplify IN_SET macro considerably
2022-12-07 08:17:55 -06:00