summaryrefslogtreecommitdiff
path: root/initd
Commit message (Collapse)AuthorAgeFilesLines
* init: attempt to mount efivarfsDaniel Golle2023-01-161-3/+4
| | | | | | | Mount efivarfs to /sys/firmware/efi/efivars if available. Tested-by: Oskari Rauta <oskari.rauta@gmail.com> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* init: only relabel rootfs if started from initramfsDaniel Golle2022-06-011-3/+4
| | | | | | | | | Do not relabel all the filesystem if not running from initramfs, it should only be needed in this case. Read-write (ext4) labels should be set when generating the filesystem just like it's done for squashfs. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* init: selinux: don't relabel virtual filesystemsDaniel Golle2022-06-011-1/+3
| | | | | | | Attempting to relabel /dev/console, /proc or /sys results in an error message. Avoid that by excluding them when relabeling rootfs on boot. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* init: restore SELinux labels after policy is loadedDaniel Golle2022-05-031-8/+19
| | | | | | | | Introduce an additional SELinux init step to calling restorecon to label the filesystem. This fixes SELinux on initramfs or systems with ext4 or ubifs read-write root filesystem. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* procd: completely remove tmp-on-zram supportRui Salvaterra2022-03-033-152/+4
| | | | | | The configuration settings were removed from the package, this is now dead code. Signed-off-by: Rui Salvaterra <rsalvaterra@gmail.com>
* procd: clean up /dev/pts mountsRui Salvaterra2022-01-111-1/+1
| | | | | | | The default mode is already 600, no need to specify it. Access times are also irrelevant. Signed-off-by: Rui Salvaterra <rsalvaterra@gmail.com>
* procd: mount /dev with noexecRui Salvaterra2022-01-111-1/+1
| | | | | | | | | | | | | | | | | | /dev is writable. Allowing execution inside it makes it a possible attack vector. Kees Cook recently sent a kernel patch [1] in order to mount /dev as noexec and nosuid for systems which rely on CONFIG_DEVTMPFS_MOUNT=y to create/populate /dev, which isn't our case (it's procd's responsibility). Add noexec to the /dev mount flags, since we already use nosuid (and keep the coldplug flags symmetric, while at it). This carries the risk of breaking very old, pre-KMS graphics drivers [2], but it shouldn't be a problem for systems built in the last ~15 years. The vast majority of our targets doesn't have a GPU, anyway. :) [1] https://lore.kernel.org/all/YcMfDOyrg647RCmd@debian-BULLSEYE-live-builder-AMD64/ [2] https://lore.kernel.org/all/CAPXgP12e5LpN6XVxaXOHhH=u8XXN==2reTaJDCoCk4tP4QduDQ@mail.gmail.com/ Signed-off-by: Rui Salvaterra <rsalvaterra@gmail.com>
* initd: fix off-by-one error in mkdev.cNick Hainke2021-08-311-1/+1
| | | | | | | | | | Substract 1 from bufsize so len can not be out of bounds. Same hanling as in "udevtrigger.c" in "sysfs_resolve_link". Replaces: 8eb1d783 Coverity CID: 1330087 Readlink used insecurely Signed-off-by: Nick Hainke <vincent@systemli.org>
* Revert "initd: fix off-by-one error in mkdev.c"Nick Hainke2021-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | | This reverts commit 8eb1d783cca6e0d501dd3a2f94262ffc36ae6482. This line reads a symbolic link into the string buffer "buf". len = readlink(buf2, buf, sizeof(buf)); The commit replaced now buf[len] = 0; with buf[sizeof(buf) - 1] = '\0'; However, that does not work since readlink does not null-terminate the string written into "buf" and "buf[len] = 0" was used for that. What happens if the buffer is to small? "If the buf argument is not large enough to contain the link content, the first bufsize bytes shall be placed in buf." (Source: https://pubs.opengroup.org/onlinepubs/009695399/functions/readlink.htm) Signed-off-by: Nick Hainke <vincent@systemli.org>
* initd: fix off-by-one error in mkdev.cDaniel Golle2021-08-301-1/+1
| | | | | | | | Actually make sure buffer is 0-terminated intead of writing the 0-byte out of bounds. Coverity CID: 1330087 Readlink used insecurely Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* system: expose if system was booted from initramfsDaniel Golle2021-02-231-1/+0
| | | | | | | | | | | | | | | It can be good for UI to show to the user that the system was booted from initramfs ie. no writable permanent storage is available. I imagine LuCI only serving applications which are explicitely marked as being shown even in initramfs mode, ie. nothing but status, network->interfaces, network->wireless, system->upgrade, system->backup, system->backuprestore tabs. Also sysupgrade could take into account we are running on initramfs and perform offline backup/restore of whatever is in the flash. In that way OpenWrt-generated initramfs-images can serve as recovery OS on devices with dual-boot in a meaningful way. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* initd/init: add minimal SELinux policy loading supportThomas Petazzoni2020-08-101-0/+38
| | | | | | | | | | | | In order to support SELinux in OpenWrt, this commit introduces minimal support for loading the SELinux policy in the init code. The logic is very much inspired from what Busybox is doing: call selinux_init_load_policy() from libselinux, and then re-execute init so that it runs with the SELinux policy in place and enforced. Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com> [fix spelling of OpenWrt] Signed-off-by: Paul Spooren <mail@aparcar.org>
* initd: attempt to mount cgroup2Daniel Golle2020-08-061-1/+1
| | | | | | Prepare for using cgroup2 in procd and ujail. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* procd: replace exit(-1) with exit(EXIT_FAILURE)Michael Heimpold2019-10-273-6/+6
| | | | Signed-off-by: Michael Heimpold <mhei@heimpold.de>
* procd: Switch to nanosleepRosen Penev2019-09-201-1/+2
| | | | | | | | | | usleep has been deprecated by POSIX.1-2001 and removed in POSIX.1-2008. Fixes compilation when libc does not include usleep (optional with uClibc-ng). nanosleep also has the advantage of being more accurate. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* sysupgrade: support "backup" attributeRafał Miłecki2019-09-111-1/+1
| | | | | | | | This new attribute allows passing path of the backup archive. It provides much more flexibility than hardcoding /tmp/sysupgrade.tgz. It may help avoiding some cp/mv for user-provided backup archive. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* system: support passing "options" to the "sysupgrade" ubus methodRafał Miłecki2019-08-221-1/+1
| | | | | | | | | | | | | Object passed as "options" gets translated into environment variables UPGRADE_OPT_*. E.g. "options": { "foo": 5 } will result in setting UPGRADE_OPT_FOO=5. This allows stage2 sysupgrade to get options explicitly. So far it was guessing what to do by checking for existence of some files (e.g. sysupgrade.tgz). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* procd: detect lxc container and behave accordinglyPaul Spooren2019-05-082-12/+19
| | | | | | | | | | | | | | meaning to not mount some specific parts witch cause trouble. The patch is based on previous work of @mikma to combine OpenWrt with lxd[0]. This patch however adds a detection copied from *virt-what* to check /proc/1/environment for the string "container". Thanks to @dangowrt for the cleanup. [0]: https://github.com/containercraft/openwrt-lxd/blob/master/patches/procd-openwrt-18.06/001_lxd_no_mounts.patch Signed-off-by: Paul Spooren <mail@aparcar.org>
* procd: add SIGPWR as signalPaul Spooren2019-04-261-0/+1
| | | | | | to use procd in LXC containers they have to support SIGPWR to shutdown. Signed-off-by: Paul Spooren <mail@aparcar.org>
* early: set /tmp permissions explicitlyHans Dedecker2018-11-231-1/+1
| | | | | | | | | In case ramfs is used as tmpfs it creates /tmp with permissions 755 which are the the default permissions. Therefore when mounting tmp set permissions explicitly to 1777 Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> Acked-by: John Crispin <john@phrozen.org>
* procd: Add %m to several functions that return errno.Rosen Penev2018-01-024-13/+13
| | | | | | Might help with debugging. No size impact. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* procd: Replace strerror(errno) with %m.Rosen Penev2018-01-021-4/+4
| | | | | | Saves 1496 bytes from compiled size under glibc. No functional difference. Signed-off-by: Rosen Penev <rosenp@gmail.com>
* procd: initd: fix path allocation in early_insmodNathan Hintz2017-12-301-1/+1
| | | | | | | | | | Noticed that /tmp was not being created on /dev/zram0. This was on ixp4xx (nslu2) using GCC 6.3 and musl. The allocation should be using the length of the passed string (module path), not the size of the pointer to the string. Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
* preinit: define _GNU_SOURCEHans Dedecker2017-06-161-0/+1
| | | | | | | In uClibc getdelim is only defined if _GNU_SOURCE is defined; fix compilation issue by defining _GNU_SOURCE Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
* init: add support for sysupgrades triggered from preinitMatthias Schiffer2017-05-291-5/+41
| | | | | | | This will allow to add support for sysupgrades via upgraded from failsafe mode. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
* procd: update modprobe pathNathan Hintz2017-02-211-5/+5
| | | | | | | Commit 81aeba9b7f619ee1af1a64f355ae8001fa147d03 in LEDE source.git moved modprobe to the "/sbin" directory. Update procd with the new path. Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
* add missing includesFelix Fietkau2017-02-112-0/+2
| | | | | | Including sys/sysmacros.h is now necessary for makedev() on glibc 2.25. Signed-off-by: Felix Fietkau <nbd@nbd.name>
* init: fix /tmp permissions on zramMatthias Schiffer2017-01-261-0/+6
| | | | | | | mkfs.ext4 will create the filesystem with 755, we need to chmod to 1777 explicitly. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
* procd: Fix memory leaks found by cppcheckRosen Penev2016-12-051-0/+1
| | | | Signed-off by: Rosen Penev <rosenp@gmail.com>
* make /var/{run, lock, state} not world writable (0755)Etienne CHAMPETIER2016-06-171-3/+3
| | | | | | | | | since commit be950c5e56b86509e1e237931d0ac8203372be82 (09/03/2013) /var/{run,lock,state} are world writable (0777) which is a security issue before that they were created by /etc/init.d/boot with normal permissions (0755), so revert to that state Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* initd: fix descriptor leakJo-Philipp Wich2016-05-161-1/+8
| | | | | | | Close the descriptor to /tmp/.preinit returned by creat() in order to avoid an fd leak in the init process. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* initd: use patch_stdio() for kmodloader stdio redirectionJo-Philipp Wich2016-05-161-11/+3
| | | | Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* initd: use patch_stdio() for early console setupJo-Philipp Wich2016-05-161-13/+5
| | | | Signed-off-by: Jo-Philipp Wich <jo@mein.io>
* preinit: create a sentinel file during preinitJohn Crispin2016-05-151-0/+3
| | | | Signed-off-by: John Crispin <john@phrozen.org>
* init: reduce delay after starting kmodloaderFelix Fietkau2016-03-051-2/+2
| | | | Signed-off-by: Felix Fietkau <nbd@openwrt.org>
* initd: allow overriding early PATH through build time defineJo-Philipp Wich2016-02-082-1/+5
| | | | Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* Align early init PATH with system wide OpenWrt path valueJo-Philipp Wich2016-01-141-1/+1
| | | | | | | | | | Changeset r47080 globally unified the executable search path in OpenWrt, now update procd to use the same path value. This fixes diverging path values observed in programs launched by netifd which inherits the early path value from procd. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* explicitely ignore return value of symlink(3) callDaniel Golle2015-10-261-1/+2
| | | | | | | | | | | | glibc sets __attribute_warn_unused_result__ on symlink(3) if FORTIFY_SOURCE is set. This breaks procd which deliberately ignores the result of the symlink(3) call early during init as there wouldn't be anything better to do in that case other than ignoring the error and trying to survive. Introduce libc-compat.h to work-around libc anomalities. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* Add MS_NODEV MS_NOEXEC MS_NOSUID mount options where neededEtienne CHAMPETIER2015-10-031-6/+6
| | | | | | | | | | | | | | | These options aren't mandatory, but can prevent some future bugs from being exploited. Good reading: http://lwn.net/Articles/647757/ Value chosen by looking at fedora 22 / ubuntu 14.04 Not tested yet (away from my tests routers) Not touching jail/jail.c as this conflict with my pending patch serie Signed-off-by: Etienne CHAMPETIER <champetier.etienne@gmail.com>
* move /dev/shm to /tmp/shmDaniel Gimpelevich2015-09-151-4/+8
| | | | | | | Since the /dev filesystem is tiny, /dev/shm needs to live somewhere else. Signed-off-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
* fix /dev/shm permissions, this time for realDaniel Gimpelevich2015-06-181-0/+3
| | | | | | Previous patch did not account for umask, now adding that. Signed-off-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
* fix /dev/shm permissionsDaniel Gimpelevich2015-06-171-1/+1
| | | | | | | | | On my Ubuntu system, the permissions are 1777. They are incorrect in procd, leading to this: https://forum.openwrt.org/viewtopic.php?id=57073 This in intended for both CC and DD. Signed-off-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
* remove ->John Crispin2015-05-231-2/+0
| | | | | | [ 1.240000] init: failed to symlink /tmp -> /var Signed-off-by: John Crispin <blogic@openwrt.org>
* properly handle return codesJohn Crispin2015-03-283-5/+5
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* switch to _DEFAULT_SOURCE for modern glibc compatJohn Crispin2015-03-121-1/+1
| | | | Signed-off-by: Jeff Waugh <jdub@bethesignal.org>
* Convert log calls to ulog() apiJo-Philipp Wich2015-02-253-3/+2
| | | | Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
* procd: increase memory allocated for tmpfs on zramNathan Hintz2015-01-281-1/+1
| | | | | | | | | Devices with <= 32MB of ram get half of memory allocated to zram (up to 16MB). Devices with > 32MB of ram get just 8MB of memory allocated to zram. Increase memory allocated to devices with > 32MB ram to 16MB. Signed-off-by: Nathan Hintz <nlhintz@hotmail.com>
* previous commit accidentiall dropped the cgroup mountJohn Crispin2014-12-021-0/+1
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* add support for zram compressed tmpfsJohn Crispin2014-12-023-21/+159
| | | | Signed-off-by: John Crispin <blogic@openwrt.org>
* initd: mount cgroupLuka Perkov2014-11-141-0/+1
| | | | | | | If kernel is compiled with cgroup support it should be mounted. This change does not effect kernels without cgroup support. Signed-off-by: Luka Perkov <luka@openwrt.org>