Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3707956pxb; Mon, 24 Jan 2022 15:58:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+YL7YGa+LfHKShjR/REe9359OMA/TUtZS/nFH16YxQO5VqLGVVxxUzMO/TQABx8ipgRrF X-Received: by 2002:a17:903:4115:b0:14a:efa0:2779 with SMTP id r21-20020a170903411500b0014aefa02779mr16201182pld.12.1643068729585; Mon, 24 Jan 2022 15:58:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643068729; cv=none; d=google.com; s=arc-20160816; b=TtkZqnk2CWGm4Joy4tWsNCyV1Hfu51Muukvc5iHTaOSSN6cd7iRmXpSZhlVCKTXBRm RHLY6VmjMMWWBQFAW0YjzQhLVfKD3GL01nrppwV//kA3gEWijuPgFl+k8KeEORoHSYyk EG5WFuZhYE07TYvpesgC771GLTwp9YvIFrh9lG0EJw5g00noyfMxaAsHXp8D9IJ8YuLo MCinUKpZTIzTOLArzoItdcn/8RG7R0Rf8nc5wPRZbCcoeWqgWx+LmYu0dAtPrzrVlZR/ NuHYjcsc7FZb9c6pGkeM7yO1/F88FBzui/OAQ1Yo65eSfFU8G7xm77gbTpw64zN2DS0Y aflQ== 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=Wv4tVJwmN9CVLM1V+MCG701x1BsoiMzXb0AG1ma1jXc=; b=ussEmQYPiLkBGXxJLce+1KE9gEcvtirRELXiVgJZy7+3Bz51Boyy+r8AWZkNxQfyhx z6ZZV6ngaVH+SLPmhoNYwoyg/cU2UzZ+aHfsDa94Z8pXgqv03WEuhW0auJmxKBTWTyDD ogqqSm2dAXLr5SLp6SZUT7EoSGlyD5Pb2H9okce4khOBPKdKjZmLlPy3la+uaDvAqfl7 LuQrzoxZBTV09z9K38qrIrUDjjtLQwjhF0NMykgp/o9KYMzRS2LvFdn3l13uBoI/OcuQ TSUHKF+5LvHXOYNt6AepNjiazPx7Vw98EHLkCWeLVDq5cO93zSWLUV0XTFV+PoDSZImn 2LsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g9To24dj; 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 u4si5269251plf.534.2022.01.24.15.58.36; Mon, 24 Jan 2022 15:58:49 -0800 (PST) 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=g9To24dj; 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 S2366462AbiAXXwv (ORCPT + 99 others); Mon, 24 Jan 2022 18:52:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1845967AbiAXXOG (ORCPT ); Mon, 24 Jan 2022 18:14:06 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A2F4C0A02BB; Mon, 24 Jan 2022 13:20:11 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id EB804B80CCF; Mon, 24 Jan 2022 21:20:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 223F2C340E4; Mon, 24 Jan 2022 21:20:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059208; bh=9AfX050h7vqtW4uHKfS+QEoh4ELln8/kbkjaziam404=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g9To24djME78oELHXqHMg5/fIoRyUzMyFhSkb26Ojm7xKw4aSHYB809KV1BC6i/nI e1t9+xF++fyNnGNoM8ni2APkp9rJfZXUXZc5a7OmFcZtjPSKsVCu0la3/2CnSVWiqL Kt2AiOH02X+R49T0St9oh6Ur5O+k1mH6shDDG1qU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nguyen Dinh Phi , syzbot+4c4ffd1e1094dae61035@syzkaller.appspotmail.com, Marcel Holtmann , Sasha Levin Subject: [PATCH 5.16 0539/1039] Bluetooth: hci_sock: purge socket queues in the destruct() callback Date: Mon, 24 Jan 2022 19:38:48 +0100 Message-Id: <20220124184143.393483007@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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: Nguyen Dinh Phi [ Upstream commit 709fca500067524381e28a5f481882930eebac88 ] The receive path may take the socket right before hci_sock_release(), but it may enqueue the packets to the socket queues after the call to skb_queue_purge(), therefore the socket can be destroyed without clear its queues completely. Moving these skb_queue_purge() to the hci_sock_destruct() will fix this issue, because nothing is referencing the socket at this point. Signed-off-by: Nguyen Dinh Phi Reported-by: syzbot+4c4ffd1e1094dae61035@syzkaller.appspotmail.com Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_sock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index f2506e656f3e4..33b3c0ffc3399 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -889,10 +889,6 @@ static int hci_sock_release(struct socket *sock) } sock_orphan(sk); - - skb_queue_purge(&sk->sk_receive_queue); - skb_queue_purge(&sk->sk_write_queue); - release_sock(sk); sock_put(sk); return 0; @@ -2059,6 +2055,12 @@ static int hci_sock_getsockopt(struct socket *sock, int level, int optname, return err; } +static void hci_sock_destruct(struct sock *sk) +{ + skb_queue_purge(&sk->sk_receive_queue); + skb_queue_purge(&sk->sk_write_queue); +} + static const struct proto_ops hci_sock_ops = { .family = PF_BLUETOOTH, .owner = THIS_MODULE, @@ -2112,6 +2114,7 @@ static int hci_sock_create(struct net *net, struct socket *sock, int protocol, sock->state = SS_UNCONNECTED; sk->sk_state = BT_OPEN; + sk->sk_destruct = hci_sock_destruct; bt_sock_link(&hci_sk_list, sk); return 0; -- 2.34.1