From patchwork Mon Jun 24 14:35:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 167596 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4311632ilk; Mon, 24 Jun 2019 07:36:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHgk5FhRRFk2T3NKjwinEnUAB8TU5+tAyW07yboArgSXGOXiASSr/653NNcTGrTYPMi+p1 X-Received: by 2002:a17:902:4aa3:: with SMTP id x32mr25871691pld.119.1561387004369; Mon, 24 Jun 2019 07:36:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561387004; cv=none; d=google.com; s=arc-20160816; b=JnHSUWCj03R7SIgykW8zhBgIdCy4HJagCZASEhBd4plzTqlIo6hgEioTju2mnnBS7r TapEdiHyJnmhR9AD9v3rHMpiWeTB1uE5SDsC9na4pI2dOia6rp8uKqZopc53qm2lBUhi 8Y1Qgr/wRNkZOuSmmZksYNV5TkznepnXq24LZam1iOtPCHJs33WZXyFWEzB51UbaoHQn +lnuxUTVMxLUvFeLZxoInwhKVLqJq4uW9xrmjjtAvudme/Pw4Ci8kasiwh5G3KW84+wv w2ddKdSMiU2yNXFMexCcAFlVl6/Hu7s3NEnxDvwYYfdExYV/NbGQ5C+pjc5giFJg4jop nqiA== 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=DZPfN+Ov2iz5Z1ZizuE04/VlBYITjSfIUnxIaYVKesDDuFMGm712pHCS7LdPKH1VoR ckkvtd5O/zHoFGBRg+OEozHJdjP/YBXUDiCoJVnMywpojPOqKtCg0WEQjG2MFI37qufl w7vJDy1N3X0w0KDoZKz00PUCbyh9YsX3TiXIwdSDgAOBda1XVogBX7/pwQcsyU9MM860 gNQbUTBl+rcZ2yasWkC2FWiRa37xl19JRl701Cc9PkKZqMIQ2Uuxm+QpIKkLrojusOGV du3heyeTiUrJf8bJqkx7xXyyjT/0hvJFBY0MDo0XQRUL0yNPtg6MM05FQtcWnVL3U11f H5KQ== 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 m14si2983945pgb.335.2019.06.24.07.36.44; Mon, 24 Jun 2019 07:36:44 -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 S1728768AbfFXOgm (ORCPT + 30 others); Mon, 24 Jun 2019 10:36:42 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33264 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727344AbfFXOgj (ORCPT ); Mon, 24 Jun 2019 10:36:39 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 45CACF383ECDD524113B; Mon, 24 Jun 2019 22:36:37 +0800 (CST) Received: from localhost.localdomain (10.67.212.75) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Jun 2019 22:36:28 +0800 From: John Garry To: CC: , , , , , , John Garry Subject: [PATCH v2 4/6] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Mon, 24 Jun 2019 22:35:06 +0800 Message-ID: <1561386908-31884-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1561386908-31884-1-git-send-email-john.garry@huawei.com> References: <1561386908-31884-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",