linux/drivers/net
Feng Liu dae64749db virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
The virtio_net driver currently deals with different versions and types
of virtio net headers, such as virtio_net_hdr_mrg_rxbuf,
virtio_net_hdr_v1_hash, etc. Due to these variations, the code relies
on multiple type casts to convert memory between different structures,
potentially leading to bugs when there are changes in these structures.

Introduces the "struct skb_vnet_common_hdr" as a unifying header
structure using a union. With this approach, various virtio net header
structures can be converted by accessing different members of this
structure, thus eliminating the need for type casting and reducing the
risk of potential bugs.

For example following code:
static struct sk_buff *page_to_skb(struct virtnet_info *vi,
		struct receive_queue *rq,
		struct page *page, unsigned int offset,
		unsigned int len, unsigned int truesize,
		unsigned int headroom)
{
[...]
	struct virtio_net_hdr_mrg_rxbuf *hdr;
[...]
	hdr_len = vi->hdr_len;
[...]
ok:
	hdr = skb_vnet_hdr(skb);
	memcpy(hdr, hdr_p, hdr_len);
[...]
}

When VIRTIO_NET_F_HASH_REPORT feature is enabled, hdr_len = 20
But the sizeof(*hdr) is 12,
memcpy(hdr, hdr_p, hdr_len); will copy 20 bytes to the hdr,
which make a potential risk of bug. And this risk can be avoided by
introducing struct skb_vnet_common_hdr.

Change log
v1->v2
feedback from Willem de Bruijn <willemdebruijn.kernel@gmail.com>
feedback from Simon Horman <horms@kernel.org>
1. change to use net-next tree.
2. move skb_vnet_common_hdr inside kernel file instead of the UAPI header.

v2->v3
feedback from Willem de Bruijn <willemdebruijn.kernel@gmail.com>
1. fix typo in commit message.
2. add original struct virtio_net_hdr into union
3. remove virtio_net_hdr_mrg_rxbuf variable in receive_buf;

Signed-off-by: Feng Liu <feliu@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-08-23 09:40:18 +01:00
..
appletalk
arcnet
bonding bonding: update port speed when getting bond speed 2023-08-22 15:10:35 +02:00
caif
can can: esd_usb: Add support for esd CAN-USB/3 2023-08-03 09:24:30 +02:00
dsa net: dsa: microchip: Remove unused declarations 2023-08-22 10:28:13 -07:00
ethernet mlx4: Delete custom device management logic 2023-08-23 08:25:28 +01:00
fddi
fjes
hamradio
hippi
hyperv eth: add missing xdp.h includes in drivers 2023-08-03 08:38:07 -07:00
ieee802154 net: Explicitly include correct DT includes 2023-07-27 20:33:16 -07:00
ipa net: Explicitly include correct DT includes 2023-07-27 20:33:16 -07:00
ipvlan
mctp
mdio net: mdio: xgene: remove useless xgene_mdio_status 2023-08-19 19:25:27 +01:00
netdevsim net: netdevsim: mimic tc-taprio offload 2023-08-09 15:59:21 -07:00
pcs net: pcs: lynxi: implement pcs_disable op 2023-08-21 19:08:57 -07:00
phy dp83640: Use list_for_each_entry() helper 2023-08-23 09:39:15 +01:00
plip
ppp
pse-pd
slip
team Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-08-18 12:44:56 -07:00
thunderbolt
usb eth: r8152: try to use a normal budget 2023-08-15 19:07:12 -07:00
vmxnet3 vmxnet3: Add XDP support. 2023-08-14 08:03:52 +01:00
vxlan vxlan: vnifilter: Use GFP_KERNEL instead of GFP_ATOMIC 2023-08-22 10:58:45 -07:00
wan
wireguard genetlink: use attrs from struct genl_info 2023-08-15 15:00:45 -07:00
wireless wlcore: spi: Remove redundant of_match_ptr() 2023-08-16 09:59:40 +01:00
wwan
xen-netback xen/netback: Fix buffer overrun triggered by unusual packet 2023-08-03 09:04:08 +02:00
Kconfig netconsole: Enable compile time configuration 2023-08-17 19:25:42 -07:00
LICENSE.SRC
Makefile
Space.c
amt.c
bareudp.c
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
loopback.c
macsec.c net: macsec: Use helper functions to update stats 2023-08-14 08:06:24 +01:00
macvlan.c net: macvlan: convert to ndo_hwtstamp_get() / ndo_hwtstamp_set() 2023-08-02 19:11:06 -07:00
macvtap.c
mdio.c
mhi_net.c net: mhi: Remove redundant initialization owner in mhi_net_driver 2023-08-10 17:29:42 -07:00
mii.c
net_failover.c
netconsole.c netconsole: Enable compile time configuration 2023-08-17 19:25:42 -07:00
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
sungem_phy.c
tap.c pull-request: bpf-next 2023-08-03 2023-08-03 15:34:36 -07:00
tun.c tun: add __exit annotations to module exit func tun_cleanup() 2023-08-17 19:11:10 -07:00
veth.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2023-08-18 12:44:56 -07:00
virtio_net.c virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting 2023-08-23 09:40:18 +01:00
vrf.c vrf: Remove unnecessary RCU-bh critical section 2023-08-22 10:58:50 -07:00
vsockmon.c
xen-netfront.c page_pool: split types and declarations from page_pool.h 2023-08-07 13:05:19 -07:00