Received: by 10.213.65.68 with SMTP id h4csp219756imn; Fri, 23 Mar 2018 03:10:58 -0700 (PDT) X-Google-Smtp-Source: AG47ELu1R8M/zEPQ57OPJE08IUkhZlWY75U5C7AuIpYkIu4SJHs+wcdaay3oZJ/1doQzE7/McBm2 X-Received: by 2002:a17:902:4481:: with SMTP id l1-v6mr29059265pld.43.1521799858617; Fri, 23 Mar 2018 03:10:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521799858; cv=none; d=google.com; s=arc-20160816; b=LJxS0SZlC5PkRB5yDaOTmmpfZIcu7SkGm9VFErz7Z1yIK0qg+5dD6dJMX/U+j/Atd+ Pir2qEVFiWUQ46IX7B0sg4CynHCRrQ4I5UD8SH5H1ItcSqS4l3LENoDAaQTriUW+6Zq9 iF2G1PblW8ljcD9D6rNbl8GGNqIg2g4l3yPSbsSsDhJHuAHW1iMEweIyeSagyvEBILrj O5s/8SaBXigfuReind4r1NgblHOYJQkj8urXjqBJWgL9xle95JaAexWwe/TzGXQkQg7b ECq4gOo1Wb2rIhxHV/m1t252JcxuVDcYNhaHcIuKR3Q4+bOEmB4pB5U/PKGAO8YJbFzl GslA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=cFY0cC94q/bdegjxcK0XAVp+uTX049naUN/KozEBRQE=; b=vmuKXhy74+Sih9Vpy9R7LH8Nm4ZKpsj/zZAtDSICbR17fJWnobsl6NyYTe08ImQrAm iVU8ULHiIG18DL3daTBFnqMyUTotDjoFJwtOlI7BmfTSkNy3MdJmoNvoqR9C3y0aeEhH 877ZgeKmDhO1tEHx7KqDamNw/9c3lEedrZ6Mp5fsNo9lGZ1u8bUk/kmARQrk5BL99ROA 6BG3IoXEzqnANI0J69shjh0eK5aZM2ir7MWbfm908CLSCPYEVTg/kupIVsBW5ikBpdBX v3vglCK0F2WZN1Qf1/IVA0DFEPRRStSSZB3lRCfiBev3BH/2D5lIc56r4onoYdHB5dCA SRCw== 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 c12-v6si7997565pll.498.2018.03.23.03.10.43; Fri, 23 Mar 2018 03:10:58 -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 S932544AbeCWKJn (ORCPT + 99 others); Fri, 23 Mar 2018 06:09:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42230 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932483AbeCWKJk (ORCPT ); Fri, 23 Mar 2018 06:09:40 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 63034F80; Fri, 23 Mar 2018 10:09:39 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dean Jenkins , Marcel Holtmann , Sasha Levin Subject: [PATCH 4.9 107/177] Bluetooth: hci_ldisc: Add protocol check to hci_uart_tx_wakeup() Date: Fri, 23 Mar 2018 10:53:55 +0100 Message-Id: <20180323094209.999581866@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094205.090519271@linuxfoundation.org> References: <20180323094205.090519271@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dean Jenkins [ Upstream commit 2d6f1da168e1d62c47f7d50135ac4cbd8411dcb1 ] Before attempting to schedule a work-item onto hu->write_work in hci_uart_tx_wakeup(), check that the Data Link protocol layer is still bound to the HCI UART driver. Failure to perform this protocol check causes a race condition between the work queue hu->write_work running hci_uart_write_work() and the Data Link protocol layer being unbound (closed) in hci_uart_tty_close(). Note hci_uart_tty_close() does have a "cancel_work_sync(&hu->write_work)" but it is ineffective because it cannot prevent work-items being added to hu->write_work after cancel_work_sync() has run. Therefore, add a check for HCI_UART_PROTO_READY into hci_uart_tx_wakeup() which prevents scheduling of the work queue when HCI_UART_PROTO_READY is in the clear state. However, note a small race condition remains because the hci_uart_tx_wakeup() thread can run in parallel with the hci_uart_tty_close() thread so it is possible that a schedule of hu->write_work can occur when HCI_UART_PROTO_READY is cleared. A complete solution needs locking of the threads which is implemented in a future commit. Signed-off-by: Dean Jenkins Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/bluetooth/hci_ldisc.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/bluetooth/hci_ldisc.c +++ b/drivers/bluetooth/hci_ldisc.c @@ -125,6 +125,9 @@ static inline struct sk_buff *hci_uart_d int hci_uart_tx_wakeup(struct hci_uart *hu) { + if (!test_bit(HCI_UART_PROTO_READY, &hu->flags)) + return 0; + if (test_and_set_bit(HCI_UART_SENDING, &hu->tx_state)) { set_bit(HCI_UART_TX_WAKEUP, &hu->tx_state); return 0;