Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3300466pxk; Mon, 21 Sep 2020 10:03:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQzzUv3giWpuNyFsDTCpe7ZT684xueiWnErwe/VxgrqH4U1OfrzrcNmTnL2cQgrA65ohvV X-Received: by 2002:aa7:d059:: with SMTP id n25mr636480edo.270.1600707811654; Mon, 21 Sep 2020 10:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707811; cv=none; d=google.com; s=arc-20160816; b=pLluIyXd+RPFKWvt1/r3sEErn0Nr/0WCGTUISYtpxyobjYaNkcbgju1qrtRnPHbYnu 2YXZnLpWU5944ApxlXUHwY/jc0H2oHbu4dVselVij0cNipdkSAKWXY0RY6bQeKhpa+9R 1hvOnUcva2fNchwuUlV+D1scrbCY4DVlmRDDJ+4kXAnOsHDMKqGbGTiXTGEVdmjolDdv epFFEvmbhwtdVtjS/znkw+9C8L2eLGQEXq7JgU6oabzMWtKKBWHjgW30a9cFzkOp1QdC T3tFn7N8iFDfdSfGz/hyRW1iTB/k7osMkqUhhQz5Zg30NfchgBMa3mFlSWKCkQloKR1m ELfw== 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=O5jshVG4LK+BtfJyQM94jhQL54eXmFozcF7Lo69EceM=; b=El/9lQ74C+OR032xNcqM9sA+fRqxA8RO/+yQYe/3GzObk3cyfaAXvGXDC6TocQOdb+ kePwKVIBSYrjBSNMCnN3F27NNfW7b/3+j1i77AUcIQ1ulnWEWFREeiSrkuMnyFDBWzS0 NrTQftRAXj5xNeCpNOCd4jFgn4dtQnc/Z+I2uLF8iTBM2jBk1xGNT9A+yHdx8/AMBXs7 F48tpmR4Dhunf8IhX8oB/pJvCH0t/Y/B2qg/ZBbrjWsJOWaIFqNyBVaTrXgjWvb7kJ5o pJ79P6axRMAUyVPaG3eBbGcuQcrMnrKsyz9Zf6pwSZvxgmh9YBEfpQ4fy+BYDPl+3nEf gosQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=GGz00EzT; 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=fail (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 i21si8410041edv.439.2020.09.21.10.03.07; Mon, 21 Sep 2020 10:03:31 -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=@kernel.org header.s=default header.b=GGz00EzT; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729170AbgIUQif (ORCPT + 99 others); Mon, 21 Sep 2020 12:38:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:39390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729162AbgIUQiV (ORCPT ); Mon, 21 Sep 2020 12:38:21 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE15A206DC; Mon, 21 Sep 2020 16:38:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706301; bh=FuB4ajYoaUynKMIrAN1kcjaEdbWHw6VWOX4Am06KcgU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GGz00EzTRJnot15IlzHneb8+EUigN0ip/gR6esqknsNivayqFjyelVlZ89/4G8vqX rJejw0sxLPMgM2CPNcRWijZAO+gCaJpgrLsPcXwsPuwVdawR1g4SzMXWvBFRbb0pBv 5jByy1JKd4Obo0yLb6OTLd0yKekcdkwhD/AK/Ahg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Dryomov , Jeff Layton Subject: [PATCH 4.14 45/94] rbd: require global CAP_SYS_ADMIN for mapping and unmapping Date: Mon, 21 Sep 2020 18:27:32 +0200 Message-Id: <20200921162037.622813486@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162035.541285330@linuxfoundation.org> References: <20200921162035.541285330@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: Ilya Dryomov commit f44d04e696feaf13d192d942c4f14ad2e117065a upstream. It turns out that currently we rely only on sysfs attribute permissions: $ ll /sys/bus/rbd/{add*,remove*} --w------- 1 root root 4096 Sep 3 20:37 /sys/bus/rbd/add --w------- 1 root root 4096 Sep 3 20:37 /sys/bus/rbd/add_single_major --w------- 1 root root 4096 Sep 3 20:37 /sys/bus/rbd/remove --w------- 1 root root 4096 Sep 3 20:38 /sys/bus/rbd/remove_single_major This means that images can be mapped and unmapped (i.e. block devices can be created and deleted) by a UID 0 process even after it drops all privileges or by any process with CAP_DAC_OVERRIDE in its user namespace as long as UID 0 is mapped into that user namespace. Be consistent with other virtual block devices (loop, nbd, dm, md, etc) and require CAP_SYS_ADMIN in the initial user namespace for mapping and unmapping, and also for dumping the configuration string and refreshing the image header. Cc: stable@vger.kernel.org Signed-off-by: Ilya Dryomov Reviewed-by: Jeff Layton Signed-off-by: Greg Kroah-Hartman --- drivers/block/rbd.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -4534,6 +4534,9 @@ static ssize_t rbd_config_info_show(stru { struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + return sprintf(buf, "%s\n", rbd_dev->config_info); } @@ -4635,6 +4638,9 @@ static ssize_t rbd_image_refresh(struct struct rbd_device *rbd_dev = dev_to_rbd_dev(dev); int ret; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + ret = rbd_dev_refresh(rbd_dev); if (ret) return ret; @@ -6159,6 +6165,9 @@ static ssize_t do_rbd_add(struct bus_typ bool read_only; int rc; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -6311,6 +6320,9 @@ static ssize_t do_rbd_remove(struct bus_ bool force = false; int ret; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + dev_id = -1; opt_buf[0] = '\0'; sscanf(buf, "%d %5s", &dev_id, opt_buf);