Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1037107imm; Wed, 4 Jul 2018 10:16:11 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfUblYQEGwlxyCfj5Mrquw5S3VrBi+0qYR/F27jM6yRCZp82vGjQ4bQkPkoL1zqRWyYwa58 X-Received: by 2002:a65:44c3:: with SMTP id g3-v6mr2651132pgs.231.1530724571495; Wed, 04 Jul 2018 10:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530724571; cv=none; d=google.com; s=arc-20160816; b=ViquS4n3DIgVF9XficlZ+s1iYwfpLPiysvU96OvTY4hBBNHCB4QVvsnR8jvaA5i9vk 4IGsSLjhBGwjoSIaGHvlcdZ29ivPQ3iTambcTsuV5kPz0EigGuf9l+SDtoDBugPLl4Kh +skEu44sg37Kx/bYVgyzrVkzd6zehWvbqXOtvToiEoCFRmlId1u0oNPv3YXTKFZyf7gw FnxcQPLGzb/V/E/6tcNsMYhBEUniDijOLEkVYBgW98M4HJra4CMzP6Ql1uPMnKFUNNd/ GWErZWoVKcDOSROSRggRZclsTQcfOEKPoHuGuJMQX2AxXU5o2zP3kyOSoqWo1NPRcEjg IZeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=ntqcqPXF217R3RxT4vOvfQUh7oer2nBFyoGxO1e1mQg=; b=zT8Kjohd3jW1UhUdEvL1Pkrp+S/LtvuNNk/KinCEZK0Umf9HMBslLfDZmylGTgrD6u pNmsLSRklCS6BB5+x2aA+uguqkvnoDEQvCCX72MHk88ZCcMF51FZ7keNPvFHIfOe9gTP 77Pq1ZQAlv/bWTmpFQXo3pybvmwyqJhH0aQTjG7bskWQCQemiix86XfnyMrWrzFmFdH4 a/FzOD/EL2NUh4sWSlVBYzCCJXoSCJF74IONfnP4+BMpBW1Ij5hF9Pfb+xes70BShGs+ h60L+60be62xNeOjz2EAiLO5Czaw+OA65b1qTRd+HquIM4IrX189V80T9ueG9nvOj9/B c7Bw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n123-v6si4118368pfn.9.2018.07.04.10.15.56; Wed, 04 Jul 2018 10:16:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753049AbeGDROS (ORCPT + 99 others); Wed, 4 Jul 2018 13:14:18 -0400 Received: from mga18.intel.com ([134.134.136.126]:22812 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752567AbeGDROQ (ORCPT ); Wed, 4 Jul 2018 13:14:16 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 10:14:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,306,1526367600"; d="scan'208";a="72260956" Received: from saamir-mobl.ger.corp.intel.com (HELO localhost) ([10.252.34.242]) by orsmga002.jf.intel.com with ESMTP; 04 Jul 2018 10:13:58 -0700 Date: Wed, 4 Jul 2018 20:13:57 +0300 From: Jarkko Sakkinen To: Shirish S Cc: linux-integrity@vger.kernel.org, Peter Huewe , Jason Gunthorpe , Arnd Bergmann , Greg Kroah-Hartman , open list Subject: Re: [PATCH] tpm: Fix NULL pointer dereference in tpm_transmit() Message-ID: <20180704171357.GB6724@linux.intel.com> References: <1530695020-21888-1-git-send-email-shirish.s@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1530695020-21888-1-git-send-email-shirish.s@amd.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 04, 2018 at 02:33:40PM +0530, Shirish S wrote: > During system shutdown, > tpm_class_shutdown() when called with TPM_CHIP_FLAG_TPM2 > flag set, makes chip->ops NULL. > > However tpm_chip_unregister() called later in shutdown > sequence tries to access chip->ops in tpm_try_transmit() > leading the NULL pointer dereference. > > This patch fixes this issue. > Below is the trace for reference: > > BUG: unable to handle kernel NULL pointer dereference at > 0000000000000048 > IP: tpm_transmit+0x267/0x565 > PGD 0 P4D 0 > Oops: 0000 [#1] PREEMPT SMP NOPTI > ... > task: ffff937c847fe580 task.stack: ffffa79f80b04000 > RIP: 0010:tpm_transmit+0x267/0x565 > RSP: 0018:ffffa79f80b07c08 EFLAGS: 00010286 > RAX: 0000000000000000 RBX: ffff937ca9bc8000 RCX: ffff937c847fe580 > RDX: 0000000000000000 RSI: 0000000000000002 RDI: ffffffff98e3cd40 > RBP: ffffa79f80b07c88 R08: 000000000001fff4 R09: 0000000000000000 > R10: 0000000000000000 R11: 0000000000000000 R12: ffffa79f80b07cd4 > R13: 000000000000008c R14: ffffffffffffffc3 R15: 0000000000000000 > FS: 00007ef31f747740(0000) GS:ffff937caed00000(0000) > knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 0000000000000048 CR3: 00000001243d2000 CR4: 00000000001406e0 > Call Trace: > tpm_transmit_cmd+0x25/0x70 > tpm2_shutdown+0x69/0xa3 > ? __radix_tree_replace+0xd9/0x120 > ? idr_replace_ext+0x92/0xb6 > tpm_chip_unregister+0xaa/0xdb > cr50_i2c_shutdown+0x1e/0x41 > device_shutdown+0x157/0x193 > kernel_power_off+0x35/0x6e > SYSC_reboot+0x120/0x1a3 > ? do_writepages+0x36/0x6e > ? do_writepages+0x36/0x6e > ? sync_inodes_one_sb+0x17/0x17 > ? _raw_spin_unlock+0xe/0x20 > ? iput+0x87/0x1bd > do_syscall_64+0x64/0x72 > entry_SYSCALL_64_after_hwframe+0x3d/0xa2 > > Signed-off-by: Shirish S > --- > drivers/char/tpm/tpm-interface.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c > index e32f6e8..b14d196 100644 > --- a/drivers/char/tpm/tpm-interface.c > +++ b/drivers/char/tpm/tpm-interface.c > @@ -411,6 +411,14 @@ static ssize_t tpm_try_transmit(struct tpm_chip *chip, > unsigned long stop; > bool need_locality; > > + /* chip->ops is made NULL in tpm_class_shutdown() > + * This case is hit when tpm_chip_unregister() is called post > + * tpm_class_shutdown(), hence exit early and return > + * transmit operation not permitted > + */ > + if (!chip->ops) > + return -EPERM; > + > rc = tpm_validate_command(chip, space, buf, bufsiz); > if (rc == -EINVAL) > return rc; > -- > 2.7.4 > What is cr50 anyway? /Jarkko