Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp456525lqh; Tue, 7 May 2024 04:43:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX5PmWD8vwSkccbMmu3zb6EayfGxQcEF/NYI2ohD49PEg71VVEgZbHDhW+yfSnOf0HTGYB9aGSjMT17p0zd8cjZRjEh6QT86UUdI5dMsA== X-Google-Smtp-Source: AGHT+IHzg4/2HLM99ZBdilNCbXxgrtsgNHAxuEA+6UM0uwmKuOywgwI/X8yX+t9oWuVzcBG6g738 X-Received: by 2002:a17:907:7210:b0:a59:bf43:4e40 with SMTP id dr16-20020a170907721000b00a59bf434e40mr6339604ejc.14.1715082193941; Tue, 07 May 2024 04:43:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715082193; cv=pass; d=google.com; s=arc-20160816; b=dXCcjd0VqL401JmKVKpaFpZWqHiRKbUnxjHmwDcavWH9TP027zAt5csW7JsXfhRH32 uzcAPp5fkahOLhSwETtt7ySegP/3h8Ed7a/XfmPoQJ+MlZ8KBi6m27BW3a5kkH6jXX/o AtJjBCx7LwY5dGRwH8lR2UMWNrPT/7jNNGgn4kWV9zNshdGie3TOb9GmSAqVuJivKMCV omff5OJfJ+XzcSHi3090IBZScDY5rtDwajpIGlMORxvU0cMoYLCecxbqza541blZjgAm nVAzBu58eMxF7jM5ikrY+nAuDm5sEEyrsrexEt2MiW6SjS1KddzhCdlE2uwLqG0PqYad BN9Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=3GOe4pCPH4ThgIN4Jd11fDyADYSLVPX3AV6lDXMGAH0=; fh=S0skQssNQgmZ6MQBp7XxKc+/7AnA1ySb2Mifmz4dUNE=; b=KNDM3sueH+/VLOdCvTzkDBmpqSRgJ5ylFy/K3HpM56idhKVT68SsqhyRM+EpsezeoD rNbUXctHHD2PszU9YFK+Y46sWMf5N7vKFuOBtYYluU8cJxzqKb1Bh0LC9dU7VD/uXt2D NW48SulOQANUZZTiS0FqddudNSNjoFE7gPuiCdXsZvo2os34y3b4l/dyjux+d79x2mA7 KTcDgTlLMhZ8upA0/RUvuKoI+05OU8WH66RE/UaMTTXX+UFRaTZ63RSfF3svbD+2x6Ta acoenWfICEV5wAkuIqXgifA8ffJ7AamBT5ogRHcPpnwkHDpJNHjvEeWUpWytpJfRmspN cXmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=altlinux.org); spf=pass (google.com: domain of linux-bluetooth+bounces-4346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4346-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qw18-20020a1709066a1200b00a59df67edefsi1571014ejc.431.2024.05.07.04.43.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 04:43:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=altlinux.org); spf=pass (google.com: domain of linux-bluetooth+bounces-4346-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4346-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AAA3E1F22956 for ; Tue, 7 May 2024 11:43:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E7B5152172; Tue, 7 May 2024 11:43:05 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from air.basealt.ru (air.basealt.ru [194.107.17.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 158046F525; Tue, 7 May 2024 11:43:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.39 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715082184; cv=none; b=NjoTVaABLKUkpnJ7sTkjtcb7nYv9Jmgae3egx+2PjHU8UYzkSICwCDQmOQ9WkDsaRsp/bJdcsni0miu/S3m1vFFY9bK/LTt6zMKIrBQtnephKxAJiVHyInzv7yVXKLcQ66hB24PT95vHPC60hlHFLvsy9saTnH/ChL3aAiXBYsM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715082184; c=relaxed/simple; bh=48MNBx4lKU8jug/3dAjRcd+PwBhYp8+m1AtXcjxvV+4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=u0EPHIIqqr0R6YiX+xWNz9/qNtck2kXXV24FA3iy76r1v3eltRqWKH0mgyVKbYRUkxRas7iAqesiIungxjZLAIH1jLKF2WPkMx6X0w2bcs8kGdz7/tWEHYHVerWGfgtpyIW6O6F5t+JeuyC776BANipRUoBOs1qA/6WYZJ7k7CE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.39 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: by air.basealt.ru (Postfix, from userid 490) id 668D72F20249; Tue, 7 May 2024 11:42:52 +0000 (UTC) X-Spam-Level: Received: from shell.ipa.basealt.ru (unknown [176.12.98.74]) by air.basealt.ru (Postfix) with ESMTPSA id 0DF652F20245; Tue, 7 May 2024 11:42:52 +0000 (UTC) From: Alexander Ofitserov To: oficerovas@altlinux.org, Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , Eric Dumazet , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org Cc: lvc-project@linuxtesting.org, dutyrok@altlinux.org, kovalev@altlinux.org Subject: [PATCH] Bluetooth: RFCOMM: possible deadlock in rfcomm_dlc_exists Date: Tue, 7 May 2024 14:42:44 +0300 Message-ID: <20240507114244.120751-1-oficerovas@altlinux.org> X-Mailer: git-send-email 2.42.1 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This bug was found by syzkaller. This bug is also very similar to another RFCOMM possible deadlock in rfcomm_dlc_exists. Both of these bugs are present in syzbot. Patch fixes two of these possible dedlock errors. Also this particular patch was already written in march of 2023 by Hillf Danton, but seems like it just got lost or forgotten. Links to these bugs and original patch on syzbot: Link: https://syzkaller.appspot.com/bug?extid=b69a625d06e8ece26415 Link: https://syzkaller.appspot.com/bug?extid=d7ce59b06b3eb14fd218 Link: https://syzkaller.appspot.com/text?tag=Patch&x=133a6835c80000 Signed-off-by: Alexander Ofitserov --- net/bluetooth/rfcomm/core.c | 2 +- net/bluetooth/rfcomm/sock.c | 2 -- net/bluetooth/rfcomm/tty.c | 11 +++++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c index 1d34d849703329..d8502914e3602c 100644 --- a/net/bluetooth/rfcomm/core.c +++ b/net/bluetooth/rfcomm/core.c @@ -490,8 +490,8 @@ static int __rfcomm_dlc_close(struct rfcomm_dlc *d, int err) rfcomm_dlc_lock(d); d->state = BT_CLOSED; - d->state_change(d, err); rfcomm_dlc_unlock(d); + d->state_change(d, err); skb_queue_purge(&d->tx_queue); rfcomm_dlc_unlink(d); diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c index 29aa07e9db9d71..cbff37b3273407 100644 --- a/net/bluetooth/rfcomm/sock.c +++ b/net/bluetooth/rfcomm/sock.c @@ -865,9 +865,7 @@ static int rfcomm_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned lon if (err == -ENOIOCTLCMD) { #ifdef CONFIG_BT_RFCOMM_TTY - lock_sock(sk); err = rfcomm_dev_ioctl(sk, cmd, (void __user *) arg); - release_sock(sk); #else err = -EOPNOTSUPP; #endif diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c index 69c75c041fe10a..5be21b987141fc 100644 --- a/net/bluetooth/rfcomm/tty.c +++ b/net/bluetooth/rfcomm/tty.c @@ -403,9 +403,12 @@ static int __rfcomm_create_dev(struct sock *sk, void __user *arg) return -EPERM; if (req.flags & (1 << RFCOMM_REUSE_DLC)) { + lock_sock(sk); /* Socket must be connected */ - if (sk->sk_state != BT_CONNECTED) + if (sk->sk_state != BT_CONNECTED) { + release_sock(sk); return -EBADFD; + } dlc = rfcomm_pi(sk)->dlc; rfcomm_dlc_hold(dlc); @@ -422,13 +425,13 @@ static int __rfcomm_create_dev(struct sock *sk, void __user *arg) } id = rfcomm_dev_add(&req, dlc); - if (id < 0) - return id; if (req.flags & (1 << RFCOMM_REUSE_DLC)) { /* DLC is now used by device. * Socket must be disconnected */ - sk->sk_state = BT_CLOSED; + if (!(id < 0)) + sk->sk_state = BT_CLOSED; + release_sock(sk); } return id; -- 2.42.1