]> git.ipfire.org Git - thirdparty/util-linux.git/log
thirdparty/util-linux.git
4 years agolibuuid: check quality of random bytes
Samanta Navarro [Sun, 8 Nov 2020 11:47:18 +0000 (11:47 +0000)] 
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>
4 years agosfdisk: fix backward --move-data
Karel Zak [Fri, 6 Nov 2020 10:38:51 +0000 (11:38 +0100)] 
sfdisk: fix backward --move-data

* fix final message where number of moved sectors overflow number of
  all moved sectors

* align last step size before we use it for backward mode source and
  destination offsets calculation

Addresses: https://github.com/karelzak/util-linux/issues/1176
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'whereis' of https://github.com/ferivoz/util-linux
Karel Zak [Fri, 6 Nov 2020 08:44:52 +0000 (09:44 +0100)] 
Merge branch 'whereis' of https://github.com/ferivoz/util-linux

* 'whereis' of https://github.com/ferivoz/util-linux:
  whereis: extend test case
  whereis: filter bin, man and src differently
  whereis: do not strip suffixes
  whereis: do not ignore trailing numbers
  whereis: add --disable-whereis to configure
  whereis: add lib32 directories
  whereis: support zst compressed man pages
  whereis: fix out of boundary read

4 years agoMerge branch 'sfdisk-json-dump' of https://github.com/xnox/util-linux
Karel Zak [Thu, 5 Nov 2020 10:37:51 +0000 (11:37 +0100)] 
Merge branch 'sfdisk-json-dump' of https://github.com/xnox/util-linux

4 years agosfdisk: correct --json --dump false exclusive
Dimitri John Ledkov [Wed, 4 Nov 2020 12:35:38 +0000 (12:35 +0000)] 
sfdisk: correct --json --dump false exclusive

`--json` implies `--dump`, thus `--json --dump` must be
allowed. `--list-free` is incompatible with `--dump`, and thus also
with `--json`. Currently `--json --dump` is prohibited, even though
`--list-free` is not specified at all.

Regression introduced in 03154d2cf25c1d5ce908da9e72d324004b8d5722.

Signed-off-by: Dimitri John Ledkov <xnox@ubuntu.com>
4 years agowhereis: extend test case
Samanta Navarro [Wed, 4 Nov 2020 11:39:00 +0000 (11:39 +0000)] 
whereis: extend test case

Previous commits are covered with these test cases.

Removed dependency on system layout.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: filter bin, man and src differently
Samanta Navarro [Wed, 4 Nov 2020 11:38:00 +0000 (11:38 +0000)] 
whereis: filter bin, man and src differently

Consider "s." prefixes for source code files only (even though I do not
know which VCS does that), compression suffixes for manual pages and
strict matching for executables.

Calling "whereis python3" is kind of okay to return python3.8 next to
python3, but python3.8-config is not the same tool as python3.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: do not strip suffixes
Samanta Navarro [Wed, 4 Nov 2020 11:37:00 +0000 (11:37 +0000)] 
whereis: do not strip suffixes

The whereis implementations of FreeBSD, macOS, NetBSD, and OpenBSD do
not strip suffixes. Although whereis is not a POSIX tool and has no
shared standard, even its manual page indicates that the supplied names
are command names.

Commands do not have a suffix on Linux systems.

Stripping suffixes actually leads to issues with tools like fsck.ext4,
since fsck.ext4 is not the same tool as fsck and definitely not the same
tool as fsck.minix.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: do not ignore trailing numbers
Samanta Navarro [Wed, 4 Nov 2020 11:36:00 +0000 (11:36 +0000)] 
whereis: do not ignore trailing numbers

The commands diff and diff3 are so distinct that their manual pages
should not be mixed in whereis output.

Theoretically this works for commands and binaries with links to each
other, e.g. gpg and gpg2, but if gpg is version 1 and gpg2 is version 2
then manual pages do not match either.

Also the while loop does not decrement "i" while incrementing "dp". The
effect of this is that the output of whereis depends on manual pages
being compressed or not.

The easiest solution is to not ignore trailing numbers.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: add --disable-whereis to configure
Samanta Navarro [Wed, 4 Nov 2020 11:35:00 +0000 (11:35 +0000)] 
whereis: add --disable-whereis to configure

Allow a build of util-linux without whereis.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: add lib32 directories
Samanta Navarro [Wed, 4 Nov 2020 11:34:00 +0000 (11:34 +0000)] 
whereis: add lib32 directories

These directories are sometimes used by Linux distributions.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: support zst compressed man pages
Samanta Navarro [Wed, 4 Nov 2020 11:33:00 +0000 (11:33 +0000)] 
whereis: support zst compressed man pages

