Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1390256imu; Wed, 16 Jan 2019 18:50:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN4sBCpPMAChvlwGHPt97czO/KWx6hYcB9TcSA97y72eisKd1ctVEtxmfQE4RbujXqOmMwcR X-Received: by 2002:a63:6ecf:: with SMTP id j198mr12081449pgc.3.1547693430024; Wed, 16 Jan 2019 18:50:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547693429; cv=none; d=google.com; s=arc-20160816; b=eFZiK3f4kuxuhe0IdbN45p22Tv09hKFSKMh8NyEder+Irors08C8zve/TKZLTQy8DJ ekxWSsygGDA+OdFLNcreg8t5dlmLHcduRsSyxXwQuhCw1mHn46ikTfsF3JlOTC01HGlK ubjWmSm3COMrBmhYgOat/qFXs/IrcjcrEndSTxwZYIkYjG76xpRAvGaOCXqZyOarH5SC /AcgqbwMjwPMsGl9kW2CW59q1xYQvqjiftEmDA6u7udy/aWtv9LQf1FquGRjs3KfxRzI IZyCgBxxwDU0XpesKs2c3F1AGhqMe6I5Ljzz2ckPjakIqibJyBVbaKcT04MHCYuXpuim WrNw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=2wbI6TVkcf/2JIsBbxP2lZSBPIgA9AL/8Mv+hmwKmwo=; b=K5QMNy1d1NOauwiETclrRovQggJECRKMS22kwQt63MCLBg05EZ4vyRqFZpuQXx9HyV k8pc+iaxMQu4mkzfBlI+2ULSAcCxt2QgEmmnSKChvCXw6BBG7vtVAzJLqST5jDctJmLp IWlyit7n7hd9XSkFPQvPjVYN22HEu3LnF3LwY9JFCdE1VxnHdXJ9+wpUIA7LrdqXmf0G 2YyLQ8ZypzDzhjA/7oFwd9SSMU0WhzW/WY0HrcEFv5MHf45CREZmZM6k6Gcf9q7X+lNw hdHm+choImj6q31BKVq4tB1OSAzZTIjSDCX9CpokUNS5idPMVmyfP7wTRAuWKLiwuAgE QfXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 33si321516plu.169.2019.01.16.18.50.11; Wed, 16 Jan 2019 18:50:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2391704AbfAPJht (ORCPT + 99 others); Wed, 16 Jan 2019 04:37:49 -0500 Received: from mga01.intel.com ([192.55.52.88]:30317 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391688AbfAPJhs (ORCPT ); Wed, 16 Jan 2019 04:37:48 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 01:37:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,485,1539673200"; d="scan'208";a="115060200" Received: from mylly.fi.intel.com (HELO [10.237.72.89]) ([10.237.72.89]) by fmsmga007.fm.intel.com with ESMTP; 16 Jan 2019 01:37:46 -0800 Subject: Re: [PATCH] PCI: fix using __initdata memory after free in disable_acs_redir parameter To: Logan Gunthorpe , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Bjorn Helgaas Cc: Stephen Bates References: <20190115173203.14850-1-logang@deltatee.com> From: Jarkko Nikula Message-ID: <48a93172-25a2-d6a6-e908-7d27249f1bc2@linux.intel.com> Date: Wed, 16 Jan 2019 11:37:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190115173203.14850-1-logang@deltatee.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi On 1/15/19 7:32 PM, Logan Gunthorpe wrote: > The disable_acs_redir parameter stores a pointer to the string passed to > pci_setup(). However, the string passed to PCI setup is actually a > temporary copy allocated in static __initdata memory. After init, once > the memory is freed, it is no longer valid to reference this pointer. > > This bug was noticed in v5.0-rc1 after a change in commit c5eb1190074c > ("PCI / PM: Allow runtime PM without callback functions") caused > pci_disable_acs_redir() to be called during shutdown which manifested > as an unable to handle kernel paging request at: > > RIP: 0010:pci_enable_acs+0x3f/0x1e0 > Call Trace: > pci_restore_state.part.44+0x159/0x3c0 > pci_restore_standard_config+0x33/0x40 > pci_pm_runtime_resume+0x2b/0xd0 > ? pci_restore_standard_config+0x40/0x40 > __rpm_callback+0xbc/0x1b0 > rpm_callback+0x1f/0x70 > ? pci_restore_standard_config+0x40/0x40 > rpm_resume+0x4f9/0x710 > ? pci_conf1_read+0xb6/0xf0 > ? pci_conf1_write+0xb2/0xe0 > __pm_runtime_resume+0x47/0x70 > pci_device_shutdown+0x1e/0x60 So this doesn't happen if you revert c5eb1190074c? I guess this is due dev->state_saved being true set by pci_pm_runtime_suspend() -> pci_save_state() after my patch and now pci_pm_runtime_resume() -> pci_restore_standard_config() -> pci_restore_state() reach the pci_enable_acs(). I think this is possible to trigger also before my patch if device has the runtime PM callback defined? > It was also likely possible to trigger this bug when hotplugging PCI > devices. > > To fix this, instead of storing a pointer, we use kstrdup to copy the > disable_acs_redir_param to its own buffer which will never be freed. > I wasn't able to trigger this but I saw "PCI: Can't parse disable_acs_redir parameter: " followed by a few lines of junk during boot when I defined pci=disable_acs_redir=0000:00:xy.z which disappear after your patch. Tested-by: Jarkko Nikula Reviewed-by: Jarkko Nikula