Commit Graph

818 Commits

Author SHA1 Message Date
Karel Zak 17d5b26436 su: (pty) change owner and mode for pty
The current situation:

 # su --pty - kzak
 $ ll $(tty)
 crw--w---- 1 root tty 136, 9 Feb 23 11:53 /dev/pts/9
 $ mesg
 mesg: cannot open /dev/pts/9: Permission denied

the pseudo-terminal is still owned by the original user.

New version:

 # su --pty - kzak
 # ll $(tty)
 crw--w---- 1 kzak tty 136, 9 Feb 23 11:56 /dev/pts/9
 # mesg
 is y

The patch follows login(1) to change the pty owner and group. It
follows "TTYPERM" and "TTYGROUP" from login.defs (or econf lib).

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 11:52:45 +01:00
Karel Zak 726ffb4a26 login: move generic setting to ttyutils.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 11:46:10 +01:00
Karel Zak 27e6b3a92e lib/strutils: add ul_stralnumcmp()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-23 09:19:48 +01:00
Sami Loone ee978576b1 agetty: tty eol defaults to REPRINT
Adapting tty eol settings from defaults misbehaves as CTRL('r') aka
REPRINT is confused with CR. Consequently --skip-login does not set
tty CR<->NL translations and thus acts against advertised CR as eol
default.

[kzak@redhat.com:
   It seems this issue has been introduced by commit f566447 where we
   merged sulogin and agetty terminal initialization together to the file
   include/ttyutils.h.

  The original agetty has really used .eol=13 (aka CR) for the default.
  The problem is invisible for sulogin(1) because it always asks for a
  password and .eol= is set to NL/CR, the same agetty when it asks for
  username.]

Addresses: https://github.com/karelzak/util-linux/pull/1247
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-10 17:48:46 +01:00
Karel Zak ec89bec1cd Merge branch 'gh-actions-bionic' of https://github.com/mrc0mmand/util-linux
* 'gh-actions-bionic' of https://github.com/mrc0mmand/util-linux:
  ci: run the build test for each pull request
  ci: build both w/ and w/o sanitizers on GH Actions
  ci: code cleanup
  ci: deal with uninstrumented binaries using instrumented libs
  text-utils: correctly detect ASan under clang
  ci: use the correct compiler version
  ci: 'downgrade' Ubuntu version to Bionic
2021-02-05 10:29:26 +01:00
Karel Zak 12d776c833 include/pathnames: cleanup /proc/sys/kernel use
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-02 16:54:12 +01:00
Karel Zak 9a823f1536 Merge branch 'uclampset-v3' of https://github.com/qais-yousef/util-linux
* 'uclampset-v3' of https://github.com/qais-yousef/util-linux:
  uclampset: Plumb in bash-completion
  uclampset: Plump into the build system
  uclampset: Add man page
  Add uclampset schedutil
  Move sched_attr struct and syscall definitions into header file
2021-02-02 16:53:50 +01:00
Qais Yousef 5407f89782 Add uclampset schedutil
Utilization clamping is a new kernel feature that got merged in 5.3. It
allows controlling the performance of a process by manipulating the
utilization such that the task appears bigger or smaller than what it
really is.

There's a system-wide control to to restrict what maximum values the
process are allowed to use.

Man page added in a later patch attempts to explain the usage in more
detail.

Signed-off-by: Qais Yousef <qais.yousef@arm.com>
2021-02-02 10:56:26 +00:00
Frantisek Sumsal c40b3cd03d text-utils: correctly detect ASan under clang
__SANITIZE_ADDRESS__ is not defined when compiling with clang, so cover
both use cases with a special set of macros
2021-02-01 11:59:47 +01:00
Karel Zak 867df2617c lib: use ul_prefix for close_all_fds() and mkdir_p()
The names are too generic and it makes problems in static libraries.

Addresses: https://gitlab.com/cryptsetup/cryptsetup/-/issues/623
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-28 10:27:21 +01:00
Karel Zak 7397f2c1f9 build-sys: add restrict keyword fallback
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-22 13:28:02 +01:00
Karel Zak b105446e69 mkswap: remove deprecated SELinux matchpathcon()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 14:58:43 +01:00
Karel Zak e1de70b3c3 chfs-chfn: remove deprecated selinux_check_passwd_access()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 14:27:15 +01:00
Karel Zak b5debf7105 lib/selinux-utils: cleanup function names
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:33:41 +01:00
Karel Zak 68f4aa2a2f build-sys: move selinux_utils.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-13 13:30:31 +01:00
Sami Kerola a75700d86e
lib/fileutils: make close_all_fds() to be similar with close_range()
The util-linux close_all_fds() serves the same purpose as close_range()
that will over time obsolete local implementation completely.  For
upcoming few years it is best to have a fallback that uses same input
arguments as the new system call.  That allows surrounding code and
variables not to be affected by version of mass file descriptor closing
function.

