Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: wwan: iosm: Convert single instance struct member to flexible array

struct mux_adth actually ends with multiple struct mux_adth_dg members.
This is seen both in the comments about the member:

/**
* struct mux_adth - Structure of the Aggregated Datagram Table Header.
...
* @dg: datagramm table with variable length
*/

and in the preparation for populating it:

adth_dg_size = offsetof(struct mux_adth, dg) +
ul_adb->dg_count[i] * sizeof(*dg);
...
adth_dg_size -= offsetof(struct mux_adth, dg);
memcpy(&adth->dg, ul_adb->dg[i], adth_dg_size);

This was reported as a run-time false positive warning:

memcpy: detected field-spanning write (size 16) of single field "&adth->dg" at drivers/net/wwan/iosm/iosm_ipc_mux_codec.c:852 (size 8)

Adjust the struct mux_adth definition and associated sizeof() math; no binary
output differences are observed in the resulting object file.

Reported-by: Florian Klink <flokli@flokli.de>
Closes: https://lore.kernel.org/lkml/dbfa25f5-64c8-5574-4f5d-0151ba95d232@gmail.com/
Fixes: 1f52d7b62285 ("net: wwan: iosm: Enable M.2 7360 WWAN card support")
Cc: M Chetan Kumar <m.chetan.kumar@intel.com>
Cc: Bagas Sanjaya <bagasdotme@gmail.com>
Cc: Intel Corporation <linuxwwan@intel.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Sergey Ryazanov <ryazanov.s.a@gmail.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230620194234.never.023-kees@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Kees Cook and committed by
Paolo Abeni
dec24b3b 2174a08d

+7 -10
+6 -9
drivers/net/wwan/iosm/iosm_ipc_mux_codec.c
··· 626 626 if (adth->signature != cpu_to_le32(IOSM_AGGR_MUX_SIG_ADTH)) 627 627 goto adb_decode_err; 628 628 629 - if (le16_to_cpu(adth->table_length) < (sizeof(struct mux_adth) - 630 - sizeof(struct mux_adth_dg))) 629 + if (le16_to_cpu(adth->table_length) < sizeof(struct mux_adth)) 631 630 goto adb_decode_err; 632 631 633 632 /* Calculate the number of datagrams. */ 634 633 nr_of_dg = (le16_to_cpu(adth->table_length) - 635 - sizeof(struct mux_adth) + 636 - sizeof(struct mux_adth_dg)) / 634 + sizeof(struct mux_adth)) / 637 635 sizeof(struct mux_adth_dg); 638 636 639 637 /* Is the datagram table empty ? */ ··· 647 649 } 648 650 649 651 /* New aggregated datagram table. */ 650 - dg = &adth->dg; 652 + dg = adth->dg; 651 653 if (mux_dl_process_dg(ipc_mux, adbh, dg, skb, if_id, 652 654 nr_of_dg) < 0) 653 655 goto adb_decode_err; ··· 847 849 adth->if_id = i; 848 850 adth->table_length = cpu_to_le16(adth_dg_size); 849 851 adth_dg_size -= offsetof(struct mux_adth, dg); 850 - memcpy(&adth->dg, ul_adb->dg[i], adth_dg_size); 852 + memcpy(adth->dg, ul_adb->dg[i], adth_dg_size); 851 853 ul_adb->if_cnt++; 852 854 } 853 855 ··· 1424 1426 1425 1427 if (adth->signature == cpu_to_le32(IOSM_AGGR_MUX_SIG_ADTH)) { 1426 1428 nr_of_dg = (le16_to_cpu(adth->table_length) - 1427 - sizeof(struct mux_adth) + 1428 - sizeof(struct mux_adth_dg)) / 1429 + sizeof(struct mux_adth)) / 1429 1430 sizeof(struct mux_adth_dg); 1430 1431 1431 1432 if (nr_of_dg <= 0) 1432 1433 return payload_size; 1433 1434 1434 - dg = &adth->dg; 1435 + dg = adth->dg; 1435 1436 1436 1437 for (i = 0; i < nr_of_dg; i++, dg++) { 1437 1438 if (le32_to_cpu(dg->datagram_index) <
+1 -1
drivers/net/wwan/iosm/iosm_ipc_mux_codec.h
··· 161 161 u8 opt_ipv4v6; 162 162 __le32 next_table_index; 163 163 __le32 reserved2; 164 - struct mux_adth_dg dg; 164 + struct mux_adth_dg dg[]; 165 165 }; 166 166 167 167 /**