Add zst as extension for manual pages. Current version of man-db
supports zst extension out of the box.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agowhereis: fix out of boundary read
Samanta Navarro [Wed, 4 Nov 2020 11:32:00 +0000 (11:32 +0000)] 
whereis: fix out of boundary read

If whereis encounters a short file name then an out of boundary
read can occur.

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agomisc: fix typos
Samanta Navarro [Wed, 4 Nov 2020 11:31:00 +0000 (11:31 +0000)] 
misc: fix typos

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agomisc: fix typos [codespell]
Samanta Navarro [Wed, 4 Nov 2020 11:30:00 +0000 (11:30 +0000)] 
misc: fix typos [codespell]

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
4 years agosfdisk: (docs) add more information about GPT attribute bits
Karel Zak [Wed, 4 Nov 2020 09:29:30 +0000 (10:29 +0100)] 
sfdisk: (docs) add more information about GPT attribute bits

Addresses: https://github.com/karelzak/util-linux/issues/1171
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agodocs: rename to getopt-example
Karel Zak [Tue, 3 Nov 2020 14:23:03 +0000 (15:23 +0100)] 
docs: rename to getopt-example

Addresses: https://github.com/karelzak/util-linux/commit/27114b297424ecf1b745b1a71f6d40be0e56e67e#commitcomment-43591002
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'execl-null' of https://github.com/DankRank/util-linux
Karel Zak [Tue, 3 Nov 2020 11:40:35 +0000 (12:40 +0100)] 
Merge branch 'execl-null' of https://github.com/DankRank/util-linux

* 'execl-null' of https://github.com/DankRank/util-linux:
  cast NULL to char * when using execl

4 years agolib/randutils: rename random_get_bytes()
Sami Kerola [Mon, 2 Nov 2020 22:26:18 +0000 (22:26 +0000)] 
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>
4 years agocast NULL to char * when using execl
Egor Chelak [Thu, 29 Oct 2020 17:49:07 +0000 (19:49 +0200)] 
cast NULL to char * when using execl

When calling variadic functions, NULL must be explicitly cast to a
desired type.
This is noted in the exec(3) manpage.

The call in newgrp.c was changed for consistency.

Signed-off-by: Egor Chelak <egor.chelak@gmail.com>
4 years agoul: fix use of unsigned number
Karel Zak [Wed, 21 Oct 2020 10:45:02 +0000 (12:45 +0200)] 
ul: fix use of unsigned number

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agodmesg: add --since and --until
Karel Zak [Wed, 21 Oct 2020 10:03:45 +0000 (12:03 +0200)] 
dmesg: add --since and --until

$ date
Wed 21 Oct 2020 12:05:07 PM CEST

$ dmesg --ctime --since '1 hour ago'
[Wed Oct 21 11:47:13 2020] AAA
[Wed Oct 21 11:55:48 2020] BBB

$ dmesg --ctime --since '1 hour ago' --until '10 minutes ago'
[Wed Oct 21 11:47:13 2020] AAA

Addresses: https://github.com/karelzak/util-linux/issues/1166
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoul: small coding changes
Karel Zak [Wed, 21 Oct 2020 09:16:34 +0000 (11:16 +0200)] 
ul: small coding changes

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'ul-refactor' of https://github.com/kerolasa/util-linux
Karel Zak [Wed, 21 Oct 2020 09:08:11 +0000 (11:08 +0200)] 
Merge branch 'ul-refactor' of https://github.com/kerolasa/util-linux

* 'ul-refactor' of https://github.com/kerolasa/util-linux:
  ul: flip comparisons to lesser to greater order
  ul: use size_t to measure memory allocation size
  ul: improve function and variable names
  ul: rename enumerated mode symbols
  ul: remove function like putwp preprocessor define
  ul: free most allocations ncurses did during setupterm()
  ul: replace global runtime variables with a control structure
  ul: add a term capabilities tracking structure
  ul: remove function prototypes
  ul: tidy up coding style
  ul: add basic tests

4 years agocal: do not use putp(), directly use stdio functions
Karel Zak [Wed, 21 Oct 2020 08:19:26 +0000 (10:19 +0200)] 
cal: do not use putp(), directly use stdio functions

It seems our putp() based output is not portable as some ncurses
implementations strictly follow POSIX where putp() accepts only
terminfo capability strings and nothing else.

We already use standard stdio.h functions to output terminfo strings
(e.g.  for colors). It seems we can do the same for cal(1) to
highlight the current day.

Note that mix putp() and fputs() is bad idea due to different
buffering ways in some cases (see cal.c git log for more details).

This patch also reduces complexity of the code as we can directly
output to stdout without snprintf to string.

