Search Linux Wireless

Re: [PATCH 1/2] wifi: rtw89: coex: add annotation __counted_by() for struct rtw89_btc_btf_set_slot_table

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxx>
> Signed-off-by: Ping-Ke Shih <pkshih@xxxxxxxxxxx>

Thanks for this!

Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>

> ---
>  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



[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux