* 'fuzz' of https://github.com/evverx/util-linux:
tests: pack testcases into zip archives
tests: integrate test_last_fuzz into the testsuite
tests: add a fuzzer for process_wtmp_file
docs: mention OSS-Fuzz and CIFuzz and how to build fuzz targets locally
tools: make it possible to set all the fuzzing flags with config-gen
build-system: make "make distcheck" work
travis: set CXX correctly
travis: turn on --enable-fuzzing-engine
build-sys: add support for --enable-fuzzing-engine
tests: integrate test_mount_fuzz into the testsuite
tests: take exit codes into account
tests: add a fuzzer for mnt_table_parse_stream
Looks like those specifiers haven't been used since 6c9ab254ae
(where sscanf was removed) was merged. This should help to get
util-linux to compile with MSan. Currently it's failing with
```
...
configure: error: libmount selected, but required scanf string alloc modifier not available
...
configure:20240: ./conftest
==116617==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x496fd6 in main /home/vagrant/util-linux/conftest.c:171:6
#1 0x7f5eb85ea1a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
#2 0x41c2cd in _start (/home/vagrant/util-linux/conftest+0x41c2cd)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/vagrant/util-linux/conftest.c:171:6 in main
Exiting
configure:20240: $? = 77
...
configure:20265: $? = 0
configure:20265: ./conftest
MemorySanitizer: bad pointer 0x000000496e60
==116627==MemorySanitizer CHECK failed: /builddir/build/BUILD/compiler-rt-9.0.1.src/lib/msan/../sanitizer_common/sanitizer_allocator_secondary.h:177 "((IsAligned(reinterpret_cast<uptr>(p), page_size_))) != (0)" (0x0, 0x0)
#0 0x41d1d8 in MsanCheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/home/vagrant/util-linux/conftest+0x41d1d8)
#1 0x484e1e in __sanitizer::CheckFailed(char const*, int, char const*, unsigned long long, unsigned long long) (/home/vagrant/util-linux/conftest+0x484e1e)
#2 0x42066c in __msan::MsanDeallocate(__sanitizer::StackTrace*, void*) (/home/vagrant/util-linux/conftest+0x42066c)
#3 0x424bc9 in free (/home/vagrant/util-linux/conftest+0x424bc9)
#4 0x496fae in main /home/vagrant/util-linux/conftest.c:173:2
#5 0x7f2245f311a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
#6 0x41c2cd in _start (/home/vagrant/util-linux/conftest+0x41c2cd)
configure:20265: $? = 77
configure: program exited with status 77
...
| }
configure:22568: result: no
configure:22926: error: libmount selected, but required scanf string alloc modifier not available
```
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
Add '-S' or '--softirq' for irqtop/lsirq, instead of interrupts, show
softirqs infomation. Because there is no more description of softirq,
do not show 'NAME' column by default.
Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
Timestamps in kernel log comes from monotonic clocksource which does not
tick when system suspended. Suspended time easily sums into hours and days
rendering human readable timestamps in dmesg useless.
Adjusting timestamps accouring to current delta between boottime and
monotonic clocksources produces accurate timestamps for messages printed
since last resume. Which are supposed to be most interesting.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
All simple function to parse --lock <mode> and $LOCK_BLOCK_DEVICE,
and to flock the fd.
The supported <mode> is:
"1" or "yes" - LOCK_EX
"0" or "no" - do nothing
"nonblock" - LOCK_EX | LOCK_NB
The function tries LOCK_NB before the solo LOCK_EX and prints
inform user that it will wait, for example:
session A:
# sfdisk --lock /dev/sdc
session B:
# sfdisk --lock /dev/sdc
sfdisk: /dev/sdc: device already locked, waiting to get lock ...
^C
# sfdisk --lock=nonblock /dev/sdc
sfdisk: /dev/sdc: device already locked
Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
Lsblk throws the following error for nvmeNcXnY devices.
lsblk: nvme1c1n1: unknown device name
This is because nvmeNcXnY devices are hidden and do not have
the file /sys/block/<nvmeNcXnY>/dev.
Following patch was added
https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=d51f05bfecb299a830897106460bf395be440c0a
Which made lsblk read from /sys/block/<nvmeNcXnY>/device/dev
which do exist for nvmeNcXnY devices.
After the above patch, the unknown error goes away.
However, another error is encountered in the very next step.
nvme1c1n1: failed to initialize sysfs handler
This is because lsblk looks for /sys/dev/block/242:1
(nvmeNcXnY major:minor) pathname which usually exists for other
block devices but not for the nvmeNcXnY devices as they are hidden.
Below patch does not even print this error for hidden devices
and exits silently.
[kzak@redhat.com: - add prefix to make sysfs_devname_is_hidden()
usable for /sys dumps
- use the function in initialize_device() more early]
Signed-off-by: Ritika Srivastava <ritika.srivastava@oracle.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
It seems that directories like /etc/motd.d are already used by PAM or
by another stuff. Let's keep it in admin/distro hands and do not
change the current default.
Signed-off-by: Karel Zak <kzak@redhat.com>
The current standard is to use directories to make it easy for
distributions to share resources. This patch also add /etc/motd.d
and /run/motd.d to the default MOTD_FILE=.
Addresses: https://github.com/karelzak/util-linux/issues/10341
Signed-off-by: Karel Zak <kzak@redhat.com>
We already have mbs_safe_nwidth() but it assumes that all "bad" chars
will be encoded by \x<hex>. Now we need also function that do not care
about encoding.
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'map-user' of https://github.com/mat8913/util-linux:
unshare: Support names for map-user/group options
lib/pwdutils: add xgetgrnam
unshare: allow custom uid/gid mappings in userns
This patch prevents to call the function strlen() with a NULL string
argument that leads to a segmentation fault.
Signed-off-by: Gaël PORTAY <gael.portay@collabora.com>
This adds support to unshare for time namespaces. With the newly added
options '-t, --time' and '--monotonic' and '--boottime' it is now
possible to change CLOCK_MONOTONIC and CLOCK_BOOTTIME in a new time
namespace.
The time namespace has been merged in kernel version 5.6 and an easy way
to test it is using CLOCK_BOOTTIME and the uptime command:
# uptime
11:08:26 up 20:28, 1 user, load average: 0.00, 0.00, 0.00
# ./unshare --fork --time --boottime 100000000 uptime
11:08:29 up 1158 days, 6:15, 1 user, load average: 0.00, 0.00, 0.00
Signed-off-by: Adrian Reber <areber@redhat.com>
Let's consolidate the code, we need to use it in libfdisk too. It
seems better to keep it generic and libblkid independent.
This patch also removes blkid_encode_alloc(), this function is overkill.
Signed-off-by: Karel Zak <kzak@redhat.com>
* 'various-fixes' of https://github.com/kerolasa/util-linux:
kill: include sys/types.h before checking SYS_pidfd_send_signal
libfdisk: fix pointer wraparound warning
hwclock: update yacc file
script: fix minor warning
getopt: use examples installation directory in man page
fstrim: randomize timer start time across 100 minutes
various: use threadsafe versions of time functions [lgtm scan]
write: fix potential string overflow
Including sys/types.h must happen before SYS_pidfd_send_signal is checked,
because that header defines variable in normal conditions. When sys/types.h
does not have SYS_pidfd_send_signal then fallback is defined in config.h
that is included by default, and has therefore worked fine before and after
this change.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Deprecating calls to not-thread safe asctime(), ctime(), and localtime()
calls is pretty close to pointless change. Lets do it to reduce lgtm scan
warnings with justification it's nicer to use static analysis tools when
they have very few positives.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Let's add "Arguments:" section to the --help output and describe
{K,M,G...}iB suffixes there.
Addresses: https://github.com/karelzak/util-linux/pull/917
Co-Author: ed <ed@s5h.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
* fix double free
* keep strrealloc() semantic compatible with classic realloc() (do not
free original pointer on failed memory allocation).
* remove unnecessary goto
Signed-off-by: Karel Zak <kzak@redhat.com>
It's mostly wrappers for compatibility and another trivial stuff etc.
Let's keep it as public domain to make it more portable to LGPL, GPL
and BSD code.
Signed-off-by: Karel Zak <kzak@redhat.com>
CC: Sami Kerola <kerolasa@iki.fi>
CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Move the helper functions that parse ISO data & sector size info into
a separate, shared header.
These will addtionally be used by libblkid's iso9660 parser.
Signed-off-by: Daniel Drake <drake@endlessm.com>
* 'kill-pidfd' of https://github.com/kerolasa/util-linux:
kill: use pidfd system calls to implement --timeout option
build-sys: add missing NR underscore to UL_CHECK_SYSCALL()
At times there is need in scripts to send multiple signals to a process.
Often these cases require some amount of waiting before follow-up signal
should be sent.
One common case is process termination, where first script tries to kill
process gracefully but if that does not work SIGKILL is sent. Functionality
like that is commonly done by periodically checking if signalled pid exist
or not, and if it does another signal is sent possibly to an unrelated
process that reused pid number. That means polling a pid is prone to a data
race. Also if the first signal immediately kills the process one polling
interval is lost in sleep.
Another example when multiple signal need to be sent is various daemon
process control situations, such as Upgrading Executable on the Fly (see
reference). This happens to be the case that inspired change author to make
sequential signaling a little bit easier.
Reference: http://nginx.org/en/docs/control.html#upgrade
Pull-request: https://github.com/karelzak/util-linux/pull/902
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
It some cases it makes sense to disable ECHO flag also when script
used in pipe. This new option allows to keep full control in user's
hands.
Signed-off-by: Karel Zak <kzak@redhat.com>
We need a proper way how to inform child (shell) that the game is
over. It seems the best is to send EOF to child rather than
immediately break PTY mainloop where we have poll(), because shell can
still produce data etc.
Signed-off-by: Karel Zak <kzak@redhat.com>
For tools like su(1) is ECHO flag unexpected for use-case like
echo 'date' | su - user
but script(1) need the echo to keep input recorded.
The patch also return execlp() use to script(1) code.
Signed-off-by: Karel Zak <kzak@redhat.com>
The parse-date.y is used only for hwclock, let's keep it together.
Note that the file (originally from gnulib) has GPLv3 license, so it's
better to make it obvious that we use it really only for hwclock (also
GPL).
Signed-off-by: Karel Zak <kzak@redhat.com>
* improve strdup_to_offset() readability
* add strdup_between_offsets() and strdup_between_structs() to have
better support for use-cases when we copy structs
Signed-off-by: Karel Zak <kzak@redhat.com>
In commit b1418ed14 (lib/path: add ul_path_stat(), fix absolute paths,
2019-10-15), a new function `ul_path_stat()` was added to "path.h". This
new function prototype causes a compiler warning on musl libc based
systems due to one of the parameters having the unknown type `struct
stat` due to the <sys/stat.h> header not being included.
Fix the warning by including the header.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
The classic way which is based on file-descriptors table size is
pretty expensive (due to table size) and forces code to do many
unnecessary close() calls. It seems better to use /proc/self/fds and
close used descriptors only.
Addresses: https://github.com/karelzak/util-linux/issues/883
Signed-off-by: Karel Zak <kzak@redhat.com>
* add ul_path_stat()
* make sure all paths for ul_path_..() functions are always
interpreted relatively to the context directory and prefix. This is
difference between ul_path_ API and standard libc "at" functions. We
do not use any exception for absolute paths. The reason is that we
need to read from prefixed paths although application assume absolute
path (/dev/sda1 means /prefix/dev/sda1 if a /prefix is defined).
Signed-off-by: Karel Zak <kzak@redhat.com>
Now the code is duplicate on many places, but all we usually need is to
remember child status. It seems good enough to have very simple
callback child_die() to inform application about a change.
The patch also add PID to all signal related callbacks.
Signed-off-by: Karel Zak <kzak@redhat.com>
This allows to control mainloop behavior from PTY applications. For
example you can write to child (shell) process independently on the
current stdin.
Signed-off-by: Karel Zak <kzak@redhat.com>
The idea is to consolidate script(1), scriptlive(1) and su(1) --pty
and use the same code everywhere.
TODO: add callbacks for stdin/out logging (necessary for script(1)).
Signed-off-by: Karel Zak <kzak@redhat.com>
Sorry detail-oriented people tend to wipe these out if they notice them.
Add in automated tools and lots of excess end-of-line spaces get wiped
out.
Addresses: https://github.com/karelzak/util-linux/pull/849
Signed-off-by: Karel Zak <kzak@redhat.com>
Add the --keep-caps option to unshare to preserve capabilities that
are granted when creating a new user namespace. This allows the child
process to retain privilege within the new user namespace without also
being UID 0.
In order to avoid closing standard streams multiple times, commit
52aa1a661 (include/closestream: avoid close more than once, 2019-06-13)
introduced code to set the standard output and error streams to `NULL`.
As musl libc defines standard streams as constant pointers, the change
causes compiler errors on systems with that libc. According to ISO C89,
being able to assign to the standard text streams is not a requirement
for any C implementation, see footnote 238 in chapter §7.19.5.6:
The primary use of the freopen function is to change the file
associated with a standard text stream (stderr, stdin, or stdout),
as those identifiers need not be modifiable lvalues to which the
value returned by the fopen function may be assigned.
This commit implements a new function `flush_standard_stream` that tries
to reliably flush standard streams without actually closing them. By not
calling fclose(3P), we can neatly avoid the issue of accessing standard
streams in an unspecified state and thus remove the infringing `NULL`
assignments.
Properly flushing standard streams without fclose(3P) proves to be more
intricate than one may expect, though, as some filesystems like NFS may
defer flushing until they see a close(3P) of the underlying descriptor.
One may call fsync(3P) to remedy that, but this may incur a heavy
performance penalty in some scenarios. To work around the issue and
still get proper errors, we duplicate the stream's file descriptor and
close that one instead, which is sufficient to cause a flush.
Note that both `close_stdout` and `close_stdout_atexit` are misnamed
after this change, as we do not actually close the streams now. In order
to avoid unnecessary code churn, we still retain their current names.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
There are two things happening in this commit. 1) Move each function
attribute to it's own line 2) move function return value after attributes so
that function inputs and outputs are on same line.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
There is a c_isascii function that can be used.
isascii is deprecated and not available with some libcs like uClibc-ng
where it can be compile time disabled.
Turned out lsblk is passing null as argument to xstrdup(), so fix that and
add assert() to make sure promise of not returning null is kept in future.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The device can be inaccessible for non-root user or busy (already used
by another process). In this case it seems better to read information
from /sys.
Note that /sys does not provide struct watchdog_info.options, so we
cannot print list of supported watchdog features.
Addresses: https://github.com/karelzak/util-linux/issues/804
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's use miscdev /dev/watchdog as fallback only. We need (if possible)
cdev /dev/watchdog0 as this device has entry in /sys/class/watchdog.
Signed-off-by: Karel Zak <kzak@redhat.com>
Let's keep compilers and static analyzers happy. The idea is to use
memcpy() to copy from buffer to variable and use all label as unsigned
char rather than vectorize by uint32_t.
Signed-off-by: Karel Zak <kzak@redhat.com>
The __has macros are more portable (supported by gcc as well as
clang).
The old __GNUC_PREREQ is deprecated and it should be removed in
future. (Well, the __has macros are supported since gcc 5, so we
should be patient as some old stable distros (e.g. RHEL 7) use gcc
4.x).
This patch helps clang to correctly analyze our xalloc.h stuff.
Signed-off-by: Karel Zak <kzak@redhat.com>
Recent lscpu fix caused gcc -Wnull-dereference to go off that this change
addresses.
Reference: b94acada9e
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
From the test input string ':' characters are removed:
cat x86_64-epyc_7451/sys/devices/system/cpu/vulnerabilities/spectre_v2
Mitigation: Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
It seems better to have a way to control when atexit(close_stdout()) is
used, because close stdout means that for example ASAN (or another
into binary integrated tool) is not able to print the final summary.
Signed-off-by: Karel Zak <kzak@redhat.com>
This warning is repeated 112 times when compiling with all warnings.
xalloc.h:23:1: warning: function '__err_oom' could be declared with
attribute 'noreturn' [-Wmissing-noreturn]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The partition scanner in kernel depends on blocksize. We need to set
the blocksize before we call LOOP_SET_STATUS64 (this ioctl triggers
the scanner).
This patch extends the internal API to save blocksize into loopdev
context to be usable later for loopcxt_setup_device().
Signed-off-by: Karel Zak <kzak@redhat.com>
Now the internal API uses loopcxt_set_...() to set context variables
as well as to call ioctls. This patch introduces loopcxt_ioctl_...()
to makes things more obvious to readers.
Signed-off-by: Karel Zak <kzak@redhat.com>
Assumption all years since 1970 have been exactly 365 days long has it's
problems when leap years happen. Lets use struct tm fields that are
provided by localtime_r(), making year and day to be correctly compared even
when it's late new years eve somewhere else than UTC-0.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* add struct ul_timer as API abstraction to hide differences between
timer_create() and setitimer()
* add setitimer() detection to ./configure.ac
* add fallback code to use setitimer() if timer_create() not available
(for example on OSX)
Addresses: https://github.com/karelzak/util-linux/issues/584
Signed-off-by: Karel Zak <kzak@redhat.com>