Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1844720pxb; Mon, 13 Sep 2021 06:48:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJh8I++9m9LASdYycrp0kKskMIEpW8Roy4pr0qIkFH/vY231vy6WmLPOuwjCyaJ5m2T6dI X-Received: by 2002:a02:cc59:: with SMTP id i25mr9702214jaq.125.1631540883815; Mon, 13 Sep 2021 06:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631540883; cv=none; d=google.com; s=arc-20160816; b=qFy0PZIhsOhDDZ0d1ptF5Unx0hlYuAPDbwTB9TDh8vGJFM64gV1GD/X3SpnbD+s6nG 5jF3NrhvfAcaKGFLJ7e7yPYGITNeDs4pBo25WhCUkSdVXY1KFnOTVR9pJAKEAdZ+3cNv J1JlH1SCcwd3IF7GOkDbHJZFhvzX3TnkLrsM8r5ZD3gSMjm+1g4v+qChXYPZlVqu8zX3 ofjfJt4YJq3kV1XOG5Wo1iN6FgDDIqu5iAxJTuHTL1213GCsPdjzxYb+tqQEy1MfGSsm z4ZkBu9QTdR3yzxsa4V86+5dO8BR/fHZx+7o9FUyGycA+sx3T1rn4h4JRmfm0QZkPGVU Az8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cz1g+LBXZYjBF++GUbpz110XK4MYmh1/AfA3JBrRmqQ=; b=kLawavipPYMxrRzWLVKSY/HHaqtcopY00BrOn00xB0TKQg9+Bb5KvYhKfhcDSavDpR 8hT9ULxXxpkZqIyqOAFI8mhSt6q9/rTcjbnHTwqAYBj22jIqAt+6ghJL0zPeCzjImBIh Na9XcLIebsMLhu/gD7KGpcaOLyPesJDUMLNMIwY3TNUmTnopi1KwRB9WiyD4JYK8iWoi zGxRsz8VexG6c5h86Cgw9p9gG7ffFjdA9geXWJ8kJcBmvBjlfEFQ1G0zFaHTx3+OLfJy f3K2pP7C2tJTgWV3/8+FEccO2BOoWZoVvJSyJXuk1B+xUWUXmIlmfClX1V0Vt6N5DkST tu5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Acp7fMRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si6170544ild.118.2021.09.13.06.47.50; Mon, 13 Sep 2021 06:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Acp7fMRL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243414AbhIMNrz (ORCPT + 99 others); Mon, 13 Sep 2021 09:47:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:41194 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242962AbhIMNmi (ORCPT ); Mon, 13 Sep 2021 09:42:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2101B6142A; Mon, 13 Sep 2021 13:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539821; bh=f1zQrSy7+nxWJFjmB0J4pAKu+qqdkGMgHpBP4qEm290=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Acp7fMRLmIDqndS6HvMyXFuD7k3GVfFoMhwFH+1X/DdtlE5tXt3nC1l4d69W2ZyMO faGcPX0s81++6bGNn1cjeOLamt9Wbo0VRYt3TePR8IUwceZrWIWWa45jRmzwwti4IO Ug+UFiaGGcsJPe8AU/7cdB3G7hmvQxWkMg5+MHGM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Desmond Cheong Zhi Xi , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 5.10 141/236] Bluetooth: fix repeated calls to sco_sock_kill Date: Mon, 13 Sep 2021 15:14:06 +0200 Message-Id: <20210913131105.153700268@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Desmond Cheong Zhi Xi [ Upstream commit e1dee2c1de2b4dd00eb44004a4bda6326ed07b59 ] In commit 4e1a720d0312 ("Bluetooth: avoid killing an already killed socket"), a check was added to sco_sock_kill to skip killing a socket if the SOCK_DEAD flag was set. This was done after a trace for a use-after-free bug showed that the same sock pointer was being killed twice. Unfortunately, this check prevents sco_sock_kill from running on any socket. sco_sock_kill kills a socket only if it's zapped and orphaned, however sock_orphan announces that the socket is dead before detaching it. i.e., orphaned sockets have the SOCK_DEAD flag set. To fix this, we remove the check for SOCK_DEAD, and avoid repeated calls to sco_sock_kill by removing incorrect calls in: 1. sco_sock_timeout. The socket should not be killed on timeout as further processing is expected to be done. For example, sco_sock_connect sets the timer then waits for the socket to be connected or for an error to be returned. 2. sco_conn_del. This function should clean up resources for the connection, but the socket itself should be cleaned up in sco_sock_release. 3. sco_sock_close. Calls to sco_sock_close in sco_sock_cleanup_listen and sco_sock_release are followed by sco_sock_kill. Hence the duplicated call should be removed. Fixes: 4e1a720d0312 ("Bluetooth: avoid killing an already killed socket") Signed-off-by: Desmond Cheong Zhi Xi Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/sco.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 8ae8af33ae91..600b1832e1dd 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -85,7 +85,6 @@ static void sco_sock_timeout(struct timer_list *t) sk->sk_state_change(sk); bh_unlock_sock(sk); - sco_sock_kill(sk); sock_put(sk); } @@ -177,7 +176,6 @@ static void sco_conn_del(struct hci_conn *hcon, int err) sco_sock_clear_timer(sk); sco_chan_del(sk, err); bh_unlock_sock(sk); - sco_sock_kill(sk); sock_put(sk); } @@ -394,8 +392,7 @@ static void sco_sock_cleanup_listen(struct sock *parent) */ static void sco_sock_kill(struct sock *sk) { - if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket || - sock_flag(sk, SOCK_DEAD)) + if (!sock_flag(sk, SOCK_ZAPPED) || sk->sk_socket) return; BT_DBG("sk %p state %d", sk, sk->sk_state); @@ -447,7 +444,6 @@ static void sco_sock_close(struct sock *sk) lock_sock(sk); __sco_sock_close(sk); release_sock(sk); - sco_sock_kill(sk); } static void sco_skb_put_cmsg(struct sk_buff *skb, struct msghdr *msg, -- 2.30.2