Displaying 9 results from an estimated 9 matches for "virtio_net_common_hdr".
2023 Aug 17
1
[PATCH net-next v2] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...> 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 virtio_net_hdr_mrg_rxbuf.
You mean virtio_net_common_hdr?
I'm not sure I follow the reasoning. Because then hdr_len might be
sizeof(virtio_net_hdr_mrg_rxbuf), but sizeof(virtio_net_common_hdr) is
larger. So the same issue remains?
Indeed, everywhere this patches replaces the one with the other, you
have to verify that nothing was using sizeof(*hdr)...
2023 Aug 17
1
[PATCH net-next v2] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...1 file changed, 23 insertions(+), 13 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 1270c8d23463..03cf744de512 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -303,6 +303,13 @@ struct padded_vnet_hdr {
char padding[12];
};
+struct virtio_net_common_hdr {
+ union {
+ struct virtio_net_hdr_mrg_rxbuf mrg_hdr;
+ struct virtio_net_hdr_v1_hash hash_v1_hdr;
+ };
+};
+
static void virtnet_rq_free_unused_buf(struct virtqueue *vq, void *buf);
static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf);
@@ -344,9 +351,10 @@ static int rxq2...
2023 Aug 17
1
[PATCH net-next v2] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...SH_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 virtio_net_hdr_mrg_rxbuf.
>
> You mean virtio_net_common_hdr?
>
It is a typo, will correct it.
> I'm not sure I follow the reasoning. Because then hdr_len might be
> sizeof(virtio_net_hdr_mrg_rxbuf), but sizeof(virtio_net_common_hdr) is
> larger. So the same issue remains?
>
static int virtnet_probe(struct virtio_device *vdev)
{
[...]
i...
2023 Aug 21
3
[PATCH net-next v3] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...-
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 8e9f4cfe941f..8c74bc8cfe68 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -303,6 +303,14 @@ struct padded_vnet_hdr {
char padding[12];
};
+struct virtio_net_common_hdr {
+ union {
+ struct virtio_net_hdr hdr;
+ struct virtio_net_hdr_mrg_rxbuf mrg_hdr;
+ struct virtio_net_hdr_v1_hash hash_v1_hdr;
+ };
+};
+
static void virtnet_rq_free_unused_buf(struct virtqueue *vq, void *buf);
static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf);
@@ -34...
2023 Aug 17
1
[PATCH net-next v2] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...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 virtio_net_hdr_mrg_rxbuf.
> >
> > You mean virtio_net_common_hdr?
> >
> It is a typo, will correct it.
>
> > I'm not sure I follow the reasoning. Because then hdr_len might be
> > sizeof(virtio_net_hdr_mrg_rxbuf), but sizeof(virtio_net_common_hdr) is
> > larger. So the same issue remains?
> >
> static int virtnet_probe(...
2023 Aug 15
1
[PATCH net v1] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...> > > > @@ -344,9 +344,10 @@ static int rxq2vq(int rxq)
> > > > return rxq * 2;
> > > > }
> > > >
> > > > -static inline struct virtio_net_hdr_mrg_rxbuf *skb_vnet_hdr(struct sk_buff *skb)
> > > > +static inline struct virtio_net_common_hdr *
> > > > +skb_vnet_common_hdr(struct sk_buff *skb)
> > > > {
> > > > - return (struct virtio_net_hdr_mrg_rxbuf *)skb->cb;
> > > > + return (struct virtio_net_common_hdr *)skb->cb;
> > > > }
> > > >
> >...
2023 Aug 15
1
[PATCH net v1] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...> > > > @@ -344,9 +344,10 @@ static int rxq2vq(int rxq)
> > > > return rxq * 2;
> > > > }
> > > >
> > > > -static inline struct virtio_net_hdr_mrg_rxbuf *skb_vnet_hdr(struct sk_buff *skb)
> > > > +static inline struct virtio_net_common_hdr *
> > > > +skb_vnet_common_hdr(struct sk_buff *skb)
> > > > {
> > > > - return (struct virtio_net_hdr_mrg_rxbuf *)skb->cb;
> > > > + return (struct virtio_net_common_hdr *)skb->cb;
> > > > }
> > > >
> >...
2023 Aug 16
1
[PATCH net v1] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...h
>>>>> @@ -201,6 +201,13 @@ struct virtio_net_hdr_mrg_rxbuf {
>>>>> struct virtio_net_hdr hdr;
>>>>> __virtio16 num_buffers; /* Number of merged rx buffers */
>>>>> };
>>>>> +
>>>>> +struct virtio_net_common_hdr {
>>>>> + union {
>>>>> + struct virtio_net_hdr_mrg_rxbuf mrg_hdr;
>>>>> + struct virtio_net_hdr_v1_hash hash_v1_hdr;
>>>>> + };
>>>>> +};
>>>>
>>>> Does this belong in...
2023 Aug 16
1
[PATCH net v1] virtio_net: Introduce skb_vnet_common_hdr to avoid typecasting
...v1.
The union was added to overload csum use on tx with RSC use on rx, in
commit 22b436c9b568. I don't quite follow why there now are three
structs, rather than two. The first two seem to both implement csum
partial. Anyway, not super important here.
> In addition, I put this new structure virtio_net_common_hdr in uapi,
> hoping it could be used in future user space application to avoid
> potential risks caused by type coercion (such as the problems mentioned
> in the patch description ). So I think it should be in this header file.
> What do you think?
Adding anything to UAPI has a high b...