Commit Graph

10680 Commits

Author SHA1 Message Date
Evgeny Vereshchagin
3e3f699b1e
ci: get around https://github.com/lxc/lxc/issues/3798
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-21 10:05:01 +02:00
Evgeny Vereshchagin
060c1b13ff
ci: switch to lxc-exercise from the lxc-ci repository
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-21 10:05:00 +02:00
Evgeny Vereshchagin
33132141d3
ci: link lib[au]san with init.lxc.static statically
init.lxc.static is run in arbitrary containers where the libasan library lxc has been built with
isn't always installed. To make it work let's override GCC's default and link both libasan
and libubsan statically. It should help to fix issues like
```
++ lxc-execute -n c1 -- sudo -u ubuntu /nnptest
lxc-init: error while loading shared libraries: libasan.so.5: cannot open shared object file: No such file or directory
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-21 10:04:59 +02:00
Evgeny Vereshchagin
b347825b83
ci: an attempt to run the tests under ASan/UBsan
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-21 10:04:58 +02:00
Evgeny Vereshchagin
816d252c18
apparmor: turn bytes into null-terminated strings before calling strcspn
```
==70349==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000009fb at pc 0x000000433b70 bp 0x7ffcde087810 sp 0x7ffcde086fd0
READ of size 12 at 0x6020000009fb thread T0
    #0 0x433b6f in strcspn (/usr/bin/lxc-execute+0x433b6f)
    #1 0x7f720413a5cb in apparmor_process_label_get /home/runner/work/lxc/lxc/src/lxc/lsm/apparmor.c:449:8
    #2 0x7f720413bc2a in apparmor_prepare /home/runner/work/lxc/lxc/src/lxc/lsm/apparmor.c:1104:13
    #3 0x7f720409b6e9 in lxc_init /home/runner/work/lxc/lxc/src/lxc/start.c:848:8
    #4 0x7f72040a395a in __lxc_start /home/runner/work/lxc/lxc/src/lxc/start.c:2009:8
    #5 0x7f7203fc7186 in lxc_execute /home/runner/work/lxc/lxc/src/lxc/execute.c:99:9
    #6 0x7f7204000e44 in do_lxcapi_start /home/runner/work/lxc/lxc/src/lxc/lxccontainer.c:1112:9
    #7 0x7f7203ff0c07 in lxcapi_start /home/runner/work/lxc/lxc/src/lxc/lxccontainer.c:1149:8
    #8 0x4c6912 in main /home/runner/work/lxc/lxc/src/lxc/tools/lxc_execute.c:224:9
    #9 0x7f72034ac0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #10 0x41d93d in _start (/usr/bin/lxc-execute+0x41d93d)
+ echo ---

0x6020000009fb is located 0 bytes to the right of 11-byte region [0x6020000009f0,0x6020000009fb)
allocated by thread T0 here:
    #0 0x496399 in realloc (/usr/bin/lxc-execute+0x496399)
    #1 0x7f7203fcf85c in fd_to_buf /home/runner/work/lxc/lxc/src/lxc/file_utils.c:463:10
    #2 0x7f720413a52b in apparmor_process_label_get /home/runner/work/lxc/lxc/src/lxc/lsm/apparmor.c:442:8
    #3 0x7f720413bc2a in apparmor_prepare /home/runner/work/lxc/lxc/src/lxc/lsm/apparmor.c:1104:13
    #4 0x7f720409b6e9 in lxc_init /home/runner/work/lxc/lxc/src/lxc/start.c:848:8
    #5 0x7f72040a395a in __lxc_start /home/runner/work/lxc/lxc/src/lxc/start.c:2009:8
    #6 0x7f7203fc7186 in lxc_execute /home/runner/work/lxc/lxc/src/lxc/execute.c:99:9
    #7 0x7f7204000e44 in do_lxcapi_start /home/runner/work/lxc/lxc/src/lxc/lxccontainer.c:1112:9
    #8 0x7f7203ff0c07 in lxcapi_start /home/runner/work/lxc/lxc/src/lxc/lxccontainer.c:1149:8
    #9 0x4c6912 in main /home/runner/work/lxc/lxc/src/lxc/tools/lxc_execute.c:224:9
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-21 10:04:55 +02:00
Christian Brauner
71c436462c
commands: don't needlessly allocate
Fixes: #3796
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-18 17:50:48 +02:00
Christian Brauner
7ed8a62218
process_utils: free stack after return
Fixes: #3789
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-18 17:50:48 +02:00
Christian Brauner
a905c1eda8
configure: fix sanitizer compilation
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-18 17:50:47 +02:00
Christian Brauner
370f27e167
error_utils: add missing macro.h include
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-18 17:50:46 +02:00
Evgeny Vereshchagin
48d0042063
tests: pass on ASAN/UBSAN options to several tests
to make it easier to run them under ASan/UBSan.

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-18 17:50:45 +02:00
Evgeny Vereshchagin
742467fe11
tests: stop cutting off right square brackets in share_ns
Closes https://github.com/lxc/lxc/issues/3791

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-18 17:50:45 +02:00
Evgeny Vereshchagin
7b2876362f
tests: switch to the "busybox" template in lxc-test-checkpoint-restore
criu can't seem to dump systemd-logind used in Ubuntu due to what appears to be
https://github.com/checkpoint-restore/criu/issues/1430.
Let's switch to busybox where all the processes hopefully can be dumped.

