Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1825075pxb; Mon, 13 Sep 2021 06:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIAb3tJUIRWZGis+lsshAWKoZo9eWfwZZase06vXLZIWzWneA82hlPcBw4vl4G0nMVMpbK X-Received: by 2002:a6b:f007:: with SMTP id w7mr9087371ioc.112.1631539450608; Mon, 13 Sep 2021 06:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631539450; cv=none; d=google.com; s=arc-20160816; b=DJLVCH9qB1SNY7kwM+M9VzsuMrrtil0Xi/bbELjlsF2rwkUGzDmdFVzpWd1OF2tzRL pfvN2+4UcYA2fCi44Y76a6CLtjSoQchtS08IwKi7VxeNFTulUO5VwqThoE3mz2OgqmP/ +uLhC/Gw4UilEOn7CcpHe0nFXTeHcIEw8tMHO6na6Agux9e34mraY2il80ddcimhnndI O3iIhu7u84UwAozo/Jqm4PiOW9P3sRF9oBur9g5BRYEJjaTty37E/hBelKjRLYFXEHmq DOBphKER8S0N8VxC0qntykj3Pff7ffPfJOujuVlm8yziuj9HaQXjc0IlrEU6jyq30pCQ nx2g== 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=zCBA8EzNgOZ2cNhzdIR19dbwCd2ZAsIFA4afzi8vSnw=; b=diJb+JLv+wXtHcbcniBRfvPLNddjw6DQHCb23NaHn9VZ/YXR562u2iuo+Kbm0UMp/t FrVPW3uScXUnkzlXDSpOn1x7484g65pYXjLbgJOzCCSkNNQ+w0Mul9OhgQaWukeCpEf2 ka8Lq6SCymX0EMCA3xn/iMQakqKVXe9G80ruuUH9g0NI/QM4yuD5CyzXYzb3UmtE4KL2 9uhAI0TWuaRypaRPWzNMcmjvYOGv+BgYT2hErJ3Crr33zN1vOfsERc4S7UVuciv97bzc 1OmMb70D4wcYW+/wZYJetzw8/OmbQT90HuVmrgo9dKZ1ZdRGx98KOW2ZvptJVEArHGLS MPXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Zt2KgZRW; 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 i31si7376274jac.56.2021.09.13.06.23.58; Mon, 13 Sep 2021 06:24:10 -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=Zt2KgZRW; 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 S241244AbhIMNXl (ORCPT + 99 others); Mon, 13 Sep 2021 09:23:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:37736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240787AbhIMNVg (ORCPT ); Mon, 13 Sep 2021 09:21:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 20698610D1; Mon, 13 Sep 2021 13:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539220; bh=hz+FCjRyrHYKNnCaXFg+Cr7J/8r92pasC0qfYDzeeVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zt2KgZRW8rx445MLAdTnwylxBES2h4loafJN8pXPf9EDI7aBo4gOHYO6orqLT/iZj yvpBXM1LpuRFkMsmRsWfHdP+V7c/h0QOi6eJCuhYgkEzN66KIChGP+hFfxIIo/wHFK sYiKKL1fBA6Cig+b50Vq+CiMn5y0rrEILM+fJ6tU= 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.4 086/144] Bluetooth: fix repeated calls to sco_sock_kill Date: Mon, 13 Sep 2021 15:14:27 +0200 Message-Id: <20210913131050.833305156@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131047.974309396@linuxfoundation.org> References: <20210913131047.974309396@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 335264706aae..1b7540cb8e5c 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -84,7 +84,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); } @@ -176,7 +175,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); } @@ -393,8 +391,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); @@ -446,7 +443,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_sock_init(struct sock *sk, struct sock *parent) -- 2.30.2