Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1295698pxv; Thu, 1 Jul 2021 23:40:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0e+ZbOjxO7YAyS84YfEbNFeicwSR4JBMfmAbm8i0WtYUwdh9f7fpu7jR09VuT33oFGP4o X-Received: by 2002:a02:b388:: with SMTP id p8mr2972385jan.88.1625208021733; Thu, 01 Jul 2021 23:40:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625208021; cv=none; d=google.com; s=arc-20160816; b=EQjFQOdKpLwYNbsKorkiMUHBNaCPzVtGqqF1F9n0txsGsWhH1PZw69t284u7F+7ubj TA4Yq4XzSEulGrnb9cWRJ3e/QYAz2sj/aGMsaHGwG8fHF/jEelmia8vwdf5s8cRHsxuP QpN6fIxTO9LcK2dlkmYbCrOsfVs5xEX9yrtnEd+NzftfTI/cYRNI2XEwhXuG5Qmhsbdk bwnA7sJM8bihJwbuMh3zygtIVX4oZX3Rjo8cTVaWD1PhQxf/aDJC+60U1TGNH+PM/AbM EqyyfBTOx9OscsZIkqKIJX3PCclyGxI91LRJpDmTk05x7DRjPqy9Tmhrng+2OULMhapV 23iw== 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=cBN6hQKzqa1/wNiy5ngK9DyiIbmdqSPf7A0zVhXH9fc=; b=W8HiJkr3DZ9xrHIaDrHBGSwpJdjswkT2dm4UwnfEhLCSqC+d6cePABTIvfE7DcN/TG PZYm773LE0hSx4G2GcMvZXWhpFhSTva2d14/jrpnHtvZYEBOKzGPM9Cf4RKcVuRpM+Me s4CKXkVFURMnpwk2t1AGcLiZ0VVTihFhnRp2+DEnjkgHtPfc7UdFgP+3ZL+G69WNV06H RRJbhF3okqraP9+MGB7tL8mL03L2P3a5HLZazly/KLTJyhNkRnMuNqvSDjgN4VYntDt6 Ek9hu9cquVs4pwda/dVg2aAFnW4yVTPnwWHYbSWWLciAe3GBpwgjHJ9U9W9fqxWKu/gd cd4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cEZKplZt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si2093551ilo.50.2021.07.01.23.40.09; Thu, 01 Jul 2021 23:40:21 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cEZKplZt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230034AbhGBGl2 (ORCPT + 99 others); Fri, 2 Jul 2021 02:41:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:40986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbhGBGl1 (ORCPT ); Fri, 2 Jul 2021 02:41:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E08A613FB; Fri, 2 Jul 2021 06:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625207936; bh=JyTuKCLD1I+mEBP/UUmCbI9VqTb4ZjTS2241I8Zw7m8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=cEZKplZtL8srXuLJGv/iX8oV+tZDjo1cheBCKnXUX++bzqX7mZnYYaWm8Jm8hvWx5 L54VLWSk/tMt/F29Pv77LKoK+9GGTpBqW583/Gks9PiZXUhuQN9j6zAZFwz8cAllFC zGzuIqJqVKUcAMstY6P8eT3alh2rj8DEdquTIjRcbg+UYA3QeYpG6D68J4FhBIS2E6 5oRneLbF1t9VIC5b+FSnEFqCnEcHVED638x+FJmWdDN9cOgJJGeAtiyxJpNWBpZTzy uEzM+IYnsMcREGx8DZ47EzTMJEMt1NFY0Z5c2qSS//pkUguHD2SVUZTnES+Uf0vXjo JD2PpjKD5QdEQ== Date: Fri, 2 Jul 2021 09:38:53 +0300 From: Jarkko Sakkinen To: Saubhik Mukherjee Cc: peterhuewe@gmx.de, jgg@ziepe.ca, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org, andrianov@ispras.ru Subject: Re: [PATCH] char: tpm: vtpm_proxy: Fix race in init Message-ID: <20210702063853.x27z6yzsdxp7u4y6@kernel.org> References: <20210623132226.140341-1-saubhik.mukherjee@gmail.com> <20210629172700.yxqnedbayumo5f24@kernel.org> <20210629210524.hze6yb23pps3flnv@kernel.org> <2b7d8d44-791e-284a-a700-5465fbc2c100@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2b7d8d44-791e-284a-a700-5465fbc2c100@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 30, 2021 at 12:54:30PM +0530, Saubhik Mukherjee wrote: > On 6/30/21 2:35 AM, Jarkko Sakkinen wrote: > > On Tue, Jun 29, 2021 at 08:27:00PM +0300, Jarkko Sakkinen wrote: > > > On Wed, Jun 23, 2021 at 06:52:26PM +0530, Saubhik Mukherjee wrote: > > > > vtpm_module_init calls vtpmx_init which calls misc_register. The file > > > > operations callbacks are registered. So, vtpmx_fops_ioctl can execute in > > > > parallel with rest of vtpm_module_init. vtpmx_fops_ioctl calls > > > > vtpmx_ioc_new_dev, which calls vtpm_proxy_create_device, which calls > > > > vtpm_proxy_work_start, which could read uninitialized workqueue. > > > > > > > > To avoid this, create workqueue before vtpmx init. > > > > > > > > Found by Linux Driver Verification project (linuxtesting.org). > > > > > > > > Signed-off-by: Saubhik Mukherjee > > > > --- > > > > drivers/char/tpm/tpm_vtpm_proxy.c | 19 +++++++++---------- > > > > 1 file changed, 9 insertions(+), 10 deletions(-) > > > > > > > > diff --git a/drivers/char/tpm/tpm_vtpm_proxy.c b/drivers/char/tpm/tpm_vtpm_proxy.c > > > > index 91c772e38bb5..225dfa026a8f 100644 > > > > --- a/drivers/char/tpm/tpm_vtpm_proxy.c > > > > +++ b/drivers/char/tpm/tpm_vtpm_proxy.c > > > > @@ -697,23 +697,22 @@ static int __init vtpm_module_init(void) > > > > { > > > > int rc; > > > > - rc = vtpmx_init(); > > > > - if (rc) { > > > > - pr_err("couldn't create vtpmx device\n"); > > > > - return rc; > > > > - } > > > > - > > > > workqueue = create_workqueue("tpm-vtpm"); > > > > if (!workqueue) { > > > > pr_err("couldn't create workqueue\n"); > > > > - rc = -ENOMEM; > > > > - goto err_vtpmx_cleanup; > > > > + return -ENOMEM; > > > > + } > > > > + > > > > + rc = vtpmx_init(); > > > > + if (rc) { > > > > + pr_err("couldn't create vtpmx device\n"); > > > > + goto err_destroy_workqueue; > > > > } > > > > return 0; > > > > -err_vtpmx_cleanup: > > > > - vtpmx_cleanup(); > > > > +err_destroy_workqueue: > > > > + destroy_workqueue(workqueue); > > > > return rc; > > > > } > > > > -- > > > > 2.30.2 > > > > > > > > > > > > > > Reviewed-by: Jarkko Sakkinen > > > > Taking reviewed-by back. > > > > You're lacking fixes tag. Please re-send with one. > > > > /Jarkko > > > > Thank you for noticing. I sent the patch containing the Fixes tag in reply > to your last message. (https://lkml.org/lkml/2021/6/30/104) Please do not do that. Instead, version your patches (git format-patch -vX) and send them as separate threads. It's all documented: https://www.kernel.org/doc/html/v5.13/process/submitting-patches.html /Jarkko