Addresses: https://github.com/karelzak/util-linux/pull/1167
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoul: flip comparisons to lesser to greater order
Sami Kerola [Fri, 16 Oct 2020 21:35:06 +0000 (22:35 +0100)] 
ul: flip comparisons to lesser to greater order

1 < 2 < x < 4 is the order is the natural of values.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: use size_t to measure memory allocation size
Sami Kerola [Fri, 16 Oct 2020 21:26:15 +0000 (22:26 +0100)] 
ul: use size_t to measure memory allocation size

The size_t is the type libc memory allocation functions use.  The size_t
also provides allocation range that is enough not to a simple tool like this
to perform paranoia size checks.  Just let the realloc(3) fail if there is
not enough memory available to handle the requested line size.  That is a
lot more straightforward.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: improve function and variable names
Sami Kerola [Fri, 16 Oct 2020 20:42:18 +0000 (21:42 +0100)] 
ul: improve function and variable names

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: rename enumerated mode symbols
Sami Kerola [Wed, 14 Oct 2020 21:51:37 +0000 (22:51 +0100)] 
ul: rename enumerated mode symbols

First two are are ISO/IEC 2022 graphic character sets G0 (normal) and G1
(alternative), that one has to Switch In (SI) and Switch Out (SO).  The rest
are about how ul(1) is interacting with various text emphasis.

Reference: https://tldp.org/HOWTO/Keyboard-and-Console-HOWTO-6.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: remove function like putwp preprocessor define
Sami Kerola [Wed, 14 Oct 2020 21:15:03 +0000 (22:15 +0100)] 
ul: remove function like putwp preprocessor define

The #ifdef HAVE_WIDECHAR can be removed, because the command already is
using wide character functions elsewhere without fallbacks.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: free most allocations ncurses did during setupterm()
Sami Kerola [Sat, 1 Aug 2020 23:58:35 +0000 (00:58 +0100)] 
ul: free most allocations ncurses did during setupterm()

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: replace global runtime variables with a control structure
Sami Kerola [Tue, 30 Jun 2020 21:17:01 +0000 (22:17 +0100)] 
ul: replace global runtime variables with a control structure

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: add a term capabilities tracking structure
Sami Kerola [Mon, 29 Jun 2020 21:00:14 +0000 (22:00 +0100)] 
ul: add a term capabilities tracking structure

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: remove function prototypes
Sami Kerola [Mon, 29 Jun 2020 20:41:38 +0000 (21:41 +0100)] 
ul: remove function prototypes

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: tidy up coding style
Sami Kerola [Mon, 29 Jun 2020 20:21:50 +0000 (21:21 +0100)] 
ul: tidy up coding style

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoul: add basic tests
Sami Kerola [Sat, 1 Aug 2020 12:20:30 +0000 (13:20 +0100)] 
ul: add basic tests

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agolibmount: Fix 0x%u usage
Dr. David Alan Gilbert [Sat, 17 Oct 2020 12:05:34 +0000 (13:05 +0100)] 
libmount: Fix 0x%u usage

There's a couple of places which use varients on "0x%u" in format strings;
that's almost always wrong - you either want 0x%x or just %u.  In libmount's
case it's flags, so I'm assuming the intention really is hex.  In the ja.po
case it's %u in the original msgid.

Signed-off-by: Dr. David Alan Gilbert <dave@treblig.org>
4 years agosfdisk: do not free device name too soon [coverity scan]
Sami Kerola [Sun, 9 Aug 2020 12:58:10 +0000 (13:58 +0100)] 
sfdisk: do not free device name too soon [coverity scan]

Fixes use after free error.

CID: 360798
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agologin: close() only a file descriptor that is open [coverity scan]
Sami Kerola [Sun, 9 Aug 2020 12:34:00 +0000 (13:34 +0100)] 
login: close() only a file descriptor that is open [coverity scan]

CID: 360819
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agoswitch_root: fix double close [coverity scan]
Karel Zak [Fri, 16 Oct 2020 09:56:35 +0000 (11:56 +0200)] 
switch_root: fix double close [coverity scan]

Up on successful fdopendir(3) file descriptior that will be closed, that
happens in recursiveRemove() switch_root(8) function.

CID: 360697
Reference: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopendir.html
Co-Author: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agofsck, libblkid: fix printf format string issue [coverity scan]
Sami Kerola [Sun, 9 Aug 2020 11:59:38 +0000 (12:59 +0100)] 
fsck, libblkid: fix printf format string issue [coverity scan]

According to coverirty a printf format string contains an unrecognized
format specifier (CWE-628).  Lets avoid glibc extension "%m" that is same
as "%s", strerror(errno).

CID: 360699
CID: 360718
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agonsenter / switch_root: fix insecure chroot [coverity scan]
Sami Kerola [Sun, 9 Aug 2020 11:51:11 +0000 (12:51 +0100)] 
nsenter / switch_root: fix insecure chroot [coverity scan]

