Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp469085ybt; Fri, 10 Jul 2020 04:43:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1qwllOyxZxDB81Nl9xaBU6JsNZS4lu3NPZYOsbbz6yw7QGgHMKQM3e3vgWmf8wVVpdG5a X-Received: by 2002:a17:906:70cf:: with SMTP id g15mr42065042ejk.531.1594381383322; Fri, 10 Jul 2020 04:43:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594381383; cv=none; d=google.com; s=arc-20160816; b=CvYNQiD/t07RB47zKwHFdcF/DxfmVZIgRG5fId2MclJ4Gs7BgPpvVtiRsZgtga4RJm H778CTqp4SzksBud2DYqBBjZYQLuHbybLEXTFJv8JFRExCRRIMR2A2z2f8JtU3ILiPY9 k1PEptImGloI4kSJXGMmsqwXxCSk/xnWOrk1fEYGR2zOH1U9icunvCmXxWekr7M1Fg9K 3f/0gwO84zV3Nd2/fh9QB5CZCw8dFWBpaS1log/3SXaafiKBRUk1bBrX/6OSEAfV/ZYE dgCK38pv7tac8ZYofw4ukRpRtQxMh9gHF+4FE5MpkYB9S7s9+/HJDWSG8nVkVcpWUJib y0kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=2zbYOPHRKjPZtjvqEJ10oaRL9G6l/o7FLkr1c+C60+4=; b=abSdykqmZrifPHXar7VJJ3xonZ3XronK0Pa7K4OInlaVPvGGX1E2dG8bcHG2aWdBRO 8zEL/VdpbzoUP2vfiWYAsuqtPlgLMN6PYr+J9t7aYNSFXwfiPtKm96A3pH0vF+3ozrgw bsmk+67VDtbNdDP5FfFtEqELmO38mSXWUhC4JGBtP0cLIGhmuEXOPaHYLlbOr1LZE3OB P71LP0suY5+zCmy4ZxA3YXmy3ULU1WZbWea+7JhkCktNK7+SgisPAoLnrCltDgH85pGw Pr2vHxhr70WMfleMQuEm0mff02Oo+igTwNghVD1os1l82V3zr9Hmi5U2oNi1SR92fCQb c70Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id r8si4258419edl.19.2020.07.10.04.42.40; Fri, 10 Jul 2020 04:43:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1727828AbgGJLkH (ORCPT + 99 others); Fri, 10 Jul 2020 07:40:07 -0400 Received: from mga03.intel.com ([134.134.136.65]:53565 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726828AbgGJLkF (ORCPT ); Fri, 10 Jul 2020 07:40:05 -0400 IronPort-SDR: aJV7CgbdijTx+fy6IFDRB2UdxlZaj0XJbQw7d9tFBky2fNsj89MzXPeN5nLHtbZibBCOMJ0UKq Ki810C6ww1Dg== X-IronPort-AV: E=McAfee;i="6000,8403,9677"; a="148173814" X-IronPort-AV: E=Sophos;i="5.75,335,1589266800"; d="scan'208";a="148173814" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jul 2020 04:40:04 -0700 IronPort-SDR: GgUGeJx380Kb043Ycq+vOjyyyY2kot0/3TdLXU2AGXiqyVLKWd5yRL/sqOaCsjJoPfu0fEcd/O T20s/oE8UqBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,335,1589266800"; d="scan'208";a="324588693" Received: from taverna-mobl.ger.corp.intel.com (HELO localhost) ([10.252.53.137]) by orsmga007.jf.intel.com with ESMTP; 10 Jul 2020 04:40:01 -0700 Date: Fri, 10 Jul 2020 14:40:00 +0300 From: Jarkko Sakkinen To: Andrey Pronin Cc: peterhuewe@gmx.de, jgg@ziepe.ca, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, groeck@chromium.org Subject: Re: [PATCH] tpm: avoid accessing cleared ops during shutdown Message-ID: <20200710114000.GD2614@linux.intel.com> References: <20200710002209.6757-1-apronin@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200710002209.6757-1-apronin@chromium.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 09, 2020 at 05:22:09PM -0700, Andrey Pronin wrote: > This patch prevents NULL dereferencing when using chip->ops while > sending TPM2_Shutdown command if both tpm_class_shutdown handler and > tpm_del_char_device are called during system shutdown. > > Both these handlers set chip->ops to NULL but don't check if it's > already NULL when they are called before using it. > > This issue was revealed in Chrome OS after a recent set of changes > to the unregister order for spi controllers, such as: > b4c6230bb0ba spi: Fix controller unregister order > f40913d2dca1 spi: pxa2xx: Fix controller unregister order > and similar for other controllers. I'm not sure I fully understand the scenario. When does thi happen? Why does not tpm_del_char_device need this? The changes listed tell me nothing. Why they have this effect? I'm just trying to understand whether this could be a regression or not. I neither understand what you mean by "and similar for other controllers." NAK for the reason that I don't understand what I'm merging. /Jarkko > > Signed-off-by: Andrey Pronin > --- > drivers/char/tpm/tpm-chip.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c > index 8c77e88012e9..a410ca40a3c5 100644 > --- a/drivers/char/tpm/tpm-chip.c > +++ b/drivers/char/tpm/tpm-chip.c > @@ -296,7 +296,7 @@ static int tpm_class_shutdown(struct device *dev) > struct tpm_chip *chip = container_of(dev, struct tpm_chip, dev); > > down_write(&chip->ops_sem); > - if (chip->flags & TPM_CHIP_FLAG_TPM2) { > + if (chip->ops && (chip->flags & TPM_CHIP_FLAG_TPM2)) { > if (!tpm_chip_start(chip)) { > tpm2_shutdown(chip, TPM2_SU_CLEAR); > tpm_chip_stop(chip); > @@ -479,7 +479,7 @@ static void tpm_del_char_device(struct tpm_chip *chip) > > /* Make the driver uncallable. */ > down_write(&chip->ops_sem); > - if (chip->flags & TPM_CHIP_FLAG_TPM2) { > + if (chip->ops && (chip->flags & TPM_CHIP_FLAG_TPM2)) { > if (!tpm_chip_start(chip)) { > tpm2_shutdown(chip, TPM2_SU_CLEAR); > tpm_chip_stop(chip); > -- > 2.25.1 >