Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2388132ybb; Mon, 30 Mar 2020 05:19:20 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu2sc3qQhfwBrCi8CJksCFfxohRVX7VSJKqQaCJFTUeqrUol4wPQtOcXfhe76DFM5Z5y0+L X-Received: by 2002:a05:6830:18f4:: with SMTP id d20mr9040532otf.91.1585570760536; Mon, 30 Mar 2020 05:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585570760; cv=none; d=google.com; s=arc-20160816; b=Qcyn40nOQ9RLYdBSwOE1COl+wmEmy/Auy/ddjKhLX8iOnCS9WP8drbc44eZauqd6nG zAtrXREyHUxtvYmBzroNRYwEeP8L0p0JlggCs+J9i0/OkjQ8aiM6Kb0Uv3cUG5DIdH7v TzhaqZYXNIwbThxv6c6MoIJFEaGXrGOyKaJ12f/YY4XWBHxnZeJG3YzTMKYckg85eITY FxT/S6PJbD8EiUUjCknta+Rl2a0AJTFwR2XCiV5IlVQ/A3XDZl5px5/QdT0yi6pMwHfb bT9DwG4dvIiWV35eIyUtkkQBWagF4v9fAbYTddNE0mRTs+ho8choal6bD06cVtEk2jtn NDwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NpqkeKOUFjuRdXVQukw9WC0DP/Ab15G+RGVoaBI0Wbc=; b=R9ow1kasHOlgUMyt0C69kS0ZvjSWoqnZSBncZLMKXfYIF/3akMFScqCusDnNE4BWiK g4izaxP/FnL3nhK5gRphMDe0asZfYRpy0NI4yfoRzULMGdx9QEIQi8ygt83nl94NJuLp E88Mug4490P40g8E+xQK0aDqd/uBZJFFJYtGprbn36YiFX+J2sW/7GvgXbR4bwlWW9aI Cs0jqPc/8pT6FNPAfsbMZxtxBOiSaVI7/5nFaN0OYlp3IyZb1VOG5oWjqIoY0UHh8b4M OKYazSzdHaEcH6i+6U5TBOqmlWWlkLEKjEthD7Ryqnb1nIwqaJO/Ts4rmCSLVP3ADh8J pmUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s+OkQu9G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e17si6221480oti.82.2020.03.30.05.19.08; Mon, 30 Mar 2020 05:19:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s+OkQu9G; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730079AbgC3MCK (ORCPT + 99 others); Mon, 30 Mar 2020 08:02:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:48350 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729669AbgC3MCK (ORCPT ); Mon, 30 Mar 2020 08:02:10 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0866020716; Mon, 30 Mar 2020 12:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1585569729; bh=47YsEWohAAs8MnT+k+kCYLDngMt9bFmeSZqLlVeipBE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s+OkQu9Gxp3v9mVaZy+WheTLpcDUNSzWO04A1k4JJdtMtmhosdksnERIsGCBI3HGR z4R9rqs5dIVOjhdqzHZMCbQitophlX/XAvaL3+9ercT7sNKyLwn0um85JWEqylyg48 RYYcN/z48VYK1n+rlBHKSFHvFKbQKd/gms59EfCA= Date: Mon, 30 Mar 2020 14:02:07 +0200 From: Greg KH To: madhuparnabhowmik10@gmail.com Cc: hariprasad.kelam@gmail.com, colin.king@canonical.com, tony.olech@elandigitalsystems.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, andrianov@ispras.ru Subject: Re: Possible data-race related bug in u132_hcd module. Message-ID: <20200330120207.GA2807@kroah.com> References: <20200330115243.11107-1-madhuparnabhowmik10@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200330115243.11107-1-madhuparnabhowmik10@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 30, 2020 at 05:22:43PM +0530, madhuparnabhowmik10@gmail.com wrote: > Hi, > > This bug is found by? Linux Driver Verification project (linuxtesting.org). > > The bug is related to the parallel execution of u132_probe() function and?u132_hcd_exit() function in u132_hcd.c. In case the module is unloaded when the probe function is executing there can be data race as the mutex lock?u132_module_lock is not used properly.? Please note that module unloading, while a nice thing to have, is never something that happens automatically :) > i) Usage of mutex lock only when writing into the u132_exiting variable in?u132_hcd_exit(). The lock is not used when this variable is read in?u132_probe(). > > Moreover, this variable does not serve its?purpose, as even if locking?is used while the u132_exiting variable is read in probe(), the function may still miss that exit function is executing if it acquires the mutex before exit() function does. > > How to fix this? > > ii) Usage of mutex while adding entries in?u132_static_list in probe function but not in exit function while unregistering. > This should be easy to fix by holding the mutex in the exit function as well. > > There can be other synchronization problems related to the usage of u132_module_lock in this module, I have only spotted these so far. > > Please let me know if this bug report is helpful and I can send a patch fixing it. Please just send a patch, no need to ever ask if you should, that's the best way to report and fix anything. thanks, greg k-h