Proposed-by: Karel Zak <kzak@redhat.com>
Reference: https://github.com/karelzak/util-linux/pull/1205#discussion_r534080128
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:09:14 +00:00
Sami Kerola f0649c0d83
login: use close_range() system call when possible
This system call was added while back, but does not have glibc support yet.
Lets try to use the new facility early on.  The promise in reference link is
that the new call is faster, and works when /proc is not mounted.

Reference: https://lwn.net/Articles/789000/
Reference: https://lwn.net/Articles/789023/
Reference: https://kernelnewbies.org/LinuxChanges#Linux_5.9.New_close_range.28.29_system_call_for_easier_closing_of_file_descriptors
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-03 20:09:14 +00:00
Karel Zak 58b510e580 libsmartcols: sanitize variable names on export output
The shells are very restrictive about variable names, only [:alnum:]
chars are allowed (and alphabetic chars as the first char).  The
library will replace "bad" chars with "_". The char '%' at the end is
replaced by _PCT.

Addresses: https://github.com/karelzak/util-linux/issues/1201
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-03 12:14:10 +01:00
Érico Rolim e411b8a63d lib/procutils: add proc_is_procfs helper.
Also add missing include in procutils.h for the definition of pid_t.
2020-11-18 14:30:50 -03:00
Karel Zak 5d68f974b4 lib/strutils: add normalize_whitespace()
This function removes extra whitespace.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak ad2659383c include/strutils: make xstrncpy() compatible with over-smart gcc 9
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-13 09:19:02 +01:00
Karel Zak 37bcd05602 lib/jsonwrt: add new functions to write in JSON
We need JSON formatting stuff also outside libsmartcols.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-12 11:19:13 +01:00
Karel Zak 782cc33a02 build-sys: fix sendfile use
* OSX uses different prototype
* include file is not covered by HAVE_SYS_SENDIFLE_H

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-09 15:30:06 +01:00
Karel Zak df8a8d1373 Merge branch 'libuuid' of https://github.com/ferivoz/util-linux
* 'libuuid' of https://github.com/ferivoz/util-linux:
  libuuid: check quality of random bytes
2020-11-09 12:31:17 +01:00
Karel Zak bb123ad503 Merge branch 'vipw-shortwrite' of https://github.com/DankRank/util-linux
* 'vipw-shortwrite' of https://github.com/DankRank/util-linux:
  ul_copy_file: make defines for return values
  read_all: return 0 when EOF occurs after 0 bytes
  ul_copy_file: add test program
  ul_copy_file: handle EAGAIN and EINTR
  ul_copy_file: use all_read/all_write
  ul_copy_file: use BUFSSIZ for buffer size
  nologin: use ul_copy_file
  login: use ul_copy_file
  configure.ac: check for sendfile
  ul_copy_file: use sendfile
  vipw: move copyfile to the lib
  vipw: fix short write handling in copyfile
2020-11-09 11:06:27 +01:00
Egor Chelak cabbf61fab ul_copy_file: make defines for return values
Suggested-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:20:14 +02:00
Egor Chelak 418eb09482 read_all: return 0 when EOF occurs after 0 bytes
Originally it would return -1 (without setting errno) if the fd was
already at EOF when you called read_all.

This is already fixed in sendfile_all.

Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:51 +02:00
Egor Chelak 212bde6cf7 ul_copy_file: handle EAGAIN and EINTR
I did this by implementing a function called sendfile_all() similar to
read_all()/write_all().

The manpage for sendfile doesn't mention EINTR, but I decided to check
it anyway, just in case.

Suggested-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:19:39 +02:00
Egor Chelak b9dcd38462 vipw: move copyfile to the lib
Also, a bug in pw_tmpfile was fixed: copyfile used tmp_file to report
errors, but pw_tmpfile only assigned that variable _after_ calling
copyfile.

Suggested-by: Sami Kerola <kerolasa@iki.fi>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
2020-11-09 07:18:42 +02:00
Samanta Navarro e4be3ee01d libuuid: check quality of random bytes
If a libuuid application is unable to access /dev/random or /dev/urandom
then uuid generation by uuid_generate falls back to uuid_generate_time.
This could happen in chroot or container environments.

The function ul_random_get_bytes from lib/randutils.c uses getrandom if
it is available. This could either mean that the libuuid application
skips good random bytes because the character special files do not exist
or the application trusts in good random bytes just because these files
are accessible but not necessarily usable, e.g. limit of open file
descriptors reached, lack of data, kernel without getrandom, etc.

This commit modifies ul_random_get_bytes to return an integer which
indicates if random bytes are of good quality (0) or not (1). Callers
can decide based on this information if they want to discard the random
bytes. Only libuuid checks the return value. I decided to return 1
instead of -1 because -1 feels more like an error, but weak random bytes
can be totally fine.

Another issue is that getrandom sets errno to specific values only in
case of an error, i.e. with return value -1. Set errno to 0 explicitly
if getrandom succeeds so we do not enter the fallback routine for
ENOSYS by mistake. I do not think that this is likely to happen, but it
really depends on possible wrapper function supplied by a C library.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
2020-11-08 11:48:23 +00:00
Sami Kerola 364de8f4f5 lib/randutils: rename random_get_bytes()
Rename random_get_bytes() to avoid colliding a Solaris library function that
has the same name.

