From patchwork Fri Feb 17 12:19:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thompson X-Patchwork-Id: 94154 Delivered-To: patches@linaro.org Received: by 10.140.20.99 with SMTP id 90csp141950qgi; Fri, 17 Feb 2017 04:20:03 -0800 (PST) X-Received: by 10.223.146.34 with SMTP id 31mr6179369wrj.201.1487334003543; Fri, 17 Feb 2017 04:20:03 -0800 (PST) Return-Path: Received: from mail-wr0-x231.google.com (mail-wr0-x231.google.com. [2a00:1450:400c:c0c::231]) by mx.google.com with ESMTPS id d18si3320025wrd.124.2017.02.17.04.20.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 04:20:03 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.thompson@linaro.org designates 2a00:1450:400c:c0c::231 as permitted sender) client-ip=2a00:1450:400c:c0c::231; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: domain of daniel.thompson@linaro.org designates 2a00:1450:400c:c0c::231 as permitted sender) smtp.mailfrom=daniel.thompson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-wr0-x231.google.com with SMTP id c4so28933989wrd.2 for ; Fri, 17 Feb 2017 04:20:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=450aCTb+kN33d9ZilYMyBXkbDnt8qA0m2j5PqLM5HVk=; b=QDf7HymcvmDdcjSQr96FFbnMKVx2u/J/YAM2Sy3azHNBRrTLX/xtIgpenyW3rITFze sOsAHy8m/Mqf/YQ5EaddXK3dVxcoD5b83mjMM6x4yNzW57INA86dtqvf7vXFnPqA43v7 +OXZCtP34f9+ixe0cbaul4s+/ca5sVl573NRg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=450aCTb+kN33d9ZilYMyBXkbDnt8qA0m2j5PqLM5HVk=; b=soOMIJTEGgFqqGPE92wBwYBGxBP3Y3IB61ru9KkwEfOl6q5Il7PD0EfarBVTvGuKKJ TfossqoU9yKXqRu6YWkLXew48A9EkVdqBDUeraoyxNelPnWMUJba0zf8eWvHGK4+eKSy r+/E6KMvGfXIxW4eer+oMFu8PrxjSvUy0QQiqGPsC8BqetkEpZXqNa8QwlOF4sBUiSSu cS6fgqzS5wXwCGp1fLyjI9I/BIDTc+JZNmOmFabh/qKbrMWwrv2WYk/iQlhPjsZ/DPPs 0dAb5oCLlNvOxM6wvbduOi/fbeAuZEFiwj9HD2ZHCfDYIOICVCOYaOT8BnJB00oiYKaD vAng== X-Gm-Message-State: AMke39kgpbFQ0BGx+hRJlY4NU4fycmAaWsMbB1wgAaa/8ILODXAcUBONTWA4RefVE4aVHCW7/eo= X-Received: by 10.223.167.66 with SMTP id e2mr6130303wrd.48.1487334003154; Fri, 17 Feb 2017 04:20:03 -0800 (PST) Return-Path: Received: from wychelm.lan (cpc87149-aztw31-2-0-cust149.18-1.cable.virginm.net. [77.101.221.150]) by smtp.gmail.com with ESMTPSA id w207sm1480657wmw.29.2017.02.17.04.20.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Feb 2017 04:20:02 -0800 (PST) From: Daniel Thompson To: Andrew Morton Cc: Daniel Thompson , linux-kernel@vger.kernel.org, patches@linaro.org Subject: [PATCH] initramfs: Provide a way to ignore image provided by bootloader Date: Fri, 17 Feb 2017 12:19:40 +0000 Message-Id: <20170217121940.30126-1-daniel.thompson@linaro.org> X-Mailer: git-send-email 2.9.3 Many "embedded" architectures provide CMDLINE_FORCE to allow the kernel to override the command line provided by an inflexible bootloader. However there is currrently no way for the kernel to override the initramfs image provided by the bootloader meaning there are still ways for bootloaders to make things difficult for us. Fix this by introducing INITRAMFS_FORCE which can prevent the kernel from loading the bootloader supplied image. We use CMDLINE_FORCE (and its friend CMDLINE_EXTEND) to imply that the system has an inflexible bootloader. This allow us to avoid presenting this config option to users of systems where inflexible bootloaders aren't usually a problem. Signed-off-by: Daniel Thompson --- init/initramfs.c | 2 +- usr/Kconfig | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) -- 2.9.3 diff --git a/init/initramfs.c b/init/initramfs.c index b32ad7d97ac9..cc9d9ec4abba 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -610,7 +610,7 @@ static int __init populate_rootfs(void) char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size); if (err) panic("%s", err); /* Failed to decompress INTERNAL initramfs */ - if (initrd_start) { + if (initrd_start && !IS_ENABLED(CONFIG_INITRAMFS_FORCE)) { #ifdef CONFIG_BLK_DEV_RAM int fd; printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n"); diff --git a/usr/Kconfig b/usr/Kconfig index 6278f135256d..c0c48507e44e 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -21,6 +21,16 @@ config INITRAMFS_SOURCE If you are not sure, leave it blank. +config INITRAMFS_FORCE + bool "Ignore the initramfs passed by the bootloader" + depends on CMDLINE_EXTEND || CMDLINE_FORCE + help + This option causes the kernel to ignore the initramfs image + (or initrd image) passed to it by the bootloader. This is + analogous to CMDLINE_FORCE, which is found on some architectures, + and is useful if you cannot or don't want to change the image + your bootloader passes to the kernel. + config INITRAMFS_ROOT_UID int "User ID to map to 0 (user root)" depends on INITRAMFS_SOURCE!=""