Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp996419iob; Fri, 13 May 2022 19:01:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySTBPbypydMk561MRXmJgN3lV1+cvNrCJDqWC+t0z8OnQ41E0Pq+S85mwHhzGatPagVkGA X-Received: by 2002:a5d:4b8b:0:b0:20c:f8c5:b9bc with SMTP id b11-20020a5d4b8b000000b0020cf8c5b9bcmr836158wrt.282.1652493718553; Fri, 13 May 2022 19:01:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652493718; cv=none; d=google.com; s=arc-20160816; b=fe3hvHz5rIa6YKCFaOrDh4fHSLFhfZ6x70jdAyiYXo9SDkgxDlCHnmk52QLjh0uwWV rFrDVs9H4bi3ac+C+2Dhhthqw84HOwEIow7wEH4C2fbWuUO/Y9SfRmWPxJoWW2eUsjRZ qc60MwCKvNQ4nlX2sD9Gq59RYbKiMz5fDohSx0iDQlgObPQ1rdtb1eqW/gzb/G7tO9vq 6qs/56Gl4VWBTYEX2AB7NpFhLqzMqt9tQ7MLwFn9DZX0sK79xey7I9iEj/p6IG/h5dpU +ZrMmSUTiskH09gea/zYY/HLEVM/7OKrZ8OtJNZgTaJ+/xDwhiRo4hWvh4HrELkYqgwm gr5Q== 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=zLp/pAk4lZBVI8+RDrpjY58v+0bZwaeKAKRQHeKKXSo=; b=opjUutnankhH5BQY/vRnd8SXxk2Br8Q+yQOt4AUvN1sovAM2UMZQ+l4CBnDtpyIqon zwt9UrMbEA2J9gBhvM/rn7i3UZommlVNfz7u7TDtzMb0i8x04dFgykYQArRljw4lCdKH sJW2L5e+ucSM/nWcvRqV/qLuLtafxJ+xqemvAwIZ8ygEIZXCf1jp4uIyBdQf1tFLejWW Ak17sx7smJ5P+zJuMeFMDJE0vHhmJSG5NQUZrC1Zh2TziibWfiZ8aTFo2b1WNU6MBpnq fXtjD1RiNOIklstnBxIwBj1OaMSoTZvQvZh9kMSii1exlBPtcpeVSL6sr2p+ZZEPDBOD N1wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bpdlGr93; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id y9-20020a05600015c900b0020ac67db675si4904763wry.1005.2022.05.13.19.01.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 19:01:58 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bpdlGr93; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 A77FC478A0E; Fri, 13 May 2022 17:23:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354081AbiEMO3x (ORCPT + 99 others); Fri, 13 May 2022 10:29:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381117AbiEMO0p (ORCPT ); Fri, 13 May 2022 10:26:45 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4869250E11; Fri, 13 May 2022 07:26:43 -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 C11DDB82C9D; Fri, 13 May 2022 14:26:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F6BBC34100; Fri, 13 May 2022 14:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652452000; bh=HWTMEGbsHhXtcvzhDNm8UxDIRyRvfDBRzlYitpsBLYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpdlGr93yMLojJR+ushecK87W9x7WFJea7+IllbE+3b40Yq5Zamo+qsvU2wk/76MY 6+4tyNAZMErkhTuVcK6iWSvz7AhZR7kSdZ5Z7RacrmENMZ86vbytsQvkObgbx03434 x25SWjnn8Drd37RzWCEAGs8Fi5Fs+U7rm18E352c= 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 5.4 15/18] Bluetooth: Fix the creation of hdev->name Date: Fri, 13 May 2022 16:23:41 +0200 Message-Id: <20220513142229.598090397@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513142229.153291230@linuxfoundation.org> References: <20220513142229.153291230@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 @@ -3304,10 +3304,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; @@ -3316,7 +3316,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);