Closes https://github.com/lxc/lxc/issues/3792

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-18 17:50:42 +02:00
Christian Brauner
42f652435c
lxccontainer: fix container creation error paths
Fixes: #3782
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-15 10:26:22 +02:00
Evgeny Vereshchagin
b4ad57ae87
tests: fix a memory leak in attach
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-15 10:26:21 +02:00
Evgeny Vereshchagin
257562c244
tests: fix a memory leak in cgpath
```
==131188==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 568 byte(s) in 1 object(s) allocated from:
    #0 0x7f8918943bc8 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10dbc8)
    #1 0x7f89181ee5a3 in lxc_container_new /home/vagrant/lxc/src/lxc/lxccontainer.c:5264
    #2 0x55ffc5022869 in test_container /home/vagrant/lxc/src/tests/cgpath.c:176
    #3 0x55ffc5023023 in main /home/vagrant/lxc/src/tests/cgpath.c:233
    #4 0x7f891709e0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-15 10:26:17 +02:00
Christian Brauner
8e2ef39ba5
Revert "confile: make lxc_get_config() and lxc_get_config_net() always return non-NULL"
This reverts commit 674791ed75.

Our stable queue tool somehow still listed this patch as pending when it
had already been applied earlier.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-13 14:42:15 +02:00
Evgeny Vereshchagin
2cba1595e6
tests: fix a memory leak in lxcpath
```
$ sudo ./src/tests/lxc-test-lxcpath

=================================================================
==95911==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 39 byte(s) in 1 object(s) allocated from:
    #0 0x7effafc8d3dd in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x963dd)
    #1 0x7effaf5a2de6 in lxcapi_config_file_name /home/vagrant/lxc/src/lxc/lxccontainer.c:3190
    #2 0x562961680c30 in main /home/vagrant/lxc/src/tests/lxcpath.c:49
    #3 0x7effae5150b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Direct leak of 21 byte(s) in 1 object(s) allocated from:
    #0 0x7effafc8d3dd in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x963dd)
    #1 0x7effaf5a2de6 in lxcapi_config_file_name /home/vagrant/lxc/src/lxc/lxccontainer.c:3190
    #2 0x56296168115e in main /home/vagrant/lxc/src/tests/lxcpath.c:77
    #3 0x7effae5150b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Direct leak of 21 byte(s) in 1 object(s) allocated from:
    #0 0x7effafc8d3dd in strdup (/lib/x86_64-linux-gnu/libasan.so.5+0x963dd)
    #1 0x7effaf5a2de6 in lxcapi_config_file_name /home/vagrant/lxc/src/lxc/lxccontainer.c:3190
    #2 0x562961680f0a in main /home/vagrant/lxc/src/tests/lxcpath.c:63
    #3 0x7effae5150b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

