Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4936599ybi; Tue, 30 Jul 2019 10:45:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqyoU5q2zD2JNCPuHMhPvKUJqJusZbDPAQas3+mJIlHUl6SY2dWaOt6Pafwc93+F7Puw4bd/ X-Received: by 2002:a63:2b0c:: with SMTP id r12mr109902340pgr.206.1564508737796; Tue, 30 Jul 2019 10:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564508737; cv=none; d=google.com; s=arc-20160816; b=FXntNXac/ILfi6mCXN7n/Bej873fDVQ6o0i3SgMYOd30SQFZhYo900q5ZoLax64clZ afuNULanXwByGuvA3JvTmvzpxKy1FON371/24VSU16hZvfM55dC0ebkHUZzXF2O4r4qc QvgZ9DLI8FzWTYx+aSBiSbErt50aGEM8burSi/KMl0Y2RrHhJF/5qp77ruX0vjfRECul +An2/s43sZGHzBr+R9ie7EyKFGbdt0wnySjgB3T6JN5VaUrLlClWNGxB6b2I05aVQ6AQ 34e+h0k3TMWUKF5ZoJPig5lI7NxzTLymQRp6zS4jUafH/S1OpP45t3QNBa9fopaMjab1 k6JQ== 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=Y2rJlQbQ6kKEKyQDypw8Ej7MFpvXr6kiIjzkmk770KI=; b=GuW95h3G8YPB64dL+82MVsvFmHQEmlJUi/JVgQ1MOrPhZW5Gm6EvR3PINvhodNuKKS RNVLviQCWuH1WSHFvkHDOElGZlKQ8dQCHdMA3t0nuZimV2qfajZygERNlCFu0OgXsuaQ UWDzn4UYkeDQF3+z3AlxM23QOVGOq4+8VfbSvIk8BOulRlzhOwo/kPU2LFKpsEKzZtF8 DSe3hlGp0C1+u6EQReIfMkD98DDG+Ij8JrrRB9SHgq932FFDAghjsBYhkbPuBhbBBYwz LDMYRmZXB+covr6IlIJGbAMerbW/sVGSOMmtGlb7+zW6bgA5JuFXADCr2unXnpKwIm47 nyxA== 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 u8si28482857plq.291.2019.07.30.10.45.22; Tue, 30 Jul 2019 10:45:37 -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 S1731088AbfG3NcS (ORCPT + 99 others); Tue, 30 Jul 2019 09:32:18 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3251 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731038AbfG3NcH (ORCPT ); Tue, 30 Jul 2019 09:32:07 -0400 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 66C0CBEC2A8FB601871B; Tue, 30 Jul 2019 21:32:05 +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; Tue, 30 Jul 2019 21:31:55 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH v4 4/5] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Tue, 30 Jul 2019 21:29:55 +0800 Message-ID: <1564493396-92195-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1564493396-92195-1-git-send-email-john.garry@huawei.com> References: <1564493396-92195-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain 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. Cc: stable@vger.kernel.org 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(-) 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", -- 2.17.1