All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Kent <raven@themaw.net>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Howells <dhowells@redhat.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH 0/3] autofs: fix may_umount_tree()
Date: Mon, 11 Jul 2022 11:37:35 +0800	[thread overview]
Message-ID: <165751053430.210556.5634228273667507299.stgit@donald.themaw.net> (raw)

The function used by autofs to check if a tree of mounts may be umounted
doesn't work with mount namespaces.

Some time ago an attempt to fix it, appart from the implementation being
wrong, failed to take advantage of cases that allowed the check to
terminate early and so was too inefficient to be considered for merge.

This series utilizes cases for which the check can be terminated early
as best it can.

The patches in this series are prefixed with vfs becuase they are
changes to the VFS code but the only caller of the may_umount_tree()
function is the autofs file system.

For the interested here is a procedure that can be used to reproduce
the problem on a current kernel:

- Add this line to /etc/auto.master:
/- /etc/auto.test -t 5

- create the map /etc/auto.test as:
/test -fstype=tmpfs :tmpfs

- Enable debug logging in automount:

sed -i '/^#logging =/c logging = debug' /etc/autofs.conf
systemctl restart autofs.service

The autofs debug logging output can be observed in another terminal
using "journalctl -f".

Use the following script to run the two tests below.

$ cat /usr/local/bin/test.sh
#!/bin/sh
set -e
exec > >(logger --id=$$) 2>&1
echo Starting test
# Change to the /test directory to keep the mount active
cd /test
grep /test /proc/self/mountinfo
sleep 10
echo Ending test

1. Run the test script as root from the root mount namespace.
- observe that automount reports "expire_proc_direct: 1 remaining in /-"
  until after the script exits.
- correct behaviour.

2. Run the test script as root from a new mount namespace by using:

# unshare -m --propagation unchanged test.sh

- Observe that automount reports "expiring path /test" before the
  script has exited and tries to unmount /test.
  This fails with ">> umount: /test: target is busy." until the script
  exits.
- incorrect behaviour.

Signed-off-by: Ian Kent <raven@themaw.net>
---

Ian Kent (3):
      vfs: track count of child mounts
      vfs: add propagate_mount_tree_busy() helper
      vfs: make may_umount_tree() mount namespace aware


 fs/autofs/expire.c    | 14 ++++++++--
 fs/mount.h            |  1 +
 fs/namespace.c        | 40 +++++++++++++++++++---------
 fs/pnode.c            | 61 +++++++++++++++++++++++++++++++++++++++++++
 fs/pnode.h            |  1 +
 include/linux/mount.h |  5 +++-
 6 files changed, 107 insertions(+), 15 deletions(-)

--
Ian


             reply	other threads:[~2022-07-11  3:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11  3:37 Ian Kent [this message]
2022-07-11  3:37 ` [PATCH 1/3] vfs: track count of child mounts Ian Kent
2022-07-20  1:50   ` Al Viro
2022-07-20  2:17     ` Ian Kent
2022-07-20  7:26       ` Ian Kent
2022-07-26  5:11       ` Ian Kent
2022-07-26  7:10         ` Ian Kent
2022-07-11  3:37 ` [PATCH 2/3] vfs: add propagate_mount_tree_busy() helper Ian Kent
2022-07-20  1:54   ` Al Viro
2022-07-20  2:31     ` Ian Kent
2022-07-20  2:39       ` Al Viro
2022-07-11  3:37 ` [PATCH 3/3] vfs: make may_umount_tree() mount namespace aware Ian Kent

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=165751053430.210556.5634228273667507299.stgit@donald.themaw.net \
    --to=raven@themaw.net \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.