Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2318977pxb; Mon, 20 Sep 2021 18:41:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyA1zxJTt9sND99YMQMUqe5dK4ljTJttLt0PBuDh5j8pBbaB3APbFKSs0dq7L9+gcmVA+GF X-Received: by 2002:a92:c56d:: with SMTP id b13mr9352831ilj.86.1632188498551; Mon, 20 Sep 2021 18:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188498; cv=none; d=google.com; s=arc-20160816; b=v/4kYXFzbYlzzJK5nBpu6QSjPVkwO6/EDIe6WBX2TbpSiwqFhQjbau+Suc8nX5d4/0 Igp69CtMNHI2OLlMdcAD08UjG20SmNo8WDXKKUCrYr27BVQaK5zpTmLFFXODckSip/LD n//GNpcv1OReh9SczTJyREe5PWjaVms7Zi3f9I0JezG9rM1g8IryoK0kSo5B8IZDDFto oDGpSX524FZkFES087qnW+6AB/608hNsLqJSW/ruO1pV9/hvGHKQE65qHDqmBjIha6aC 6Dgv+BFy1K03oONt7Z5u6q9Xgaq8m/T+D6i2XG4eYFKeQpBvKYXPW6gi4mM7iOeC59GW BSyA== 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=CXq7JFld6pHJHcPbWPsryLTIXvue+RETlIbAdnxRCdo=; b=yhT/bJQVBJKET2hxhgboSK0A4itj+puzjmAjxNF/NPJnfsTb1RjvyHw9K1fO96Vvjm kg5DTkxMDmEX3n9SmS8KRv658yCveLi5+weonH5VXKfTdfaU7MCiYQePsTtUopVAIMi1 fpEKZkhDfCfzvjywOpWqehp654Mb4suw1p65uNxiiCUDqHl/AhMx6h6ZnOgYZd6wpLfb kptBdt90RGBydvdvFA4twt5cPt7RZnm9ui4dvYcztKS/CHIrGNBxNMKojr4VFHH4+3TK XnIYo6dZg4bOFdpuuecVY6ZdXoJ2Ly6md7C4xQvSeaBSHskhKM4bQiPW953L+blzmnGC qOjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AUcuRplA; 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 p8si18602510ilh.169.2021.09.20.18.41.27; Mon, 20 Sep 2021 18:41:38 -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=AUcuRplA; 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 S244270AbhITQtg (ORCPT + 99 others); Mon, 20 Sep 2021 12:49:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:35806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243253AbhITQsZ (ORCPT ); Mon, 20 Sep 2021 12:48:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B586A61268; Mon, 20 Sep 2021 16:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156415; bh=GCwUDMsFmbVux04PeiOGhO2O80RocRZ7qLtJsgRhJEU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AUcuRplAux0Z8EC2pvHovZW/VAHq+OvIpEMnkN7s+ItCQ4H2Be0ckzkN+ntA5LKna Mogj530KIupKky7oD4PdqbwGRkRL2Rv0bjo12DyUcZPFDuPJtQCJoBYt0O2wvE87rw Bq1q8oGhykWP4beWpJ1Odh+UBIPO4o2Wt7SFwb34= 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 4.4 048/133] Bluetooth: fix repeated calls to sco_sock_kill Date: Mon, 20 Sep 2021 18:42:06 +0200 Message-Id: <20210920163914.218558386@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 cad0d2750735..701d230fb9cf 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -83,7 +83,6 @@ static void sco_sock_timeout(unsigned long arg) sk->sk_state_change(sk); bh_unlock_sock(sk); - sco_sock_kill(sk); sock_put(sk); } @@ -175,7 +174,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); } @@ -392,8 +390,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); @@ -445,7 +442,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