If a call to chroot is not followed by a call to chdir("/") the chroot jail
confinement can be violated.  See also CWE-243.

CID: 360718
CID: 360800
Reference: http://cwe.mitre.org/data/definitions/243.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agologin: ensure getutxid() does not use uninitialized variable [coverity scan]
Sami Kerola [Sat, 8 Aug 2020 19:06:42 +0000 (20:06 +0100)] 
login: ensure getutxid() does not use uninitialized variable [coverity scan]

Field ut.ut_pid is uninitialized when calling getutxline().  The safest
option is to ensure all struct data is initialized in the function.

CID: 360793
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agolib/pager: fix improper use of negative value [coverity scan]
Sami Kerola [Sat, 8 Aug 2020 19:02:01 +0000 (20:02 +0100)] 
lib/pager: fix improper use of negative value [coverity scan]

The close(2) cannot accept a negative number.

CID: 360777
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agounshare: fix bad bit shift operation [coverity scan]
Sami Kerola [Sat, 8 Aug 2020 18:45:30 +0000 (19:45 +0100)] 
unshare: fix bad bit shift operation [coverity scan]

Variable cap was 32 bits and shifting it by 64 bits resulted to the shift
going over a variable boundary.

CID: 360799
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agohardlink: fix hardlink pcre leak
Sami Kerola [Sat, 8 Aug 2020 18:05:29 +0000 (19:05 +0100)] 
hardlink: fix hardlink pcre leak

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agocol: fix --help short option in usage() output
Sami Kerola [Wed, 14 Oct 2020 20:22:45 +0000 (21:22 +0100)] 
col: fix --help short option in usage() output

The col(1) is using unusual -H as --help short option.  The -h is used for
--tabs (horizontal tab?) in this implementation.

Fixes: 62dee0176a0c8e687d9ff0cb87342a0f8b893aaa
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
4 years agotests: update sfdisk wipe tests
Karel Zak [Fri, 16 Oct 2020 08:59:17 +0000 (10:59 +0200)] 
tests: update sfdisk wipe tests

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agosfdisk: disable bootbits protection on '--wipe always'
Karel Zak [Thu, 15 Oct 2020 10:04:15 +0000 (12:04 +0200)] 
sfdisk: disable bootbits protection on '--wipe always'

Addresses: https://github.com/karelzak/util-linux/issues/1156
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agomkfs.minix: add --lock and LOCK_BLOCK_DEVICE
Karel Zak [Wed, 14 Oct 2020 09:33:13 +0000 (11:33 +0200)] 
mkfs.minix: add --lock and LOCK_BLOCK_DEVICE

Addresses: https://github.com/karelzak/util-linux/issues/921
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'master' of https://github.com/eric-simpson/util-linux
Karel Zak [Wed, 14 Oct 2020 08:24:25 +0000 (10:24 +0200)] 
Merge branch 'master' of https://github.com/eric-simpson/util-linux

* 'master' of https://github.com/eric-simpson/util-linux:
  do not require sys/syscall.h on non-linux platforms

4 years agoMerge branch 'dusty-remove-fstab-condition' of https://github.com/dustymabe/util...
Karel Zak [Wed, 14 Oct 2020 08:23:20 +0000 (10:23 +0200)] 
Merge branch 'dusty-remove-fstab-condition' of https://github.com/dustymabe/util-linux

* 'dusty-remove-fstab-condition' of https://github.com/dustymabe/util-linux:
  fstrim: remove fstab condition from fstrim.timer

4 years agodo not require sys/syscall.h on non-linux platforms
Eric Simpson [Tue, 13 Oct 2020 16:55:05 +0000 (12:55 -0400)] 
do not require sys/syscall.h on non-linux platforms

In order to build util-linux on other platforms (such as IBM i), do not require the linux-specific sys/syscall.h.

4 years agotests: update atari partx tests
Karel Zak [Tue, 13 Oct 2020 16:34:39 +0000 (18:34 +0200)] 
tests: update atari partx tests

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agofstrim: remove fstab condition from fstrim.timer
Dusty Mabe [Tue, 13 Oct 2020 15:26:16 +0000 (11:26 -0400)] 
fstrim: remove fstab condition from fstrim.timer

In 9995da0 we added support to fstrim to be able to fall back to
`/proc/self/mountinfo` if `/etc/fstab` didn't exist, but we forgot
to remove the `/etc/fstab` condition from the timer. Let's remove
that condition from the timer so we can go back to periodically
running `fstrim.service`.

4 years agotests: update atari blkid tests
Karel Zak [Tue, 13 Oct 2020 14:29:19 +0000 (16:29 +0200)] 
tests: update atari blkid tests

