Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp2817398rwl; Sat, 5 Nov 2022 12:14:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7yAKjzXiNALG+FgRWdLQEO2cPosQch7xkovJlvg6X0INdU/9A1v7mf698zkij3XL5IXaW7 X-Received: by 2002:a17:907:3c81:b0:77a:327a:815f with SMTP id gl1-20020a1709073c8100b0077a327a815fmr40686565ejc.422.1667675650848; Sat, 05 Nov 2022 12:14:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667675650; cv=none; d=google.com; s=arc-20160816; b=vC+BkCR7RIjeWAijDz78Z59sNPtt1/sG3d0Hnt7y93HhTTpRpkSm/3+ouFIkYayKcJ FTobyeXTJT007aAHmWNYpk+NTSfSRkWc6z6AYApelBqWOcRfiDjCDIQWbcLHIxo26YNN 7Q5wQTtrau88oTPNW75GhRayNIiGbYeGgtTjo5vSuGDQtR6nS/eMPTJImIGUz553iM6k FwWS8aQg6aoe/L/mH80a7u8mMkSttW83f1BeC3dGGPl6nMiojF0ntsuhZojOYpQM1kji wR/COKlh3ujhrgR+1QpVoxb77QLvn4kA4NHaChM+d9YIztMMUaN1U3fJqW0KvCZ+yvmj WDDQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=fMzdSVUxKzfJHte4Vux2hVjWJ41SsNMVC7KP71E/b/A=; b=rImNPeI1ZjUkEzkxm2aytLcNfQSlloDUrtuiZSxXn4ZKPVFpXHyLmTV0H9B3wPhfAX Aejqfq0QSHQaIR2yU0PaYjnlT3nnHLqHWwI8zdz/nkni887dxCSomNIlpQVGgDUYF2Zo JMSKrJpCePCvDBEMyAtk0Ex+yqsQNJ9hVb0BKZJW11h8S9eiZdp6smYgY7GjbOA3WCIc ZyrwlV5h6IR6Uu6gVD/NPZJrphYG8uEC/y5FaFWZ5ChMibEdaf/LyA3pp/mBDa06PJKq pJL2dwmUvIUOZZhT5w4ZxNgBC2tvFxyetU55/dDx9Ff8wrSBkCJLMlnN/vD4YsubfUWL 7L4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bsp4D4uY; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ov9-20020a170906fc0900b0073ced0e9bb1si2318434ejb.189.2022.11.05.12.13.35; Sat, 05 Nov 2022 12:14:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bsp4D4uY; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229593AbiKETFx (ORCPT + 99 others); Sat, 5 Nov 2022 15:05:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229542AbiKETFx (ORCPT ); Sat, 5 Nov 2022 15:05:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F21A9583 for ; Sat, 5 Nov 2022 12:04:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667675096; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fMzdSVUxKzfJHte4Vux2hVjWJ41SsNMVC7KP71E/b/A=; b=Bsp4D4uY4xKa+28fS1YcocwuX1C0agJ8JSBM7TmWF1oC/kD/KsK7Pk+iXyvfARg7EJ9IsK Oey28NYVV/ueCjmUtc270buPXBYjwOA0rKUEy3PYwCcvq/8M+r/JUo58HVAyFg72G3nPZ9 0F6TQXoWIZjVc4xUn6qjKJchhgKaqNU= Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-640-f8isVAiePUidgjzGrxktSg-1; Sat, 05 Nov 2022 15:04:55 -0400 X-MC-Unique: f8isVAiePUidgjzGrxktSg-1 Received: by mail-pl1-f199.google.com with SMTP id s15-20020a170902ea0f00b00187050232fcso5877444plg.3 for ; Sat, 05 Nov 2022 12:04:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fMzdSVUxKzfJHte4Vux2hVjWJ41SsNMVC7KP71E/b/A=; b=uEbf1mR5OCZX2tdQUJO8lsGjSAehifTUro5jTIGNMEJVsm5M2vQM7ISJnh9odzotDZ 0BMu5tHJ2A9TKnQ8s/8C1/8rY0Z5Sda0aBd7binmSTo2oPZy1Gn1vrJC3lDU79b2dfVm +bdXXzICl0gBdRu/RVw3eCdsAu0GVoysqRebWY/SYBfjIbUXt1L8LTDNKeytDceg+86l mRDM6wutKJXdVZNFJmJDSKecRhNnk5u4Xj/4lCGwI71aKfDd/YTV19Ch/VzlVKHjxN/D /2GjQwefH06cPS8Do9bMa2LKjvLvHI1u6zm3YXCBXPE4s4fbd++mtT0Rluus4F9SWn3f ZrOQ== X-Gm-Message-State: ACrzQf0WEwAf/13kmLd+LOOLix/f447vXJiRLaXV7WquXTR6H1v0fbvU OlWrkj068Qo1l/5qr2BU9ym7nZLyYuuL64G6XBGnfomyVFSUPGw7ZMlYxsofFaP3NiVtyE94bxg CAaLY+17wyLhypRsTq4XfavgFu0pV X-Received: by 2002:a05:6a00:a8c:b0:558:991a:6691 with SMTP id b12-20020a056a000a8c00b00558991a6691mr42009590pfl.53.1667675093778; Sat, 05 Nov 2022 12:04:53 -0700 (PDT) X-Received: by 2002:a05:6a00:a8c:b0:558:991a:6691 with SMTP id b12-20020a056a000a8c00b00558991a6691mr42009574pfl.53.1667675093464; Sat, 05 Nov 2022 12:04:53 -0700 (PDT) Received: from ryzen.. ([240d:1a:c0d:9f00:fc9c:8ee9:e32c:2d9]) by smtp.gmail.com with ESMTPSA id jd10-20020a170903260a00b00185507b5ef8sm2009003plb.50.2022.11.05.12.04.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Nov 2022 12:04:53 -0700 (PDT) From: Shigeru Yoshida To: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Shigeru Yoshida , syzbot+19a9f729f05272857487@syzkaller.appspotmail.com Subject: [PATCH] Bluetooth: Fix use-after-free read in hci_cmd_timeout() Date: Sun, 6 Nov 2022 04:04:46 +0900 Message-Id: <20221105190446.1324053-1-syoshida@redhat.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org syzbot reported use-after-free in hci_cmd_timeout() [1]. The scenario for the issue is as follows: Task Workqueue ---------------------------------------------------------------------- hci_dev_open_sync ... hci_dev_init_sync <- failed ... if (hdev->sent_cmd) kfree_skb(hdev->sent_cmd) hci_cmd_timeout ... if (hdev->sent_cmd) sent = hdev->sent_cmd->data ^^ UAF occurred hdev->sent_cmd = NULL When hci_dev_init_sync() failed, hci_dev_open_sync() frees hdev->send_cmd and set it to NULL. However, hci_cmd_timeout() can run just after freeing hdev->sent_cmd because hdev->cmd_timer is not canceled. This patch fixes the issue by canceling hdev->cmd_timer before freeing hdev->sent_cmd. Link: https://syzkaller.appspot.com/bug?id=cb23ebfc8f304f510fb717cb783fe8b496c7ffb1 [1] Reported-by: syzbot+19a9f729f05272857487@syzkaller.appspotmail.com Signed-off-by: Shigeru Yoshida --- net/bluetooth/hci_sync.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 76c3107c9f91..a011065220e4 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4696,6 +4696,7 @@ int hci_dev_open_sync(struct hci_dev *hdev) hdev->flush(hdev); if (hdev->sent_cmd) { + cancel_delayed_work_sync(&hdev->cmd_timer); kfree_skb(hdev->sent_cmd); hdev->sent_cmd = NULL; } -- 2.38.1