Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1131340pxb; Wed, 29 Sep 2021 18:10:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSTEl9VcPUg7yPC8tUGJvdlac7bwmoUA1XroY4B9FGKI10vjZIt4WKeQ2eV97DIeTy4g2s X-Received: by 2002:a50:cf4d:: with SMTP id d13mr3755742edk.50.1632964245044; Wed, 29 Sep 2021 18:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632964245; cv=none; d=google.com; s=arc-20160816; b=HxJms//G5UFMb5Z07CSV7dmcsgm1ORDh4F+UJznzwefreEW8QK0H0qUX9g1Sqsd5tL f1xvFgucoHULPAefE1I476n92VvBepn4UQwSgjUa+ZRajEgrVxizUqPfvHVXekz9wuNx 24adpnS541TkDbvQ/6vNuWB6FE73un88eaacaFv+ERvKiJsNRDqIAGITEyq9taF1uPRV dOoM3vxxOkQojhSeScmwPdexg58amYJOl9w7cP/UcPDwaLxJbRvD9CSGRNySXhAS5akx qT7+iSb0PFkKujVSKXe9/363Dxr0OY/+c+M3n/3fh6l6MSyxn2KnX7yTJwzb/jukFbr/ me/w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=v2B4VVfL4/tTXxXVHtvNs0p962pyCFP4yI4/5Q/ox50=; b=OTelgMcvL2vqHFCbN+IbQVaJ+2usnxc0I07X2fTWkcoof1cDWdq0Fc938V3KaLDQuV cbM40RHHfyNGNmPpb73sdLCIvfWMzNRNGisE4K/NiNJpmnucPJtzl7JdSy+RLa2+X/rW 07KugFcgR8B1aEgv3olY+wvw3T2LQJwZQ/Uft5cUaLslrXavL6FIyOSB5Puaxv7q6KnN VN4ptPzw0jKQruc90t7zDpSXk7f+Y26KPWP/LeyDFFXnEgd1sRLwLEGGmfIiemqYuffF ADJDtJwMM7KZYRssGRuVf7BjmwXKWGAtsJ+u5NWRYQup5sFRb5k/vHI9FAg4XFL1n9Hx Y3JA== ARC-Authentication-Results: i=1; mx.google.com; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e21si1813773ejl.49.2021.09.29.18.10.21; Wed, 29 Sep 2021 18:10:45 -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; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347640AbhI3BHW (ORCPT + 99 others); Wed, 29 Sep 2021 21:07:22 -0400 Received: from mga02.intel.com ([134.134.136.20]:24480 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347152AbhI3BHO (ORCPT ); Wed, 29 Sep 2021 21:07:14 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10122"; a="212330104" X-IronPort-AV: E=Sophos;i="5.85,334,1624345200"; d="scan'208";a="212330104" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 18:05:31 -0700 X-IronPort-AV: E=Sophos;i="5.85,334,1624345200"; d="scan'208";a="521027367" Received: from yzhu3-mobl.amr.corp.intel.com (HELO skuppusw-desk1.amr.corp.intel.com) ([10.254.37.25]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Sep 2021 18:05:30 -0700 From: Kuppuswamy Sathyanarayanan To: Greg Kroah-Hartman , Borislav Petkov Cc: x86@kernel.org, Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , Andreas Noever , "Michael S . Tsirkin" , Michael Jamet , Yehezkel Bernat , "Rafael J . Wysocki" , Mika Westerberg , Jonathan Corbet , Jason Wang , Dan Williams , Andi Kleen , Kuppuswamy Sathyanarayanan , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-usb@vger.kernel.org, virtualization@lists.linux-foundation.org Subject: [PATCH v2 2/6] driver core: Add common support to skip probe for un-authorized devices Date: Wed, 29 Sep 2021 18:05:07 -0700 Message-Id: <20210930010511.3387967-3-sathyanarayanan.kuppuswamy@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210930010511.3387967-1-sathyanarayanan.kuppuswamy@linux.intel.com> References: <20210930010511.3387967-1-sathyanarayanan.kuppuswamy@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org While the common case for device-authorization is to skip probe of unauthorized devices, some buses may still want to emit a message on probe failure (Thunderbolt), or base probe failures on the authorization status of a related device like a parent (USB). So add an option (has_probe_authorization) in struct bus_type for the bus driver to own probe authorization policy. Reviewed-by: Dan Williams Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/base/dd.c | 5 +++++ drivers/thunderbolt/domain.c | 1 + drivers/usb/core/driver.c | 1 + include/linux/device/bus.h | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/drivers/base/dd.c b/drivers/base/dd.c index 68ea1f949daa..0cd03ac7d3b1 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -544,6 +544,11 @@ static int really_probe(struct device *dev, struct device_driver *drv) !drv->suppress_bind_attrs; int ret; + if (!dev->authorized && !dev->bus->has_probe_authorization) { + dev_dbg(dev, "Device is not authorized\n"); + return -ENODEV; + } + if (defer_all_probes) { /* * Value of defer_all_probes can be set only by diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c index 3e39686eff14..6de8a366b796 100644 --- a/drivers/thunderbolt/domain.c +++ b/drivers/thunderbolt/domain.c @@ -321,6 +321,7 @@ struct bus_type tb_bus_type = { .probe = tb_service_probe, .remove = tb_service_remove, .shutdown = tb_service_shutdown, + .has_probe_authorization = true, }; static void tb_domain_release(struct device *dev) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index fb476665f52d..f57b5a7a90ca 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -2028,4 +2028,5 @@ struct bus_type usb_bus_type = { .match = usb_device_match, .uevent = usb_uevent, .need_parent_lock = true, + .has_probe_authorization = true, }; diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index 062777a45a74..571a2f6e7c1d 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -69,6 +69,9 @@ struct fwnode_handle; * @lock_key: Lock class key for use by the lock validator * @need_parent_lock: When probing or removing a device on this bus, the * device core should lock the device's parent. + * @has_probe_authorization: Set true to indicate to the driver-core to skip + * the authorization checks and let bus drivers + * handle it locally. * * A bus is a channel between the processor and one or more devices. For the * purposes of the device model, all devices are connected via a bus, even if @@ -112,6 +115,7 @@ struct bus_type { struct lock_class_key lock_key; bool need_parent_lock; + bool has_probe_authorization; }; extern int __must_check bus_register(struct bus_type *bus); -- 2.25.1