From patchwork Wed Dec 20 11:35:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Martinez Canillas X-Patchwork-Id: 10125543 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46EEF6019C for ; Wed, 20 Dec 2017 11:37:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40C6A29612 for ; Wed, 20 Dec 2017 11:37:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34DB829711; Wed, 20 Dec 2017 11:37:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94ED29612 for ; Wed, 20 Dec 2017 11:37:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754857AbdLTLh2 (ORCPT ); Wed, 20 Dec 2017 06:37:28 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:41907 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754875AbdLTLfs (ORCPT ); Wed, 20 Dec 2017 06:35:48 -0500 Received: by mail-wr0-f196.google.com with SMTP id p69so13170995wrb.8 for ; Wed, 20 Dec 2017 03:35:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZkAGFzEAirVrl7IvtACMHJyQILWV2u/lYpz3Jf2npvI=; b=oCdPg/VftRSiMibCI5VSjK2Ij87AI4yKO7+EjdcfKacI2dv1N+C6scHXUu88osQE13 ymCzVJx+wbubiOZL7spfrlij+yFiNiLVuwJO0C8GyJdJfRJ/DRgT9Y9qMljApZjcDtpV H+ml7BPd2Iaj5F/+x7TC+zPI98WXk6yqSgUmOIvEJ1ZxdFmbR+B5JMug7q7T3jZ0+TfY g+wGetWnJnl4rBWsLX6ZN5GlPGuM2gGzDEy6Ag7NqX5BLq6Zlw7/xClfXrPmoqubNqRv taxKvc/1GqljG5VKjI/C2vlJTO2J1Rve6uEB1fV9zHUXRXBJf57/Fbwega7R0su25vSK N44w== X-Gm-Message-State: AKGB3mKQXZ1GklUoe+7Y+ou8wYL1LVJ4B44i7+TKUT5UxPx51sR1FpSe VDvsNPfyWJmPYDnL0+XHPfbbdw== X-Google-Smtp-Source: ACJfBouCXX5k3GviBhPiriXXfRsnZ+o30u5fZ+iJgjTr6LSZLkEmaC69Vz4XRGVg4prVAe5oxQakaA== X-Received: by 10.223.138.197 with SMTP id z5mr7825079wrz.154.1513769747669; Wed, 20 Dec 2017 03:35:47 -0800 (PST) Received: from minerva.home ([90.77.100.34]) by smtp.gmail.com with ESMTPSA id b18sm18353767wra.44.2017.12.20.03.35.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Dec 2017 03:35:47 -0800 (PST) From: Javier Martinez Canillas To: linux-kernel@vger.kernel.org Cc: James Ettle , Hans de Goede , Azhar Shaikh , Javier Martinez Canillas , Arnd Bergmann , Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , Greg Kroah-Hartman , linux-integrity@vger.kernel.org Subject: [PATCH 1/4] tpm: fix access attempt to an already unmapped I/O memory region Date: Wed, 20 Dec 2017 12:35:35 +0100 Message-Id: <20171220113538.16099-2-javierm@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171220113538.16099-1-javierm@redhat.com> References: <20171220113538.16099-1-javierm@redhat.com> Sender: linux-integrity-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The driver maps the I/O memory address to control the LPC bus CLKRUN_EN, but on the error path the memory is accessed by the .clk_enable handler after this was already unmapped. So only unmap the I/O memory region if it will not be used anymore. Also, the correct thing to do is to cleanup the resources in the inverse order that were acquired to prevent issues like these. Signed-off-by: Javier Martinez Canillas Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen --- drivers/char/tpm/tpm_tis_core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c index c2227983ed88..3455abbb2035 100644 --- a/drivers/char/tpm/tpm_tis_core.c +++ b/drivers/char/tpm/tpm_tis_core.c @@ -923,7 +923,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, rc = tpm_chip_register(chip); if (rc && is_bsw()) - iounmap(priv->ilb_base_addr); + goto out_err; if (chip->ops->clk_enable != NULL) chip->ops->clk_enable(chip, false); @@ -931,12 +931,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq, return rc; out_err: tpm_tis_remove(chip); - if (is_bsw()) - iounmap(priv->ilb_base_addr); if (chip->ops->clk_enable != NULL) chip->ops->clk_enable(chip, false); + if (is_bsw()) + iounmap(priv->ilb_base_addr); + return rc; } EXPORT_SYMBOL_GPL(tpm_tis_core_init);