Commit Graph

10491 Commits

Author SHA1 Message Date
Karel Zak a67054f9be libfdisk: make table-length usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-18 14:15:02 +02:00
Sassan Panahinejad d96153f8c8 sfdisk: Add support for altering GPT size
Adds a header option to alter the GPT table length
2016-05-18 13:56:25 +02:00
Sassan Panahinejad a18e726c66 libfdisk: Add support for altering GPT size
This is useful in two situations:

1. More than 128 partitions are required. Or

2. The partition table must be restricted in size, such as when a system
expects to find a bootloader at a location that would otherwise overlap the
partition table.

The gdisk partitioner supports this feature.

libfdisk is already capable of reading and writing partition tables of any
size, but previously could only create ones of 128 entries and could not
resize.

This change should be fairly safe, as it has no effect unless explicitly
activated.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-18 13:48:04 +02:00
Sassan Panahinejad 304cf9499d fdisk: Add support for altering GPT size
Adds an options (l) to the GPT menu to resize the GPT.
2016-05-18 13:46:35 +02:00
Sassan Panahinejad 083c35b9f6 libfdisk: fix range checking for fdisk_set_last_lba 2016-05-18 13:46:35 +02:00
Karel Zak 28b6c76f8a logger: add man page note about the default --tag
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-16 15:05:28 +02:00
Karel Zak 40c9c3a6b7 libfdisk: add API for work with labelitems
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-12 14:37:29 +02:00
Karel Zak e4c5250dfb libfdisk: move fdisk_field_...() functions to field.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-12 12:21:59 +02:00
Karel Zak 3c201431ee lib/timeutils: add strxxx_iso() functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-11 15:31:02 +02:00
Karel Zak 627258104b ramctl: add support for zram-control
Based on patch from Timofey Titovets.

Addresses: https://github.com/karelzak/util-linux/issues/318
Reported-by: Timofey Titovets <nefelim4ag@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-11 12:43:40 +02:00
Karel Zak a3a125b922 libfdisk: use fdisk_add_partition() for unused partno
For example:

   sfdisk -N <parno>

may address unused partition. In this case we need to redirect from
fdisk_set_partition() to fdisk_add_partition() and follow default
setting (used all free space).

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-10 10:52:31 +02:00
Karel Zak 94af67f2aa Merge branch 'no-fork' of https://github.com/terryburton/util-linux 2016-05-09 13:28:52 +02:00
Sami Kerola c8a6f83e85 setterm: remove unnecessary translation string
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-05-09 12:57:01 +02:00
Karel Zak 98297e65a1 setterm: de-duplicate color option string parsing
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-09 12:35:41 +02:00
Wayne Pollock 3e90d04af9
write: fix setuid related regression
The write(1) is commonly a setuid binary, because common users cannot by
default write to each others terminals.  Since the commit in reference, that
is part of releases v2.24 to v2.28, the write(1) has used access(2) to check
capability to write to a destination terminal.  The catch is that access(2)
uses real UID and GID to when performing the accessibility.  The obvious
correction is to avoid access(2) when in context of setuid binaries.

As a smaller fix, but equally important fix, ensure the 'msgsok' variable is
initialized to indicate no access.  Uninitialized variable will almost
certainly do wrong thing at the time of check.

Breaking-commit: 0233a8ea18
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Wayne Pollock <profwaynepollock@gmail.com>
2016-05-07 22:49:41 +01:00
Sami Kerola f0b3b904c7 scriptreplay: avoid re-implementing strtod_or_err()
And use isnan() to detect NaN.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-05-05 11:46:54 +02:00
Sami Kerola ba660b9911 scriptreplay: improve error message
Use human numbering for lines - that is start counting from 1.  And tell in
error message what the number means.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-05-05 11:46:54 +02:00
Victor Dodon 14f644f386 sfdisk: exit with error if rereading partition table fails
Use the return value of fdisk_reread_partition_table in write_changes so that
sfdisk exits with error if re-reading the partition table fails.

Signed-off-by: Victor Dodon <dodonvictor@gmail.com>
2016-05-05 11:43:07 +02:00
Karel Zak 832bbc73b2 build-sys: remove obsolete [cs]fdisk LDADDs
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 15:02:02 +02:00
Karel Zak 3d6db3fdb1 sfdisk: add --wipe-partitions=auto|never|default
The option allows to remove filesystes/RAIDs from newly created
partitions before the partition table is updated (and partition
device created).

