Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2515421pxp; Mon, 7 Mar 2022 17:38:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJyMlYecfNGbQ/gkZ2RMTIU+BsX05E8joXbNETs8IRvlH4D77RhavLiMuCj146taPJDxatHK X-Received: by 2002:a17:906:19c6:b0:6ce:98a4:5ee6 with SMTP id h6-20020a17090619c600b006ce98a45ee6mr10863945ejd.567.1646703511639; Mon, 07 Mar 2022 17:38:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646703511; cv=none; d=google.com; s=arc-20160816; b=q4RlBLwtRI5JBzLD6//i54qtYCV0O1N+iyo/rTcAi4KN55GY9ypkxUJ8rK3qq+x8Hg pXnUgMECfcr1nkSK0C4bh1ntRQvCK7P8rlRwb5lxKC5oBUq1gbkWMAYkWJpr9+08tv9p h6GPmvgNychuCh+X0rVARHTYpmM0FLWX/wT4QAQBrT21pN5mbEnccoWtoJcsnnZcJ/ry QcQ8ogsVg9YgkFLBY4/nxAtlJiCvn/OG61GjW78YNLuFZ/dSIRGjGwye5x12eI2A7/QH EcVw2bhD+ON+ZnRXgW2d7l6T34+Vme4MZgwDrp9gmpJHO46UePtCr0HRhnzEEkYaN/Dk gS6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:date:cc:to:from:subject:message-id:dkim-signature :dkim-signature; bh=BzE63vs6WT7QVNGgq1e43uane0ZvJe2J5cyAo86acFw=; b=TuQxVvP+B1rdiELcoUmL9oKgAu3xrS+cMLRAqXkv61J/B7v3Y6YEaMbYQQT/NUstdF ce1Pg4/wYC1LmmVFW1rsURWL/n4LsmgjQl+0jy1IUF7SprR0X3oDfTUgz3L0Fwa4B8A7 JqHZT/6632KKPhLw1M8hmSa8dM5on4IrPaUWM3UV8VpsyPz5cjURuVDttoYKWxuR5wDl +I6TtCf28l3ZXhJaqe1/yPJg7aEh8i896oygiEUzh0cOJHxwRlkFSmGjWaJ6q1/ypK8c +IiNQXfhUQnztH713kJvHFawoljEPlmRcIsv15699btzduNAhDNkIGO/s7GGKYRfNVGs 6f8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=UD85TI7V; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=UD85TI7V; 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=hansenpartnership.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ek18-20020a056402371200b004159b8a598bsi8459111edb.185.2022.03.07.17.38.04; Mon, 07 Mar 2022 17:38:31 -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=@hansenpartnership.com header.s=20151216 header.b=UD85TI7V; dkim=pass header.i=@hansenpartnership.com header.s=20151216 header.b=UD85TI7V; 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=hansenpartnership.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245443AbiCGU7D (ORCPT + 99 others); Mon, 7 Mar 2022 15:59:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236691AbiCGU7B (ORCPT ); Mon, 7 Mar 2022 15:59:01 -0500 Received: from bedivere.hansenpartnership.com (bedivere.hansenpartnership.com [IPv6:2607:fcd0:100:8a00::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB493DEF9; Mon, 7 Mar 2022 12:58:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1646686686; bh=pqCW5Q4jBooVQ4Ak0RS+cgqbLH7tCSHyZBzKzD6KeGM=; h=Message-ID:Subject:From:To:Date:From; b=UD85TI7VFQmmhulPSuKnt7aFjqdyDITLIZmpoOx8lpePZerV/t1J5fi2gTqQ1JRPS OMxKDei+Rl+xHHNr4QIBrAdW1qr2O3S+VhicYmW4ih4VPFbYCqGq+fJ5MuZGB1QQus X/tEYMoVZ3Q5LuptRyfo/vJ7gFsCkXCqJvf0erkw= Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id 48F9D1281471; Mon, 7 Mar 2022 15:58:06 -0500 (EST) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nnGsnpXZNI1N; Mon, 7 Mar 2022 15:58:06 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=hansenpartnership.com; s=20151216; t=1646686686; bh=pqCW5Q4jBooVQ4Ak0RS+cgqbLH7tCSHyZBzKzD6KeGM=; h=Message-ID:Subject:From:To:Date:From; b=UD85TI7VFQmmhulPSuKnt7aFjqdyDITLIZmpoOx8lpePZerV/t1J5fi2gTqQ1JRPS OMxKDei+Rl+xHHNr4QIBrAdW1qr2O3S+VhicYmW4ih4VPFbYCqGq+fJ5MuZGB1QQus X/tEYMoVZ3Q5LuptRyfo/vJ7gFsCkXCqJvf0erkw= Received: from jarvis.int.hansenpartnership.com (unknown [IPv6:2601:5c4:4300:c551::527]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bedivere.hansenpartnership.com (Postfix) with ESMTPSA id 5CBC1128111C; Mon, 7 Mar 2022 15:58:05 -0500 (EST) Message-ID: <3953c743ce7e7fc1db26f5b849b53df671b2f221.camel@HansenPartnership.com> Subject: [PATCH] tpm: use try_get_ops() in tpm-space.c From: James Bottomley To: Jarkko Sakkinen Cc: Sergey Temerkhanov , Peter Huewe , Jason Gunthorpe , Jerry Snitselaar , linux-integrity@vger.kernel.org, linux-kernel Date: Mon, 07 Mar 2022 15:58:03 -0500 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,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 As part of the series conversion to remove nested TPM operations: https://lore.kernel.org/all/20190205224723.19671-1-jarkko.sakkinen@linux.intel.com/ exposure of the chip->tpm_mutex was removed from much of the upper level code. In this conversion, tpm2_del_space() was missed. This didn't matter much because it's usually called closely after a converted operation, so there's only a very tiny race window where the chip can be removed before the space flushing is done which causes a NULL deref on the mutex. However, there are reports of this window being hit in practice, so fix this by converting tpm2_del_space() to use tpm_try_get_ops(), which performs all the teardown checks before acquring the mutex. Signed-off-by: James Bottomley Reviewed-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2-space.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/char/tpm/tpm2-space.c b/drivers/char/tpm/tpm2-space.c index 265ec72b1d81..ffb35f0154c1 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); } -- 2.34.1