The old images of the atari label are truncated and in-table stored
sizes do not match with real images sizes -- libblkid checks it now.

I have no idea how to generate ICD format, let's ignore it in tests
for now.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibblkid: make Atari more robust
Karel Zak [Tue, 13 Oct 2020 14:19:20 +0000 (16:19 +0200)] 
libblkid: make Atari more robust

* ignore large disks
* check in-table stored device size
* check bad sectors list
* check partition dimensions against in-table device size

Addresses: https://github.com/karelzak/util-linux/issues/1159
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolosetup: increase limit of setup attempts
Karel Zak [Tue, 13 Oct 2020 10:55:44 +0000 (12:55 +0200)] 
losetup: increase limit of setup attempts

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolosetup: avoid infinite busy loop
Karel Zak [Tue, 13 Oct 2020 08:31:42 +0000 (10:31 +0200)] 
losetup: avoid infinite busy loop

issue report:
 if i run the heavy duty test from #16859 a couple of times I can get
 the loopback layer in the kernel into a state where there's a loopback
 block device allocated, that you can open, but where both LOOP_CLR_FD
 and _SET_FD fail with EBUSY. and /dev/loop-control still returns it as
 the next free one...  weird state util-linux losetup when called to
 allocate a new device then freezes

This commit:
* restrict number of attempts to 16
* use 200000ms sleep between attempts
* add note about non-atomic loop device setup to the man page

Reported-by: Lennart Poettering <lennart@poettering.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agobash-completion: (lsblk) update columns
Karel Zak [Mon, 12 Oct 2020 11:19:35 +0000 (13:19 +0200)] 
bash-completion: (lsblk) update columns

and fix lsblk --help output

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolsblk: add --width option
Karel Zak [Mon, 12 Oct 2020 10:10:33 +0000 (12:10 +0200)] 
lsblk: add --width option

Addresses: https://github.com/karelzak/util-linux/issues/1160
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/sysfs: fix doble free [coverity scan]
Karel Zak [Fri, 9 Oct 2020 11:46:35 +0000 (13:46 +0200)] 
lib/sysfs: fix doble free [coverity scan]

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibblkid: fix Atari prober logic
Karel Zak [Fri, 9 Oct 2020 11:06:08 +0000 (13:06 +0200)] 
libblkid: fix Atari prober logic

Addresses: https://github.com/karelzak/util-linux/issues/1159
Addresses: https://github.com/karelzak/util-linux/issues/1116
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibblkid: use /sys to read all block devices
Karel Zak [Wed, 7 Oct 2020 11:49:45 +0000 (13:49 +0200)] 
libblkid: use /sys to read all block devices

The old implementation uses /proc/partitions where devices are
filtered by kernel (missing devices with ext_range=1 and removable
devices).

The problem with the old implementation is whole-disk heuristic based
on device name, order of devices, etc.

The new implementation use the same code to read also removable
devices.

Addresses: https://github.com/karelzak/util-linux/issues/1151
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agobuild-sys: use _DATA to install getopt examples
Karel Zak [Tue, 6 Oct 2020 13:47:02 +0000 (15:47 +0200)] 
build-sys: use _DATA to install getopt examples

* rename the files to getopt-example.*
* use automake _DATA rather than _SCRIPT

Addresses: https://github.com/karelzak/util-linux/issues/1149
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agodocs: add hint about make install-strip and link to Documentation/
Karel Zak [Tue, 6 Oct 2020 13:35:09 +0000 (15:35 +0200)] 
docs: add hint about make install-strip and link to Documentation/

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agologin: move proctitle code to login.c
Karel Zak [Tue, 6 Oct 2020 13:13:29 +0000 (15:13 +0200)] 
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>
4 years agolib: add missing headers to .c files
Karel Zak [Tue, 6 Oct 2020 13:03:45 +0000 (15:03 +0200)] 
lib: add missing headers to .c files

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agobuild-sys: exclude GPL from libcommon
Karel Zak [Tue, 6 Oct 2020 11:26:36 +0000 (13:26 +0200)] 
build-sys: exclude GPL from libcommon

The library is not distributed and almost all code in this ar(1)
archive is Public Domain or LGPL ... but let's avoid any doubts and do
not mix non-GPL and GPL code there.

Addresses: https://github.com/karelzak/util-linux/issues/1157
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/procutils: use Public Domain for this file
Karel Zak [Tue, 6 Oct 2020 11:15:29 +0000 (13:15 +0200)] 
lib/procutils: use Public Domain for this file

