]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: Fix access check for utab in context
authorKarel Zak <kzak@redhat.com>
Mon, 22 Apr 2024 11:09:04 +0000 (13:09 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 22 Apr 2024 11:09:04 +0000 (13:09 +0200)
The function mnt_has_regular_utab() properly detects that the utab is
not writable, but this is ignored by the high-level context API. As a
result, the library later attempts to update the file and ends up with
a warning in mount(8):

 $ mkdir sys
 $ unshare --map-root-user --mount
 $ mount --rbind /sys sys
 $ umount --lazy sys; echo $?
 umount: /home/user/sys: filesystem was unmounted, but failed to update userspace mount table.
 16

In this case, the utab should be ignored.

Fixes: https://github.com/util-linux/util-linux/issues/2981
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c

index 952287a26a56971f5a58c9e722732c2bfd9e0170..5206c1d58797c52105f9f0be90b94453a3048b18 100644 (file)
@@ -367,8 +367,7 @@ const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt)
 {
        assert(cxt);
 
-       context_init_paths(cxt, 1);
-       return cxt->utab_path;
+       return mnt_context_utab_writable(cxt) ? cxt->utab_path : NULL;
 }