Commit Graph

11125 Commits

Author SHA1 Message Date
Shaun Tancheff 70bb534511 blkzonecmd, blkreport: Add new commands for ZAC/ZBC drives
This patch adds:
 - blkreset to issue Reset (Write Pointer) zone commands
 - blkreport to retrieve drive zone information

[kzak@redhat.com: - cleanup man page and usage()
                  - remove command line options aliases,
                  - use strtosize_or_err()
                  - remove unnecessary -ludev
                  - use blkdev.h stuff]

Signed-off-by: Shaun Tancheff <shaun@tancheff.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-09 13:19:44 +01:00
Karel Zak a18f17ad2b hwclock: remove if-if-condition 2017-02-09 11:42:01 +01:00
Karel Zak 1dc2aaadba Merge branch 'hwclock-jwp-reviewed' of git://github.com/kerolasa/lelux-utiliteetit
* 'hwclock-jwp-reviewed' of git://github.com/kerolasa/lelux-utiliteetit: (25 commits)
  hwclock: remove --compare option
  hwclock: remove trailing dot from messages that include system error message
  hwclock: make --date=argument less prone to injection
  hwclock: fix rtc atexit registration
  hwclock: clarify cmos inb and outb preprocessor directives
  hwclock: try RTCGET and RTCSET only when normal rtc fails
  hwclock: stream line synchronize_to_clock_tick_rtc()
  hwclock: improve coding style
  hwclock: remove division by zero [asan]
  hwclock: add debugging to open_rtc()
  hwclock: remove magic constants from interpret_date_string()
  hwclock: use symbolic magic values passed in between functions
  hwclock: initialize struct adjtime members
  hwclock: alloate date_resp parsing buffer in interpret_date_string()
  hwclock: simplify save_adjtime() execution flow
  hwclock: remove dead code and other minor fixes
  hwclock: move error messages to determine_clock_access_method()
  hwclock: clarify set_cmos_epoch() code
  hwclock: move command-line options to control structure
  hwclock: remove unnecessary type casts
  ...
2017-02-09 11:35:50 +01:00
Carlos Santos 4953018e23 build-sys: improve detection of the "isnan" function in uClibc
Since commit beceb14b45, MATH_LIBS is set
to "-lm" when the isnan function is detected. In uClibc, however, isnan
is a macro that calls __isnan, __isnanf, or __isnanl, depending on the
size of the argument (double, float or long double).

Fixes:
  http://autobuild.buildroot.net/results/2c2/2c29a78ed81ca844a87dcd076ab3e14ea080296d/
  http://autobuild.buildroot.net/results/404/404b10f359b2ae8a7216729fa1bab37fed2d3d4c/

Signed-off-by: Carlos Santos <casantos@datacom.ind.br>
2017-02-09 11:31:49 +01:00
Karel Zak 9e66fd30d7 umount: exclude selinuxfs from --all
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1417722
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-09 11:21:49 +01:00
Sami Kerola 92931ab28d
hwclock: remove --compare option
Compare functionality was printing nonsense values.  There is no knowledge
of anyone using this broken functionality.  Instead of deprecating the code
for months, and removing it after few release, it is removed immediately.
Needless to say this is unusual removal.

Reference: http://marc.info/?l=util-linux-ng&m=148396210506652&w=2
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola c9a86ff664
hwclock: remove trailing dot from messages that include system error message
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 9c65888e82
hwclock: make --date=argument less prone to injection
This change should not improve security much.  One hopes hwclock --set is
restricted for root only.  Where hwclock is allowed to run via sudo, or has
setuid setup, there is a pretty easy privilege escalation via subshell.

