Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1040871iob; Fri, 13 May 2022 20:43:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+4fCJt8sQ86wErqH2L5z5HjReAo2a/K12TDiTlNWpHBiSg/8VDHRIbp7//cVBpUxBE1hO X-Received: by 2002:a7b:c842:0:b0:394:8d6c:2768 with SMTP id c2-20020a7bc842000000b003948d6c2768mr7135368wml.205.1652499836648; Fri, 13 May 2022 20:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652499836; cv=none; d=google.com; s=arc-20160816; b=uN/4bO4goI4Rybbf9N3yeafAPw8OD/89oAVc7Sf/osekzvqnH5/z/uOnRyVA4i2fJm YbSlSC8CG+e3ljpLzG/d8A8oFDvKQH6o+yy9dRI4gdo7l0U+t5LjK9JJ/Kc61rtd57F9 LZtLmMGZbGn9Miyh9JI08AIYFnBPN28tvmunzet4yRYF9hb1oE+/CDkLPMCo8sLaol26 1zvSqNqlIzZ6u73j5fBYMTqW+DrG6OfwtEI2k9KleNLKl1lznDmamNim2gSZMzdqoftU Hv4/l/boh2gpA85BSvC9ZfCr+7GtI63+ilwJz2UfEohRv8x9svuZRQyJPi0qEyIl/F8E W13w== 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=fSRK0slhkxgFeVkGmkuv9MS4WXSDzX5UJt8nlzYwGmQ=; b=SqcpI/fIu2QozehBICMY7wLmtCyJKAZjZRZGOhXhKJvajGG+3ECqcuNALFh85PEkKJ J6NHwRf2fOVbVbgiX6CmLjUxoycLrK2xB8u89Tn6q2jCPDPs/Pj+gnH0E5ooUiYW4P/i ZmOdUm2Vfx/yzsEkrUHXJeGfln8zB72H4vgnbVul5WnlKvgsNQXHWNDMuDjRKZiAplDa eGO7cVA92PhW2DgxVil41oTTsXZ3SAXcMoLu1Pzm9RrTr4yRfQGpW13LBbIb+CysamVJ JZnequVHadNKSvslCyGn4pZCQfsuqrkYXG8gFhUvmKkLziDawIRZYLiIR/JBeNPEGllD O5qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qHjx+8sa; 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 x17-20020adfec11000000b0020ad660fdd4si3293101wrn.937.2022.05.13.20.43.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 20:43:56 -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=qHjx+8sa; 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 1B53F19FB8; Fri, 13 May 2022 17:18:05 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358459AbiEMOYx (ORCPT + 99 others); Fri, 13 May 2022 10:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377121AbiEMOYm (ORCPT ); Fri, 13 May 2022 10:24:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24EC5E776; Fri, 13 May 2022 07:24:38 -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 16882B83066; Fri, 13 May 2022 14:24:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 785ADC34100; Fri, 13 May 2022 14:24:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652451875; bh=PBa8sL0oCxRUeHCvlHrhvKzDLOopX+Bs1SglWaSBGi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qHjx+8saEJaYsVRxgjKiZL+GoCksflC6C2WIZ7Cjndt2AqSKxwlD8grc0WngNAQuJ GzpHSbd+82fNhezvZg9F3sXFcJe0QahkP8b86+mDiOYx1Rmb82hW/RSTed0mdRNopS sLTjGftCW5ZzGA+2vvU0JmuNycYmjwhEoCIhTIYo= 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.9 5/7] Bluetooth: Fix the creation of hdev->name Date: Fri, 13 May 2022 16:23:20 +0200 Message-Id: <20220513142226.071179784@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220513142225.909697091@linuxfoundation.org> References: <20220513142225.909697091@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 @@ -32,6 +32,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 @@ -3064,10 +3064,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; @@ -3076,7 +3076,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);