Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp947756pxu; Thu, 15 Oct 2020 22:54:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzy/twO4r8i8G1mDkEmYcc6Pw9AF1+/UGrvSw7muYgxCeU2kzyL7YA/Br/Sebcxbxp5W51A X-Received: by 2002:aa7:d988:: with SMTP id u8mr2135926eds.64.1602827654272; Thu, 15 Oct 2020 22:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602827654; cv=none; d=google.com; s=arc-20160816; b=gmUxl1YBaNCHKAV+c+G0qPUGnKht3//ORtINE5BQ+jIPVZdd8+QrKW4LaxFyo706En 243N95ldZO1tMExl++JSgrSeRG8OYb+YK9ejhHwkSpFHSXWUwOr8yZidNQjVSG9NnZ2C yHzEBt8QWijR0Qm295YLtla5tCiYQ9bc3vOVwB/zrUMep0lhdMmugBt7l2tdjrBBZPaG nZSd28DoPTPWFQkMSv3uMa4zv46CE9koUVF0HmOLWWA14kra/mV9GN2vkf+jNG61Sdr+ KJXrrWovlkkHA8fvRQi4099eRTxk8AxPPjLamKPS+XpXn0H08rDRwoddJhLi81mld77g h0mg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=kI/NTRnsuiqMq/19qfG8dHccdcc45HtUzVtiWVJOA54=; b=nDI63ib0K9mU664gjcpmr6JkBKhWevo78XCwMM7KsxDeftj3ei0v7kT2q36YsP+q5L 1e/bMPQw8vkzEJLOY4oeTKgFKRA3OafYGnbqlyca7AVkEG/8BHZ7o4NPEMt3CqwOGyAp PesKH+YQqVlE/sMFEsq5BvNNlyntCJIvKUal5jFoc04z9ZhFeos8XhQBMYdfCZNHQ9Ee zkL1amVme6lNyp/Br+DNj4gsjQCREnMi1CXeR0ce+8gmLRlpifmDdzlKCuQNghwgDkVv AUMxp5DCNMomsGM/CueEbrHH+kkzzDXqworpI9/tQe4Cw5GRP2t1GtxhNHy8xGfKTNKH p3aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=pD5FJ7dG; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cd12si983187ejb.745.2020.10.15.22.53.51; Thu, 15 Oct 2020 22:54:14 -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=@gmail.com header.s=20161025 header.b=pD5FJ7dG; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390417AbgJPFwr (ORCPT + 99 others); Fri, 16 Oct 2020 01:52:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390204AbgJPFwq (ORCPT ); Fri, 16 Oct 2020 01:52:46 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A5EEC061755; Thu, 15 Oct 2020 22:52:46 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id n14so838569pff.6; Thu, 15 Oct 2020 22:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kI/NTRnsuiqMq/19qfG8dHccdcc45HtUzVtiWVJOA54=; b=pD5FJ7dGZbZIGvMFGfGVp6uhM0aQbeJzP5nuTKxe6hekA+xD+Bz7avwlOlqMZVaxda 4gA9MxiFUWw7PitLTs/C0cLZVbksoy67J1NbwAozTllcMgXBvWl+3zXD3/lcn8p8A58a vTlV4BojkNq0clIkEDio75syqxacmUyDRc7NWbCzDglDqM+sE8uj2RH/Yc9/N6LOx6Mf NufIzGnE9X2rCdVx85BwGqFt1Aum7/TQAqwuOqcAQQoaQQikuFUdKa6NHLc1ol93+pdA w/tEcuxYyRn8DLxilt9izQMErmMZmaquSOJMZv9YNKaVLXk9JbfpDmYduD7/YdMIQBac i/5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kI/NTRnsuiqMq/19qfG8dHccdcc45HtUzVtiWVJOA54=; b=JRh/uIrpBVzfkXXBS9TEOOWsmWihIUkrH4Jk99C+PD07qwkZQFX4SlFzFFUA+/Itua 9/ij5cyTBdODaMw2unNBWfroRpS8oH8QNhfWWbA7xrIfxdjs8jJBCwY7taOwQUx/iuJC /Dh1ZBH8OvsqIrbHWFWFOkYfl1Pf6NfEI+ZIlKxVPuo2wlog/cvy0tDIPwEO2H/FkGoP 53c7F04xKdNpz9Mzb0UsGn0F5S64AYxUPzhtEDDi/Fwi1Q95dyBlcXoaM8cyltBRXD80 kLih0aQBmAI7tlyfm3bhkxImMoqYaFNlr4W9iMw5Zt5pUCTFf9GGlp0BjIiHHU+n9Mkq lwZg== X-Gm-Message-State: AOAM532puCibg2cm+s6CcLxBGvJP51cUy+mcie0C4W/YjYLLSpytPTaB ITwgcASzA/d2vzkrmx+nhI80o375+kg= X-Received: by 2002:a63:cf46:: with SMTP id b6mr1794900pgj.49.1602827565724; Thu, 15 Oct 2020 22:52:45 -0700 (PDT) Received: from localhost.localdomain ([49.207.214.53]) by smtp.gmail.com with ESMTPSA id u14sm1308110pjf.53.2020.10.15.22.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2020 22:52:45 -0700 (PDT) From: Allen Pais To: linux-pci@vger.kernel.org Cc: bhelgaas@google.com, ast@kernel.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, Allen Pais , Allen Pais Subject: [RFC] PCI: allow sysfs file owner to read the config space with CAP_SYS_RAWIO Date: Fri, 16 Oct 2020 11:22:35 +0530 Message-Id: <20201016055235.440159-1-allen.lkml@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Allen Pais Access to pci config space is explictly checked with CAP_SYS_ADMIN in order to read configuration space past the frist 64B. Since the path is only for reading, could we use CAP_SYS_RAWIO? This patch contains a simpler fix, I would love to hear from the Maintainers on the approach. The other approach that I considered was to introduce and API which would check for multiple capabilities, something similar to perfmon_capable()/bpf_capable(). But I could not find more users for the API and hence dropped it. The problem I am trying to solve is to avoid handing out CAP_SYS_ADMIN for extended reads of the PCI config space. Signed-off-by: Allen Pais --- drivers/pci/pci-sysfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 6d78df981d41..6574c0203475 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -666,7 +666,8 @@ static ssize_t pci_read_config(struct file *filp, struct kobject *kobj, u8 *data = (u8 *) buf; /* Several chips lock up trying to read undefined config space */ - if (file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN)) + if (file_ns_capable(filp, &init_user_ns, CAP_SYS_ADMIN) || + file_ns_capable(filp, &init_user_ns, CAP_SYS_RAWIO)) size = dev->cfg_size; else if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS) size = 128; -- 2.25.1