$ sudo ./hwclock --set --date='2000-10-20$(touch /tmp/hwclock.inject)'

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 926ffe7451
hwclock: fix rtc atexit registration
Commit 27f9db17bd missed a minus sign from
comparison.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 6b06669e2a
hwclock: clarify cmos inb and outb preprocessor directives
The cmos only works when architecture is i386, x86_64, or alpha.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola fc35f2db79
hwclock: try RTCGET and RTCSET only when normal rtc fails
The RTCGET and RTCSET are in use for sparcs with sbus, so try them as
fallback rather than always.

Reference: https://github.com/torvalds/linux/blob/master/fs/compat_ioctl.c#L967-L974
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 4bfd519eee
hwclock: stream line synchronize_to_clock_tick_rtc()
Flip if clauses to hit common case first.  This should be easier and quicker
to read and run.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola bd0786895d
hwclock: improve coding style
Make string constants to be symbolical declarations.  Use longer variable
name for rtc and cmos function pointer values.  Exclude code that is
architecture specific with preprocessor directives.  And remove message
duplication.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 85932da89e
hwclock: remove division by zero [asan]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 067b60280a
hwclock: add debugging to open_rtc()
Earlier when open_rtc() returned -1 the char *rtc_dev_name end up having
NULL that made it unsuitable to be used in error message.  Now one can debug
what paths the open_rtc() tries to use when one has to debug why 'cannot
open rtc device' happen.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:38 +00:00
Sami Kerola 6b3cb18669
hwclock: remove magic constants from interpret_date_string()
The constants function returned were not used.  In same go clean up
execution flow a little bit.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 0f32118e70
hwclock: use symbolic magic values passed in between functions
The manipulate_clock() is seeing return value from
busywait_for_rtc_clock_tick().

And the get_permissions_cmos() can see i386_iopl() return value.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola a8775f4e7f
hwclock: initialize struct adjtime members
Avoid any chance of using uninitialized values.  It looks like the earlier
code did take care of that, but it was less obvious about the fact.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 710684e81d
hwclock: alloate date_resp parsing buffer in interpret_date_string()
This makes overflowing the variable in question impossible.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 4aca5fe247
hwclock: simplify save_adjtime() execution flow
Return early to avoid excessive nesting.  In same go remove any chance of
overflow by using appropriate allocation.  And update variable names to be
easier to understand.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola c6ea9ef6cb
hwclock: remove dead code and other minor fixes
Use #ifdef rather than #if to avoid undefined preprocessor identifier
warning.

Remove dead code.  The #if 0 ensured the code has not been used for long
time, which is good because the linux/mc146818rtc.h is not been part of
user-api for long time.

Value of the adjtime_p->last_calib_time is checked if it has value of zero,
so testing none-zero bit later is necessarily true, and therefore does not
need to be checked.

And at the and remove unnecessary boolean variable.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 8f729d60fa
hwclock: move error messages to determine_clock_access_method()
This makes main() a little bit shorter.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola d0d3469139
hwclock: clarify set_cmos_epoch() code
Variable set_epoc is unnecessary, and removal of it makes it obvious what is
happening in this function.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 336f7c5f68
hwclock: move command-line options to control structure
The control structure is read-only everywhere else but in main().  Almost
all changes are about how variables are referred, with one exception.  Calls
to read_adjtime() from manipulate_clock() and compare_clock() are moved to
main().  This way it is possible to keep variable that tells if hwclock is
using UTC-0 be part of control structure.

Changes within #ifdef __alpha__ segments were tested by flipping the
preprocessor directivive otherway around and getting good compilaton all the
way to the point where linking on none-alpha system failed.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola b68e1f44ab
hwclock: remove unnecessary type casts
Most of the casts did nothing, with exception of couple printouts where
format specifier is updated to match with the variable type.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 183a2715b1
hwclock: do not hardcode date command magic string twice
Variable 'magic' already contains string 'seconds-into-epoch'.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:37 +00:00
Sami Kerola 48e7ed5e3f
hwclock: remove hwclock_exit() indirection
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:36 +00:00
Sami Kerola 1030c325c0
hwclock: remove FLOOR macro in favour of floor(3)
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-04 23:39:30 +00:00
Sami Kerola b72a75e993
lib: add timegm() portability function to lib/timeutils.c
Local timegm() is a replacement function in cases it is missing from libc
implementation.  Hopefully the replacement is never, or very rarely, used.

