Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6675303rwb; Mon, 12 Dec 2022 05:10:54 -0800 (PST) X-Google-Smtp-Source: AA0mqf6bWCf9VDC02vQFbBJ98RCvK+q1AZC5sq1ZOET+7EHWpt14i2llNlsQWrTDlN5QNLSDVNN1 X-Received: by 2002:a17:90a:ab97:b0:20d:bd62:979d with SMTP id n23-20020a17090aab9700b0020dbd62979dmr16601931pjq.26.1670850654449; Mon, 12 Dec 2022 05:10:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670850654; cv=none; d=google.com; s=arc-20160816; b=HhV+u0uFCOB6kCjGTDW1T8UHjmzkUOHXxvoNdt46J28IrD6UeR9rEvXzpvHYDI7RU7 pNgDdoJ3DAXn7DQX8LB6+e6sp+Me4kYu1AwYvjvi3S/5DDVTVNYz4CfwS90vbob0GJcQ 3/Em/WuHCrnyPzsMSpbXnHH8ncxhCC1MRKFd//ioh7n4d3HQiO6iaR3mvCXhAwywEXPw GVYHWxAXl/r8sETH522mLpB/d0IKB/Oq2TTKjcZtrQVNznZJimIxgz+HgiwqxBnq67p+ aWQx/MasWoe5M3HD89IER8LT2w88EhOBNBulP/eib8U6sWguo//kKJkCXVvb0rVYZjSI r+WA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :message-id:date:subject:cc:from:dkim-signature; bh=dxskmic1Yr1+fUcs56ZWXNvxVz9bJt1msmiC1km1d2I=; b=Abq6S/bJ7WJk1xBo58+ezhWoLGyqfXZ/xK9aHAmaqyiKgdH3uTofGBvkG6VCPHFjb5 CxSbzXhRRBeT+4J8uiYTNsli4Upf+txG6BOs61raACVzT03LiRAVesBQfnxhnXlAc9iZ s/u5sm7sWmZympVi7l2I6LqMxBfO7PI1rJhOg3tvwdK3FyX1pHjrd6GmA4p974XYw63h qhBiHpjYb7Owcm3ZdByhcuuXgupq9kAGtoQSMroQ7RjT1q07zA1Gjnmb31OVzBmawYQs ujwY6JoZxUtJt+pFZ2Knp/Bl3Fy6xNI44XGG0UyHxmFJaRhX4eijvRVhkb7AUBfmZtMn h27Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@oracle.com header.s=corp-2022-7-12 header.b=Y9n3VwiQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lx1-20020a17090b4b0100b0021bc843908esi11000877pjb.119.2022.12.12.05.10.31; Mon, 12 Dec 2022 05:10:54 -0800 (PST) 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=fail header.i=@oracle.com header.s=corp-2022-7-12 header.b=Y9n3VwiQ; 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=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232491AbiLLNJM (ORCPT + 99 others); Mon, 12 Dec 2022 08:09:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbiLLNJC (ORCPT ); Mon, 12 Dec 2022 08:09:02 -0500 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39FC21276B; Mon, 12 Dec 2022 05:09:00 -0800 (PST) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BC98JdN023527; Mon, 12 Dec 2022 13:08:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2022-7-12; bh=dxskmic1Yr1+fUcs56ZWXNvxVz9bJt1msmiC1km1d2I=; b=Y9n3VwiQoek16COca9Z+xE4V8FWJX8daNOYz4pjVgqQQ9qcBJ2xsMeJYoUCSZCTZjKHU tYoNKUmjwvBCQyiW7opAqPCp8gKhnYttjrXcVvwLRt8LZEM0ehjNnJfBdzJeeUtI0vzn hw+0B7FOGATOi1YmVHf/4PVVrf1EGvMmDoFSmdMfx/AwzDxXQUfs35zkseoUrw6XPo+c omtjBfW8V6Pf9zeIMwcb2kVNy6qSOCu0E1PRQm7ru47JAm5ErxFqg5XL9QM//hGOxgmB DgtVZrNs76gTyIUwZPhT7E6lNnMAmiOkR9BoCNmO/hjnjIJ+GrdBBJiWtsoI1dTon6t/ Lg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mcj092n3v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Dec 2022 13:08:40 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BCBvkII034709; Mon, 12 Dec 2022 13:08:40 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgj40sj5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Dec 2022 13:08:40 +0000 Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2BCD8dRO038889; Mon, 12 Dec 2022 13:08:39 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3mcgj40shq-1; Mon, 12 Dec 2022 13:08:39 +0000 From: Harshit Mogalapalli Cc: harshit.m.mogalapalli@oracle.com, harshit.m.mogalapalli@gmail.com, error27@gmail.com, darren.kenny@oracle.com, Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Brian Gix , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: Fix a buffer overflow in mgmt_mesh_add() Date: Mon, 12 Dec 2022 05:08:28 -0800 Message-Id: <20221212130828.988528-1-harshit.m.mogalapalli@oracle.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-12_02,2022-12-12_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212120122 X-Proofpoint-ORIG-GUID: e01joMMkITDIIWfYrGbDlKhSpFsgVQH1 X-Proofpoint-GUID: e01joMMkITDIIWfYrGbDlKhSpFsgVQH1 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Smatch Warning: net/bluetooth/mgmt_util.c:375 mgmt_mesh_add() error: __memcpy() 'mesh_tx->param' too small (48 vs 50) Analysis: 'mesh_tx->param' is array of size 48. This is the destination. u8 param[sizeof(struct mgmt_cp_mesh_send) + 29]; // 19 + 29 = 48. But in the caller 'mesh_send' we reject only when len > 50. len > (MGMT_MESH_SEND_SIZE + 31) // 19 + 31 = 50. Fixes: b338d91703fa ("Bluetooth: Implement support for Mesh") Signed-off-by: Harshit Mogalapalli --- This is based on static analysis, I am unsure if we should put an upper bound to len(48) instead. This limit on length changed between v4 and v5 patches of Commit: ("Bluetooth: Implement support for Mesh") in function mesh_send() v4: https://lore.kernel.org/all/20220511155412.740249-2-brian.gix@intel.com/ v5: https://lore.kernel.org/all/20220720194511.320773-2-brian.gix@intel.com/ --- net/bluetooth/mgmt_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt_util.h b/net/bluetooth/mgmt_util.h index 6a8b7e84293d..bdf978605d5a 100644 --- a/net/bluetooth/mgmt_util.h +++ b/net/bluetooth/mgmt_util.h @@ -27,7 +27,7 @@ struct mgmt_mesh_tx { struct sock *sk; u8 handle; u8 instance; - u8 param[sizeof(struct mgmt_cp_mesh_send) + 29]; + u8 param[sizeof(struct mgmt_cp_mesh_send) + 31]; }; struct mgmt_pending_cmd { -- 2.38.1