DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata
@ 2018-08-13 16:03 David Marchand
  2018-08-13 16:03 ` [dpdk-dev] [RFC 2/2] ethdev: check received mbufs sanity David Marchand
  2018-08-23  7:39 ` [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata Olivier Matz
  0 siblings, 2 replies; 5+ messages in thread
From: David Marchand @ 2018-08-13 16:03 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko, Olivier Matz

Add some basic check on the segments offset and length metadata:
always funny to have a < 0 tailroom cast to uint16_t ;-).

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_mbuf/rte_mbuf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
index e714c5a..7eeef12 100644
--- a/lib/librte_mbuf/rte_mbuf.c
+++ b/lib/librte_mbuf/rte_mbuf.c
@@ -200,6 +200,8 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
 	pkt_len = m->pkt_len;
 
 	do {
+		if (m->data_off + m->data_len > m->buf_len)
+			rte_panic("bad segment metadata\n");
 		nb_segs -= 1;
 		pkt_len -= m->data_len;
 	} while ((m = m->next) != NULL);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [dpdk-dev] [RFC 2/2] ethdev: check received mbufs sanity
  2018-08-13 16:03 [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata David Marchand
@ 2018-08-13 16:03 ` David Marchand
  2018-08-24 10:17   ` David Marchand
  2018-08-23  7:39 ` [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata Olivier Matz
  1 sibling, 1 reply; 5+ messages in thread
From: David Marchand @ 2018-08-13 16:03 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko, Olivier Matz

Let's check the mbufs given by the drivers directly in the rx handler.
The only drawback is that you need CONFIG_RTE_LIBRTE_MBUF_DEBUG to be set
for this to actually do some real checks.

Signed-off-by: David Marchand <david.marchand@6wind.com>
---
 lib/librte_ethdev/rte_ethdev.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index 7070e9a..8843307 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -3803,6 +3803,7 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 {
 	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
 	uint16_t nb_rx;
+	uint16_t index;
 
 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
@@ -3816,6 +3817,9 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 	nb_rx = (*dev->rx_pkt_burst)(dev->data->rx_queues[queue_id],
 				     rx_pkts, nb_pkts);
 
+	for (index = 0; index < nb_rx; index++)
+		__rte_mbuf_sanity_check(rx_pkts[index], 1);
+
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
 	if (unlikely(dev->post_rx_burst_cbs[queue_id] != NULL)) {
 		struct rte_eth_rxtx_callback *cb =
-- 
2.7.4

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata
  2018-08-13 16:03 [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata David Marchand
  2018-08-13 16:03 ` [dpdk-dev] [RFC 2/2] ethdev: check received mbufs sanity David Marchand
@ 2018-08-23  7:39 ` Olivier Matz
  2018-08-23  7:45   ` David Marchand
  1 sibling, 1 reply; 5+ messages in thread
From: Olivier Matz @ 2018-08-23  7:39 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

Hi David,

On Mon, Aug 13, 2018 at 06:03:45PM +0200, David Marchand wrote:
> Add some basic check on the segments offset and length metadata:
> always funny to have a < 0 tailroom cast to uint16_t ;-).
> 
> Signed-off-by: David Marchand <david.marchand@6wind.com>
> ---
>  lib/librte_mbuf/rte_mbuf.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
> index e714c5a..7eeef12 100644
> --- a/lib/librte_mbuf/rte_mbuf.c
> +++ b/lib/librte_mbuf/rte_mbuf.c
> @@ -200,6 +200,8 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
>  	pkt_len = m->pkt_len;
>  
>  	do {
> +		if (m->data_off + m->data_len > m->buf_len)
> +			rte_panic("bad segment metadata\n");

What about spliting the test into two? This would help to clarify
the error messages. I also suggest add casts to uint32 to ensure
that there is no overflow.

		if (m->data_off_len > m->buf_len)
			rte_panic("data offset too big in mbuf segment\n");
		if ((uint32_t)m->data_off + (uint32_t)m->data_len > (uint32_t)m->buf_len)
			rte_panic("data length too big in mbuf segment\n");

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata
  2018-08-23  7:39 ` [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata Olivier Matz
@ 2018-08-23  7:45   ` David Marchand
  0 siblings, 0 replies; 5+ messages in thread
From: David Marchand @ 2018-08-23  7:45 UTC (permalink / raw)
  To: Olivier Matz; +Cc: dev, Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko

On Thu, Aug 23, 2018 at 9:39 AM, Olivier Matz <olivier.matz@6wind.com> wrote:
> On Mon, Aug 13, 2018 at 06:03:45PM +0200, David Marchand wrote:
>> Add some basic check on the segments offset and length metadata:
>> always funny to have a < 0 tailroom cast to uint16_t ;-).
>>
>> Signed-off-by: David Marchand <david.marchand@6wind.com>
>> ---
>>  lib/librte_mbuf/rte_mbuf.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/lib/librte_mbuf/rte_mbuf.c b/lib/librte_mbuf/rte_mbuf.c
>> index e714c5a..7eeef12 100644
>> --- a/lib/librte_mbuf/rte_mbuf.c
>> +++ b/lib/librte_mbuf/rte_mbuf.c
>> @@ -200,6 +200,8 @@ rte_mbuf_sanity_check(const struct rte_mbuf *m, int is_header)
>>       pkt_len = m->pkt_len;
>>
>>       do {
>> +             if (m->data_off + m->data_len > m->buf_len)
>> +                     rte_panic("bad segment metadata\n");
>
> What about spliting the test into two? This would help to clarify
> the error messages. I also suggest add casts to uint32 to ensure
> that there is no overflow.

Sure, will do.

-- 
David Marchand

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [dpdk-dev] [RFC 2/2] ethdev: check received mbufs sanity
  2018-08-13 16:03 ` [dpdk-dev] [RFC 2/2] ethdev: check received mbufs sanity David Marchand
@ 2018-08-24 10:17   ` David Marchand
  0 siblings, 0 replies; 5+ messages in thread
From: David Marchand @ 2018-08-24 10:17 UTC (permalink / raw)
  To: dev; +Cc: Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko, Olivier Matz

On Mon, Aug 13, 2018 at 6:03 PM, David Marchand
<david.marchand@6wind.com> wrote:
> Let's check the mbufs given by the drivers directly in the rx handler.
> The only drawback is that you need CONFIG_RTE_LIBRTE_MBUF_DEBUG to be set
> for this to actually do some real checks.

Comments ?


-- 
David Marchand

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-08-24 10:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-13 16:03 [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata David Marchand
2018-08-13 16:03 ` [dpdk-dev] [RFC 2/2] ethdev: check received mbufs sanity David Marchand
2018-08-24 10:17   ` David Marchand
2018-08-23  7:39 ` [dpdk-dev] [RFC 1/2] mbuf: add a sanity check on segment metadata Olivier Matz
2018-08-23  7:45   ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).