Since kernel 2.6.25 Linux now supports read-only bind-mounts. See http://lwn.net/Articles/281157/ Unfortunately (and this is by design, so will not be changed in the kernel any time soon) a remount is required before such a bind mount is actually mounted read-only! Reproducible: Always Steps to Reproduce: 1. Create a bind mount in fstab with ro as an option 2. Allow /etc/init.d/localmount to auto-mount above on boot 3. Try to write to the bind mount Actual Results: Write succeeds! Bind mount is silently mounted read/write. Expected Results: Write should fail. This bug existed with the /etc/init.d/localmount script provided by the sys-apps/baselayout-1.x packages as reported in bug 303235. Attached are two patches which are both possible fixes. The first is a patch to /etc/init.d/localmount to remount read-only bind-mounts. The second is a patch to sys-apps/util-linux providing the same functionality built into the mount command. Thanks to Andrey Hippo for providing a link to the second of those patches. # emerge --info Portage 2.1.9.42 (!../mnt/repositories/stable/x86-64bit-server/portage/profiles/default/linux/amd64/10.0, gcc-4.4.5, libc-0-r0, 2.6.34-xen-r4 x86_64) ================================================================= System uname: Linux-2.6.34-xen-r4-x86_64-Quad-Core_AMD_Opteron-tm-_Processor_2354-with-gentoo-2.0.2 Timestamp of tree: Fri, 27 May 2011 02:30:01 +0000 app-shells/bash: 4.1_p9 dev-lang/python: 2.6.6-r2, 2.7.1-r1, 3.1.3-r1 sys-apps/baselayout: 2.0.2 sys-apps/openrc: 0.8.2-r1 sys-apps/sandbox: 2.4 sys-devel/autoconf: 2.65-r1 sys-devel/automake: 1.11.1::gentoo sys-devel/binutils: 2.20.1-r1::gentoo sys-devel/gcc: 4.4.5 sys-devel/gcc-config: 1.4.1-r1 sys-devel/libtool: 2.2.10 sys-devel/make: 3.81-r2 sys-kernel/linux-headers: 2.6.36.1 sys-libs/glibc: 2.12.2 virtual/os-headers: 0 ACCEPT_KEYWORDS="amd64" ACCEPT_LICENSE="*" CBUILD="x86_64-pc-linux-gnu" CFLAGS="-O2 -pipe" CHOST="x86_64-pc-linux-gnu" CONFIG_PROTECT="/etc" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/eselect/postgresql /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo" CXXFLAGS="-O2 -pipe" DISTDIR="/mnt/portage/distfiles" EMERGE_DEFAULT_OPTS="-K --binpkg-respect-use y" FEATURES="assume-digests binpkg-logs collision-protect distlocks fixlafiles fixpackages news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch" FFLAGS="" GENTOO_MIRRORS="http://gentoo.tiscali.nl/ http://gentoo.mneisen.org/ http://de-mirror.org/distro/gentoo/" LANG="en_GB.utf8" LDFLAGS="-Wl,-O1 -Wl,--as-needed" LINGUAS="en en_GB" MAKEOPTS="-j4" PKGDIR="/mnt/portage/packages" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/mnt/portage/portage" PORTDIR_OVERLAY="/mnt/portage/overlays/hacking-gentoo /mnt/portage/overlays/hacking-dev" SYNC="rsync://rsync.gentoo.org/gentoo-portage" USE="3dnow 3dnowext acl amd64 apache2 bash-completion bzip2 caps cli cracklib crypt cups cxx dri fam fortran gdbm gif gnutls gpm iconv ipv6 java6 jce jpeg ldap mailwrapper mmx modules mudflap multilib nat ncurses nls nptl nptlonly openmp pam pcre perl png postgres pppd python readline session snmp sse sse2 ssl sysfs tcpd truetype unicode vhosts xml xorg zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http" CALLIGRA_FEATURES="braindump flow karbon kexi kpresenter krita tables words" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx" INPUT_DEVICES="keyboard mouse evdev" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en en_GB" PHP_TARGETS="php5-3" RUBY_TARGETS="ruby18" USERLAND="GNU" VIDEO_CARDS="fbdev glint intel mach64 mga neomagic nouveau nv r128 radeon savage sis tdfx trident vesa via vmware dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" Unset: CPPFLAGS, CTARGET, INSTALL_MASK, LC_ALL, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Created attachment 275337 [details, diff] Patch to /etc/init.d/localmount to remount read-only bind-mounts
Created attachment 275339 [details, diff] patch to util-linux/mount/mount.c to remount read-only bind-mounts
Comment on attachment 275337 [details, diff] Patch to /etc/init.d/localmount to remount read-only bind-mounts use `fstabinfo` instead of attempting to parse fstab yourself
Comment on attachment 275339 [details, diff] patch to util-linux/mount/mount.c to remount read-only bind-mounts this needs to go to the upstream util-linux mailing list http://vger.kernel.org/vger-lists.html#util-linux
(In reply to comment #4) > Comment on attachment 275339 [details, diff] > patch to util-linux/mount/mount.c to remount read-only bind-mounts > > this needs to go to the upstream util-linux mailing list > > http://vger.kernel.org/vger-lists.html#util-linux Shame they don't want it! I guess this can be closed like the vast majority of my other reports then. :-(
what do mean they dont want it ? did you post the patch and they rejected it ?
It doesn't look like it. The patch was submitted to them against 2.17.2 and we are now on 2.19.1 and there is still no sign they are interested. The problem seems to be that both the kernel and mount are "working as expected" which is a shame as it means RO bind mounts are always mounted RW - which is great if you are trying to bind something into a CHROOT and don't want anything writing to it.