Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1130878pxb; Wed, 29 Sep 2021 18:09:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4hen8pmR3LDvbJCkSCoWWTd66Ck2LkrMrq4/23TL8X9he17suK8eua3pHZzbuxl8zA8OB X-Received: by 2002:a17:906:a59:: with SMTP id x25mr3523241ejf.33.1632964196963; Wed, 29 Sep 2021 18:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632964196; cv=none; d=google.com; s=arc-20160816; b=O+q6jSwT147k5hVkgCGs/6Kxrk76VzdAfro/sr26sSJ0ghE2Dwz7RRJCEOV3KcpH5p yg/ZmglTMGPi+4e8kkpKlNFoqUXjqeDUt8CKjc4TonFBHr9s2jFORgZpx12EXJh7JURg n+KFv2FM1egYaiTiarrHD/m6zce4248F8NvUqy1718FVHIRfCIjiYs9nAzdBTQ6fzuMN 8dEVErQl6pqLGa+EwFAfVyHrUyjq7a3C5VcK6tK8z8uDnurlv8jrsa29eIh2f/9zibcO XCFX04jFb3oGokB1abbfOssVxNRTygPisxEt9HK+dq2TnE8X91dlKX8Zlo8s5IbF8GE4 kC6g== 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=1gXOaziFikfz104e0fonSAIcPRCR9t76jKWCI2aS4zs=; b=oQ21WZW4XUOWFTekii1FAEu/ia9XkbHyw06Lf/T60LF9/1lXlPhjjfwms5RKeUggUj vfHPFdtcE8rswZ3T5uLwJX51n1T4G9i++IGeUdglAQPfolmaNr86aGAWI6C8/O6Ace8X MLuHkzFaTWfbnyE4i5djnA01hCy+ZUMV/QE14Y6vgyxtBPBm+w3v+8qOUpcggBhsbxJf ot2O9QAuE4zsaYlsboioS8mZ/LzM3VXGqYKT0Gxp+47Y+/qWhrohpKdQ/+uVH1c9/ueC IVSvyjjzTGJaW5Qb70Uj6qVlq2ck+Gigo5aKH9vqwQPadXuMmRd06S02shiitFEMxsau lPyQ== 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 f10si1984149ejf.597.2021.09.29.18.09.30; Wed, 29 Sep 2021 18:09:56 -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 S1347615AbhI3BHT (ORCPT + 99 others); Wed, 29 Sep 2021 21:07:19 -0400 Received: from mga02.intel.com ([134.134.136.20]:24481 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347347AbhI3BHP (ORCPT ); Wed, 29 Sep 2021 21:07:15 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10122"; a="212330108" X-IronPort-AV: E=Sophos;i="5.85,334,1624345200"; d="scan'208";a="212330108" 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:33 -0700 X-IronPort-AV: E=Sophos;i="5.85,334,1624345200"; d="scan'208";a="521027370" 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:31 -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 3/6] driver core: Allow arch to initialize the authorized attribute Date: Wed, 29 Sep 2021 18:05:08 -0700 Message-Id: <20210930010511.3387967-4-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 Authorized device attribute is used to authorize or deauthorize the driver probe of the given device. Currently this attribute is initialized to "true" (allow all) by default. But for platforms like TDX guest, in which the host is an untrusted entity, it has a requirement to disable all devices by default and allow only a trusted list of devices with hardened drivers. So define a variable "dev_default_authorization" which is used to initialize the "authorized" attribute in device_initialize(). Also allow arch code to override the default value by updating dev_default_authorization value. More discussion about the need for device/driver filter and the use of allow list can be found in article [1] titled "firewall for device drivers". Also note that USB and Thunderbolt both override this initial value in their respective device initializations so this is not a regression for those buses. [1] - https://lwn.net/Articles/865918/ Reviewed-by: Dan Williams Signed-off-by: Kuppuswamy Sathyanarayanan --- drivers/base/core.c | 7 +++++++ include/linux/device.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index e65dd803a453..98717f00b90b 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -47,6 +47,12 @@ static int __init sysfs_deprecated_setup(char *arg) early_param("sysfs.deprecated", sysfs_deprecated_setup); #endif +/* + * Default authorization status set as allow all. It can be + * overridden by arch code. + */ +bool __ro_after_init dev_default_authorization = true; + /* Device links support. */ static LIST_HEAD(deferred_sync); static unsigned int defer_sync_state_count = 1; @@ -2855,6 +2861,7 @@ void device_initialize(struct device *dev) #ifdef CONFIG_SWIOTLB dev->dma_io_tlb_mem = &io_tlb_default_mem; #endif + dev->authorized = dev_default_authorization; } EXPORT_SYMBOL_GPL(device_initialize); diff --git a/include/linux/device.h b/include/linux/device.h index 899be9a2c0cb..c97b1e59d23a 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -959,6 +959,8 @@ int devtmpfs_mount(void); static inline int devtmpfs_mount(void) { return 0; } #endif +extern bool dev_default_authorization; + /* drivers/base/power/shutdown.c */ void device_shutdown(void); -- 2.25.1