The default is "auto" in this case wipe is enabled in interactive mode
only and user's confirmation (yes/no dialog) is required. Note that
keep filesystem signature on partition is pretty valid use-case, so we
don't erase anything by default.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 12:47:17 +02:00
Karel Zak ba465623d8 fdisk: add --wipe-partitions=auto|never|default
The option allows to remove filesystes/RAIDs from newly created
partitions before the partition table is updated (and partition
device created).

The default is "auto" in this case wipe is enabled in interactive mode
only and user's confirmation (yes/no dialog) is required. Note that
keep filesystem signature on partition is pretty valid use-case, so we
don't erase anything by default.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 12:43:35 +02:00
Karel Zak 131e38a28e libfdisk: add fdisk_wipe_partition()
Now libfdisk provides functionality wipe disk device only ([s]fdisk
option --wipe).

This patch allows to probe for filesystems/RAIDs on newly created
partitions.  It means we can remove signatures before the partition
node (device) is created. This reduces udev events and it's
unnecessary to call wipefs for all partitions.  For example

  sfdisk --wipe=always --wipe-partitions=always /dev/sda <<<
  ...
  EOF

is a elegant way how to create new disk layout without any obsolete
filesystems/RAIDs.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-05-04 12:32:52 +02:00
Karel Zak 55ad13c26f libblkid: make I/O errors on CDROMs non-fatal
It seems too tricky to get a real size of the data track on hybrid
disks with audio+data. It seems overkill to analyze all header in
libblkid and on some disks it's probably possible to get I/O error
almost everywhere due to crazy copy protection etc.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-28 13:54:01 +02:00
Karel Zak 6548ac6aa7 Revert "libblkid: check for multi-session CDROMs"
This reverts commit a14cc9a504.

We need a better way (probably analyze track ioctls CDROMREADTOCHDR
and CDROMREADTOCENTRY) to get also proper track size.

The original patch works only if data track is the last track.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-27 18:49:36 +02:00
Karel Zak a14cc9a504 libblkid: check for multi-session CDROMs
.. and read last session if probing offset is not specified.

udev uses cdrom_id to get last session offset, so people don't see a
problem with hybrid media (audio+data), but if you execute blkid on
command line (without -O <offset>) then you get I/O errors.

It seems that we can use the same way as kernel filesystem iso9960
driver when session= mount option is not specified ... just use
CDROMMULTISESSION ioctl to get last session offset and probe this last
session rather than all medium.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-27 14:18:41 +02:00
Karel Zak b362a4cb98 libfdisk: don't offer zero length freespace
Reported-by: Kay Sievers <kay@vrfy.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-25 11:59:06 +02:00
Karel Zak 8fcdce8fff libsmartcols remove duplicate code
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 14:17:21 +02:00
Karel Zak deb1c90327 libmount: remove duplicate code
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 13:59:06 +02:00
Karel Zak b6782d8697 tests: move getopt to separate directory
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 13:39:31 +02:00
Karel Zak d08b58c491 mount: add note about loopdev reuse to mount.8
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 13:14:12 +02:00
Stanislav Brabec b2c2c42a8e mount: Handle EROFS before calling mount() syscall
If the loop device is already initialized read-only, the new code for loop
device reuse returns -EROFS. There is no solution of this situation. But mount
can behave in the same way, as it does for EROFS returned by mount syscall: Try
again in read-only mode.

Before:
mount: /mnt/2: mount failed: Read-only file system

After:
mount: /btrfs.img is used as read only loop, mounting read-only

Note: It would be nice to mention loop device name in the warning message, but
it is not available in the mount context.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-04-22 12:50:14 +02:00
Stanislav Brabec bdf46c4df9 libmount: reuse existing loop device
According to the Al Viro[1], kernel has no way to detect that a single file is
used by multiple loop devices, and multiple mounts of the same file using
different loop devices will result in a data corruption. Exactly this now
happens, if multiple btrfs sub-volumes in one file are mounted with "-oloop".