Reported-by: Sad Clouds <cryintothebluesky@gmail.com>
Reference: https://lore.kernel.org/util-linux/20201101141608.ba365cf67d92ee3973226de9@gmail.com/
Reference: https://blogs.oracle.com/solaris/solaris-random-number-generation-v2
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-11-03 12:38:45 +01:00
Karel Zak b21d741c21 login: move proctitle code to login.c
The functions are used only by login(1), let's keep the code in
login.c only.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-06 15:15:15 +02:00
Karel Zak a61955ba1f lib/loopdev: cosmetic changes to LOOP_CONFIGURE
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-10-05 14:52:20 +02:00
Karel Zak 558880dd35 Merge branch 'frkaya/loopconfig' of https://github.com/franksinankaya/util-linux
* 'frkaya/loopconfig' of https://github.com/franksinankaya/util-linux:
  loopdev: use LOOP_CONFIG ioctl
2020-10-05 14:51:45 +02:00
Sinan Kaya d5fd456c88 loopdev: use LOOP_CONFIG ioctl
Prefer to use the new LOOP_CONFIG ioctl.
https://lwn.net/Articles/820408/

Signed-off-by: Sinan Kaya <sinan.kaya@microsoft.com>
2020-09-30 20:04:21 -04:00
Karel Zak 1918b4dd9d build-sys: add missing header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 14:03:15 +02:00
Karel Zak 0a9939816c lib/buffer: add simple grow-able buffer
The goal is to use it in libmount when generate options strings
and in libsmartcols to replace libscols_buffer.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-29 12:06:11 +02:00
nl6720 5362bfa3ea
libfdisk: add "Linux /usr" and "Linux /usr verity" GPT partition types
See https://systemd.io/DISCOVERABLE_PARTITIONS/ and https://github.com/systemd/systemd/pull/17101 .

Move ARM after x86-64, so that x86 and x86-64 are next to one another.

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-09-21 18:26:53 +03:00
Karel Zak 14bb8e3ca6 lsblk: ignore only loopdevs without backing file
* do not ignore all empty devices, we need more smart solution

* ignore only loop devices without backing file, for example:
 # touch img
 # losetup -f img
 losetup: img: Warning: file is smaller than 512 bytes; the loop device may be useless or invisible for system tools.

 - old version display nothing
 - new version:

 # lsblk /dev/loop0
 NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
 loop0   7:0    0   0B  0 loop

Addresses: https://github.com/karelzak/util-linux/issues/1118
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-09 12:23:33 +02:00
Soumendra Ganguly 75ccd75a2f script: cleanup --echo
Permanently turn off current stdin ECHO when it is a terminal and enable setting slave ECHO instead.
Fix other minor typos, update documentation.

[kzak@redhat.com: - remove irrelevant changes
                  - keep --echo argument unchanged]

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-27 12:56:46 +02:00
Karel Zak e113093ce9 lib/env: add function to save and restore unwanted variables
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-08-25 10:43:07 +02:00
nl6720 80a54e2b3e
libfdisk: add systemd-homed user's home GPT partition type
See https://systemd.io/HOME_DIRECTORY/ .
Additionally update the URL of the Boot Loader Specification.

Signed-off-by: nl6720 <nl6720@gmail.com>
2020-08-22 15:40:06 +03:00
Karel Zak c87cce57d8 Merge branch 'fuzz' of https://github.com/evverx/util-linux
* '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
2020-08-10 14:40:44 +02:00
Evgeny Vereshchagin 0be452a82a build-system: stop looking for %ms and %as
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>
2020-08-06 14:27:20 +00:00
Evgeny Vereshchagin 681d3a9586 build-system: make "make distcheck" work
It failed with:
```
make[5]: Entering directory '/home/travis/build/karelzak/util-linux/util-linux-2.36.32-0fea/_build/sub/po'
make[5]: *** No rule to make target '../../../include/fuzz.h', needed by 'util-linux.pot-update'.  Stop.
make[5]: Leaving directory '/home/travis/build/karelzak/util-linux/util-linux-2.36.32-0fea/_build/sub/po'
Makefile:896: recipe for target 'update-po' failed
make[4]: *** [update-po] Error 2
```

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2020-08-06 12:33:11 +00:00
Evgeny Vereshchagin 7b4ab119f4 tests: integrate test_mount_fuzz into the testsuite
Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2020-08-06 12:33:11 +00:00
zhenwei pi b6ce063b04 irqtop/lsirq: support softirq
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>
2020-07-23 12:23:56 +02:00
Karel Zak 655d736da3 lib/path: add ul_path_is_accessible()
This function allow to check that path_cxt is usable. Note that
ul_new_path() does not open the path.

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-08 08:50:07 +02:00
Konstantin Khlebnikov 9bf622dad9 dmesg: adjust timestamps according to suspended time
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>
2020-06-04 10:57:36 +02:00
Karel Zak 37b302046a lib/blkdev: add support for --lock and LOCK_BLOCK_DEVICE
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>
2020-05-26 17:30:39 +02:00