CC: Ruediger Meier <ruediger.meier@ga-group.nl>
Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-03 22:31:18 +00:00
Sami Kerola 12f1cdda3d
hwclock: remove UTC-0 localization hack
Use timegm(3) instead rather than re-implement same functionality with
mktime(3) combined with removal of TZ localization.

Reviewed-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-03 22:31:18 +00:00
Karel Zak e7e7697612 cfdisk: add copyright to help
... to make it obvious this is a new cfdisk.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-02 10:28:38 +01:00
Karel Zak 1a3397906d libmount: make rootfs lookup by parent-id more robust
The root FS id really does not have to be the smallest one.

Reported-by: Michal Soltys <soltys@ziu.info>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 16:20:12 +01:00
Karel Zak 2f4eb047e5 cfdisk: support UI refresh on ^L
Addresses: https://github.com/karelzak/util-linux/issues/404
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 15:34:57 +01:00
Karel Zak dffab154d2 su: properly clear child PID
Reported-by: Tobias Stöckmann <tobias@stoeckmann.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-02-01 11:58:09 +01:00
Karel Zak 904ffe1fd2 lscpu: don't use path_exist() before path_fopen()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 20:55:07 +01:00
Karel Zak 56cda4b7e3 docs: add BUG REPORTING section to README
Addresses: https://github.com/karelzak/util-linux/issues/405
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 16:18:11 +01:00
Karel Zak 4dfc54b6b1 lscpu: make osrelease file optional
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 13:44:43 +01:00
Karel Zak f164c08dfa Merge branch 'master' of https://github.com/Pedro-MC/util-linux
* 'master' of https://github.com/Pedro-MC/util-linux:
  findmnt: flush stdout after each (un)(re)mount event, when polling.
2017-01-31 13:01:01 +01:00
Denis Chaplygin 833f9a7aae fallocate: Added posix_fallocate() support.
No all filesystems support Linux fallocate. The new option allow use
posix implementation if necessary.

Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-31 12:51:28 +01:00
Stanislav Brabec 7572fb2b8c lscpu: Detect Windows Subsystem for Linux
Windows 10 implements Windows Subsystem for Linux (WSL).

WSL does not implement support for SIGSEGV handler, which is used inside
is_vmware_platform(). As a result, lscpu crashes there.

Implement WSL detection, and as a side effect, work around the crash.
Note that none of existing virtualization types exactly matches.
But the the closest would be "container".

References:

Provide a way to positively detect WSL from an app compiled on Linux.
https://github.com/Microsoft/BashOnWindows/issues/423

missing support for SIGSEGV handler
https://github.com/Microsoft/BashOnWindows/issues/1637

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-01-31 12:28:32 +01:00
Stanislav Brabec afa382f2e0 fstrim: de-duplicate btrfs sub-volumes
There was a comparison of roots in uniq_fs_source_cmp(). As we care only on
device names, comparing roots makes only a little sense, and it breaks on btrfs.
As a result, FITRIM ioctl() is called for each subvolume. But by design, only
one TRIM is needed for the whole btrfs volume.

Remove it to be able to de-duplicate btrfs subvolumes.

Fixes opensuse #1020077.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2017-01-31 12:26:01 +01:00
Pedro Miguel Carvalho 18efba189e findmnt: flush stdout after each (un)(re)mount event, when polling.
Addresses: karelzak#407
2017-01-29 12:03:23 +00:00
Karel Zak 6d8a31f6db logger: support sub-trees in the ID for RFC5424
The current code supports <name>@<digit> only, but we also need
<name>@<digit>.<digit>[. ...]

