Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1253512rwl; Wed, 29 Mar 2023 15:08:40 -0700 (PDT) X-Google-Smtp-Source: AKy350Y4kLf3oDywDLjS+tPVl1JtRF4GwhHcknO+n7iSTUknMfpQlw42COUZQLkjLsGyWXFKGpsX X-Received: by 2002:a62:4e10:0:b0:5a8:aca5:817d with SMTP id c16-20020a624e10000000b005a8aca5817dmr18371961pfb.5.1680127720313; Wed, 29 Mar 2023 15:08:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680127720; cv=none; d=google.com; s=arc-20160816; b=N2hPVaExT1LEPD1+AYluLhiqHlVMOEaO+1WdMHPdgFrbU2TFLuMCzLnXVPJb6vsguL X6u9TOkci9Mig3c2EHloL8mtV2Y3i+Dx3bFjMcIUcyPtVaElkm20NSjNp5JVE9x9B1y1 52iVZQ0FafpmMFzJMPNPo8961pTlBybJj8LDBKDZDmReq6Z4SCVaO1v7xPofHIDBjwky 6Ig7PVSUA5zAIg2Q6ZFQSHEg+YHiRujbwiXuN3rcKYlooyuHrKe1IXUV+76YNvR1UrWM dnNVK+F5YnQn1Eyijm/9aT+HVLa5/su80nG/bNhnXyiHbiI5QU2o+eeKPhijA/JrrXjb b/vw== 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=EgDze7aqZ1Q+5qYyPYloWez6eQaGaY6kU4+L6XMLTL4=; b=zqc8eBcLracQr6Q+j5+/Hitv01XHBbdsu7ODbEadW6TRpmdjx6Omvmd3aPguu3YKsE tAa3+gN+pfirZu/KzCzx+pf41GUiDawCtz6jvLYv7RQYSBeYndUxOsVSs/iQkg8WKAQb KAxb22bD3IVVStRWQU+b2YNTptNisYiARJptUEuF3blmrUJWr6zJsPOzR+mPfJLFCybQ H5QiO5IyNqEhtzArPb8bVi30WgpCeXXJhZs0PoNxCvz8LF+ddPwGfYWdIUp0Vge29T7K Q6xdoyRes7OQWOsfUqJ7XP3nJUdnnXAOKIIz4R607Rz2VXSNtk186pRYJpUiO1uFzxyM dpOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=H8XGfUKP; 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 k4-20020aa788c4000000b005ee01126a92si21397263pff.120.2023.03.29.15.08.25; Wed, 29 Mar 2023 15:08:40 -0700 (PDT) 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=H8XGfUKP; 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 S230096AbjC2V7J (ORCPT + 99 others); Wed, 29 Mar 2023 17:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjC2V7I (ORCPT ); Wed, 29 Mar 2023 17:59:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C72F4215; Wed, 29 Mar 2023 14:59:07 -0700 (PDT) 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 ADAF661E30; Wed, 29 Mar 2023 21:59:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C155CC433EF; Wed, 29 Mar 2023 21:59:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680127146; bh=iEM/0Fm3C9Mz+VkwKIyILQMrriOXiXAyc5Zvgo+7W14=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H8XGfUKPdcGGSEWAtahG1IWSCbT1OXW33pR8xCDXoaHTDCzc8wQlwwJ+qIzBP3tsQ fMRos4lgbJY2ptbIp2gRxlFblq+1ECVJrlYOKPm4PqnF7LfxaO9BJkpF51eiFmwj6y Rs0unKPWq/ylYCcm30+3McqZLildXpd8k/SQ7xRO5WKOtmkEj6dwm6PutWnr9gK7hJ kb7LMnPVw4JI8EKrVbpNi69H846oAZorNfa/Xfd2IdNTkHvB31LvW/8nozFVosHW3j SLQHQvF3uEMWXiZhcbhIq2n1TwbPndIK0U+aJC6e8u8YxRRubVrgdhJ5FBoBldgYr7 MBYJHP3bzSZXw== Date: Thu, 30 Mar 2023 00:59:03 +0300 From: Jarkko Sakkinen To: Harshit Mogalapalli Cc: error27@gmail.com, Peter Huewe , Jason Gunthorpe , Greg Kroah-Hartman , linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH next] tpm: Fix a possible dereference of ERR_PTR in tpm_init() Message-ID: <20230329215903.632cn3lrkpi3lz2p@kernel.org> References: <20230321061416.626561-1-harshit.m.mogalapalli@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230321061416.626561-1-harshit.m.mogalapalli@oracle.com> X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=unavailable 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 Mon, Mar 20, 2023 at 11:14:15PM -0700, Harshit Mogalapalli wrote: > Smatch reports: > drivers/char/tpm/tpm-interface.c:470 tpm_init() error: > 'tpm_class' dereferencing possible ERR_PTR() > > If class_create() returns error pointer, we are dereferencing a possible > error pointer. Fix this by moving the dereference post error handling. > > Fixes: a010eb881243 ("tpm: fix up the tpm_class shutdown_pre pointer when created") > Signed-off-by: Harshit Mogalapalli > --- > This is based on static analysis, only compile tested. > --- > drivers/char/tpm/tpm-interface.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c > index 43e23a04433a..4463d0018290 100644 > --- a/drivers/char/tpm/tpm-interface.c > +++ b/drivers/char/tpm/tpm-interface.c > @@ -467,12 +467,13 @@ static int __init tpm_init(void) > int rc; > > tpm_class = class_create("tpm"); > - tpm_class->shutdown_pre = tpm_class_shutdown; > if (IS_ERR(tpm_class)) { > pr_err("couldn't create tpm class\n"); > return PTR_ERR(tpm_class); > } > > + tpm_class->shutdown_pre = tpm_class_shutdown; > + > tpmrm_class = class_create("tpmrm"); > if (IS_ERR(tpmrm_class)) { > pr_err("couldn't create tpmrm class\n"); > -- > 2.38.1 > Reviewed-by: Jarkko Sakkinen BR, Jarkko