From patchwork Thu Jun 20 10:31:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167321 Delivered-To: patch@linaro.org Received: by 2002:ac9:6410:0:0:0:0:0 with SMTP id r16csp1665202ock; Thu, 20 Jun 2019 03:33:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqz7UZbzG+m0j7zVeTaygTRnxhFDXIxFoQinogAojHa+lYCs9egbts/F8D+WsTDlQxufetWm X-Received: by 2002:a17:90a:b903:: with SMTP id p3mr2318320pjr.79.1561026837107; Thu, 20 Jun 2019 03:33:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561026837; cv=none; d=google.com; s=arc-20160816; b=Rz/7AhptebzY+qINJNG7Lj31FQrNV0bw935FJ58P8lKfz4FY2hnbG8jnAgxyG+i5sL xRm09KlszVfB4D2PXQ4a5HcdYF8GciTBMYtG9hf7wVsFQ/T5nqrKIO5e+g6my68d6cHi Jpnp7G3OAOfoh6dN0gpT+k92ZZZg/Wc6v5+Y9yzzy7cPGPSeMQNGo1ypWgCX0hWgpVBB MwlCwrO76CXKBejWgfQFM37X1TRww3ijd97HNPuqq+YeIQ/zeBN1evZmin2KFVmDEcKr mYXZag7Ku9KN9GUQ2TKd20BQPFh1dTmKNzTUKUc2HEv2k9ZBoNVynBZQhr5B9YZxrmOq Nekw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=/V1IWL280c+6QECD0i6Sq1jjHPccUq/RMQJVBUUXt8M=; b=zzuWCyqGyBMYm2SieNaQm89XO7O+kSBKpgJc05aOka5TdapKRUEWZ5CXZKyOYI6aQ4 hUyI/+PULT3u8pdFpV8PHlnPFisOTM+H2Hg2nuFF6WaYC9Zm0O0TOXzaZUkl9aLkPcCq G65eLY1vyZokmtwwxyos8g48P1L4lNoC95Lr55Ryn+5zCVfsMCtockYr57kXitbqDqXT DDXgsAt13GHcCAdI+5AdcN7UUnQ1/EYRx3K8IzD2blJqqxhpNmvCQ6hmu+Qz7oZEhdk2 0FaW0eOCNDWblt9F3FmTCE89zwj8kaUQm93H8DfoFjvJNhEeRT0B9IWTlN9kK6MiD4bW 0btw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t4si18949064pfh.261.2019.06.20.03.33.56; Thu, 20 Jun 2019 03:33:57 -0700 (PDT) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731617AbfFTKdz (ORCPT + 30 others); Thu, 20 Jun 2019 06:33:55 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:18649 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726620AbfFTKdg (ORCPT ); Thu, 20 Jun 2019 06:33:36 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E24B49282C1C1A264A80; Thu, 20 Jun 2019 18:33:32 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.439.0; Thu, 20 Jun 2019 18:33:26 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH 3/5] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Thu, 20 Jun 2019 18:31:54 +0800 Message-ID: <1561026716-140537-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561026716-140537-1-git-send-email-john.garry@huawei.com> References: <1561026716-140537-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.212.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If, after registering a logical PIO range, the driver probe later fails, the logical PIO range memory will be released automatically. This causes an issue, in that the logical PIO range is not unregistered and the released range memory may be later referenced. Fix by unregistering the logical PIO range. And since we now unregister the logical PIO range for probe failure, avoid the special ordering of setting logical PIO range ops, which was a previous (poor) attempt at a safeguard against this. Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings") Signed-off-by: John Garry --- drivers/bus/hisi_lpc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) -- 2.17.1 diff --git a/drivers/bus/hisi_lpc.c b/drivers/bus/hisi_lpc.c index 19d7b6ff2f17..6d301aafcad2 100644 --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -606,24 +606,25 @@ static int hisi_lpc_probe(struct platform_device *pdev) range->fwnode = dev->fwnode; range->flags = LOGIC_PIO_INDIRECT; range->size = PIO_INDIRECT_SIZE; + range->hostdata = lpcdev; + range->ops = &hisi_lpc_ops; + lpcdev->io_host = range; ret = logic_pio_register_range(range); if (ret) { dev_err(dev, "register IO range failed (%d)!\n", ret); return ret; } - lpcdev->io_host = range; /* register the LPC host PIO resources */ if (acpi_device) ret = hisi_lpc_acpi_probe(dev); else ret = of_platform_populate(dev->of_node, NULL, NULL, dev); - if (ret) + if (ret) { + logic_pio_unregister_range(range); return ret; - - lpcdev->io_host->hostdata = lpcdev; - lpcdev->io_host->ops = &hisi_lpc_ops; + } io_end = lpcdev->io_host->io_start + lpcdev->io_host->size; dev_info(dev, "registered range [%pa - %pa]\n",