From patchwork Tue Jun 14 13:16:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Andrianov X-Patchwork-Id: 9175917 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 91F7F60573 for ; Tue, 14 Jun 2016 14:20:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 834C226490 for ; Tue, 14 Jun 2016 14:20:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 78468282ED; Tue, 14 Jun 2016 14:20:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90F8726490 for ; Tue, 14 Jun 2016 14:20:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751571AbcFNOTx (ORCPT ); Tue, 14 Jun 2016 10:19:53 -0400 Received: from mail.ispras.ru ([83.149.199.45]:41973 "EHLO mail.ispras.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750762AbcFNOTw (ORCPT ); Tue, 14 Jun 2016 10:19:52 -0400 Received: from carpenter.intra.ispras.ru (pluton2.ispras.ru [83.149.199.44]) by mail.ispras.ru (Postfix) with ESMTPSA id 63B9154006A; Tue, 14 Jun 2016 17:19:48 +0300 (MSK) Message-ID: <5760039B.4050902@ispras.ru> Date: Tue, 14 Jun 2016 17:16:11 +0400 From: Pavel Andrianov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: James Cameron CC: Dan Williams , Kalle Valo , libertas-dev@lists.infradead.org, LDV list , netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, vaishali.thakkar@oracle.com Subject: Re: [ldv-project] [net] libertas: potential race condition References: <57569424.9040906@ispras.ru> <1465310395.29158.2.camel@redhat.com> <20160607225114.GA21437@us.netrek.org> In-Reply-To: <20160607225114.GA21437@us.netrek.org> Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 08.06.2016 02:51, James Cameron пишет: > On Tue, Jun 07, 2016 at 09:39:55AM -0500, Dan Williams wrote: >> On Tue, 2016-06-07 at 13:30 +0400, Pavel Andrianov wrote: >>> Hi! >>> >>> There is a potential race condition in >>> drivers/net/wireless/libertas/libertas.ko. >>> In the function lbs_hard_start_xmit(..), line 159, a socket buffer >>> is >>> written to priv->current_skb with a spin_lock protection. >>> In the function lbs_mac_event_disconnected(..), lines 50-51, the >>> field >>> current_skb is cleaned. There is no protection used. The >>> corresponding >>> handlers are activated at the same time in lbs_start_card(..) and >>> then >>> may be executed simultaneously. Note, there are two structures >>> lbs_netdev_ops and mesh_netdev_ops, which have the target handler >>> lbs_hard_start_xmit. >>> Is it a real race or I have missed something? >> Yeah, it looks like it should be grabbing priv->driver_lock before >> clearing priv->currenttxskb in lbs_mac_event_disconnected(). Care to >> submit a patch after testing? Do you have any of that hardware? > I've hardware, with serial console. > > Can test any patch, on USB (8388) or SDIO (8686). > Hi! I've prepare the patch for this issue. Could you test it? Thank you. Tested-by: James Cameron From b1a9e157ccdf8650da93844fd2dbdb6fca509b59 Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 14 Jun 2016 16:59:00 +0400 Subject: [PATCH] libertas: Add spinlock to avoid race condition lbs_mac_event_disconnected may free priv->currenttxskb while lbs_hard_start_xmit accesses to it. The patch adds a spinlock for mutual exclusion. Signed-off-by: Pavel --- drivers/net/wireless/marvell/libertas/cmdresp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/marvell/libertas/cmdresp.c b/drivers/net/wireless/marvell/libertas/cmdresp.c index c95bf6d..c67ae07 100644 --- a/drivers/net/wireless/marvell/libertas/cmdresp.c +++ b/drivers/net/wireless/marvell/libertas/cmdresp.c @@ -27,6 +27,8 @@ void lbs_mac_event_disconnected(struct lbs_private *priv, bool locally_generated) { + unsigned long flags; + if (priv->connect_status != LBS_CONNECTED) return; @@ -46,9 +48,11 @@ void lbs_mac_event_disconnected(struct lbs_private *priv, netif_carrier_off(priv->dev); /* Free Tx and Rx packets */ + spin_lock_irqsave(&priv->driver_lock, flags); kfree_skb(priv->currenttxskb); priv->currenttxskb = NULL; priv->tx_pending_len = 0; + spin_unlock_irqrestore(&priv->driver_lock, flags); priv->connect_status = LBS_DISCONNECTED; -- 1.7.11.7