Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3050636rwe; Mon, 29 Aug 2022 05:09:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GwJF9l5i3q6RZ9Su5gqjyYSHG3vRZBOHK7ht7vQ1XKLbOIIGKwd+LTlXCiAKhG2eAGvVy X-Received: by 2002:a17:907:9495:b0:734:e049:3d15 with SMTP id dm21-20020a170907949500b00734e0493d15mr13957657ejc.187.1661774982133; Mon, 29 Aug 2022 05:09:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661774982; cv=none; d=google.com; s=arc-20160816; b=ePsNn7aa4WEhr+zpvacGorPUC/vhHoKsefE+A03khhVI75/4kMVC3/Sfde8Qp+X+VS 6g211xHEe9e6k2+1qfLT6EKwLZOq5D+04GRGBU6PCkRqYX6oyW2DvX/7FVXQbw8LVgCa U+RYw5zjE1rTpiB01Fcy5vSPFNdRx6GAGBak7yodlHBLQgd1kcj/GqHG3g9PZ+BklFpc 683YpAKWo3is4DzDHPVE9zxYiHtVzkIP+n1txWg26zHor2p5HZAL5gooF25342xpol1w rFw88HkdAj1Ks77E9OQTKODzqQGFuZ2oaLKF25F9zjxsmeU6cP27XcMN2dCsippOSoln G03A== 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=1ag2UtBhdqQMJrEVh/a9kfZ9d+l36PYBxyot9aiOjzQ=; b=HJa4RUJTFNgE0cvC4jZNu66RI6/xHTldgzkI8agXrycum9kU9dFZ5QyxOhsoCwyW0c X8HxBHDPvm+Jm7z2K/Dg+Z9SJf9FfSm/qGUj36CBBFDFXzVEmFZWCr0e4SmvzJJcMXu0 fmi7HEg7TCA0rV7bkaAUEftzYnuShJINg0aE9txnJaHZwUfCAgtmiRSWSo/BliHnVo6U VrmXsnBkruIEitdxPcl/IzREG5bKn3VczC6cXyLQe3D4fInp54pYFIucJw3qmEWvK5Fl F/Lh5tDqOUmuhJzSGmV/Y6aVLNrc6E+qMLjkzrIYskmmIQvMUgDX++ECedvkp+IEzXaM x2Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dOwk5L6o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id du6-20020a17090772c600b0073d72e1633bsi9813274ejc.908.2022.08.29.05.09.16; Mon, 29 Aug 2022 05:09:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dOwk5L6o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231176AbiH2LMr (ORCPT + 99 others); Mon, 29 Aug 2022 07:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbiH2LMH (ORCPT ); Mon, 29 Aug 2022 07:12:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B85B1F2; Mon, 29 Aug 2022 04:08:50 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 097DD611F6; Mon, 29 Aug 2022 11:08:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 18EC6C433D6; Mon, 29 Aug 2022 11:08:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771329; bh=nxFzwG/Su71x1AgWj7cs9KQ+UqjXZBU327nkcS2HGEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dOwk5L6oJz/2mysobMCAgG3Y39EnvIua3kAJ7YUtco7v4e5LSjx/CBScBsYPkGcox 7w8hJVQyHbnXqe8dFY86F66Bn4v2z8bXRsBsmfdvNqxWBii9Ql3ZeihvuPjma8zv02 klKwZVuWVwbddwXdvn/XBHugHIBje1cRTKt75UXE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Seth Forshee , "Christian Brauner (Microsoft)" , Sasha Levin Subject: [PATCH 5.19 017/158] fs: require CAP_SYS_ADMIN in target namespace for idmapped mounts Date: Mon, 29 Aug 2022 12:57:47 +0200 Message-Id: <20220829105809.545246034@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Seth Forshee [ Upstream commit bf1ac16edf6770a92bc75cf2373f1f9feea398a4 ] Idmapped mounts should not allow a user to map file ownsership into a range of ids which is not under the control of that user. However, we currently don't check whether the mounter is privileged wrt to the target user namespace. Currently no FS_USERNS_MOUNT filesystems support idmapped mounts, thus this is not a problem as only CAP_SYS_ADMIN in init_user_ns is allowed to set up idmapped mounts. But this could change in the future, so add a check to refuse to create idmapped mounts when the mounter does not have CAP_SYS_ADMIN in the target user namespace. Fixes: bd303368b776 ("fs: support mapped mounts of mapped filesystems") Signed-off-by: Seth Forshee Reviewed-by: Christian Brauner (Microsoft) Link: https://lore.kernel.org/r/20220816164752.2595240-1-sforshee@digitalocean.com Signed-off-by: Christian Brauner (Microsoft) Signed-off-by: Sasha Levin --- fs/namespace.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index e6a7e769d25dd..a59f8d645654a 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4238,6 +4238,13 @@ static int build_mount_idmapped(const struct mount_attr *attr, size_t usize, err = -EPERM; goto out_fput; } + + /* We're not controlling the target namespace. */ + if (!ns_capable(mnt_userns, CAP_SYS_ADMIN)) { + err = -EPERM; + goto out_fput; + } + kattr->mnt_userns = get_user_ns(mnt_userns); out_fput: -- 2.35.1