Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp46438pxk; Tue, 15 Sep 2020 17:21:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYy2xojBxXn4t9o8CMxpGB1iCHrw+bMHWR9Z2X+YSHWzeKsjTpRvQBmcpb4xSMhzbP2i9C X-Received: by 2002:a50:99d5:: with SMTP id n21mr25109024edb.88.1600215665922; Tue, 15 Sep 2020 17:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600215665; cv=none; d=google.com; s=arc-20160816; b=u0vGfLz5/80VAWUWSLfOluRsWA4fig59Y1NnpM/TWy/wzSbKp0BkIrNVAP3ag9gIj1 bwvUPwYAoOI3AWuelo02fFw6SyIltjtEKXCQC9Wec0UZmHN/KnWqYEYMIMZZa+W7/1JN HUMpqbSVVNbNDbAm+Mw/+VaV2VQzu32b38s4H3EGSSEfH697TLJb7dB+CoOnwTovyidl as54vJesu1aScim9wkYCab7B0UWKUz09VZiu0iBL+b9lueGr5d0ahNbyem7wvYeY28/Y vLjTJwQ4W19ZZ0IfQrCLnrFSDdGJsOTOIjyDWA+dnBkrfI1M8l2LjXkhiImEMMpmYCZP UM0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Pfg76it+V81iPLm71xzdNbA9HFmPmwjhhZEDhcXXU3k=; b=m/7h8zaXLlI+8Yyhxt5xZ1boPMquCD0l8GQassBL3SYL7/Vt+72cngw2v8h/LfV7Wq ckRwCOqGEJtBxDbq7c5QNfi/WbTjOd/6srMWgPkHFXGt1MfWXtEJw++7h77vOZELWn1u FEzTd8L1+0lzb2vdOBiiz8D95wEnGlGmi3Ibuxxra00guPq9G73dMEbps0WJOmKCAO1y NpN6qNgG2/Ch+aB+ROqmx970H2XUwlHXzP0BrXhizGa/4NKcaM0zReRgaRbPw9pz+LVW ggfQ1u5pXHXG+zD/1kh91XiaU7Rc9rH0v0nomHjjdpCxsBu8Tq1k3yv+GuJVBAMYN7dg U6cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nxLzkaIO; 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 d25si10091564eje.181.2020.09.15.17.20.43; Tue, 15 Sep 2020 17:21:05 -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=nxLzkaIO; 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 S1727270AbgIPASH (ORCPT + 99 others); Tue, 15 Sep 2020 20:18:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:38306 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726893AbgIOOWr (ORCPT ); Tue, 15 Sep 2020 10:22:47 -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 AC01E222B9; Tue, 15 Sep 2020 14:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600179486; bh=zD4SVIcRQppcHX/ycAMOypWWIqRTeJm0DNg3QO+q2hY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nxLzkaIOq5ZQ+1SdU9wvvgc6Yl4NdfZuATTLAgCDfaxNSFYqr1IVZZpwThfifjwYu 8AmQCcChEZDdGHgbqlIOgspQ3F0TDGo3QtdlWq2Wi791T94lvgRldKVGI+lX0apmt4 nR20GR8P4L0XHQYu45dLR61q6f+DbszXoZl4BcLk= 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.19 63/78] rbd: require global CAP_SYS_ADMIN for mapping and unmapping Date: Tue, 15 Sep 2020 16:13:28 +0200 Message-Id: <20200915140636.727772488@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140633.552502750@linuxfoundation.org> References: <20200915140633.552502750@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org 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 @@ -4124,6 +4124,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); } @@ -4235,6 +4238,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; @@ -5846,6 +5852,9 @@ static ssize_t do_rbd_add(struct bus_typ struct rbd_client *rbdc; int rc; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + if (!try_module_get(THIS_MODULE)) return -ENODEV; @@ -5995,6 +6004,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);