Make use of multiple -oloop mounting the same file safe: Do a loop devices
lookup, and if a loop device is already initialized, use it.

Hopefully it is possible, as "losetup -d" will return OK, even if the device
itself is in use, and is not released.

Problems:

There is a risk of race condition between the lookup and real mount.

Once loop device is initialized read-only, kernel offers no way to turn it to
read-write. It has to fail.

References:
https://lkml.org/lkml/2016/2/26/897

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-04-22 12:50:14 +02:00
Stanislav Brabec 6e25802675 libmount: Re-organize is_mounted_same_loopfile()
First parse options, then initialize context.
No change in function.
The change is needed for loop device reuse.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
2016-04-22 12:50:14 +02:00
Karel Zak e402d6d3b1 getopt: keep pointer to 'name' in control struct
It's seems more readable than call free(argv[0]).

Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 11:29:46 +02:00
Karel Zak fd0b6a5a42 Merge branch 'scan-build' of https://github.com/kerolasa/lelux-utiliteetit
* 'scan-build' of https://github.com/kerolasa/lelux-utiliteetit:
  getopt: fix memory leaks and integer overflows [ASAN & valgrind]
  lib: avoid double free in loopdev.c
  setpwnam: fix memory leak
  libmount: fix memory leak
  build-sys: test functions does not return void
2016-04-22 11:21:16 +02:00
Yuriy M. Kaminskiy fc75981a22 fsck: fix racing between unlock/unlink and open
Process A	Process B	Process C
open()
[creates file]
lock()
[succeed]
		open()
		[open existing]
		lock()...
running()
close()
		[...succeed]
unlink()
		running()
				open()
				[creates file] {BAD!}
				lock()
				[succeed] {BAD!}
				running() {BAD!}
		close()

Cons: leaves empty (unlocked/harmless) .lock files in /run/fsck/
Signed-off-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
2016-04-22 11:07:42 +02:00
James Bottomley 854d0fef7f nsenter: enter namespaces in two passes
We have two use cases for user namespaces, one to elevate the
privilege of an unprivileged user, in which case we have to enter the
user namespace before all other namespaces (otherwise there isn't
enough permission to enter any other namespace).  And the other one is
where we're deprivileging a user and thus have to enter the user
namespace last (because that's the point at which we lose the
privileges).  On the first pass, we start at the position one after
the user namespace clearing the file descriptors as we close them
after calling setns().  If setns() fails on the first pass, ignore the
failure assuming that it will succeed after we enter the user
namespace.

Addresses: https://github.com/karelzak/util-linux/issues/315
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-22 11:03:01 +02:00
Sami Kerola b13fedd485
getopt: fix memory leaks and integer overflows [ASAN & valgrind]
The getopt(1) is short living command, and one could argue ensuring all
allocations are freed at end of execution is waste of time.  There is a
point in that, but making test-suite runs to be less noisy with ASAN is also
nice as it encourages reading the errors when/if they happen.

Reviewed-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-20 22:04:34 +01:00
Sami Kerola 34f6177a24
lib: avoid double free in loopdev.c
Found with scan-build.

Reviewed-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-20 22:03:26 +01:00
Sami Kerola 31af559e30
setpwnam: fix memory leak
Found with scan-build.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-19 21:27:54 +01:00
Sami Kerola ac943a662d
libmount: fix memory leak
Found with scan-build.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-19 21:27:54 +01:00
Sami Kerola cf582a2e86
build-sys: test functions does not return void
Found using scan-build.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-19 21:27:54 +01:00
Karel Zak 1bd62f72d8 libblkid: fix mistake in debug message
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-19 12:45:00 +02:00
Karel Zak bfebe74e3b libblkid: reduce probing area for crazy CDROMs
Linux kernel reports devices greater than area readable by read(2).
The readable area is usually 2-3 CD blocks smaller (CD block is
2048-bytes) than size returned by BLKGETSIZE. This patch checks for
this issues to avoid I/O errors in probing functions.

Reported-by: Thomas Schmitt <scdbackup@gmx.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-19 12:39:05 +02:00
Petr Uzel 445e6b1ec8 libblkid: make blkid_do_wipe() work with probes with offset
When a probe is created with an offset, e.g. via
blkid_probe_set_device(), this offset is correctly used when looking for
the signatures, but is not respected by blkid_do_wipe() function.
Therefore the signature is removed from an invalid location.

