Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2754364pxp; Tue, 8 Mar 2022 00:48:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJxd3h7z1PHHjh7VLsMzaEuAAptt+QA7G0o1NvSKx+be7rpK6acIb5k/BJWGwWQTMGvFmXep X-Received: by 2002:a17:906:1e13:b0:6ce:e50c:2a9c with SMTP id g19-20020a1709061e1300b006cee50c2a9cmr12315475ejj.546.1646729301772; Tue, 08 Mar 2022 00:48:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646729301; cv=none; d=google.com; s=arc-20160816; b=IdOY41a5swEoFKmNy6N1t860JTv4jwC9L1dWPZN6UEJ0xafiW3C/4Gjsj7P02jHt8c 0LN2PLgL1iE8ORdUtYZ4ojdzTkpQFLxC8YFOZ2WUJf8ctXTGwb49rQIyb0W/2z7xtCdA Y4ULG3tm7nVCvUwYF4bYA4vxKHrawX37BsQ5we0JL30Y6oYRqedUVIVJ1/Qgn3y5WRNu 11edWlRCgOER67uILfQzo4q8g4cq7CzqIrm7sUZSfn/oP2P1AADVNPujE9Z+5FaxzEz4 EVGDG9tFKuZNsEoW0LXWRXioHqJo6rwrMuxrHfTNZj1iJ4fV1ABtYm3Lcd40C6D2qHhk zePg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3AOuN7IalUY5Sg7X9oyDPqjBUBkB0SNA4308hv7hE1Q=; b=zFk5DIWTcibS2Q3EbXZ0IQdi1HiDdDJF1daS5bKb4LtSoG05IZa5Ore+tbKPrO/ags QNcSgOG9Ftpig8L8xRkeT7pKAb3hOFNeVDPxj9szvn4hKYwB4u4vIY1s+IjjlT+mRaq+ FLW8N2J/cxu9D6fy+ilinEQctgJBqq+J+NKoj8zCmfDYuRXUbKm3UsH1YN/5iKOgCbPt 5RBAhXTH47pzYnp7K6TiTeztufq6nnqRf3TBx9tzkgCSvZd7pYwJuJFQytZWDOJUiew+ nHWC271wZNWSntj+iE5/NIAl1M/FA1mU2trJDUwV4dpyW5qIv2J6dU/fBpDHyC6b0bgc YqHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IWGX3p+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v4-20020a50d084000000b004163027e89fsi4951333edd.467.2022.03.08.00.47.59; Tue, 08 Mar 2022 00:48:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IWGX3p+7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243876AbiCGPnO (ORCPT + 99 others); Mon, 7 Mar 2022 10:43:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243924AbiCGPnD (ORCPT ); Mon, 7 Mar 2022 10:43:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5AC176652; Mon, 7 Mar 2022 07:42:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 689B461479; Mon, 7 Mar 2022 15:42:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 67B34C340EB; Mon, 7 Mar 2022 15:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646667727; bh=vwimokoLmujACAs7ILvplWTc17PHeX1/UInnu8gaKw8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IWGX3p+743ArJ22T83/9Z72NRV0Bgp+PWTHxZ+tGuKxnKIvXYX4lEN4ZyEiyCFhRc aVlKCRmHsEbLkPGUorJmFixVg6ri1DTyKti3DlmA8EIbRrjJrghfCtDw3vTC+FOxx/ 3uv3QU4Uc4UY0fBo3fftbiKxCrElM0u5KRWhk1csSDptwopQinmbLr8ojn7lmhOBoO QR+b3ZwJNO1sOXYEMLzQZ+2sfg3IPbCdQSHrJZ45GZSS1CpbE+XKkwMsyhd9ED6CLf t8dM14PHbJ2yFh5LXe+9zNEu2EZvkw7ovZCY1lZL6gvobR0HXt4+M27AyTKz68xVWe t5Rdnboa6AhiA== Date: Mon, 7 Mar 2022 17:41:26 +0200 From: Jarkko Sakkinen To: James Bottomley Cc: Sergey Temerkhanov , Peter Huewe , Jason Gunthorpe , Jerry Snitselaar , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] tpm: Rework open/close/shutdown to avoid races Message-ID: References: <20201215133801.546207-1-s.temerkhanov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 15, 2020 at 10:51:43AM -0800, James Bottomley wrote: > On Tue, 2020-12-15 at 16:38 +0300, Sergey Temerkhanov wrote: > > Avoid race condition at shutdown by shutting downn the TPM 2.0 > > devices synchronously. This eliminates the condition when the > > shutdown sequence sets chip->ops to NULL leading to the following: > > > > [ 1586.593561][ T8669] tpm2_del_space+0x28/0x73 > > [ 1586.598718][ T8669] tpmrm_release+0x27/0x33wq > > [ 1586.603774][ T8669] __fput+0x109/0x1d > > [ 1586.608380][ T8669] task_work_run+0x7c/0x90 > > [ 1586.613414][ T8669] prepare_exit_to_usermode+0xb8/0x128 > > [ 1586.619522][ T8669] entry_SYSCALL_64_after_hwframe+0x44/0xa9 > > [ 1586.626068][ T8669] RIP: 0033:0x4cb4bb > > An actual bug report would have been helpful. However, from this trace > it's easy to deduce that tpm2_del_space() didn't get converted to the > get/put of the chip ops ... it's still trying to do its own half arsed > thing with tpm_chip_start() and the mutex. So isn't a much simpler fix > simply to convert it as below? compile tested only, but if you can > test it out I'll send a proper patch. > > James > > --- > > diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c > index 784b8b3cb903..0c0cd225046f 100644 > --- a/drivers/char/tpm/tpm2-space.c > +++ b/drivers/char/tpm/tpm2-space.c > @@ -58,12 +58,12 @@ int tpm2_init_space(struct tpm_space *space, unsigned int buf_size) > > void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space) > { > - mutex_lock(&chip->tpm_mutex); > - if (!tpm_chip_start(chip)) { > + > + if (tpm_try_get_ops(chip) == 0) { > tpm2_flush_sessions(chip, space); > - tpm_chip_stop(chip); > + tpm_put_ops(chip); > } > - mutex_unlock(&chip->tpm_mutex); > + > kfree(space->context_buf); > kfree(space->session_buf); > } > James, would it possible for you to construct a proper patch from this and send it so we could include it to the next PR (use my tree as baseline)? BR, Jarkko