It's was originally GPL, but all the current code in the file is from
me and I don't think it makes sense to use GPL here anymore. We need
to use lib/ files in LGPL as well as in GPL binaries, etc. Let's makes
things (build-system) less complicated.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/loopdev: cosmetic changes to LOOP_CONFIGURE
Karel Zak [Mon, 5 Oct 2020 11:49:16 +0000 (13:49 +0200)] 
lib/loopdev: cosmetic changes to LOOP_CONFIGURE

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'frkaya/loopconfig' of https://github.com/franksinankaya/util-linux
Karel Zak [Mon, 5 Oct 2020 12:51:45 +0000 (14:51 +0200)] 
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

4 years agoagetty: fix typo in manual page
Samanta Navarro [Sat, 3 Oct 2020 11:57:56 +0000 (11:57 +0000)] 
agetty: fix typo in manual page

4 years agologin: use mem2strcpy() rather than rely on printf()
Karel Zak [Thu, 1 Oct 2020 12:04:21 +0000 (14:04 +0200)] 
login: use mem2strcpy() rather than rely on printf()

The strings from utmp does not have to be terminated. It's seems
better to explicitly terminate it than rely on "%.*s" printf()
functionality -- printf() man page assumes that "If a precision is
given, no null byte need be present", but static analyzers are pretty
unhappy with it.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agohwclock: make tz use more robust [coverity scan]
Karel Zak [Thu, 1 Oct 2020 11:44:44 +0000 (13:44 +0200)] 
hwclock: make tz use more robust [coverity scan]

It's probably unnecessary, but let's make it more robust and keep
static analyzers happy.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoscript: don't use strings from user as printf-format [coverity scan]
Karel Zak [Thu, 1 Oct 2020 11:29:46 +0000 (13:29 +0200)] 
script: don't use strings from user as printf-format [coverity scan]

Let's avoid format string vulnerability (TAINTED_STRING).

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/buffer: make it robust for static analyzers [coverity scan]
Karel Zak [Thu, 1 Oct 2020 11:23:34 +0000 (13:23 +0200)] 
lib/buffer: make it robust for static analyzers [coverity scan]

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agochrt: don't restrict --reset-on-fork, add more info to man page
Karel Zak [Thu, 1 Oct 2020 09:20:01 +0000 (11:20 +0200)] 
chrt: don't restrict --reset-on-fork, add more info to man page

The flag works (= kernel accepts it) for all scheduling policies
and sched_getattr() returns the flag for all policies.

There is no reason for userspace to be more smart than kernel or hide
the flag when it prints sched_getattr()/sched_getscheduler() results.

 # chrt -v --reset-on-fork --batch 0 /bin/true
 pid 1315019's new scheduling policy: SCHED_BATCH|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --fifo 1 /bin/true
 pid 1315055's new scheduling policy: SCHED_FIFO|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --deadline --sched-period 10000 0 /bin/true
 pid 1315182's new scheduling policy: SCHED_DEADLINE|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --idle 0 /bin/true
 pid 1315247's new scheduling policy: SCHED_IDLE|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --rr 1 /bin/true
 pid 1315275's new scheduling policy: SCHED_RR|SCHED_RESET_ON_FORK

 # chrt -v --reset-on-fork --other 0 /bin/true
 pid 1315311's new scheduling policy: SCHED_OTHER|SCHED_RESET_ON_FORK

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agochrt: (man) add human-readable names for policies
Karel Zak [Thu, 1 Oct 2020 09:04:29 +0000 (11:04 +0200)] 
chrt: (man) add human-readable names for policies

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agochrt: use SCHED_FLAG_RESET_ON_FORK for sched_setattr()
Karel Zak [Thu, 1 Oct 2020 08:40:27 +0000 (10:40 +0200)] 
chrt: use SCHED_FLAG_RESET_ON_FORK for sched_setattr()

Reviewed by many people, used for years (but probably nobody uses
SCHED_DEADLINE with reset-on-fork), but we all missed:

- sched_setscheduler() uses SCHED_RESET_ON_FORK (0x40000000)
- sched_setattr() uses SCHED_FLAG_RESET_ON_FORK (0x01)

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1883013
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoloopdev: use LOOP_CONFIG ioctl
Sinan Kaya [Wed, 30 Sep 2020 03:28:30 +0000 (03:28 +0000)] 
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>
4 years agolscpu: don't use smbios when read snapshots
Karel Zak [Wed, 30 Sep 2020 12:57:08 +0000 (14:57 +0200)] 
lscpu: don't use smbios when read snapshots

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolib/buffer: fix end pointer initilaization
Karel Zak [Wed, 30 Sep 2020 12:35:33 +0000 (14:35 +0200)] 
lib/buffer: fix end pointer initilaization

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agobuild-sys: add missing header file
Karel Zak [Wed, 30 Sep 2020 12:03:15 +0000 (14:03 +0200)] 
build-sys: add missing header file

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agocol: enable deallocation on exit also for __SANITIZE_ADDRESS__
Karel Zak [Wed, 30 Sep 2020 11:47:35 +0000 (13:47 +0200)] 
col: enable deallocation on exit also for __SANITIZE_ADDRESS__

