summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
...
* libblkid-tiny: fix buffer overflowDaniel Golle2021-05-162-5/+2
| | | | | | | | | | | | | | | | Copying device name into a fixed-length buffer is problematic as the name can be longer than the buffer, resulting in subsequent fields getting corrupted and potentially even worse things. Drop strcpy of device name and use of the copied value as it is known anyway. Before this fix: /dev/mapper/owrt--volumes--e093cc66-rw_test: UUID="c66-rw_test" LABEL="test" VERSION="1.14" TYPE="f2fs" After this fix: /dev/mapper/owrt--volumes--e093cc66-rw_test: UUID="5eda3e52-3427-493a-a6d6-ffdb5a5836fd" LABEL="test" VERSION="1.14" TYPE="f2fs" Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: use allocated strings instead of fixed buffersDaniel Golle2021-05-161-12/+34
| | | | | | | | | device names can be pretty long when using LVM2, mount targets are user defined and can potentially also be of PATH_MAX length. Replace static buffers with dynamically allocated strings to avoid buffer overflow with too long device names or mount targets. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* block: use dynamically allocated target stringDaniel Golle2021-05-161-4/+17
| | | | | | | | Dynamically allocate string buffer for target mountpoint if needed in order to avoid the static buffer overflowing for long (device mapper) paths. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* fstools: block: fix segfault on mount with no targetDaniel Danzberger2021-05-161-1/+1
| | | | | | | | | When a UCI fstab mount config doesn't contain a target option, a 'block mount' call segfaults when comparing a mount's target (NULL) to a found mount point returned by find_mount_point() Signed-off-by: Daniel Danzberger <daniel@dd-wrt.com> Acked-by: Paul Spooren <mail@aparcar.org>
* overlay: fix syncronizing typoPetr Štetiar2021-04-071-1/+1
| | | | | | So it's now correct `synchronizing`. Signed-off-by: Petr Štetiar <ynezz@true.cz>
* partname: allow skipping existing 'rootfs_data' partitionDaniel Golle2021-03-191-1/+6
| | | | | | | | | | | | Apparently some devices with eMMC (e.g. ZyXEL NBG6817) got an exsiting GPT partition called 'rootfs_data'. This partition is then selected as rootfs_data eventhough it may not be suitable for that (too small) or serve another purpose (ie. used by vendor firmware). To avoid this, check if the kernel cmdline contains a variable fstools_ignore_partname=1 and if so, skip partname detection of volumes alltogether. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: remove superflus includeDaniel Golle2021-03-081-3/+0
| | | | | | | Turns out C header file <stropts.h> is unneeded after all. Remove it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: fix build with glibcDaniel Golle2021-03-051-0/+2
| | | | | | | | | stropts.h which is unavailable under glibc (and not needed when building against glibc). Include it only if not building against glibc. Reported by: @DazzyWalkman Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* libfstools: partname: several fixesDaniel Golle2021-03-021-16/+30
| | | | | | | | | | | partname driver didn't allow mount_root to identify the filesystem and hence the overlay filesystem state remained PENDING which lead to overlay being cleared again at every reboot. Fix that by setting v->blk early and, while at it, eliminate unneeded strdup's by storing the full device paths in a union allowing accessing the full path or the device name only. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* fstools: add partname volume driverDaniel Golle2021-02-277-126/+327
| | | | | | | | | | | | Add driver to handle block devices with (GPT) partition table which can include a partition name. If 'root=' is set on the kernel cmdline, only search for partitions on the same device. Among with other changes (ptgen, image*.mk, base-files, ...) this allows for a much more straight forward storage model on block based devices. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jffs2reset: support fristboot on unmounted UBI overlayDaniel Golle2021-01-041-0/+9
| | | | | | | | To erase the overlay partitions on systems using UBIFS overlay, instead of writing the jffs2-marker, truncating the UBI volume to 0 has the desired effect. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* block: replace local mkdir_p implementationDaniel Golle2020-12-121-20/+9
| | | | | | | Drop local mkdir_p implementation in favour of using the implementation now added to libubox. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: restorecon: guard against execl() errorsDaniel Golle2020-12-121-1/+1
| | | | | | | | | | In the current implementation, in case of execl("/sbin/restorecon") failing, the child process will also return and that will lead to even more disasterous effects. Though it seems unlikely that execl() would fail given that the file exists, simply catch that case by exiting in case execl() returns. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* jffs2-reset: allow doing a factory reset and passing a sysupgrade.tgzJohn Crispin2020-11-271-5/+8
| | | | Signed-off-by: John Crispin <john@phrozen.org>
* mount: apply SELinux labels before overlayfs mountDaniel Golle2020-10-163-0/+28
| | | | | | Use restorecon to apply SELinux labels if applicable. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* overlay: use precompiler macros for reoccuring path namesDaniel Golle2020-10-161-4/+5
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: fix log format string and indentationDaniel Golle2020-10-161-2/+2
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* mount: remove support for legacy overlayfs before v2.3Daniel Golle2020-10-161-36/+22
| | | | | | | overlayfs has been in mainline since Linux v3.18 (OpenWrt CC 15.05). Remove support for pre-mainline overlayfs. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* fstoools: add define for GLOB_ONLYDIRRosen Penev2020-07-111-0/+4
| | | | | | | | | This was originally a patch for musl. It is not present in musl as it is a GNU extension. Place it here where it belongs. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* Use autoclear for overlay loopback deviceDavid Woodhouse2020-06-171-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During a sysupgrade on a block-based device, the partition table might get updated. The partitions have to be completely unused by the time partx is invoked, or it fails thus: partx: /dev/mmcblk1: error deleting partition 3 partx: /dev/mmcblk1: error adding partition 3 That's cosmetic in some cases, but in others where the old root partition overlaps with the new partition where the config is stored during the reboot, it causes a sysugprade failure (resulting in the backup being lost and a completely clean system image). Although we carefully unmount the root and overlay file systems, the problem is that the loopback device used for the overlay isn't being torn down, and it still has a refcount on the root block partition (in the above case, /dev/mmcblk1p3). Installing losetup and adding 'losetup -D' to the switch_to_ramfs() function makes it work nicely. But the better option that doesn't add a new dependency is to use the autoclear flag when setting up the loop device, so it goes away automatically when the overlay file system is unmounted. To make that work sanely, we have to *not* close the fd right after configuring it — or it'll go away immediately. We could store the fd in the volume struct and either add destructor method or close it after performing the mount… but honestly it just seems simpler and saner to "leak" the fd in the knowledge that it'll get closed when the process exits in a few milliseconds anyway. We can revisit that if anyone really feels strongly about it. Dissent is best expressed in 'diff -up' form. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
* blockd: fix segfault triggered by non-autofs mountsDaniel Golle2020-05-121-1/+1
| | | | | | | | | | Program received signal SIGSEGV, Segmentation fault. main_autofs (argv=<optimized out>, argc=<optimized out>) at fstools-2020-05-06-eec16e2f/block.c:1193 1193: if (!m->autofs && (mp = find_mount_point(pr->dev))) { Fixes: 9ab936d ("block(d): always call hotplug.d "mount" scripts from blockd") Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: add optional "device" parameter to "info" ubus methodRafał Miłecki2020-05-061-21/+51
| | | | | | It allows getting info about specified device. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block(d): always call hotplug.d "mount" scripts from blockdRafał Miłecki2020-05-062-36/+87
| | | | | | | | | | | | | | | | This resolves problem on boot with "mount" scripts being called too early to get blockd info. With this change "mount" scripts won't get called until blockd starts. On startup it requests all devices info and calls relevant scripts. This fixes samba36-hotplug package hotplug.d script. One downside of this change is handling "mount" evens on block restart or crash. On restart "add" actions will get executed for mounted / available (autofs) devices. On crash no events will be generated. Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-December/020886.html Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: use uloop_process for calling /sbin/hotplug-call mountRafał Miłecki2020-05-062-51/+85
| | | | | | | | | | | | | | | | | | As blockd uses uloop calling any script and using waitpid() can easily result in a lock. It's enough for script to use /bin/ubus to cause that. It's not an option to drop waitpid() as it's important to e.g. call mount scripts with ACTION=remove before unmounting devices. So solving this problem requires using uloop_process. Unfortunately this means: 1. Using callbacks making code slightly more complex 2. Dropping that nice devices_update_cb() With this change however hotplug.d "mount" scripts can safely call "ubus". Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* Truncate FAT filesystem label until 1st occurance of a blank (0x20)Mirko Vogt2020-05-061-2/+4
| | | | | | | | | | | | | | According to spec the FAT filesystem label is not terminated by a \0-byte but instead has a fixed length where the name is padded by blanks. Before libblkid-tiny just passed the always 11 bytes long blank padded string through, however it makes matching for a filesystem label inconsistent with other filesystems, which use a \0-terminated string. Before: "foobar " After : "foobar" Signed-off-by: Mirko Vogt <mirko-openwrt@nanl.de>
* block: always use st_dev (device ID) of / when looking for rootRafał Miłecki2020-05-051-15/+11
| | | | | | | | | Use this method even if UBIFS extroot support is enabled. This is needed on x86 systems (using F2FS for overlay) as they may still come with F2FS enabled. Ref: https://bugs.openwrt.org/index.php?do=details&task_id=2231 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: simplify check_extroot() a bitRafał Miłecki2020-05-051-42/+47
| | | | | | Avoid too big code indent. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: add some basic extroot documentationRafał Miłecki2020-05-021-0/+16
| | | | Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* Revert "block: support hierarchical mount/umount"Rafał Miłecki2020-05-021-101/+51
| | | | | | | | | | | | This reverts commit fb0700f0fdfc4bec220203d31df87be2b4ccc467. Switching to AVL tree allows sorting devices by selected parameter (mount path) but does not implement a real hierarchical layout. That would require a tree with parent nodes being parent devices / mount paths. Cc: Yousong Zhou <yszhou4tech@gmail.com> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* Revert "block: mount_action: handle mount/umount deps"Rafał Miłecki2020-05-021-30/+13
| | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 32c3126b2f0464106d74317336b6aef1d7d5f82f. Internally stored list of devices is implemented using struct vlist_tree and keeps devices sorted by their mount target paths. This DOESN'T mean that all preceding entires of a given device are its parent devices. Making such an assumption and mounting all preceding devices results in unwanted mounts in most cases. For example having devices like: /dev/sda1 (mount target: /mnt/foo1) /dev/sda2 (mount target: /mnt/foo2) /dev/sdb1 (mount target: /mnt/bar1) /dev/sdb2 (mount target: /mnt/bar2) will result in devices vlist_tree having entries sorted like: /dev/sdb1 (bar1), /dev/sdb2 (bar2), /dev/sda1 (foo1), /dev/sda2 (foo2) Using autofs and accessing /mnt/foo2 would result in mounting all 4 partitions and spinning unneeded /dev/sdb. Cc: Yousong Zhou <yszhou4tech@gmail.com> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libfstools/mtd: attempt to read from OOB data if empty space is foundFelix Fietkau2020-04-091-4/+12
| | | | | | | When using jffs2 on NAND flash, it stores its magic in the OOB data on newly erased blocks. This change fixes identifying the filesystem type. Signed-off-by: Felix Fietkau <nbd@nbd.name>
* blockd: remove symlink linkpath file if it's a dir or linkRafał Miłecki2020-03-211-0/+7
| | | | | | | | Files like that can remain from using non-autofs mounting and can cause mounting errors after switching to autofs: blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: remove mount target file if it's a linkRafał Miłecki2020-03-211-0/+3
| | | | | | | | | Links like that can remain from using autofs and can cause mounting errors after switching to non-autofs: block: mounting /dev/sda1 (vfat) as /mnt/sda1 failed (2) - No such file or directory Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: report "target" path as "mount" for autofs available mountsRafał Miłecki2020-03-211-0/+2
| | | | | | | | Devices handled with autofs should be seen as available even if currently unmounted. Mounting is handled on demand and transparently for users. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: print symlink error code and string messageRafał Miłecki2020-03-211-2/+2
| | | | | | | It may help understanding failure reason, e.g.: blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1 (17) - File exists Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* Revert "fstools: Add support to read-only MTD partitions (eg. recovery images)"Petr Štetiar2020-01-211-15/+4
| | | | | | | | | | | | | This reverts commit f5c7c1813f52e6d7b59ecfb2f9f95e69b05b1980 which needs more work and testing as it broke at least jffs2 overlays at least on ath79 platform, marking them as read-only, thus unusable: jffs2_build_filesystem(): erasing all blocks after the end marker... jffs2: Erase at 0x009e0000 failed immediately: -EROFS. Is the sector locked? Ref: http://lists.infradead.org/pipermail/openwrt-devel/2020-January/021344.html Reported-by: Steve Brown <sbrown@ewol.com> Signed-off-by: Petr Štetiar <ynezz@true.cz>
* fstools: Add support to read-only MTD partitions (eg. recovery images)Bruno Pena2020-01-181-4/+15
| | | | | | | | | | | | This patch enables fstools to open read-only MTD partitions, which in turn also enables OpenWrt to boot from read-only partitions. The use of read-only partitions is of special importance for WiFi-only devices, where a protected read-only recovery image can be used in case something goes wrong with the main firmware (eg. user gets locked out due to bad settings, flash of an unbootable dev firmware, etc). Signed-off-by: Bruno Pena <brunompena@gmail.com>
* libblkid-tiny: fix f2fs labels by increasing label bufferPetr Štetiar2020-01-181-1/+1
| | | | | | | | | | | | | | | | f2fs max label length is 1024B (512 * uint16_t) which is way above current 256B used in `struct blkid_struct_probe` which renders labels on f2fs system unusable: $ mkfs.f2fs -l drive /dev/sda1 $ block info /dev/sda1 label buffer too small 1024 > 255 So increase the label buffer again in order to make enough space for f2fs labels. Fixes: FS#2735 Signed-off-by: Petr Štetiar <ynezz@true.cz>
* block: re-discover mtd devices on extroot mount retryJo-Philipp Wich2020-01-051-1/+1
| | | | | | | | | | | | | | | | | | When retrying extroot mounting after waiting for the underlying device to appear, the internal device cache was rebuilt without mtd devices, leading to the following error: block: extroot: unable to lookup root device /dev/... The extroot mount procedure needs access to the actual mtd root device to temporarily mount it for uuid file verification. Fix this error by rebuilding the cache with mtd devices to allow the `check_extroot()` procedure to find the internal root device. Fixes: FS#2701 Fixes: fb0700f ("block: support hierarchical mount/umount") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* libblkid-tiny: fix symbol collision with full libblkidJo-Philipp Wich2019-12-224-8/+8
| | | | | | | | | | The recent introduction of blkid_new_probe() and blkid_free_probe() in the dynamically linked libblkid-tiny caused the dlopen'd libblkid.so to call into the wrong version of blkid_new_probe() within blkid_new_probe_from_filename(), leading to memory corruption and eventual segmentation faults. Fixes: b82c5c1 ("libblkid-tiny: add functions for allocating & freeing probe struct") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* libblkid-tiny: vfat: Change parsing label in special casesPali Rohár2019-12-201-11/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | commit f0ca7e80d7a171701d0d04a3eae22d97f15d0683 upstream. * Use only label from the root directory and do not fallback to the label stored in boot sector. This is how MS-DOS 6.22, MS-DOS 7.10, Windows 98, Windows XP and also Windows 10 behave. Moreover Windows XP and Windows 10 do not touch label in boot sector anymore, so removing FAT label on those Windowses leads to having old label still stored in boot sector (which MS-DOS and Windows fully ignore). * Label entry "NO NAME" in root directory is treated as label "NO NAME" instead of empty label. In root directory it has no special meaning. String "NO NAME" has a special meaning (empty label) only for label stored in boot sector. * Label from the boot sector is now stored into LABEL_FATBOOT field. So if there are applications which depends or needs to read this label, they have ability. After this change LABEL always correspondent to the label from the root directory and LABEL_FATBOOT to the label stored in the boot sector. If some of those labels is missing or is not present (e.g. "NO LABEL" in boot sector) then particular field is not set. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> [rmilecki: drop unneeded now downstream hacks for handling spaces] Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libblkid-tiny: vfat: Fix reading labels which starts with byte 0x05Pali Rohár2019-12-201-0/+2
| | | | | | | | | | commit e526f503918cc29d8b1ccf36a5c3a34645d2be6e upstream. When FAT directory entry has leading byte 0x05 it is interpreted as byte 0xE5. This is how FAT stores file name which starts with byte 0xE5 as leading byte in 0xE5 in FAT directory entry means that file slot is empty. Fixes: #533
* libblkid-tiny: add blkid_probe_set_id_label() stubRafał Miłecki2019-12-202-1/+7
| | | | | | | This stub will allow porting more upstream code without commenting out calls and them unused variables. This will simplify maintenance. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libblkid-tiny: use separated buffer for each block device readRafał Miłecki2019-12-203-22/+39
| | | | | | | | | | | | | | | | This allows reading multiple chunks of block device data and operating on them simultaneously. Previous implementation was using a single buffer (except for reading more data than allocated size) and subsequent reads were corrupting memory of previously returned buffers. This fixes e.g. problem with reading NTFS UUID and validating VFAT signature. Implementation is based on original libblkid code which handles it similarly. Buffers are put on probe internal list and freed when releasing a probe struct. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* libblkid-tiny: add functions for allocating & freeing probe structRafał Miłecki2019-12-204-16/+57
| | | | | | | | | | This adds blkid_new_probe() and blkid_free_probe() which have to be used in place of simple struct memory allocation. They will allow extending probe struct by any extra initialization code and resources release. Newly introduced probe.c file is based on original libblkid's code. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: don't flush devices list on "hotplug" callRafał Miłecki2019-12-131-2/+0
| | | | | | | | The point of "hotplug" call is to add or remove a single entry to/from devices list. Using vlist_update() and vlist_flush() was clearing whole list (and leaving the last entry in case of adding a device). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: fix vlist memory corruptionRafał Miłecki2019-12-131-1/+1
| | | | | | | | | vlist_add() expects key to point a persistent memory as it doesn't make its copy. Passing blob_attr of current message was resulting in undefined/random behavior including list corruption and possible crashes. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block: detect: use current mp as value of target optionYousong Zhou2019-11-031-17/+24
| | | | | | | Move down the function so that no declaration of find_mount_point() is not needed Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* block: mount_device: err log only when mp deviates from specYousong Zhou2019-11-021-3/+7
| | | | | | | | Fixes possible memleak of mp as well Resolves FS#1523 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
* block: mount_device: skip extroot earlierYousong Zhou2019-11-021-4/+4
| | | | Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>