Karel Zak [Tue, 27 Jul 2021 09:10:53 +0000 (11:10 +0200)]
libfdisk: (dos) don't ignore MBR+FAT use-case
Since libblkid commit 751eca28fcfa1e325770904d7181b22e48c72b29 it does
not ignore FAT on whole-disks, so now libfdisk sees collision between
FAT and MBR. It's fine to report the collision to users, but we should
not ignore the MBR.
Thomas Abraham [Thu, 22 Jul 2021 19:43:13 +0000 (15:43 -0400)]
blockdev: allow for larger values for start sector
commit 9147d2ad8a ("blockdev: Don't fail on missing start sector") limits
the size of the start sector to 10 digits.
Multi-terrabyte devices can have partitions with a start sector larger than
10 digits, which will cause an sprintf() to abort due to overflowing the buffer.
Karel Zak [Thu, 22 Jul 2021 09:03:54 +0000 (11:03 +0200)]
lslogins: use sd_journal_get_data() in proper way
man sd_journal_get_data:
The returned data is in a read-only memory map and is only valid until the next invocation
of sd_journal_get_data().
It means that use data after 3x sd_journal_get_data() is really bad
idea. It also seems better to not assume the fields are zero
terminated as journal API works with void* and size_t to address the
data.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1984704 Signed-off-by: Karel Zak <kzak@redhat.com>
Karel Zak [Mon, 19 Jul 2021 11:34:24 +0000 (13:34 +0200)]
Merge branch 'chs' of https://github.com/pali/util-linux
* 'chs' of https://github.com/pali/util-linux:
tests: fdisk: Update CHS values in MBR partitions
libfdisk: (dos) Fix determining number of heads and sectors per track from MBR
libfdisk: (dos) Fix upper bound cylinder check in check_consistency()
libfdisk: (dos) Fix upper bound cylinder check in check()
libfdisk: (dos) Fix setting CHS values when creating new partition
libfdisk: (dos) Use helper macros cylinder() and sector() in check_consistency()
libfdisk: (dos) Put number of CHS check_consistency errors into summart message
libfdisk: (dos) Add check both begin and end CHS partition parameters
libfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA
libfdisk: (dos) Fix printing number of CHS sectors in check error message
libfdisk: (dos) Recalculate number of cylinders after changing number of heads and sectors
It looks like that old CHS values prior this change in test data are
incorrect. Possible explanation why CHS values are incorrect is in commit
message 9cade4fbf8c4 ("libfdisk: (dos) Fix determining number of heads and
sectors per track from MBR").
This change updates test data to pass test suite after applying mentioned
commit.
libfdisk: (dos) Fix determining number of heads and sectors per track from MBR
Current algorithm implemented in get_partition_table_geometry() function
is wrong. It take head bits from CHS position from the end of the last
partition and proclaim that this value is number of heads on disk. Same
does for sectors bits from CHS and proclaim that this value is number of
sectors per tracks. As number of disk heads and head bits in CHS position
are different things this just results in bogus detected disk geometry.
Implement a new algorithm to determinate number of heads and sectors per
track from partition sector offsets. In MBR table for every partition is
stored every sector offset in two formats: one as CHS and one as LBA.
Conversion from CHS to LBA is defined by formula:
LBA = (c * N_heads + h) * N_sectors + (s - 1)
So if we have two different offsets in both CHS and LBA formats, written as
(LBA1, c1, h1, s1) and (LBA2, c2, h2, s2) then we can calculate number of
heads and sectors per tracks by solving linear equations as:
Integer division also verifies that offsets were calculated from same
number of heads and sectors per track as division must be always positive
with no reminder.
There is a special case when either numerator or denominator is zero. This
indicates that comparing partition offsets have also same CHS offset
divisor which leads to fact that calculation of number of heads and sector
per tracks is not possible.
In MBR table are stored up to 8 offset numbers, so it means there are up
to the 28 of candidates which can expose number of disk heads and number of
disk sectors per track. Start with offsets which belongs to same partition
and start from the first partition. As the first partition in most cases
was used by BIOS for booting.
It is required to skip CHS values 1023/254/63 and 1023/255/63 as these
indicates that values are invalid or overflowed.
libfdisk: (dos) Fix upper bound cylinder check in check_consistency()
To determinate if CHS values are valid for consistency check and not
overflowed, it is needed to check current CHS cylinder value and not total
disk cylinder values. It is possible that also on "big" disk there is first
small partition which can be represented by CHS tuple.
libfdisk: (dos) Fix upper bound cylinder check in check()
To check if LBA sector can be represented in CHS without overflow it is
required to check for cylinder value which belongs to the LBA sector. And
not the total number of disk cylinders. Note that maximal representable
total number of disk cylinders is 1024 and therefore the last cylinder
which which can be stored in CHS tuple is 1023. Hence strict inequality is
used.
libfdisk: (dos) Fix setting CHS values when creating new partition
It does not matter if dos compatibility flag is turned on or off. CHS
values in partition entry can overflow also when dos compatibility flag is
turned off. In this case maximal representable CHS values should be used.
libfdisk: (dos) Put number of CHS check_consistency errors into summart message
Function check_consistency() prints errors to console output but does not
calculate correct error numbers in summary error message. Fix it, so fdisk
prints correct number in summary message "N errors detected.".
libfdisk: (dos) Add check both begin and end CHS partition parameters
There is no reason to check only end CHS partition parameters. Check also
begin values and correctly count errors in nerrors variable. fdisk then
print correctly summary message "N errors detected.".
libfdisk: (dos) Fix check error message when CHS calculated sector does not match LBA
Function check() checks that LBA addresses sector number matches CHS sector
number. But error message contains information about "previous sectors" and
"total sectors" which is misleading so change it.
Also rename variables 'start' and 'total' to make it clear what value is
stored in them. Note that in 'start' variable is currently stored last LBA
partition sector and in 'total' is stored last CHS partition sector. So
neither sector where partition starts nor total sectors of partition.
Code and check logic looks to be correct, just error message and variable
names are misleading. Therefore no functional changes in this patch.
Karel Zak [Wed, 14 Jul 2021 10:21:54 +0000 (12:21 +0200)]
Merge branch 'reorder' of https://github.com/pali/util-linux
* 'reorder' of https://github.com/pali/util-linux:
fdisk: move reorder diag messages to fdisk_reorder_partitions()
fdisk: do not print error message when partition reordering is not needed
Karel Zak [Wed, 14 Jul 2021 10:18:08 +0000 (12:18 +0200)]
Merge branch 'verity_corruption' of https://github.com/bluca/util-linux
* 'verity_corruption' of https://github.com/bluca/util-linux:
verity: fix verity.roothashsig only working as last parameter
verity: add support for corruption action flag
build-sys: display cryptsetup status after ./configure
fdisk: move reorder diag messages to fdisk_reorder_partitions()
The function fdisk_reorder_partitions() is also used in sfdisk and cfdisk
and these commands assume info/warn messages from the library. So move all
messages from fdisk to fdisk_reorder_partitions().
verity: fix verity.roothashsig only working as last parameter
Parsing of verity.roothashsig did not take into consideration that other options
might follow, and used the whole string as a file path. But mnt_optstr_get_option
just returns a pointer in the mount option string, it doesn't extract it, so it
would have other subsequent options too. The length parameter has to be used.
FAT32 can be formatted with boot sign 0x28 to indicate that only serial id
is present or with boot sign 0x29 which indicates that both boot label and
serial id is present.
libblkid: vfat: Fix reading FAT16 boot label and serial id
Older FAT16 variants do not have to contain boot label or serial id. Boot
sign 0x28 indicates that only serial id is present and boot sign 0x29
indicates that both boot label and serial id is present. Other boot sign
values (e.g. zero) indicates older FAT16 variant without boot label and
boot sign.
dlopen is treated as a dependency, but that's not quite right, it
should be an alternative way to link to libcryptsetup.
Search for it only if cryptsetup is not disabled, and if the cryptsetup-dlopen
is explicitly set to enabled. If it is, do not link to libcryptsetup.
Add cryptsetup support status to the meson summary.
It should set HAVE_CRYPT_ACTIVATE_BY_SIGNED_KEY, rather than HAVE_CRYPTSETUP
which enables the verity features, as it needs to detect the availability of
the crypt_activate_by_signed_key API
Ross Burton [Thu, 1 Jul 2021 19:44:31 +0000 (20:44 +0100)]
test/eject: guard asan LD_PRELOAD with use-system-commands check
This test tries to add asan to LD_PRELOAD because the just-built eject
will call the host /bin/umount, and apparently asan doesn't like this.
However, if ldd isn't present, this fails as the path to asan is the
error message saying that ldd isn't present.
As the asan workaround is only needed when executing the binaries that
have just been built and not the system binaries, only use it if the
test is on the built binaries.
Karel Zak [Wed, 30 Jun 2021 10:07:50 +0000 (12:07 +0200)]
Merge branch 'kill' of https://github.com/rossburton/util-linux
* 'kill' of https://github.com/rossburton/util-linux:
tests: check correct log file for errors in blkdiscard test
tests: don't hardcode /bin/kill in the kill tests
Huang Shijie [Thu, 17 Jun 2021 12:41:16 +0000 (12:41 +0000)]
lscpu: remove the old code
The file "/sys/firmware/dmi/tables/DMI" always exists.
The dmi_decode_cputype() can provide more information then arm_smbios_decode().
So remove it to tidy the code.
Before this patch, we can get the output from Centos 7.9 who has
"/sys/firmware/dmi/entries/4-0/raw" and "/sys/firmware/dmi/tables/DMI":
----------------------------------------------------
BIOS Vendor ID: Ampere(TM)
Model name: Neoverse-N1
BIOS Model name: Ampere(TM) Altra(TM) Processor
----------------------------------------------------
After this patch which uses "/sys/firmware/dmi/tables/DMI", in Centos 7.9, we get:
----------------------------------------------------
BIOS Vendor ID: Ampere(TM)
Model name: Neoverse-N1
BIOS Model name: Ampere(TM) Altra(TM) Processor Q00-00 CPU @ 2.8GHz
BIOS CPU family: 257
----------------------------------------------------
Ross Burton [Tue, 29 Jun 2021 15:34:20 +0000 (16:34 +0100)]
tests: don't hardcode /bin/kill in the kill tests
If the 'kill' test is executed with --use-system-commands, it calls
/bin/kill to avoid the shell's own kill command being invoked.
However, this doesn't work if the kill we want to test isn't in fact in
/bin. Instead, use $(which kill) to find a kill on the PATH and call
that directly.
Karel Zak [Wed, 23 Jun 2021 09:37:31 +0000 (11:37 +0200)]
more: fix null-pointer dereference
The command allows executing arbitrary shell commands while viewing a file by
entering '!' followed by the command. Entering a command that contains a '%',
'!', or '\' causes a segmentation violation.
The same more(1) function has a problem when not file is specified (cat
/etc/passwd | more) on command line.
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1975153 Signed-off-by: Karel Zak <kzak@redhat.com>