From patchwork Tue Jun 19 02:50:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 10472959 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4279D60244 for ; Tue, 19 Jun 2018 02:51:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 32E0F2870E for ; Tue, 19 Jun 2018 02:51:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2563428741; Tue, 19 Jun 2018 02:51:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9A962870E for ; Tue, 19 Jun 2018 02:51:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937129AbeFSCvD (ORCPT ); Mon, 18 Jun 2018 22:51:03 -0400 Received: from icp-osb-irony-out7.external.iinet.net.au ([203.59.1.107]:56078 "EHLO icp-osb-irony-out7.external.iinet.net.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934644AbeFSCvC (ORCPT ); Mon, 18 Jun 2018 22:51:02 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A2DFEwAObyhb/6c80XZcHgEGDINJgU8SK?= =?us-ascii?q?IN5lFZGAQEBAQEGgUGWWB4YAYRAgmEhNxUBAgEBAQEBAQJtBCSFUgRSKAEMAhg?= =?us-ascii?q?OAkkWE4UYDKpRgWkzGgKILYFogQuHSYEMgQeMEYJVAo0gi3YJjwmIGIUjkyQig?= =?us-ascii?q?VJNLgqCfoFsAY5vMjB6AQGQUgEB?= X-IPAS-Result: =?us-ascii?q?A2DFEwAObyhb/6c80XZcHgEGDINJgU8SKIN5lFZGAQEBAQE?= =?us-ascii?q?GgUGWWB4YAYRAgmEhNxUBAgEBAQEBAQJtBCSFUgRSKAEMAhgOAkkWE4UYDKpRg?= =?us-ascii?q?WkzGgKILYFogQuHSYEMgQeMEYJVAo0gi3YJjwmIGIUjkyQigVJNLgqCfoFsAY5?= =?us-ascii?q?vMjB6AQGQUgEB?= X-IronPort-AV: E=Sophos;i="5.51,241,1526313600"; d="scan'208";a="90291035" Received: from unknown (HELO pluto.themaw.net) ([118.209.60.167]) by icp-osb-irony-out7.iinet.net.au with ESMTP; 19 Jun 2018 10:50:18 +0800 Subject: [PATCH 1/7] autofs - fix directory and symlink access From: Ian Kent To: Andrew Morton Cc: linux-fsdevel , autofs mailing list , Kernel Mailing List Date: Tue, 19 Jun 2018 10:50:18 +0800 Message-ID: <152937661793.20656.604490449672006599.stgit@pluto.themaw.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Depending on how it is configured the autofs user space daemon can leave in use mounts mounted at exit and re-connect to them at start up. But for this to work best the state of the autofs file system needs to be left intact over the restart. Also, at system shutdown, mounts in an autofs file system might be umounted exposing a mount point trigger for which subsequent access can lead to a hang. So recent versions of automount(8) now does its best to set autofs file system mounts catatonic at shutdown. When autofs file system mounts are catatonic it's currently possible to create and remove directories and symlinks which can be a problem at restart, as described above. So return EACCES in the directory, symlink and unlink methods if the autofs file system is catatonic. Signed-off-by: Ian Kent --- fs/autofs/root.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/fs/autofs/root.c b/fs/autofs/root.c index a3d414150578..782e57b911ab 100644 --- a/fs/autofs/root.c +++ b/fs/autofs/root.c @@ -559,6 +559,13 @@ static int autofs_dir_symlink(struct inode *dir, if (!autofs_oz_mode(sbi)) return -EACCES; + /* autofs_oz_mode() needs to allow path walks when the + * autofs mount is catatonic but the state of an autofs + * file system needs to be preserved over restarts. + */ + if (sbi->catatonic) + return -EACCES; + BUG_ON(!ino); autofs_clean_ino(ino); @@ -612,9 +619,15 @@ static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry) struct autofs_info *ino = autofs_dentry_ino(dentry); struct autofs_info *p_ino; - /* This allows root to remove symlinks */ - if (!autofs_oz_mode(sbi) && !capable(CAP_SYS_ADMIN)) - return -EPERM; + if (!autofs_oz_mode(sbi)) + return -EACCES; + + /* autofs_oz_mode() needs to allow path walks when the + * autofs mount is catatonic but the state of an autofs + * file system needs to be preserved over restarts. + */ + if (sbi->catatonic) + return -EACCES; if (atomic_dec_and_test(&ino->count)) { p_ino = autofs_dentry_ino(dentry->d_parent); @@ -697,6 +710,13 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry) if (!autofs_oz_mode(sbi)) return -EACCES; + /* autofs_oz_mode() needs to allow path walks when the + * autofs mount is catatonic but the state of an autofs + * file system needs to be preserved over restarts. + */ + if (sbi->catatonic) + return -EACCES; + spin_lock(&sbi->lookup_lock); if (!simple_empty(dentry)) { spin_unlock(&sbi->lookup_lock); @@ -735,6 +755,13 @@ static int autofs_dir_mkdir(struct inode *dir, if (!autofs_oz_mode(sbi)) return -EACCES; + /* autofs_oz_mode() needs to allow path walks when the + * autofs mount is catatonic but the state of an autofs + * file system needs to be preserved over restarts. + */ + if (sbi->catatonic) + return -EACCES; + pr_debug("dentry %p, creating %pd\n", dentry, dentry); BUG_ON(!ino);