DPDK patches and discussions
 help / color / mirror / Atom feed
* ring name length simplification  in ipsec_mb_qp_create_processed_ops_ring
@ 2023-05-30 23:34 Stephen Hemminger
  2023-06-20 15:27 ` Ji, Kai
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Hemminger @ 2023-05-30 23:34 UTC (permalink / raw)
  To: Fan Zhang; +Cc: dev

I was looking at places in DPDK that are using rte_strlcpy which should be using strlcpy
directly instead.  Looking at this code in ipsec_mb, the use of strlcpy is actually
not needed at all.

/** Create a ring to place processed operations on */
static struct rte_ring
*ipsec_mb_qp_create_processed_ops_ring(
	struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
{
	struct rte_ring *r;
	char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];

	unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));

	if (n >= sizeof(ring_name))
		return NULL;

	r = rte_ring_lookup(ring_name);

1. The maximum length name allowed for rte_ring is 30 characters which comes from
RTE_MEMZONE_NAMESIZE- sizeof(RTE_RING_MZ_PREFIX) + 1 = 32 - 3 + 1 = 30

2. RTE_CRYPTODEV_NAME_MAX_LEN is 64, qp->name is in struct ipsec_mb_qp is always the same size.

3. Ring create already does a copy of name, so making a copy here is not needed.

Therefore copying the name is not going to ever catch any errors. And if qp->name is
too long it won't fail until ring_create().

Would be better to just do something simpler like:

diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
index 3e52f9567401..4af6592f12c5 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
@@ -185,12 +185,7 @@ static struct rte_ring
        struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
 {
        struct rte_ring *r;
-       char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];
-
-       unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));
-
-       if (n >= sizeof(ring_name))
-               return NULL;
+       const char *ring_name = qp->name;
 
        r = rte_ring_lookup(ring_name);
        if (r) {

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

* Re: ring name length simplification  in ipsec_mb_qp_create_processed_ops_ring
  2023-05-30 23:34 ring name length simplification in ipsec_mb_qp_create_processed_ops_ring Stephen Hemminger
@ 2023-06-20 15:27 ` Ji, Kai
  0 siblings, 0 replies; 2+ messages in thread
From: Ji, Kai @ 2023-06-20 15:27 UTC (permalink / raw)
  To: Stephen Hemminger, Fan Zhang; +Cc: dev

[-- Attachment #1: Type: text/plain, Size: 2278 bytes --]

Can you fix the commit messages with signed-off and Fixes

Acked-by: Kai Ji <kai.ji@intel.com<mailto:kai.ji@intel.com>>

________________________________
From: Stephen Hemminger <stephen@networkplumber.org>
Sent: 31 May 2023 00:34
To: Fan Zhang <fanzhang.oss@gmail.com>
Cc: dev@dpdk.org <dev@dpdk.org>
Subject: ring name length simplification in ipsec_mb_qp_create_processed_ops_ring

I was looking at places in DPDK that are using rte_strlcpy which should be using strlcpy
directly instead.  Looking at this code in ipsec_mb, the use of strlcpy is actually
not needed at all.

/** Create a ring to place processed operations on */
static struct rte_ring
*ipsec_mb_qp_create_processed_ops_ring(
        struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
{
        struct rte_ring *r;
        char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];

        unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));

        if (n >= sizeof(ring_name))
                return NULL;

        r = rte_ring_lookup(ring_name);

1. The maximum length name allowed for rte_ring is 30 characters which comes from
RTE_MEMZONE_NAMESIZE- sizeof(RTE_RING_MZ_PREFIX) + 1 = 32 - 3 + 1 = 30

2. RTE_CRYPTODEV_NAME_MAX_LEN is 64, qp->name is in struct ipsec_mb_qp is always the same size.

3. Ring create already does a copy of name, so making a copy here is not needed.

Therefore copying the name is not going to ever catch any errors. And if qp->name is
too long it won't fail until ring_create().

Would be better to just do something simpler like:

diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
index 3e52f9567401..4af6592f12c5 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
@@ -185,12 +185,7 @@ static struct rte_ring
        struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
 {
        struct rte_ring *r;
-       char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];
-
-       unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));
-
-       if (n >= sizeof(ring_name))
-               return NULL;
+       const char *ring_name = qp->name;

        r = rte_ring_lookup(ring_name);
        if (r) {

[-- Attachment #2: Type: text/html, Size: 4361 bytes --]

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

end of thread, other threads:[~2023-06-20 15:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 23:34 ring name length simplification in ipsec_mb_qp_create_processed_ops_ring Stephen Hemminger
2023-06-20 15:27 ` Ji, Kai

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).