Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1022560ybe; Wed, 4 Sep 2019 11:16:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMPJuI0A7NtmS9l7Xo1oKvncKE3giG0BJ4zl7B7exOqv74EvryozDAq6oXs77IOndsllRf X-Received: by 2002:a62:64c9:: with SMTP id y192mr33376415pfb.6.1567621013918; Wed, 04 Sep 2019 11:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567621013; cv=none; d=google.com; s=arc-20160816; b=ueAkf46tu4F43OhzEHC4hbRbDkkDj+yK6WIgQB0sVC4sFbjj6Lq635PRo1oF7/JCXN AiKJ3YZub+1APulOfje0GGppAoUs4OwgvVNbpx9/BI0ERhCh55pOvhUf8b8JqsYGKghc TydYUTNm2BDZ+7yKXIGaq2vR+FG/0q8qNpgJmD0vJFuKqeRnJqVCSajNk4/nGSVzNlOz lIOpsbdEvChlJQvX1Hp+a0yQ/6b6jKEauVmsFGWbr24Zt1vnJc+AAwQNQOAAfPKC6BIp qQXNoNwwj+GVnJhnsuh0Ut/aEjN9kSJzB5uY+SQM5lk/CTEgrGPhs/HBfaZu09510fkI k62A== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rnfcI4bz6dtjrnYErzBEIJn72fBVFlRDeJo7UYNvDmM=; b=cA4rcXM3YL/oVM8hnvNm2K9c6pbOGLMSs9tl+h0SBbwT1/s8W25cbWB7PFObuK3vtp Tb0ZdyTHsTF9OVeN6kSBzKmI1VeDLTOt08LsDma8/e23a1BRLLa3c1Efcfev1e12TcYi 6l3/wrL8h/pAzYaRPFBHQo2d1yuR6hywVQIKJWsgRbGlJ7f4QvM0VCJ4B1Tm0vN5WMT5 Casi8jI22GXyJYG9qHiHVFHyuXYLMLjsQmdTkhJ5rgjHfCl/bIoZza+IsjHksrFW/HZB SkxjW7X/ZgX1jdi90T1zyxdK3eP+rOz+gSq8yz+h4Hdzc7xsevS3eNovcLyfe0zW+Tym acUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CfBl6UNS; 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 u14si10568861pfc.222.2019.09.04.11.16.38; Wed, 04 Sep 2019 11:16:53 -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; dkim=pass header.i=@kernel.org header.s=default header.b=CfBl6UNS; 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 S2390446AbfIDSOB (ORCPT + 99 others); Wed, 4 Sep 2019 14:14:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:58934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390143AbfIDSN7 (ORCPT ); Wed, 4 Sep 2019 14:13:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 022A2206BA; Wed, 4 Sep 2019 18:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620838; bh=yYpBrXSse8jC7Y/RgIAkCtAYzAY7Kh8rMxaOmj2tflY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CfBl6UNS5dY0DSVUMxAX4vpYAGA/5Af+9ogpxSly5JicV/YgqqZjbkacNOq+lv79b 08/Jjjv/WOtgQJtJQsjM+picOBeuvMuohkhsFjzD7HcbdxJOZXC9QBUihUfl8vbvDf 2pXcuCyAeYgVDePmmfDys1T2DwtS7oB0KUE5zCsc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Garry , Wei Xu Subject: [PATCH 5.2 115/143] bus: hisi_lpc: Unregister logical PIO range to avoid potential use-after-free Date: Wed, 4 Sep 2019 19:54:18 +0200 Message-Id: <20190904175318.893845918@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Garry commit 1b15a5632a809ab57d403fd972ca68785363b654 upstream. 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 Signed-off-by: Wei Xu Signed-off-by: Greg Kroah-Hartman --- drivers/bus/hisi_lpc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/drivers/bus/hisi_lpc.c +++ b/drivers/bus/hisi_lpc.c @@ -606,24 +606,25 @@ static int hisi_lpc_probe(struct platfor 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",