linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Ping-Ke Shih <pkshih@realtek.com>
Cc: kvalo@kernel.org, linux-wireless@vger.kernel.org
Subject: Re: [PATCH 1/2] wifi: rtw89: coex: add annotation __counted_by() for struct rtw89_btc_btf_set_slot_table
Date: Wed, 11 Oct 2023 08:53:23 -0700	[thread overview]
Message-ID: <202310110850.6A47D35CA@keescook> (raw)
In-Reply-To: <20231011063725.25276-1-pkshih@realtek.com>

On Wed, Oct 11, 2023 at 02:37:24PM +0800, Ping-Ke Shih wrote:
> 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).
> 
> Use struct_size() and flex_array_size() helpers to calculate proper sizes
> for allocation and memcpy().
> 
> Don't change logic at all, and result is identical as before.
> 
> Cc: Kees Cook <keescook@chromium.org>
> Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>

Thanks for this!

Reviewed-by: Kees Cook <keescook@chromium.org>

> ---
>  drivers/net/wireless/realtek/rtw89/coex.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/wireless/realtek/rtw89/coex.c b/drivers/net/wireless/realtek/rtw89/coex.c
> index 4ba8b3df70ae..9f9da122f3f8 100644
> --- a/drivers/net/wireless/realtek/rtw89/coex.c
> +++ b/drivers/net/wireless/realtek/rtw89/coex.c
> @@ -237,7 +237,7 @@ struct rtw89_btc_btf_set_report {
>  struct rtw89_btc_btf_set_slot_table {
>  	u8 fver;
>  	u8 tbl_num;
> -	u8 buf[];
> +	struct rtw89_btc_fbtc_slot tbls[] __counted_by(tbl_num);
>  } __packed;
>  
>  struct rtw89_btc_btf_set_mon_reg {
> @@ -1821,19 +1821,17 @@ static void rtw89_btc_fw_en_rpt(struct rtw89_dev *rtwdev,
>  static void rtw89_btc_fw_set_slots(struct rtw89_dev *rtwdev, u8 num,
>  				   struct rtw89_btc_fbtc_slot *s)
>  {
> -	struct rtw89_btc_btf_set_slot_table *tbl = NULL;
> -	u8 *ptr = NULL;
> -	u16 n = 0;
> +	struct rtw89_btc_btf_set_slot_table *tbl;
> +	u16 n;

Using u16 instead of size_t here makes me nervous, but since "num" is
u8, wrap-around isn't possible. :P

-- 
Kees Cook

  parent reply	other threads:[~2023-10-11 15:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-11  6:37 [PATCH 1/2] wifi: rtw89: coex: add annotation __counted_by() for struct rtw89_btc_btf_set_slot_table Ping-Ke Shih
2023-10-11  6:37 ` [PATCH 2/2] wifi: rtw89: coex: add annotation __counted_by() to struct rtw89_btc_btf_set_mon_reg Ping-Ke Shih
2023-10-11 15:54   ` Kees Cook
2023-10-11 15:53 ` Kees Cook [this message]
2023-10-12 12:16 ` [PATCH 1/2] wifi: rtw89: coex: add annotation __counted_by() for struct rtw89_btc_btf_set_slot_table Kalle Valo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202310110850.6A47D35CA@keescook \
    --to=keescook@chromium.org \
    --cc=kvalo@kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=pkshih@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).