Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp874540pxb; Fri, 13 Aug 2021 08:12:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxubWKTdW606YDU+SDvcl6OwT2a7B4/peqctvipEiD3UYHgLuodMLuz0ZFAZeni7XfNaLH3 X-Received: by 2002:a2e:9ac7:: with SMTP id p7mr2228300ljj.96.1628867543329; Fri, 13 Aug 2021 08:12:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867543; cv=none; d=google.com; s=arc-20160816; b=cXyXxjUVall8A8ax+yektnRC+QQquLweeBbpu4xM7w/vRZmiVuY/ANcmGbeGxoceeo 8GJIhmhnAaJArClglyM/KK9HStGX1XGcnHVIrJbxKZCulqqYNo81TN7NibhZ7Gc4n/1I ffRb1mvEkUCOjjZdbdkCFo2yHa021aD2Dl7ejWQlR0+nu2qcEVac0F8ozwFtx+DyAA2V 6eu+YFEAuDwyIhL9m37dVn1h+aeTe6+ZhntWasx3AWbalPpZB+70bqkfcV1JYACa+76s oY76c+1El4h63fVdfmv7764fDQo3iP8TUXytgXghCjqPbk27RTIAtIgF+P+L4NYJMzjw Cgnw== 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=5y86UeFJ1WygKEp4XXVaoOSN6rZQh+HqESWtIjOBY80=; b=eN8z2Bm4tcbNnvcm9wmzx8PlIsVushPukv8H9m75XEAtAmZL/+b8Yj8tA5JdI95Fvj nW51ycu1z23ZLpHnhnW3yauGRnwogxxdCg/XYBPJPEFueX/HP/33k9Afsh/OenoeKK+f oX6eULWT4ojmOW1x6yLYgIeaCdVDtaL9xdk5QoDe+9s2krcLxpqPJJdRRjaMuHtM2tCd uLEEBY4ut9PoH+CTD7Uk/A7bPz+WOHEZ6pU0KBsmxlpLrFZTfdr/RITmq2oV8n4DGwSm wfebb6jLYW4TSTTJGOwMZwTzfxLyEgZVowJC0iXj8YOCVy4zhtvtUoO4p9XuVGbf+WA+ SIvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FoDN4dpE; 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 p12si2433866ejy.396.2021.08.13.08.11.56; Fri, 13 Aug 2021 08:12:23 -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=FoDN4dpE; 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 S241472AbhHMPKL (ORCPT + 99 others); Fri, 13 Aug 2021 11:10:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:51406 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241292AbhHMPJI (ORCPT ); Fri, 13 Aug 2021 11:09:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 44B596109D; Fri, 13 Aug 2021 15:08:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867321; bh=cZF+gyiBCJw0XZHtF3PVJAZBdgXcVwz2oOH2/y3iHqE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FoDN4dpEmjgJ/ltrxigDThcgUnERgmj4KyP98gkMkjCUBiIK3eGu5bXkCGzzIXAgs 9j6aZReS6A5xs3eJb8XeMTYINyt2qeC5hMQrg0qlWZFf9ibulE25XTwf6uOILHYQ7b xk6XlAcnET9NfW6mKnyt/5Vl/aYSansVL5P4C//0= 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.4 25/25] ovl: prevent private clone if bind mount is not allowed Date: Fri, 13 Aug 2021 17:06:49 +0200 Message-Id: <20210813150521.531089718@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150520.718161915@linuxfoundation.org> References: <20210813150520.718161915@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 @@ -1830,6 +1830,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 * @@ -1844,16 +1858,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); @@ -2169,19 +2194,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. */