The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to
enabled in all cases (e.g. default travis-ci, local tests, ...). It
seems more robust also check for __SANITIZE_ADDRESS__ too.

Addresses: https://github.com/karelzak/util-linux/pull/1115
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibblkid: (gpt) accept tiny devices
Karel Zak [Wed, 30 Sep 2020 11:11:01 +0000 (13:11 +0200)] 
libblkid: (gpt) accept tiny devices

GPT prober reads 2 first sectors. There is no overhead as we already
read begin of the device for another filesystems (like FAT) and we
have these sectors already in memory.

Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: (gpt) reduce number of entries to fit small device
Karel Zak [Wed, 30 Sep 2020 10:38:59 +0000 (12:38 +0200)] 
libfdisk: (gpt) reduce number of entries to fit small device

The default is 128 partitions (entries in partitions array). The size
of the entry is 128 bytes, it means 32 sectors (512-byte) for the
array. The default is too large for tiny devices and it seems better to
dynamically reduce the number to fix the device size.

The reduction is reported to user.

Example:

 $ dd if=/dev/zero of=8-sectors.img count=8 bs=512
 $ fdisk 8-sectors.img
 ...
 Command (m for help): g
 Created a new GPT disklabel (GUID: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2).
 The maximal number of partitions is 8 (default is 128).

 Command (m for help): x

 Expert command (m for help): p
 Disk 8-sectors.img: 4 KiB, 4096 bytes, 8 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disklabel type: gpt
 Disk identifier: 3DB3EECE-BCCA-6C46-95FA-7E23783BB3B2
 First LBA: 4
 Last LBA: 4
 Alternative LBA: 7
 Partition entries LBA: 2
 Allocated partition entries: 8

In this case, sectors:
 0   - PMBR
 1   - GPT header
 2-3 - GPT array of partitions (8 entries, 128 bytes each)
 4   - partition data
 5-6 - backup GPT array of partitions
 7   - backup GPT header

The smallest image is 6 sectors with 4 entries in array of partitions.

Note that Linux kernel has no problem to accept 4K image with 1
512-bytes GPT partition.

  # losetup -P -f 4K.img
  # lsblk /dev/loop0
  NAME      MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
  loop0       7:0    0    4K  0 loop
  └─loop0p1 259:5    0  512B  0 part

... but we need to fix libblkid, it ignores so small devices to probe for GPT :)

Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agofdisk: always report fdisk_create_disklabel() errors
Karel Zak [Wed, 30 Sep 2020 09:49:05 +0000 (11:49 +0200)] 
fdisk: always report fdisk_create_disklabel() errors

This is fdisk, cfdisk and sfdisk change to inform user about fdisk_create_disklabel()
issues.

Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibfdisk: (gpt) make sure device is large enough
Karel Zak [Wed, 30 Sep 2020 09:44:03 +0000 (11:44 +0200)] 
libfdisk: (gpt) make sure device is large enough

The current code creates GPT header and partitions arrays (with 128
entries ...) although there is no space for all the stuff. This patch
forces fdisk_create_disklabel() to return -ENOSPC if the last and first
usable LBA calculation is out of device size.

Addresses: https://github.com/karelzak/util-linux/issues/1147
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibblkid: improve debug for /proc/partitions
Karel Zak [Wed, 30 Sep 2020 09:37:09 +0000 (11:37 +0200)] 
libblkid: improve debug for /proc/partitions

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agocol: cleanup usage() and struct col_*
Karel Zak [Tue, 29 Sep 2020 12:20:57 +0000 (14:20 +0200)] 
col: cleanup usage() and struct col_*

- remove extra line about stdout in usage() output

- use our macros to print int about --help and --version

- remove uint8_t bit-field from struct col_ctl (it seems fragile for
  future code changes).

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agoMerge branch 'col-refactor' of https://github.com/kerolasa/util-linux
Karel Zak [Tue, 29 Sep 2020 11:41:00 +0000 (13:41 +0200)] 
Merge branch 'col-refactor' of https://github.com/kerolasa/util-linux

* 'col-refactor' of https://github.com/kerolasa/util-linux:
  col: replace LINE and CHAR typedefs with structs
  col: free memory before exit [LeakSanitizer]
  col: tidy up sources a little bit
  col: add defaults to switch case clauses
  col: flip all comparisions to numerical order
  col: use size_t when dealing with numbers that buffer sizes
  col: add structure to hold line variables
  col: add update_cur_line() function
  col: add handle_not_graphic() function
  col: initialize variables when they are declared
  col: move option handling to separate function
  col: move global variables to a control structure
  col: use inline function rather than function like define
  col: use typedef and enum to clarify struct
  col: remove function prototypes
  col: add more tests

