Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp876133pxb; Fri, 13 Aug 2021 08:14:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcE65bGGPwSY78EEU5ytNejSduu4zrGjFE3zbtt9Ko8MiB9To9rlfTvGD2g69tbtxWInkq X-Received: by 2002:a05:6602:26d2:: with SMTP id g18mr2356427ioo.194.1628867649537; Fri, 13 Aug 2021 08:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867649; cv=none; d=google.com; s=arc-20160816; b=TdvlKIyEXWEK1mPN5YO0U686wA9XnrqMWPe/ndYw5tlkrcqB60Lt9YHM1vxYDSb0Fh kPa3MIPmoPvxg5dH+ur9O7wO65NbUY7M6F3RRW4GNuxjZc9wd+b08y5a+e4AxpxrHd+0 r4lLQIzn2mDmj8abPMjL1sH8Og8UhDL7KoHfvPZG34xIpSqJA6JF+aIVyOU8goCpG5nk Oa/9dAqYAQzSVOgRe7gEhcdAWiKI+EPh5KAECMGTUfCi9JtAIJYEG2eof5y7j8OjASLn o3HpoPCdnWSklEe+NF8DUXutwHf/GBa7G8dBKedAoNsjDEw2JCg7RQQ3r/ws9Lzyiecw fD7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4UNxvfH/qxbsJULCtIIgkyL7hOgdo8KmyfhZACKSlIg=; b=WE3GidPbQeK+zty18CMqBQUZ4rVdwVQuHYsMlSelQyBcAaPZL4fE2d32/n+vSpujwu X2ujkL4pNbtDXOxxWQ1LoNqba32eYZELn2AHouztjHIpQMpgvqFFZUzhrBXw2OW6e0eT n7T5nSg8J1GAvm/8at5wBvQoQXDKZUDuUAMCcu32hPPesFYqdcg61FbXfth6EC96dECm /fCZzcAotS4THZuJaPyo40dhUSkOmnnGNCobn/3l00wQ01cUeEnZS20yt3SjaWbYsR/i vrDWoAXkuSNLAsv1ucDaluwrAMkliunbaRiuhq+DqaJJKDoHAKSFSA/TyZGl11xNSxFm j2Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0LvpoEDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si2214731ill.40.2021.08.13.08.13.52; Fri, 13 Aug 2021 08:14:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0LvpoEDV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241778AbhHMPLd (ORCPT + 99 others); Fri, 13 Aug 2021 11:11:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:54318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241792AbhHMPKt (ORCPT ); Fri, 13 Aug 2021 11:10:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D1CD46112F; Fri, 13 Aug 2021 15:10:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867422; bh=IgfsaQrxgkElCILIIQRZoJKmG2nIIYocwH+heFZayf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0LvpoEDVeSlEFb+VcecMSTHSD3obb09hvc17kmCCw+jucvVvQZ5M2JUa5i0wW2hia 1YcIZJkgq7jdBDQFdo+exoZYbMM5LkUOsoYVAkqGttX7Ps+WvTaynKsf20Wab/jeZe 7OjZ/OClisK8InSb6H2hejMCe2BrL7qRIQkzS9OA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alois Wohlschlager , Miklos Szeredi Subject: [PATCH 4.9 30/30] ovl: prevent private clone if bind mount is not allowed Date: Fri, 13 Aug 2021 17:06:58 +0200 Message-Id: <20210813150523.424083989@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.445553924@linuxfoundation.org> References: <20210813150522.445553924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miklos Szeredi commit 427215d85e8d1476da1a86b8d67aceb485eb3631 upstream. Add the following checks from __do_loopback() to clone_private_mount() as well: - verify that the mount is in the current namespace - verify that there are no locked children Reported-by: Alois Wohlschlager Fixes: c771d683a62e ("vfs: introduce clone_private_mount()") Cc: # v3.18 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/namespace.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1853,6 +1853,20 @@ void drop_collected_mounts(struct vfsmou namespace_unlock(); } +static bool has_locked_children(struct mount *mnt, struct dentry *dentry) +{ + struct mount *child; + + list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { + if (!is_subdir(child->mnt_mountpoint, dentry)) + continue; + + if (child->mnt.mnt_flags & MNT_LOCKED) + return true; + } + return false; +} + /** * clone_private_mount - create a private clone of a path * @@ -1867,16 +1881,27 @@ struct vfsmount *clone_private_mount(str struct mount *old_mnt = real_mount(path->mnt); struct mount *new_mnt; + down_read(&namespace_sem); if (IS_MNT_UNBINDABLE(old_mnt)) - return ERR_PTR(-EINVAL); + goto invalid; + + if (!check_mnt(old_mnt)) + goto invalid; + + if (has_locked_children(old_mnt, path->dentry)) + goto invalid; - down_read(&namespace_sem); new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE); up_read(&namespace_sem); + if (IS_ERR(new_mnt)) return ERR_CAST(new_mnt); return &new_mnt->mnt; + +invalid: + up_read(&namespace_sem); + return ERR_PTR(-EINVAL); } EXPORT_SYMBOL_GPL(clone_private_mount); @@ -2192,19 +2217,6 @@ static int do_change_type(struct path *p return err; } -static bool has_locked_children(struct mount *mnt, struct dentry *dentry) -{ - struct mount *child; - list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) { - if (!is_subdir(child->mnt_mountpoint, dentry)) - continue; - - if (child->mnt.mnt_flags & MNT_LOCKED) - return true; - } - return false; -} - /* * do loopback mount. */