diff options
author | Helmut Grohne <helmut@subdivi.de> | 2024-03-01 18:49:24 +0100 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2024-03-01 18:49:24 +0100 |
commit | c091a57ece33a8fd36161c319f2fa78546467b7f (patch) | |
tree | eabebaa3fe046303bd4b4b7524870db7bb6d8304 | |
parent | 3f899b25955b76dc87631188c8ff6550742e530b (diff) | |
download | python-linuxnamespaces-c091a57ece33a8fd36161c319f2fa78546467b7f.tar.gz |
fix read-only bind_mount
As we learn from util-linux, MS_RDONLY is ignored on MS_BIND. Rather
than remount, just use the new mount API as it doesn't suffer this
limitation.
-rw-r--r-- | linuxnamespaces/__init__.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/linuxnamespaces/__init__.py b/linuxnamespaces/__init__.py index ce6d44f..625f6c6 100644 --- a/linuxnamespaces/__init__.py +++ b/linuxnamespaces/__init__.py @@ -246,6 +246,10 @@ def bind_mount( source = AtLocation(source) target = AtLocation(target) try: + if readonly: + # We would have to remount to apply the readonly flag, see + # https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=9ac77b8a78452eab0612523d27fee52159f5016a + raise ValueError() srcloc = os.fspath(source) tgtloc = os.fspath(target) except ValueError: @@ -255,14 +259,12 @@ def bind_mount( with open_tree(source, otflags) as srcfd: if readonly: mount_setattr(srcfd, recursive, MountAttrFlags.RDONLY) - return move_mount(srcfd, target) + move_mount(srcfd, target) else: mflags = MountFlags.BIND if recursive: mflags |= MountFlags.REC - if readonly: - mflags |= MountFlags.RDONLY - return mount(srcloc, tgtloc, None, mflags) + mount(srcloc, tgtloc, None, mflags) _P = typing.ParamSpec("_P") |