Usecase: Wiping signatures from an area on the block device where
partition is to be created (but as it does not exist yet, there's no
device node for it and probe on the whole block device has to be used
with correct offset and length).

Reproducer:
======================== wiper.c ===========================

const char *dev;
unsigned long offset;
unsigned long size;

int main(int argc, char** argv) {

        if (argc != 4) {
                printf("usage: wiper dev offset size\n");
                exit(1);
        }

        dev = argv[1];
        offset = strtoull(argv[2], NULL, 10);
        size = strtoull(argv[3], NULL, 10);

        printf("dev=%s, off=%llu, size=%llu\n", dev, offset, size);

        int fd = open (dev, O_RDWR);
        if (fd == -1) {
                perror("open");
                exit(1);
        }

        blkid_loff_t wipe_offset = offset * SECTOR_SIZE;
        blkid_loff_t wipe_size = size * SECTOR_SIZE;

        int ret;

        blkid_probe pr;
        pr = blkid_new_probe();
        if (!pr)
                return 0;
        ret = blkid_probe_set_device(pr, fd, wipe_offset, wipe_size);
        ret = blkid_probe_enable_superblocks(pr, 1);
        ret = blkid_probe_set_superblocks_flags(pr, BLKID_SUBLKS_MAGIC);

        while (blkid_do_probe(pr) == 0) {
                ret = blkid_do_wipe(pr, 0);
        }

        blkid_free_probe(pr);
        close(fd);
}
======================== wiper.c ===========================

Steps to reproduce:
modprobe scsi_debug
parted -s /dev/sdX mklabel gpt
parted -s /dev/sdX mkpart first 2048s 4095s
mkfs.ext2 /dev/sdX1

wipefs -np /dev/sdX1

./wiper /dev/sdX1 2048 2048

Actual result: wiper gets into endless loop, because
blkid_do_wipe() wipes at wrong location (1080), leaving the signature
on /dev/sdc1. So it is again found by blkid_do_probe(), and so on.

Expected result: wiper clears the ext2 signature at offset 1049656(=1080+2048*512).

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2016-04-18 19:53:51 +02:00
Karel Zak 7997468484 pylibmount: include c.h
... for sys/sysmacros.h and major() and minor() macros.

Reported-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-04-18 13:19:12 +02:00
Yuriy M. Kaminskiy c79657ca85 losetup: fix outdated comment
From abb2a420924c792be33aa3ed825b1348ea7d51a9 Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Date: Wed, 13 Apr 2016 17:30:10 +0300
Subject: [PATCH] losetup: fix outdated comment

--direct-io argument was made optional by
f98d9641a3, but this comment was not
updated accordingly

Signed-off-by: Yuriy M. Kaminskiy <yumkam@gmail.com>
2016-04-18 11:04:16 +02:00
Karel Zak 71d5088f05 Merge branch '2016wk15' of git://github.com/kerolasa/lelux-utiliteetit
* '2016wk15' of git://github.com/kerolasa/lelux-utiliteetit:
  mount: try to tell what mount was doing when it failed
  dmesg: --notime should not suppress --show-delta
  script: check status of writes when closing outputs
  script: avoid trying fclose(NULL)
  sulogin: make fopen O_CLOEXEC specifier usage portable
  script: close file descriptors on exec
  docs: optinal option arguments should be long-only
2016-04-18 11:01:26 +02:00
Lubomir Rintel d97dc0ee25 mkswap: tolerate ENOTSUP when failing to relabel
It might be that the underlying filesystem just doesn't support SELinux
labeling. This fixes creating swap on vfat live media:

  # livecd-iso-to-disk.sh --msdos --swap-size-mb 666 ...

Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
2016-04-18 10:51:28 +02:00
Sami Kerola 592fe0175f
mount: try to tell what mount was doing when it failed
Earlier output did not give enough information to system admin to fix an
issue in /etc/fstab effectively.

$ sudo mount -a
mount: mount(2) failed: No such file or directory

Addresses: https://bugs.launchpad.net/bugs/1557145
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2016-04-16 23:09:27 +01:00