Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4814401pxj; Wed, 9 Jun 2021 02:28:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLpuz7/7jp1DdS7Bzeqpb871IkwS5C5Qx9WAjhM9zZ4N0ol7N9FP+gHMGW1qYBRdRGA4dq X-Received: by 2002:a17:906:d0da:: with SMTP id bq26mr28612844ejb.287.1623230898553; Wed, 09 Jun 2021 02:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623230898; cv=none; d=google.com; s=arc-20160816; b=WI7+PyE6V1hLZ3INM7r01lEDdyu6PD+o79zShOqlQpHdpvk96brNSBEflXT1FX5cG/ TfTYhRW6pV5nNKWiCoy9j7EC2N2tYrPXZl2Bawl4ycpk+AwMYv5YphkkdUxXf4ib+oUA X4RPrs9dxODk8EFm4MiZpKwOaYijCbC4ihpYDzVgLPucLciAgLRr0ibJjomRwB+TNsrf 8e+j2nAN+n+/aF62fRiktZMvzl4ZhLR4Hk8QF+4Q9UDy31IBPHXQLPfIxmaRo4VNtuYy u4gUrs6BBudZKaIYkT88faLU3ZMLh5pdsjm0EpokY3u3F9LCKsN/dDe7EFDuugQSk311 WcOw== 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=Iv+T7/1UccR0fnv4vX4w0MgrrhcgF/IupgqKg/OftSM=; b=U5S4O+2rtDcojs/HniR0wm0FPu7uTuFJjtWVXMp64k+nimP/iJaFz/QMYcYmJ4POYF 3mDKXjrA9PYrdXwWx5Uu38MX3l2agn1FHssMxM6rRe9VFblxwDllkDILJiT7L70+Ytli wx7yhVTRSfQIxm4FJSclNn7mG15rqOkfFui/9aXK1p687NVicUBnWCWd1ZyQXApKRtOk HWRd4NPdlczPEgMyIvAMPDQFLyx5UKWP3gQqcZ8E1FEenCfqBJ37zdukF6JUAjasKw7a iyitorqxw6zA3ighxhDQeCQi/qZkjUyealcQRfbpMdEuX3DfmMd9d0QNHq28ZDZ9smQ0 s4Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bD6Wim8v; 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 f17si2093180eds.78.2021.06.09.02.27.35; Wed, 09 Jun 2021 02:28:18 -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=bD6Wim8v; 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 S234280AbhFHSdt (ORCPT + 99 others); Tue, 8 Jun 2021 14:33:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:57600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234309AbhFHSch (ORCPT ); Tue, 8 Jun 2021 14:32:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4DE7D613B9; Tue, 8 Jun 2021 18:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177027; bh=EHZJLvG/aunoeWaZiHpji8erF1KoKgD/dmIWqn/lG2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bD6Wim8vEYWpYuqPxPiVenG0QrQJ9swPHMmMAjxhRspKGdXsbwcwyHStQO+cCb5eM I1DAMLyBWE++fQjd5ucCM+lzUG0ODDiMGrHpSK90TaJPUe4Q0qhD04yeJ78mg1ghgx jUF1RO6RDSr9h92x0pYPfnYi9KADKTsU3xywNphg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lin Ma , Marcel Holtmann Subject: [PATCH 4.9 14/29] Bluetooth: use correct lock to prevent UAF of hdev object Date: Tue, 8 Jun 2021 20:27:08 +0200 Message-Id: <20210608175928.284131791@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175927.821075974@linuxfoundation.org> References: <20210608175927.821075974@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: Lin Ma commit e305509e678b3a4af2b3cfd410f409f7cdaabb52 upstream. The hci_sock_dev_event() function will cleanup the hdev object for sockets even if this object may still be in used within the hci_sock_bound_ioctl() function, result in UAF vulnerability. This patch replace the BH context lock to serialize these affairs and prevent the race condition. Signed-off-by: Lin Ma Signed-off-by: Marcel Holtmann Signed-off-by: Greg Kroah-Hartman --- net/bluetooth/hci_sock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -750,7 +750,7 @@ void hci_sock_dev_event(struct hci_dev * /* Detach sockets from device */ read_lock(&hci_sk_list.lock); sk_for_each(sk, &hci_sk_list.head) { - bh_lock_sock_nested(sk); + lock_sock(sk); if (hci_pi(sk)->hdev == hdev) { hci_pi(sk)->hdev = NULL; sk->sk_err = EPIPE; @@ -759,7 +759,7 @@ void hci_sock_dev_event(struct hci_dev * hci_dev_put(hdev); } - bh_unlock_sock(sk); + release_sock(sk); } read_unlock(&hci_sk_list.lock); }