4 years agolscpu: use SMBIOS tables on ARM for lscpu
Jeffrey Bastian [Tue, 29 Sep 2020 11:28:16 +0000 (13:28 +0200)] 
lscpu: use SMBIOS tables on ARM for lscpu

ARM SBBR (Sever Base Boot Requirements) require SMBIOS tables, and
SMBIOS Type 4 describes the CPU manufacturer and model name (among other
details).  If SMBIOS Type 4 is present, use it to extract these strings.

Example output (before and after the patch) on an HP m400, Lenovo HR330A,
and HPE Apollo 70:

[root@hp-m400 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:           APM
Model:               1
Model name:          X-Gene
Stepping:            0x0
[root@hp-m400 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:                       AppliedMicro
Model:                           1
Model name:                      X-Gene
Stepping:                        0x0

[root@lenovo-hr330a ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:           APM
Model:               2
Model name:          X-Gene
Stepping:            0x3
[root@lenovo-hr330a ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:                       Ampere(TM)
Model:                           2
Model name:                      eMAG
Stepping:                        0x3

[root@hpe-apollo-70 ~]# /usr/bin/lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:           Cavium
Model:               1
Model name:          ThunderX2 99xx
Stepping:            0x1
[root@hpe-apollo-70 ~]# ./lscpu | grep -i -e vendor -e model -e stepping
Vendor ID:                       Cavium Inc.
Model:                           1
Model name:                      Cavium ThunderX2(R) CPU CN9980 v2.1 @ 2.20GHz
Stepping:                        0x1

[kzak@redhat.com: - move dmi_header to lscpu.h
                  - make arm_cpu_smbios() more robust for failed
    open() and read()
                  - use original arm_cpu_decode() also on failed
    arm_cpu_smbios()]

Signed-off-by: Jeffrey Bastian <jbastian@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolscpu: Add FUJITSU aarch64 A64FX cpupart
Shunsuke Nakamura [Mon, 28 Sep 2020 09:46:14 +0000 (18:46 +0900)] 
lscpu: Add FUJITSU aarch64 A64FX cpupart

Add an entry for FUJITSU aarch64 part A64FX.
I tested it on the FX1000.

Signed-off-by: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
4 years agocolumn: Deprecate --table-empty-lines in favor of --keep-empty-lines
Lennard Hofmann [Mon, 21 Sep 2020 16:26:00 +0000 (18:26 +0200)] 
column: Deprecate --table-empty-lines in favor of --keep-empty-lines

`--table-empty-lines` gives the false impression that the option
only applies to table mode.

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
4 years agocolumn: Optionally keep empty lines in cols/rows mode
Lennard Hofmann [Mon, 21 Sep 2020 16:16:20 +0000 (18:16 +0200)] 
column: Optionally keep empty lines in cols/rows mode

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
4 years agoMerge branch 'blockdev' of https://github.com/jwilk-forks/util-linux
Karel Zak [Tue, 29 Sep 2020 10:34:45 +0000 (12:34 +0200)] 
Merge branch 'blockdev' of https://github.com/jwilk-forks/util-linux

4 years agoMerge branch 'master' of https://github.com/tabraham/util-linux
Karel Zak [Tue, 29 Sep 2020 10:34:08 +0000 (12:34 +0200)] 
Merge branch 'master' of https://github.com/tabraham/util-linux

4 years agolibmount: optimize mnt_optstr_apply_flags()
Karel Zak [Tue, 29 Sep 2020 10:31:06 +0000 (12:31 +0200)] 
libmount: optimize mnt_optstr_apply_flags()

We append to the options string in loop there. It seems better to use
ul_buffer for this case to avoid duplicate strlen() and reallocs.

Signed-off-by: Karel Zak <kzak@redhat.com>
4 years agolibmount: improve mnt_split_optstr() performance
Karel Zak [Fri, 25 Sep 2020 15:23:18 +0000 (17:23 +0200)] 
libmount: improve mnt_split_optstr() performance

This function is used by fstab (etc.) parser to split VFS, FS and
userspace options to separate lists. Unfortunately, the current
implementation reallocates the final string always when append a new
option to the string.

The new implementation pre-allocate memory for the final string
according to source string length (1/2 of the original string). This
dramatically reduces realloc() calls.

For example oss-fuzz (./test_mount_fuzz) uses 800K input string, old
version needs 28s to parse the string, new version 500ms.

Addresses: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861
Signed-off-by: Karel Zak <kzak@redhat.com>