mirror-linux/drivers/net
Kees Cook 2edd8c192f net/mlx4_en: Introduce flexible array to silence overflow warning
[ Upstream commit f8f185e39b ]

The call "skb_copy_from_linear_data(skb, inl + 1, spc)" triggers a FORTIFY
memcpy() warning on ppc64 platform:

In function ‘fortify_memcpy_chk’,
    inlined from ‘skb_copy_from_linear_data’ at ./include/linux/skbuff.h:4029:2,
    inlined from ‘build_inline_wqe’ at drivers/net/ethernet/mellanox/mlx4/en_tx.c:722:4,
    inlined from ‘mlx4_en_xmit’ at drivers/net/ethernet/mellanox/mlx4/en_tx.c:1066:3:
./include/linux/fortify-string.h:513:25: error: call to ‘__write_overflow_field’ declared with
attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()?
[-Werror=attribute-warning]
  513 |                         __write_overflow_field(p_size_field, size);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Same behaviour on x86 you can get if you use "__always_inline" instead of
"inline" for skb_copy_from_linear_data() in skbuff.h

The call here copies data into inlined tx destricptor, which has 104
bytes (MAX_INLINE) space for data payload. In this case "spc" is known
in compile-time but the destination is used with hidden knowledge
(real structure of destination is different from that the compiler
can see). That cause the fortify warning because compiler can check
bounds, but the real bounds are different.  "spc" can't be bigger than
64 bytes (MLX4_INLINE_ALIGN), so the data can always fit into inlined
tx descriptor. The fact that "inl" points into inlined tx descriptor is
determined earlier in mlx4_en_xmit().

Avoid confusing the compiler with "inl + 1" constructions to get to past
the inl header by introducing a flexible array "data" to the struct so
that the compiler can see that we are not dealing with an array of inl
structs, but rather, arbitrary data following the structure. There are
no changes to the structure layout reported by pahole, and the resulting
machine code is actually smaller.

Reported-by: Josef Oskera <joskera@redhat.com>
Link: https://lore.kernel.org/lkml/20230217094541.2362873-1-joskera@redhat.com
Fixes: f68f2ff915 ("fortify: Detect struct member overflows in memcpy() at compile-time")
Cc: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://lore.kernel.org/r/20230218183842.never.954-kees@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-10 09:33:08 +01:00
..
appletalk
arcnet
bonding bonding: fix error checking in bond_debug_reregister() 2023-02-14 19:11:44 +01:00
caif
can can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL 2023-03-10 09:33:06 +01:00
dsa net: dsa: mt7530: don't change PVC_EG_TAG when CPU port becomes VLAN-aware 2023-02-14 19:11:46 +01:00
ethernet net/mlx4_en: Introduce flexible array to silence overflow warning 2023-03-10 09:33:08 +01:00
fddi
fjes
hamradio
hippi
hyperv hv_netvsc: Allocate memory in netvsc_dma_map() with GFP_ATOMIC 2023-02-14 19:11:40 +01:00
ieee802154
ipa net: ipa: generic command param fix 2023-03-10 09:33:02 +01:00
ipvlan
mctp
mdio net: mdio-mux-meson-g12a: force internal PHY off on mux switch 2023-02-01 08:34:49 +01:00
netdevsim
pcs
phy net: phy: meson-gxl: use MMD access dummy stubs for GXL, internal PHY 2023-02-14 19:11:44 +01:00
plip
ppp use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
pse-pd
slip
team
usb net/usb: kalmia: Don't pass act_len in usb_bulk_msg error path 2023-02-22 12:59:52 +01:00
vmxnet3 vmxnet3: move rss code block under eop descriptor 2023-02-22 12:59:46 +01:00
vxlan
wan net: wan: Add checks for NULL for utdm in undo_uhdlc_init and unmap_si_regs 2023-02-01 08:34:17 +01:00
wireguard
wireless wifi: mwifiex: fix loop iterator in mwifiex_update_ampdu_txwinsize() 2023-03-10 09:33:03 +01:00
wwan net: wwan: t7xx: Fix Runtime PM initialization 2023-02-09 11:28:05 +01:00
xen-netback
Kconfig
LICENSE.SRC
Makefile
Space.c
amt.c
bareudp.c
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
loopback.c
macsec.c
macvlan.c
macvtap.c
mdio.c
mhi_net.c
mii.c
net_failover.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
sungem_phy.c
tap.c tap: tap_open(): correctly initialize socket uid 2023-03-10 09:33:01 +01:00
thunderbolt.c
tun.c tun: tun_chr_open(): correctly initialize socket uid 2023-03-10 09:33:01 +01:00
veth.c
virtio_net.c virtio-net: Keep stop() to follow mirror sequence of open() 2023-02-09 11:28:11 +01:00
vrf.c
vsockmon.c
xen-netfront.c