From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752916AbbIHUSP (ORCPT ); Tue, 8 Sep 2015 16:18:15 -0400 Received: from shards.monkeyblade.net ([149.20.54.216]:54636 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752393AbbIHUSM (ORCPT ); Tue, 8 Sep 2015 16:18:12 -0400 Date: Tue, 08 Sep 2015 13:18:08 -0700 (PDT) Message-Id: <20150908.131808.2080207445306948902.davem@davemloft.net> To: eugene.shatokhin@rosalab.ru Cc: oneukum@suse.de, bjorn@mork.no, netdev@vger.kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] usbnet: Fix a race between usbnet_stop() and the BH From: David Miller In-Reply-To: <1441116333-5377-1-git-send-email-eugene.shatokhin@rosalab.ru> References: <1441094336.3328.1.camel@suse.com> <1441116333-5377-1-git-send-email-eugene.shatokhin@rosalab.ru> X-Mailer: Mew version 6.7 on Emacs 24.5 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Tue, 08 Sep 2015 13:18:11 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eugene Shatokhin Date: Tue, 1 Sep 2015 17:05:33 +0300 > The race may happen when a device (e.g. YOTA 4G LTE Modem) is > unplugged while the system is downloading a large file from the Net. > > Hardware breakpoints and Kprobes with delays were used to confirm that > the race does actually happen. > > The race is on skb_queue ('next' pointer) between usbnet_stop() > and rx_complete(), which, in turn, calls usbnet_bh(). > > Here is a part of the call stack with the code where the changes to the > queue happen. The line numbers are for the kernel 4.1.0: ... > As a result, it is possible, for example, that the skb is removed from > dev->rxq by __skb_unlink() before the check > "!skb_queue_empty(&dev->rxq)" in usbnet_terminate_urbs() is made. It is > also possible in this case that the skb is added to dev->done queue > after "!skb_queue_empty(&dev->done)" is checked. So > usbnet_terminate_urbs() may stop waiting and return while dev->done > queue still has an item. > > Locking in defer_bh() and usbnet_terminate_urbs() was revisited to avoid > this race. > > Signed-off-by: Eugene Shatokhin Applied, thanks.