From patchwork Wed Jun 26 16:26:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167843 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1158429ilk; Wed, 26 Jun 2019 09:28:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyu2QUjSdSVbkIxN71doJdPMbe7Jq/MadHwtbwn+/pWJ701i+SiPqCvMbC4JY2kJyu8B+MM X-Received: by 2002:a17:90a:9f0b:: with SMTP id n11mr5636916pjp.98.1561566534113; Wed, 26 Jun 2019 09:28:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561566534; cv=none; d=google.com; s=arc-20160816; b=NYZoOJqa81fXwq7M6GTFAu/NwDCCSqU4oaS6HQQOUwOp3J88b5Gyt/YhxnYLYANWVd PJpJ1XIkwIl7iRr+IEYQ7C5dGF3JiUgnRaUGCMLulEndh1zTrs5InJz5jhyBjELRiH55 Y8sEN8RSBOi6fYk8T7k6grAtt9cYF7VbpHG7WS50UQpatmg7ui9LiNLJLoFTcFm8WWgK PBmaC5iYWvXMmlIMWf8z//9AiMSA1liOYh+eO5lXSSrieNm2bqB8M0nGmWXeeqJkByNQ G0nYTMK9PU9HNQwDDpeAaCLLz1j9QdJnN5IlgEz9fk5ZbMZsLs8IUwJoApfeChwiq+qi ymuA== 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=vpQoSP2Vi2lg1x36aE5SBgCgPKw2EpZdNMWXXKdNWko=; b=iVWskTzdF1c6v5fNCbjR7NLtQhMlkFzMQdWAS5Ndv4C4UjfNvbuX+Sh4znHYxuwiuy YAVEgkBaaZHhwXomPGhzH/lhDaREeyf+9AhqCTjQwmYmQKumkvCEIQEcXhPrdMZoBpE0 XECQxYZUWY7FNDij+A5qjgsTZyXK4jIEVOIkltyIzE1lejItkCiWSDhhzmMNLbDCc+iJ GftgxDb9kQ6oXEW3l9OkIsj/0uvIwipUc6YuqdlI0W3eysivX+eXl1qHG0R2MYxYNynb cBQkGJHGX8Q1zfmrW4+hxL6zj/nkBkSVnrMf433tCz4bAa5HFX7vz0aBeHTnQiwIvQ9i fJAg== 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 i101si2256177pje.4.2019.06.26.09.28.53; Wed, 26 Jun 2019 09:28:54 -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 S1726682AbfFZQ2w (ORCPT + 30 others); Wed, 26 Jun 2019 12:28:52 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:50382 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726042AbfFZQ2n (ORCPT ); Wed, 26 Jun 2019 12:28:43 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 6CE17EF3578678A11DCB; Thu, 27 Jun 2019 00:28:36 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Thu, 27 Jun 2019 00:28:25 +0800 From: John Garry To: CC: , , , , , John Garry Subject: [PATCH v3 4/6] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Thu, 27 Jun 2019 00:26:56 +0800 Message-ID: <1561566418-22714-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561566418-22714-1-git-send-email-john.garry@huawei.com> References: <1561566418-22714-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 the 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",