Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp94913lqg; Fri, 26 Apr 2024 09:38:24 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfuQJ1KaBGaQfj1mCbA/MvR3zfCakvizxtK0Pwl+JwOy3NbcOy7GWexbUTVkl4cDkdWjNu3QzPh9uBkKeXlx7qZ01zlkNgcdgu29jukQ== X-Google-Smtp-Source: AGHT+IEaZXdO6HYKYFrJGzmRzKX9XRTVRXYV9ElWhFl8s78Z8xZLts1D7kqniJVT8OSuLTdMaLw0 X-Received: by 2002:a05:620a:124b:b0:790:888e:4c5a with SMTP id a11-20020a05620a124b00b00790888e4c5amr3549188qkl.34.1714149504008; Fri, 26 Apr 2024 09:38:24 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714149503; cv=pass; d=google.com; s=arc-20160816; b=nXld2ro82ITtWRtwhxjYM/4h1nMeyx8BZCudzkw4xm3LmZizLy0XHv7XXCLosdNWOd /QJP/SVGTTO9K1FvSbNx4LHMTvov/mNmeHO6Jxtjvud5Mxmx5ITrqjx8/CwSV3xaaYxH PE4VCzzFWvRoT5VMmJcpQd5xNuCfMPMJrcF9yj4J3P4X2WjO87i/M7A7OxCQn0OlgaU3 ffqMKfCFhsmYMKkFt6Se08zF3s5/3B0FBkKBP//DV7qb/D0O9tlOafjxw3lqblY24TeJ /qinnA8j8iQs+DtgXfN77SZ81nx+h0WLR20XRbmo6lS4e+5D2h0RI9zfxAmotKXlSoQk XDsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:subject:cc:to:from:date :dkim-signature; bh=2A2LfLa3DNS8UeDE3A7tRe3Bf8n6InEeNx6W484avYk=; fh=X6kffvUcJ/nhnwYrA/XNypDu+0IBsQcSzNR2Bu+p+zc=; b=IBLBBn3Vy9xX9S/ewG4dMtAmbznVFmia5u+3hh096glBjF/VF42g+l9VuBGqjmIC6C jqqIeZpcI0c769wmxvj0GwZJxTr8/deNAKkXRlGI924/7rBuWbzelhcsSnM2H7Q4Dl9p 8s/011aGh6I32oVDUHdUzr3IWrH7p28u0bPiZ71X0NqG9tPMu9evhuUIH03ItFK7tXx3 hqNDi8djhUbQJ+AUBkNRLeGcrwxQVjaCJzc7or+9+iSOXEaEZtUVcD+/H5aejqdQBTvq +IztC7dfx4Yj0kDt1/bFk2KM9toS951OxwNzGZ05IVcGDasA05cXP7dMAYTZg0eqUZDT llDw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MH36pfzL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-bluetooth+bounces-4121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wi10-20020a05620a570a00b0078ec44f70bdsi20067492qkn.279.2024.04.26.09.38.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 09:38:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-4121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MH36pfzL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-bluetooth+bounces-4121-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-4121-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B93451C21E8A for ; Fri, 26 Apr 2024 16:38:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51968153BD0; Fri, 26 Apr 2024 16:38:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MH36pfzL" X-Original-To: linux-bluetooth@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5E211DFED; Fri, 26 Apr 2024 16:38:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149494; cv=none; b=eE4CuLIJXtHzeVrbocEeOZn9WWJtx8QqN9QDpcgCrr+B49WlVrfd0Ad4VcPUz3pnyoR2TbsRvHhJpWfAn2HrijqtgVmk7EdpIo4uEslsONTUgAwwQsmOZIW3CZYjZBzaxWkldmSKDCOU75+CiA9nyYzGzuyjEVsYgSO06d1Sixg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714149494; c=relaxed/simple; bh=po/3tPrumZXnjowvfQF0vobOIrYbMuIpxi3ty3Z4bsM=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=oyBRJeshFl4tNlXFoC6zclZZl71Tfd+NIPFUdUyk3SuOJEaDwkiHSokrVWU/Ix/vAieo+Turu+YQdwxucck/7qp45ZRDNHgPr3ZcOJakYyHK3MkaBSrub+JiuuLXiRdDXN0v08l4ABCPXVW5HDwhnieDVNmhh7liDHmaxCFdYAk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MH36pfzL; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FE92C113CD; Fri, 26 Apr 2024 16:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714149494; bh=po/3tPrumZXnjowvfQF0vobOIrYbMuIpxi3ty3Z4bsM=; h=Date:From:To:Cc:Subject:From; b=MH36pfzL5D0g8R54Ia7dwcxBhngVinvMwXLHW4/ap4/EgiHy8OaPeWQVork3iJQty BLCUKNcR7mFVQYIPE0xVhMBMp2l7tKRvJ6BlEbEVFeubLwHBw7teqqZvb7mSum2p2R LhOxkHfsxW23IxmfKx8VwSGJ4Nn1RYOeLBxSfm0vRCsxgAKpl6AVVwfFFpNdnY+dha r4wD2roZproVXID2k75H/syTxz0M0ngUgRWaPE3eR1ONrpb5u3pivo6Qsl1Cil9qTs 2a/szL36z7LXJTmvt4L+V/6LgMeZ0PQg5zL3mzYwwZEoVs8EaQ+AwpCZkI332t2rMQ OoBR7zQA4nLqA== Date: Fri, 26 Apr 2024 10:38:10 -0600 From: "Gustavo A. R. Silva" To: Marcel Holtmann , Johan Hedberg , Luiz Augusto von Dentz , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] Bluetooth: hci_conn: Use __counted_by() in struct hci_cp_le_big_create_sync and avoid -Wfamnae warning Message-ID: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Prepare for the coming implementation by GCC and Clang of the __counted_by attribute. Flexible array members annotated with __counted_by can have their accesses bounds-checked at run-time via CONFIG_UBSAN_BOUNDS (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family functions). Also, -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting ready to enable it globally. So, use the `DEFINE_FLEX()` helper for an on-stack definition of a flexible structure where the size of the flexible-array member is known at compile-time, and refactor the rest of the code, accordingly. With these changes, fix the following warning: net/bluetooth/hci_conn.c:2116:50: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end] Link: https://github.com/KSPP/linux/issues/202 Signed-off-by: Gustavo A. R. Silva --- include/net/bluetooth/hci.h | 2 +- net/bluetooth/hci_conn.c | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 5c12761cbc0e..fe23e862921d 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -2216,7 +2216,7 @@ struct hci_cp_le_big_create_sync { __u8 mse; __le16 timeout; __u8 num_bis; - __u8 bis[]; + __u8 bis[] __counted_by(num_bis); } __packed; #define HCI_OP_LE_BIG_TERM_SYNC 0x206c diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 81166a5bc034..4c2efec81995 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -2112,13 +2112,11 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon, struct bt_iso_qos *qos, __u16 sync_handle, __u8 num_bis, __u8 bis[]) { - struct _packed { - struct hci_cp_le_big_create_sync cp; - __u8 bis[0x11]; - } pdu; + DEFINE_FLEX(struct hci_cp_le_big_create_sync, pdu, bis, num_bis, 0x11); + size_t pdu_size = __struct_size(pdu); int err; - if (num_bis < 0x01 || num_bis > sizeof(pdu.bis)) + if (num_bis < 0x01 || num_bis > pdu->num_bis) return -EINVAL; err = qos_set_big(hdev, qos); @@ -2128,18 +2126,16 @@ int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon, if (hcon) hcon->iso_qos.bcast.big = qos->bcast.big; - memset(&pdu, 0, sizeof(pdu)); - pdu.cp.handle = qos->bcast.big; - pdu.cp.sync_handle = cpu_to_le16(sync_handle); - pdu.cp.encryption = qos->bcast.encryption; - memcpy(pdu.cp.bcode, qos->bcast.bcode, sizeof(pdu.cp.bcode)); - pdu.cp.mse = qos->bcast.mse; - pdu.cp.timeout = cpu_to_le16(qos->bcast.timeout); - pdu.cp.num_bis = num_bis; - memcpy(pdu.bis, bis, num_bis); - - return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC, - sizeof(pdu.cp) + num_bis, &pdu); + pdu->handle = qos->bcast.big; + pdu->sync_handle = cpu_to_le16(sync_handle); + pdu->encryption = qos->bcast.encryption; + memcpy(pdu->bcode, qos->bcast.bcode, sizeof(pdu->bcode)); + pdu->mse = qos->bcast.mse; + pdu->timeout = cpu_to_le16(qos->bcast.timeout); + pdu->num_bis = num_bis; + memcpy(pdu->bis, bis, num_bis); + + return hci_send_cmd(hdev, HCI_OP_LE_BIG_CREATE_SYNC, pdu_size, pdu); } static void create_big_complete(struct hci_dev *hdev, void *data, int err) -- 2.34.1