Received: by 2002:a05:7208:208b:b0:81:d631:dc8 with SMTP id y11csp225503rby; Wed, 3 Apr 2024 07:31:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzo/C2Lg6USro1zH3iHt4imC0E3SkhF0kUh8PzIu20q8ZwhZAH8IJXWaj0eQHLhD2ZIUcLWSIoESbgrq6s8il5TzjHzGJiSNXh5Wgs5g== X-Google-Smtp-Source: AGHT+IGF91bEs3HQZAx7+lOPGeH3+Bt1n2IM+tvN08ENKi0hgPmATgrba5tb3Uf/7qCnPuSQ9osQ X-Received: by 2002:a17:902:c40e:b0:1e1:214:1b7d with SMTP id k14-20020a170902c40e00b001e102141b7dmr20609792plk.61.1712154682294; Wed, 03 Apr 2024 07:31:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712154682; cv=pass; d=google.com; s=arc-20160816; b=Kon3VS42FmXxhLx/4kozQKkFlTENcuVqj01uJQ/lRR9DM0rPPW9JyWjSPsXVshASv+ LOImhkbgD0mcnnsw0VmmazMJwWdjxw3fmuv/YOiGo1Y/SZvu3rU/k8H/fUeq8vO17V5y TeTH2aVD4cjXPfBUDmNbSiCK3dTGxd5erwghXjGEmiN5BPyNCkBu/WR5eBnzvdOkGv8M fmHUfrq0Z/kQQ2El3Lw1K1FP2R47fhAqHPEnTpTJRyRHx1STxXpKB+DpaObnt20qoUCV yK8RBBdHvsP8H0Yv2tZ1WuLGqT5uakamRFzEIqGKeZWtM+UwoqRvVfpyXQ2QjvP6+v2M JepQ== 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:dkim-signature; bh=QDHrTfQGhkv9YhmdL+gS3wLPwdQkfetGjLEEMPvsCuY=; fh=9XmeHRqSM+hCcJuOxa/9BpZVVNc1Sb+XumU5XVTFOHo=; b=IEKuADMboFsIbDu8S51C2u0oWZLedLUkXUgLrPflHaWNlI8GP/7przsQJtSCtnaldb xBO/oKOEIjgGKXRNLEQ+HvMxc3VPdWOS1iySGWhhGUxGhbjR2rSNef/c6kYKE0g92zcW 8UWURu5wJ3pn9HIm4ncHQwlzDjF2D2fT+zhnuaxlK5o7SOHvO0sONYygMyr7kg5DzhlN KaCHIO7eMI2OOoOy5WJT0Kmct0x2FD6UD8tuuUk8GWjeMvgnV4UShg1UMsmMVXfn8h0g quS5HWAwSPAel99fBwDDVl/D1mlnusWiyQ4/13/bvSGJ7JVFSAbOARXI4j7ujrDdGjER DKjQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=VqxySG08; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-bluetooth+bounces-3149-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n16-20020a170902f61000b001e2969bdfe4si987702plg.262.2024.04.03.07.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 07:31:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-3149-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b=VqxySG08; arc=pass (i=1 spf=pass spfdomain=yandex.ru dkim=pass dkdomain=yandex.ru dmarc=pass fromdomain=yandex.ru); spf=pass (google.com: domain of linux-bluetooth+bounces-3149-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B02002858DC for ; Wed, 3 Apr 2024 14:29:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D99DC14831D; Wed, 3 Apr 2024 14:27:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b="VqxySG08" X-Original-To: linux-bluetooth@vger.kernel.org Received: from forward103a.mail.yandex.net (forward103a.mail.yandex.net [178.154.239.86]) (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 94C52149E14 for ; Wed, 3 Apr 2024 14:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.154.239.86 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712154478; cv=none; b=AfZ7T44oh0SkByCQGjlEUjngGSCe5HjF4OeWJrVhRqB8DpDdxnKxV8y/zi+ml0hbxY4xspTzp2quce1ggHKtjd7du1eRfaOHLEYB7Q9OGC42+my+AXGvtJ+hJyoB8jIXgphQebXdwlcsGbbUmL+S6jgf8tZM7ppf1CGnRRrRHCA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712154478; c=relaxed/simple; bh=V5zDboOWLKCBD+kgckSQuxDbzmz/IroeXb43whbd8p8=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=HH3bADlyxcyQp0lF9Ob+b4w7sqJi3uYVGvMiFqTkKX1YuR3vEhNJIId+/9v3KA018PKPLMmHT/wAppRsDbG4Yhs0zQoyklLteiDsCZhWQSCN4SAotZFEr5HJPwcInjPwzvMeE0nNt9LO6GPzzOAhdmIp7S7t4u7xZh+plNJoKQI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru; spf=pass smtp.mailfrom=yandex.ru; dkim=pass (1024-bit key) header.d=yandex.ru header.i=@yandex.ru header.b=VqxySG08; arc=none smtp.client-ip=178.154.239.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-74.vla.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-74.vla.yp-c.yandex.net [IPv6:2a02:6b8:c0d:193:0:640:a325:0]) by forward103a.mail.yandex.net (Yandex) with ESMTPS id B49B9608FE; Wed, 3 Apr 2024 17:27:46 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-74.vla.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id kRUjtqBmBOs0-6MEmlqmM; Wed, 03 Apr 2024 17:27:46 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1712154466; bh=QDHrTfQGhkv9YhmdL+gS3wLPwdQkfetGjLEEMPvsCuY=; h=Message-ID:Date:Cc:Subject:To:From; b=VqxySG08AOhdize/tjlPe1XXZodFboFUtnJk6DG5HxoPHpnS5YqPDPRYfwZSVQrO1 IffPjkxWUCUfrG6YtDXQDEqi7UzTnvqXcBx66fTggnqJH20x6xdlRJeqw4vMnf6DNM ZHH7AXSfsUTcdaJYQ5digR7Flnarj5DLqgynjq2M= Authentication-Results: mail-nwsmtp-smtp-production-main-74.vla.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Antipov To: Luiz Augusto von Dentz Cc: linux-bluetooth@vger.kernel.org, Dmitry Antipov Subject: [PATCH] [RFC] Bluetooth: fix race condition in sco_connect() Date: Wed, 3 Apr 2024 17:27:06 +0300 Message-ID: <20240403142706.25748-1-dmantipov@yandex.ru> X-Mailer: git-send-email 2.44.0 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 patch is intended to fix the race condition between two 'sco_connect()' calls, where two instances of 'struct sco_conn' are erroneously set up to share the pointer to the same 'struct sock'. When one of the connections goes away, it destroys an underlying socket as well, leaving dangling pointer to destroyed socket within another. Next, if the latter (alive) connection enters 'sco_sock_timeout()', an attempt to do 'lock_sock()' on a destroyed socket causes use-after-free write reported by KASAN at https://syzkaller.appspot.com/bug?extid=4c0d0c4cde787116d465. Signed-off-by: Dmitry Antipov --- net/bluetooth/sco.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c index 43daf965a01e..f8e5e4c3420f 100644 --- a/net/bluetooth/sco.c +++ b/net/bluetooth/sco.c @@ -228,7 +228,7 @@ static int sco_chan_add(struct sco_conn *conn, struct sock *sk, int err = 0; sco_conn_lock(conn); - if (conn->sk) + if (conn->sk || sco_pi(sk)->conn) err = -EBUSY; else __sco_chan_add(conn, sk, parent); -- 2.44.0