Suggestion: config: devtmpfs: Allow mount parameters to be set in kernel configuration

From: D. Stussy
Date: Mon May 29 2017 - 18:56:26 EST


config: devtmpfs: Allow mount parameters to be set in kernel configuration

Why? To limit the size of the file system to prevent runaway dynamic device creation.
Even a "udev" rescue kernel takes a small size (e.g. slackware 14.2 uses 52kB and 2,666 inodes).
Setting reasonable size limits (e.g. 64k and 3,072 inodes) will accommodate most setups.
Although a remount during an initialization script can also solve this problem, why not do it correctly the first time?

Patch against kernel versions 4.10.*:
diff -bur drivers/base/Kconfig drivers/base/Kconfig
--- drivers/base/Kconfig 2017-02-26 10:09:33.000000000 +0000
+++ drivers/base/Kconfig 2017-03-04 02:48:20.299991304 +0000
@@ -59,6 +59,22 @@
rescue mode with init=/bin/sh, even when the /dev directory
on the rootfs is completely empty.

+config DEVTMPFS_OPTIONS
+ string "Automounted devtmpfs mount options"
+ default "mode=0755"
+ depends on DEVTMPFS_MOUNT
+ help
+ The devtmpfs file system mounted at /dev will be mounted with the
+ specified mount options. "Mode", "size" (or "nr_blocks"), "nr_inodes",
+ "uid" and "gid" make sense here. Options "huge" or "mpol" may be
+ available but are dependent on other kernel configuration choices.
+ See the manual page for the mount command for details.
+
+ Warning: Unrecognized options may cause the kernel not to boot.
+ Note: Options "mode", "uid", and "gid" are ignored on remounts.
+
+ If uncertain, leave the default setting at "mode=0755".
+
config STANDALONE
bool "Select only drivers that don't need compile-time external firmware"
default y
diff -bur drivers/base/devtmpfs.c drivers/base/devtmpfs.c
--- drivers/base/devtmpfs.c 2017-02-26 10:09:33.000000000 +0000
+++ drivers/base/devtmpfs.c 2017-03-03 20:53:45.879928595 +0000
@@ -24,6 +24,7 @@
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/kthread.h>
+#include <linux/kconfig.h>
#include "base.h"

static struct task_struct *thread;
@@ -358,7 +359,7 @@
if (err)
printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
else
- printk(KERN_INFO "devtmpfs: mounted\n");
+ printk(KERN_INFO "devtmpfs: mounted (%s)\n", CONFIG_DEVTMPFS_OPTIONS);
return err;
}

@@ -375,7 +376,7 @@

static int devtmpfsd(void *p)
{
- char options[] = "mode=0755";
+ char options[] = CONFIG_DEVTMPFS_OPTIONS;
int *err = p;
*err = sys_unshare(CLONE_NEWNS);
if (*err)
Spam detection software, running on the system "snarked.org",
has NOT identified this incoming email as spam. The original
message has been attached to this so you can view it or label
similar future email. If you have any questions, see
http://www.snarked.org/spam for details.

Content preview: config: devtmpfs: Allow mount parameters to be set in kernel
configuration Why? To limit the size of the file system to prevent runaway
dynamic device creation. Even a "udev" rescue kernel takes a small size (e.g.
slackware 14.2 uses 52kB and 2,666 inodes). Setting reasonable size limits
(e.g. 64k and 3,072 inodes) will accommodate most setups. Although a remount
during an initialization script can also solve this problem, why not do it
correctly the first time? [...]

Content analysis details: (3.2 points, 7.5 required)

pts rule name description
---- ---------------------- --------------------------------------------------
-1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP
0.2 STOX_REPLY_TYPE No description available.
0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail
domains are different
2.1 DATE_IN_PAST_96_XX Date: is 96 hours or more before Received: date
0.1 RCVD_IN_DNSWL_NO Sender *not* listed at http://www.dnswl.org/
1.9 STOX_REPLY_TYPE_WITHOUT_QUOTES No description available.

SAV: 3.4.1-snarked_ec212 (2015-04-28)
ASN: () _RELAYCOUNTRY_
CIP:
DCC: snarked.org 104; Body=1 Fuz1=1 Fuz2=1 (x.dcc-servers)
PYZ:
BAY: 0.5 (no autolearn_force=no)
<dns:snarked.org?type=MX> [90 mx.fakemx.net., 20 mail.snarked.net., 10 mail.snarked.org., 80 tarbaby.junkemailfilter.com.]