Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2591256ybb; Mon, 30 Mar 2020 09:05:21 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtr60tUlx2uSTAO3gPwy1H0MUoFBsApWtiDfrs9sqluDxUlV9tHv1DUPSVHZDB6DO60TBpb X-Received: by 2002:aca:ed54:: with SMTP id l81mr10503oih.69.1585584321370; Mon, 30 Mar 2020 09:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585584321; cv=none; d=google.com; s=arc-20160816; b=v4THS5/rUUSM8Q8lq7JYwkJgA0bryxZBnLugkqWmIXaDehyblGkbOu5BUVfSeSBBsT aKQGg1kMA6W/kgeur/j6D2rs8xALPPnIJ1HTZyMhrVxf8QNUb+r+E7Frowlu1ai7to1+ IYh2klweuNX4L9ujwiAokBpn8tfocN74i6w++zSGXHn2UETNOoJVuAyWGnETExq3i2zs U4fawFX5x8yUopvFHoUnG4XhvxV64h36+mLtqbg4wAbqAV1/58xNxoVOUF9oNRrv9/+O d9+AxR1c2mbVqhkEZomnMbbzDTlMomWgy4oOvtTQ8LQmUUONKr5uugdLL4kkWpKRXCLl ZS/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:in-reply-to:subject:cc:to:from:date; bh=B5ibHiPzYIGWlrAcBguaCiD/TjaIPzgVXXJKgEAg/dM=; b=FhG993ESRdnWR9q6Q9d/iLLNn79IZsBLbQLQE4RX9z8LIjjf1KiWX8fVK7xcYgQPjj VEPH2Q5A0LOK2SIWdfTPtM887OkN3N4QQOR04ca4VXR6ya2u7wnZkA8Fg0mkpbXF/jmR UwoZsR0sviwXxGBwX2kvaftigBZzAOs9MBVh82Y5CeVEJDCRmUQDF3/PrTL46G5BGavT jNlJasAD05AsCwGuuKOJRzpvedRU+1RpR1WbjGCP60A9SB85668tVTUuo+1xAmrlteWY K/t/p5es3u76euoNUyoJ1ebWIY7Cb5ZLobu+9+UXh/inyMTLTBr91dzK+NL+kMX58Yoh SKLg== ARC-Authentication-Results: i=1; mx.google.com; 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 j15si6099741oos.59.2020.03.30.09.05.01; Mon, 30 Mar 2020 09:05:21 -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; 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 S1729957AbgC3QDc (ORCPT + 99 others); Mon, 30 Mar 2020 12:03:32 -0400 Received: from netrider.rowland.org ([192.131.102.5]:53487 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1727048AbgC3QDc (ORCPT ); Mon, 30 Mar 2020 12:03:32 -0400 Received: (qmail 20357 invoked by uid 500); 30 Mar 2020 12:03:31 -0400 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 30 Mar 2020 12:03:31 -0400 Date: Mon, 30 Mar 2020 12:03:31 -0400 (EDT) From: Alan Stern X-X-Sender: stern@netrider.rowland.org To: madhuparnabhowmik10@gmail.com cc: gregkh@linuxfoundation.org, , , , , , Subject: Re: Possible data-race related bug in u132_hcd module. In-Reply-To: <20200330115243.11107-1-madhuparnabhowmik10@gmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 30 Mar 2020 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.  Normally drivers do not have to worry about races between their probe and exit routines. The exit routine should unregister the driver from its bus subsystem, and unregistration is supposed to wait until all probe and remove functions have finished executing. > 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(). I'm not familiar with u132_hcd, but the probe routine shouldn't need to use and "exiting" variable at all. > > 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? Are you certain there really is a problem? > 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. Why does the driver need a static list? > There can be other synchronization problems related to the usage of > u132_module_lock in this module, I have only spotted these so far. You should look at other drivers for comparison. They don't have to face this kind of problem. u132_hcd should be similar to them. Alan Stern