SUMMARY: AddressSanitizer: 81 byte(s) leaked in 3 allocation(s).
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-13 14:35:37 +02:00
Evgeny Vereshchagin
e46bffbb19
tests: fix a memory leak in cgpath
```
$ sudo ./src/tests/lxc-test-cgpath
Container creation tests...Passed
Container creation with LXCPATH tests...Passed

=================================================================
==57206==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 296 byte(s) in 1 object(s) allocated from:
    #0 0x7fef22c27dc6 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10ddc6)
    #1 0x557c6e3ce3d9 in cgroup_ops_init cgroups/cgfsng.c:3347
    #2 0x557c6e3d6516 in cgroup_init cgroups/cgroup.c:33
    #3 0x557c6e3788e2 in test_running_container /home/vagrant/lxc/src/tests/cgpath.c:102
    #4 0x557c6e379c69 in test_container /home/vagrant/lxc/src/tests/cgpath.c:197
    #5 0x557c6e379e37 in main /home/vagrant/lxc/src/tests/cgpath.c:233
    #6 0x7fef2136c0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)

Direct leak of 296 byte(s) in 1 object(s) allocated from:
    #0 0x7fef22c27dc6 in calloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10ddc6)
    #1 0x557c6e3ce3d9 in cgroup_ops_init cgroups/cgfsng.c:3347
    #2 0x557c6e3d6516 in cgroup_init cgroups/cgroup.c:33
    #3 0x557c6e3788e2 in test_running_container /home/vagrant/lxc/src/tests/cgpath.c:102
    #4 0x557c6e379c69 in test_container /home/vagrant/lxc/src/tests/cgpath.c:197
    #5 0x557c6e379e61 in main /home/vagrant/lxc/src/tests/cgpath.c:237
    #6 0x7fef2136c0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-13 14:35:36 +02:00
Christian Brauner
674791ed75
confile: make lxc_get_config() and lxc_get_config_net() always return non-NULL
Introduce the concept of an unsupported config item.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-13 14:35:29 +02:00
Christian Brauner
9c75153c5c
Revert "rexec: mark all fds as close-on-exec if possible"
This reverts commit 531d36ad00.

Callers might want to explicilty inhert file descriptors so we can't
close them behind their back when we exec.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-12 19:49:05 +02:00
Christian Brauner
0c167942df
attach: don't return early when calculating namespaces via pidfd
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-12 19:49:04 +02:00
Christian Brauner
c0f1dc951f
conf: don't report success when idmaptools lack all privilege
Fixes: #3777
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-12 19:49:03 +02:00
Christian Brauner
24d1ef2b2f
conf: simplify idmaptool_on_path_and_privileged()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-12 19:49:02 +02:00
Christian Brauner
933acfaa43
confile: make lxc_get_config() and lxc_get_config_net() always return non-NULL
Introduce the concept of an unsupported config item.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-12 19:49:00 +02:00
Stéphane Graber
2d6a6cb5a9
github: Try to fix action naming
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2021-04-12 19:48:56 +02:00
Christian Brauner
fe38f0b149
confile: enforce maximum subkey length
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-07 14:18:25 +02:00
Christian Brauner
b33f435db7
log: add error_ret()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-07 14:18:24 +02:00
Christian Brauner
b425aad13f
macro: ensure ret_errno() always returns negative
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-07 14:18:23 +02:00
Evgeny Vereshchagin
2be8511d3b
cifuzz: fuzz longer
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-07 14:18:22 +02:00
Evgeny Vereshchagin
dc95a270de
confile: fix a memory leak lxc_config_define_add
```
2021-04-02T05:45:54.9410345Z ==13==ERROR: LeakSanitizer: detected memory leaks
2021-04-02T05:45:54.9410737Z
2021-04-02T05:45:54.9411488Z Direct leak of 16 byte(s) in 1 object(s) allocated from:
2021-04-02T05:45:54.9412556Z     #0 0x54d752 in calloc /src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:154:3
2021-04-02T05:45:54.9413360Z     #1 0x583795 in parse_new_conf_line /src/lxc/src/lxc/confile.c:3048:8
2021-04-02T05:45:54.9414057Z     #2 0x582f1a in lxc_config_define_add /src/lxc/src/lxc/confile.c:3090:15
2021-04-02T05:45:54.9415352Z     #3 0x5810fa in LLVMFuzzerTestOneInput /src/lxc/src/tests/fuzz-lxc-define-load.c:30:6
2021-04-02T05:45:54.9419212Z     #4 0x483b93 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:599:15
2021-04-02T05:45:54.9421819Z     #5 0x48309a in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long, bool, fuzzer::InputInfo*, bool, bool*) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:505:3
2021-04-02T05:45:54.9424205Z     #6 0x485474 in fuzzer::Fuzzer::ReadAndExecuteSeedCorpora(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:814:7
2021-04-02T05:45:54.9426658Z     #7 0x485689 in fuzzer::Fuzzer::Loop(std::__Fuzzer::vector<fuzzer::SizedFile, fuzzer::fuzzer_allocator<fuzzer::SizedFile> >&) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerLoop.cpp:845:3
2021-04-02T05:45:54.9428616Z     #8 0x473717 in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerDriver.cpp:906:6
2021-04-02T05:45:54.9429989Z     #9 0x49f572 in main /src/llvm-project/compiler-rt/lib/fuzzer/FuzzerMain.cpp:20:10
2021-04-02T05:45:54.9433312Z     #10 0x7fa96041b83f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2083f)
2021-04-02T05:45:54.9433795Z
2021-04-02T05:45:54.9434661Z DEDUP_TOKEN: calloc--parse_new_conf_line--lxc_config_define_add
2021-04-02T05:45:54.9435483Z SUMMARY: AddressSanitizer: 16 byte(s) leaked in 1 allocation(s).
2021-04-02T05:45:54.9435958Z
2021-04-02T05:45:54.9436404Z INFO: a leak has been found in the initial corpus.
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-07 14:18:21 +02:00
Evgeny Vereshchagin
cc521256fa
oss-fuzz: fuzz lxc_config_define_add and lxc_config_define_load
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-07 14:18:17 +02:00
Christian Ratzenhofer
5a624e0870
templates/*.in: fixed PATH handling with spaces
if $PATH already contains a path with a space the append of the
default directories in all template scripts fails with an error
like the following:

/usr/share/lxc/templates/lxc-download: 69: export: (x86)/NVIDIA: bad
variable name

Signed-off-by: Christian Ratzenhofer <christian.ratzenhofer@cdnm.at>
2021-04-06 16:53:14 +02:00
Christian Brauner
2e6527320e
log: ensure we always return negative errno
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 16:53:13 +02:00
Christian Brauner
cfc0a48ea2
conf: fix setups where /dev is outside of LXC's control
Fixes: #3770
Suggested-by: Ruben Jenster <r.jenster@drachenfels.de>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 16:53:09 +02:00
Christian Brauner
448462dd37
confile: complain when LXC is built without AppArmor support
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:26:43 +02:00
Christian Brauner
029dff4a47
confile: complain when LXC is built without selinux support
Link: https://github.com/lxc/lxc/issues/3765
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:26:42 +02:00
Christian Brauner
f4f2fc2c31
confile: fix lxc.namespace.share.[identifier]
Link: https://github.com/lxc/lxc/pull/3763/files#r606089660
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:25:53 +02:00
Christian Brauner
cea4f8d95b
confile: simplify get_network_config_ops()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:25:02 +02:00
Christian Brauner
497b1a2ba4
string_utils: use restrict for lxc_safe_int64_residual()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:17 +02:00
Christian Brauner
5f1d274cb1
string_utils: ensure that errno is set on return
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:16 +02:00
Christian Brauner
98e8508ccf
string_utils: move to lxc-copy() sources
It's the only place where it is still used.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:15 +02:00
Christian Brauner
c0a515a328
lxc_user_nic: cleanup get_alloted()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:14 +02:00
Christian Brauner
f21078df80
lxc_user_nic: cleanup append_alloted()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:13 +02:00
Christian Brauner
1f2cdd4641
confile: cap to last bit in set_config_net_ipv4_address()
Link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32708
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:12 +02:00
Christian Brauner
636a155886
string_utils: switch to path_simplify()
Link: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32689
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:24:10 +02:00
Christian Brauner
589e822456
confile: don't jump into the global table twice
instead move networking keys into a subtable. This avoids even just the
remote danger of recursion and also speeds up config parsing.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2021-04-06 10:23:54 +02:00
Evgeny Vereshchagin
2f59375679
oss-fuzz: reject giant configs early
It should help the fuzzer to avoid running into timeouts
like https://oss-fuzz.com/testcase-detail/5132999948632064.
Hopefully, once this is merged OSS-Fuzz will report only
infinite loops as timeouts.

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-02 16:11:02 +02:00
Evgeny Vereshchagin
52c57882a0
build-system: make it compatible with ASan/UBsan/MSan
Closes: https://github.com/lxc/lxc/issues/3727

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-02 16:11:01 +02:00
Evgeny Vereshchagin
85ec1b47dc
ci: enable PAM
to make sure pam_cgfs is buildable with ASan/UBsan too

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-02 16:11:00 +02:00
Evgeny Vereshchagin
766b5f0564
ci: also build with ASan/UBsan
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2021-04-02 16:10:59 +02:00