Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1042400iob; Fri, 13 May 2022 20:47:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzatebKhAvaACfaU/Mysz+Q8SaMOfVjUT7LbJ9UgNoH01RukHz/jS5eiqIfldJGvQ3+MgFR X-Received: by 2002:adf:b613:0:b0:20a:c7db:3ce4 with SMTP id f19-20020adfb613000000b0020ac7db3ce4mr6410489wre.70.1652500044412; Fri, 13 May 2022 20:47:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652500044; cv=none; d=google.com; s=arc-20160816; b=jRmEk6CkHkokCNSoTeqNf3ZreAd513iKMgktVCbc/sJafgaJpWM34KTlkRq7oPLcu5 sLckWXB2P+5+5cqUODTgxjnZB4vYoqWHuzCxjCJAMNA7IicDPJa/VsFAGrQEwGPysvKD wmaPnr8VyCQJiIVzyOdoySmY32UQH9eZ/LzTZRti/v/Td7mYUrhfY9N6k8Is6Quhf6v5 s1g2PX3b2YEhLl+bZde0McVzcPI0Dh7o+eEC+Ry4Pqt/ZEi13WSPk2v4pPELg+22GRtd jzmVKsVYKrmxyO7YP/+cz/Ug8z6Cfiq5KcyqZhC+vRlDfLzHHXzsVRQDyPAdhgtkN6vp eF8Q== 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=q4TRYoC0rsoniiD+Lc9TAgJYKYmLG7hKR/tLXgPSq9Q=; b=vl9IAEsRBUMJHfk3gkXASBsNoudsSWVm4fDYP3XT6mk/oMX+IZ3uuXo/mXPb/6uhA0 ySysKkbj6Mi/7tFOeb1Qtml0sNeri4IKDLFqZCOMmuDe1ChO2RZsnjqwWctUGy25FmA2 8e7qs9OErFzW4PsVTOVX7s0Z0pYAxgUOL4Gdwa+J4k2n1BUEFymuZ17PIKyifkQkgh28 ebEcLu0F7Fu6lTdyQ9rov1NNvINYHUCpSgSv673afC4Ct7OiphB9z0D2UL2UgUwX5XXx Ht1VADuPkMm41L6NhdHLxG3K4MkJvApMIxBEo7TO+6SsqMl8U4NIsh16is8yMGx8GcLq k5nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yB8hWlju; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r12-20020a5d6c6c000000b0020cf8c4ff7asi1056483wrz.928.2022.05.13.20.47.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:47:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yB8hWlju; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D91A3EC336; Fri, 13 May 2022 17:21:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380921AbiEMOaT (ORCPT + 99 others); Fri, 13 May 2022 10:30:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381073AbiEMO03 (ORCPT ); Fri, 13 May 2022 10:26:29 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3143E6898F; Fri, 13 May 2022 07:26:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BDF2FB8306F; Fri, 13 May 2022 14:26:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF768C34100; Fri, 13 May 2022 14:26:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652451970; bh=f05s6427RKo5ppnzx5FO337pJ1V8YbFwt+jAzh5Z8/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yB8hWljuWTZYYWwLKWTIDw49lm9PgIIYX0k2LF5UrCJQzzDv/VYXN/wvGdzU7ppm4 6OESHhpfNs0CyVk3dxNkvS96ikQgb64A9k7LzUrR02CyPz+NzwZMtOtHpJPSRxgi6/ 6/8YT7zvyieGP7g0HXUOh8xKpzFvqeVe8oCUsmK4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Itay Iellin , Luiz Augusto von Dentz Subject: [PATCH 4.19 07/15] Bluetooth: Fix the creation of hdev->name Date: Fri, 13 May 2022 16:23:29 +0200 Message-Id: <20220513142228.113538429@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513142227.897535454@linuxfoundation.org> References: <20220513142227.897535454@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Itay Iellin commit 103a2f3255a95991252f8f13375c3a96a75011cd upstream. Set a size limit of 8 bytes of the written buffer to "hdev->name" including the terminating null byte, as the size of "hdev->name" is 8 bytes. If an id value which is greater than 9999 is allocated, then the "snprintf(hdev->name, sizeof(hdev->name), "hci%d", id)" function call would lead to a truncation of the id value in decimal notation. Set an explicit maximum id parameter in the id allocation function call. The id allocation function defines the maximum allocated id value as the maximum id parameter value minus one. Therefore, HCI_MAX_ID is defined as 10000. Signed-off-by: Itay Iellin Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Greg Kroah-Hartman --- include/net/bluetooth/hci_core.h | 3 +++ net/bluetooth/hci_core.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -34,6 +34,9 @@ /* HCI priority */ #define HCI_PRIO_MAX 7 +/* HCI maximum id value */ +#define HCI_MAX_ID 10000 + /* HCI Core structures */ struct inquiry_data { bdaddr_t bdaddr; --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3180,10 +3180,10 @@ int hci_register_dev(struct hci_dev *hde */ switch (hdev->dev_type) { case HCI_PRIMARY: - id = ida_simple_get(&hci_index_ida, 0, 0, GFP_KERNEL); + id = ida_simple_get(&hci_index_ida, 0, HCI_MAX_ID, GFP_KERNEL); break; case HCI_AMP: - id = ida_simple_get(&hci_index_ida, 1, 0, GFP_KERNEL); + id = ida_simple_get(&hci_index_ida, 1, HCI_MAX_ID, GFP_KERNEL); break; default: return -EINVAL; @@ -3192,7 +3192,7 @@ int hci_register_dev(struct hci_dev *hde if (id < 0) return id; - sprintf(hdev->name, "hci%d", id); + snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); hdev->id = id; BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);