RFC5424: 7.2.2 enterpriseId:

 In general, only the IANA-assigned private enterprise number is
 needed (a single number).  An enterprise might decide to use
 sub-identifiers below its private enterprise number.  If sub-
 identifiers are used, they MUST be separated by periods and be
 represented as decimal numbers.  An example for that would be
 "32473.1.2".

Addresses: https://github.com/karelzak/util-linux/issues/406
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-28 12:39:52 +01:00
Karel Zak 61cbc8a3f5 lib/strutils: return end pointer by isdigit_string()
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-28 12:39:30 +01:00
Karel Zak f71b96bfa1 libfdisk: (gpt) add check for entries array size
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-25 12:00:27 +01:00
Alden Tondettar a157a23f6d libblkid: Fix out of bounds reads in BEFS handling
The BEFS prober is quite trusting of whatever data is fed to it and
performs almost no bounds checks. There don't seem to be any
out-of-bounds writes as far as I can tell, but there are many ways a
corrupted image could cause libblkid to read OOB and segfault, or hang
in an infinite loop.

This fix makes a few sanity-checks of the superblock, add bounds checks
wherever they seem needed, and crudely checks for cycles in the B+ tree.

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
2017-01-25 11:43:06 +01:00
Alden Tondettar dfb8d4ba92 libblkid: Fix out of bounds reads on bad GPT header
If a GUID Partition Table claims to have more than 2**25 entries, or if the
size of each entry is not exactly 128 bytes, libblkid can read out of bounds
and segfault. Perform the appropriate checks.

[kzak@redhat.com: - fix typo]

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-01-25 11:41:22 +01:00
Alden Tondettar 999a2ffec9 libblkid: Fix out of bounds reads on bad NTFS Master File Table
The NTFS prober does not validate certain fields in struct file_attribute,
and could attempt to read the disk label from outside the space allocated
for the Master File Table.  Perform the appropriate checks.

Note that one variable (attr_off) is now 64-bit, so a check for integer
overflow has been removed as unneeded/confusing.

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
2017-01-25 11:39:10 +01:00
Alden Tondettar a7caeabadf libblkid: Fix out of bounds byte swaps in ZFS handling
A corrupted ZFS filesystem can trigger 32-bit endian-conversions of
unintended memory locations in zfs_extract_guid_name(), in several ways:

* The variable "left" (number of bytes remaining in the buffer) does not
  account for the 12 bytes of the nvlist header.

* The field nvp->nvp_namelen (name length in name/value pair) is rounded
  up to the nearest multiple of 4, but only the unrounded size is checked.

* The fields nvs->nvs_type, nvs_strlen, etc. are modified _before_ checking
  if they are within bounds.

* A negative value of nvp->nvp_namelen will bypass the check that
  nvp->nvp_namelen fits into nvp->nvp_size (size of name/value pair).

This allows for mangling of locations up to 12 + 3 + 8 == 23
bytes beyond the end of stack-based buff[4096], and up to 2**31 bytes
before its beginning.

Furthermore some debugging messages are printed from unchecked memory
locations, possibly resulting in OOB reads or setuid programs leaking
sensitive data when LIBBLKID_DEBUG is set.

This fix attempts to correct all of these problems. It also eliminates the
stack-based buffer (in case anything else was missed) and refactors things
a bit to (hopefully) make it easier to spot any mistakes.

Signed-off-by: Alden Tondettar <alden.tondettar@gmail.com>
2017-01-25 11:39:10 +01:00
Karel Zak 344d861d83 Merge branch 'shadow-man' of https://github.com/andhe/util-linux
* 'shadow-man' of https://github.com/andhe/util-linux:
  chsh: use -h as shorthand for --help instead of -u
  man: chsh(1): add login.defs to SEE ALSO
  man: chfn(1): add chsh and login.defs to SEE ALSO
2017-01-20 13:12:57 +01:00