Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp314714rwr; Thu, 4 May 2023 19:56:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4z4LPCZhw8NaRgFVudNjpip1Y/LIrVdGwHbBMl9E0GPh21/K2MX2wFn+cyItVyMywbD5dM X-Received: by 2002:a17:902:c409:b0:1ab:267e:2f2d with SMTP id k9-20020a170902c40900b001ab267e2f2dmr8080401plk.48.1683255415330; Thu, 04 May 2023 19:56:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683255415; cv=none; d=google.com; s=arc-20160816; b=xwDBZNVXBNwJ/Vl1QnM3GjjAx1fMqQyGcWCyHB5v1VQmN+JNILCWv5rckB2HpTNLuB /CT5EZyjkNCNSYknp/+Sg8ZbIivYp3+ipAEj6MC1uE54B82g1RXyBBn2hUaz+a21fjik MRBHCvIYSrcB5xaI2/f+8tMTTZ+q3/l4XsegpSSw+9ROwlMdguihZYp2PZgJsyEowPDf bxhX44+TJaswF2OgxA7O3GDNoWRPhaF/BdVBgzrB/fJmkwaEhl+QgQEzz0TJBfAhI/By w5HK4N1nrcc1XD5PIBr2Z0uCWgHAQZWveH98xpzqEK1Uo1n/DppFodWpgu47Z8lqDmGa /3bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=JPfzD8yRmlAWZjGWZJGqZ5bpaxLIBJOAuM9p1I+tZlw=; b=gl8mOrgvA50xXMP7/A36pmSNv/viJEuOlXYk/JDAXmWLe1KwujPrNdDYVacWy/vI/L Sw1UJbKejWsqa9gfZtc1tKHRglDH7TSNtGvjHlQC5i1Fdr6FZUfrZbYovVXe8LxmYXhz c8FP42PmXgFBHKR2n6glSpZaWVYHcSUxIHbCgHgkKqvirYJd6/svHkC3j6OlJq/x5o2+ Ha9SgGgn1Q9JloqWpGF9CCjnhbOA35KvVEOKNg/JHNUzkNohPdwU04MjguoFPTKdnQOw LrGKZPke0ChrNDo0gYy3YPscvablblVVOz51JHSTJrjQmja2x77HmKRRVa8XT5t78sCx dqkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BykX//U8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a170902e75100b001a51bb4ad81si690783plf.44.2023.05.04.19.56.39; Thu, 04 May 2023 19:56:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="BykX//U8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229977AbjEECvj (ORCPT + 99 others); Thu, 4 May 2023 22:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjEECvi (ORCPT ); Thu, 4 May 2023 22:51:38 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7153612094; Thu, 4 May 2023 19:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683255097; x=1714791097; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=SDFdhdekvxyYCofffHMf6rRfIuAVFmPIluPrsnQHPEE=; b=BykX//U80LZ0972eWKBejUvbB9+JObcK4lBuhH5tXHQXxUNNnucnhvb1 f7h1oWHk0NeBO/7OzGA8x4GGYDjqNfG7Vje3n3CpPO7ZwFlSGsbiw2UCS DOsakabxPmnj7utBwcUvkM9rKRkT/tZd7ix7+dt1z6KDrgPfqvn4j09qV qSi7nxoFPcib+MgMq5C46dkxlANtUZnuZp19PjR1ss+ahqqv6mhgZdrIN U+0RbKdOOFN67AQvxQnc24DFXx+k2DVHjK2DqhQX92+2X3UHxt30pN4NJ xGEHCZH+eqYQnRh6bYVK4XIsKYa81/JXzq4kMbtgn/7dqJ7uVqqIKxto7 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10700"; a="347934038" X-IronPort-AV: E=Sophos;i="5.99,250,1677571200"; d="scan'208";a="347934038" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2023 19:51:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10700"; a="841484488" X-IronPort-AV: E=Sophos;i="5.99,250,1677571200"; d="scan'208";a="841484488" Received: from syusufpa-mobl.gar.corp.intel.com (HELO [10.209.115.128]) ([10.209.115.128]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2023 19:51:36 -0700 Message-ID: <2f32591a-77d8-f620-46bf-825074ba24c2@linux.intel.com> Date: Thu, 4 May 2023 19:51:36 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.10.0 Subject: Re: [PATCH] PCI/ASPM: fix UAF by disable ASPM for link when child function is removed To: Ding Hui , bhelgaas@google.com Cc: vidyas@nvidia.com, david.e.box@linux.intel.com, kai.heng.feng@canonical.com, michael.a.bottini@linux.intel.com, rajatja@google.com, qinzongquan@sangfor.com.cn, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org References: <20230504123418.4438-1-dinghui@sangfor.com.cn> Content-Language: en-US From: Sathyanarayanan Kuppuswamy In-Reply-To: <20230504123418.4438-1-dinghui@sangfor.com.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 5/4/23 5:34 AM, Ding Hui wrote: Maybe you can use the following title? "PCI/ASPM: Fix UAF by disabling ASPM for link when child function is removed > If the Function 0 of a Multi-Function device is software removed, > a freed downstream pointer will be left in struct pcie_link_state, > and then when pcie_config_aspm_link() be invoked from any path, > we will trigger use-after-free. > > Based on the PCIe spec about ASPM Control (PCIe r6.0, sec 7.5.3.7), As per PCIe spec r6.0, sec 7.5.3.7, it is recommended > for Multi-Function Devices (including ARI Devices), it is recommended > that software program the same value in all Functions. For ARI > Devices, ASPM Control is determined solely by the setting in Function 0. > > So we can just disable ASPM of the whole component if any child > function is removed, the downstream pointer will be avoided from > use-after-free, that will also avoid other potential corner cases. > > Fixes: b5a0a9b59c81 ("PCI/ASPM: Read and set up L1 substate capabilities") > Debugged-by: Zongquan Qin Any bugzilla link with error log and reproduction steps? > Suggestion-by: Bjorn Helgaas Suggested-by? > Signed-off-by: Ding Hui > --- > drivers/pci/pcie/aspm.c | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) > > diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c > index 66d7514ca111..1bf8306141aa 100644 > --- a/drivers/pci/pcie/aspm.c > +++ b/drivers/pci/pcie/aspm.c > @@ -1010,18 +1010,17 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) > > down_read(&pci_bus_sem); > mutex_lock(&aspm_lock); > - /* > - * All PCIe functions are in one slot, remove one function will remove > - * the whole slot, so just wait until we are the last function left. > - */ > - if (!list_empty(&parent->subordinate->devices)) > - goto out; > > link = parent->link_state; > root = link->root; > parent_link = link->parent; > > - /* All functions are removed, so just disable ASPM for the link */ > + /* > + * Any function is removed (including software removing), just > + * disable ASPM for the link, in case we can not configure the same > + * setting for all functions. How about following? /* * For any function removed, disable ASPM for the link. See PCIe r6.0, * sec 7.7.3.7 for details. */ > + * See PCIe r6.0, sec 7.5.3.7. > + */ > pcie_config_aspm_link(link, 0); > list_del(&link->sibling); > /* Clock PM is for endpoint device */ > @@ -1032,7 +1031,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev) > pcie_update_aspm_capable(root); > pcie_config_aspm_path(parent_link); > } > -out: > + > mutex_unlock(&aspm_lock); > up_read(&pci_bus_sem); > } -- Sathyanarayanan Kuppuswamy Linux Kernel Developer