From patchwork Wed Jul 12 05:18:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Lu X-Patchwork-Id: 118833 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp934597vqm; Tue, 11 Jul 2023 23:03:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGU64SC79S8BMjd+zKH3IMd2Wy2YynejI6E3FUHpG01lTPeDPMXRhDOYDwdIMogREc64W1/ X-Received: by 2002:a05:6a20:1584:b0:128:b722:e789 with SMTP id h4-20020a056a20158400b00128b722e789mr17944062pzj.1.1689141835471; Tue, 11 Jul 2023 23:03:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689141835; cv=none; d=google.com; s=arc-20160816; b=tIf8j+JTTMjAGUi0MOVY+E0t5Tp6WveTg2RiBD23MCaBext1tI1n6QDH30ZCnQtLL+ JXwIaRbZVd8MRCR8XfwVUCrjDGOccqr7rOrzQlfAgSlQUL1gSrmfrbJjVbAmDM/fWsZd PG0oud0Y2nyLzs1CIEFSDaOb6Fe2XcwwcxbMkC3sazVaHzv+Hg16DTfFo7IGf8NwfbGH G7wEre+FHFcxS3zQ6xbKsMQO3qVHqgQjTfgB+ko7IKrustj5MLbAqjYB63ljcERvEjn4 hXovfvgXZICpTm7Kbv25W+BPg0DQPaCPirw8h9AoI3AApel2/THXYk7TJyi9YswWbXlr +kAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from :dkim-signature; bh=HFjVLrSlHIovITeC28nKCrvDmOrnc0uXGtIt3SR2nPc=; fh=67Twni7jn2AM1KRVye1UmD/yR5hFuxqk0AUr7ZPhul8=; b=ExWrCeMKfNlUa4pM+xLKi6xYFenbk9FxCLGoh/OFM5KJnyZP4Nhhyyc6VWQGVujIc4 Dq2n8uUfrM32+vy5kf0+JypGrBRVm8BmUj1rXvFHTrY8njE3Q8b7F6Jesi6wAG9D8yzD 2NLLds9olIUtFMel8NAKdFPhp2X2Eyuu7sxeTXqd+TtDOHpoYRpwwuZrbqXbYA8wz6fM x2wmwf/bmWTu86VMARomUd9FHkO8LP1tQV0cHUtOJ9eZcwMO5gLb6SXncvR9Z+e68rsU LgP/s4WfjN0cMNSWdKOCYPRlHAjjlJqJsDIONXMTjl2q2qnuTI6owyMg1LAxXA5Am9jd DQSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Yg1bBEQR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i30-20020a633c5e000000b00517a4a75528si2588947pgn.162.2023.07.11.23.03.41; Tue, 11 Jul 2023 23:03:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@mediatek.com header.s=dk header.b=Yg1bBEQR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231558AbjGLFT0 (ORCPT + 99 others); Wed, 12 Jul 2023 01:19:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231241AbjGLFTW (ORCPT ); Wed, 12 Jul 2023 01:19:22 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B31A6; Tue, 11 Jul 2023 22:19:17 -0700 (PDT) X-UUID: a3a99a6c207311ee9cb5633481061a41-20230712 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=HFjVLrSlHIovITeC28nKCrvDmOrnc0uXGtIt3SR2nPc=; b=Yg1bBEQRniF8y4SsvuJtDogNbDaqCPswW9n2NCkH/waEuXzu84JOa75IZXbuy2FNNXlCbY9QoMZ7v7Ysr2J910+8wLVcVddfWCgB+dswkJuOZRYCB3nBUhDo1sMFZdyXsbVJpJTY1Rtdadh2JxGjwPuhHe7bkWkR3IXZkCx5few=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.28,REQID:fd91dbcc-ccc0-47c2-9abf-1c4e56ec9467,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:176cd25,CLOUDID:514a2268-314d-4083-81b6-6a74159151eb,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1,SPR: NO,DKR:0,DKP:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_ULN X-UUID: a3a99a6c207311ee9cb5633481061a41-20230712 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1545327841; Wed, 12 Jul 2023 13:19:13 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 12 Jul 2023 13:19:12 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 12 Jul 2023 13:19:12 +0800 From: Chris Lu To: Marcel Holtmann , Johan Hedberg , Luiz Von Dentz CC: Sean Wang , Aaron Hou , Steve Lee , linux-bluetooth , linux-kernel , linux-mediatek , Chris Lu Subject: [PATCH v3] Bluetooth: btmtk: Fix null pointer when processing coredump Date: Wed, 12 Jul 2023 13:18:58 +0800 Message-ID: <20230712051857.13812-1-chris.lu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_TEMPERROR,UNPARSEABLE_RELAY,URIBL_BLOCKED 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771185890319658403 X-GMAIL-MSGID: 1771193589143499189 There may be a potential null pointer risk if offset value is less than 0 when doing memcmp in btmtk_process_coredump(). Checking offset is valid before doing memcmp. Signed-off-by: Chris Lu Co-developed-by: Sean Wang Signed-off-by: Sean Wang --- v2: fix typo v3: fix bot checking error --- drivers/bluetooth/btmtk.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 786f775196ae..0f290430ae0e 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -370,7 +370,7 @@ EXPORT_SYMBOL_GPL(btmtk_register_coredump); int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb) { struct btmediatek_data *data = hci_get_priv(hdev); - int err; + int err, offset; if (!IS_ENABLED(CONFIG_DEV_COREDUMP)) return 0; @@ -392,15 +392,15 @@ int btmtk_process_coredump(struct hci_dev *hdev, struct sk_buff *skb) if (err < 0) break; data->cd_info.cnt++; + offset = skb->len - sizeof(MTK_COREDUMP_END); /* Mediatek coredump data would be more than MTK_COREDUMP_NUM */ - if (data->cd_info.cnt > MTK_COREDUMP_NUM && - skb->len > sizeof(MTK_COREDUMP_END) && - !memcmp((char *)&skb->data[skb->len - sizeof(MTK_COREDUMP_END)], - MTK_COREDUMP_END, sizeof(MTK_COREDUMP_END) - 1)) { - bt_dev_info(hdev, "Mediatek coredump end"); - hci_devcd_complete(hdev); - } + if (data->cd_info.cnt > MTK_COREDUMP_NUM && offset > 0) + if (!memcmp((char *)&skb->data[offset], MTK_COREDUMP_END, + sizeof(MTK_COREDUMP_END) - 1)) { + bt_dev_info(hdev, "Mediatek coredump end"); + hci_devcd_complete(hdev); + } break; }