Skip to contentSkip to conversation

Enforce flag checking in API's

RFC Superseded Stephen Hemminger 7 participants 26 messages Feb 12, 2020 – Jun 16, 2020

lore
Share & tools
lore
#0 lore raw

cover Enforce flag checking in API's

Since the DPDK api's are lazy about checking for flag values it means the flags can never be extended in future releases without causing ABI breakage. This means we end up doing unnecessary symbol versioning just to work around applications that might pass in naughty bits.

This is the DPDK analog of the Linux kernel openat() problem. Openat api was added but since kernel did not check flags it ended up that another syscall openat2() was necessary before the flags could be used.

Stephen Hemminger (4):
ring: future proof flag settings
hash: check flags on creation
stack: check flags on creation
cfgfile: check flags value

 lib/librte_cfgfile/rte_cfgfile.c  | 4 ++++
 lib/librte_hash/rte_cuckoo_hash.c | 9 +++++++++
 lib/librte_ring/rte_ring.c        | 7 +++++++
 lib/librte_stack/rte_stack.c      | 5 +++++
 4 files changed, 25 insertions(+)
Signature · 1 line
2.20.1
#1 lore raw

RFC 1/4 ring: future proof flag settings

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_ring/rte_ring.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/librte_ring/rte_ring.c +7 -0
index 77e5de099b81..6cd8831649ea 100644
@@ -100,6 +100,13 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 	RTE_BUILD_BUG_ON((offsetof(struct rte_ring, prod) &
 			  RTE_CACHE_LINE_MASK) != 0);
 
+	/* future proof flags, only allow supported values */
+	if (flags & ~(RING_F_SP_ENQ | RING_F_SC_DEQ)) {
+		RTE_LOG(ERR, RING,
+			"Unsupported flags requested %d\n", flags);
+		return -EINVAL;
+	}
+		
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));
 	ret = strlcpy(r->name, name, sizeof(r->name));
Signature · 1 line
2.20.1
#2 lore raw

Re: [dpdk-dev] [RFC 1/4] ring: future proof flag settings

Quoted 23 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Wednesday, February 12, 2020 11:08 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>
Subject: [dpdk-dev] [RFC 1/4] ring: future proof flag settings

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_ring/rte_ring.c | 7 +++++++
 1 file changed, 7 insertions(+)
lib/librte_ring/rte_ring.c +0 -0
index 77e5de099b81..6cd8831649ea 100644

lib/librte_ring/rte_ring.c rte_ring_init(struct rte_ring *r, const char *name, unsigned count, · line 109

Quoted 10 lines
lib/librte_ring/rte_ring.c +7 -0
@@ -100,6 +100,13 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 	RTE_BUILD_BUG_ON((offsetof(struct rte_ring, prod) &
 			  RTE_CACHE_LINE_MASK) != 0);
 
+	/* future proof flags, only allow supported values */
+	if (flags & ~(RING_F_SP_ENQ | RING_F_SC_DEQ)) {
+		RTE_LOG(ERR, RING,
+			"Unsupported flags requested %d\n", flags);
+		return -EINVAL;
+	}
+

Good idea, I think, but seems you forgot RING_F_EXACT_SZ.

Quoted 5 lines
lib/librte_ring/rte_ring.c +0 -1
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));
 	ret = strlcpy(r->name, name, sizeof(r->name));
--

2.20.1

#3 lore raw

RFC 2/4 hash: check flags on creation

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_hash/rte_cuckoo_hash.c | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/librte_hash/rte_cuckoo_hash.c +9 -0
index 6af8ca42e94f..ab9cd91b4955 100644
@@ -32,6 +32,9 @@
 #include "rte_hash.h"
 #include "rte_cuckoo_hash.h"
 
+/* Mask of all flags supported by this version */
+#define RTE_HASH_EXTRA_FLAGS_MASK 0x2f
+
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
 		CURRENT_BKT != NULL;                                          \
@@ -164,6 +167,12 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->extra_flag & ~RTE_HASH_EXTRA_FLAGS_MASK) {
+		rte_errno = EINVAL;
+		RTE_LOG(ERR, HASH, "rte_hash_create: unsupported extra flags\n");
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 1 line
2.20.1
#4 lore raw

RFC 3/4 stack: check flags on creation

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_stack/rte_stack.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/librte_stack/rte_stack.c +5 -0
index d19824f00439..4b09ff30d6bd 100644
@@ -59,6 +59,11 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,
 	unsigned int sz;
 	int ret;
 
+	if (flags & ~(RTE_STACK_F_LF)) {
+		STACK_LOG_ERR("Unsupported stack flags %#x\n", flags);
+		return NULL;
+	}
+	
 #ifdef RTE_ARCH_64
 	RTE_BUILD_BUG_ON(sizeof(struct rte_stack_lf_head) != 16);
 #else
Signature · 1 line
2.20.1
#5 lore raw

RFC 4/4 cfgfile: check flags value

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_cfgfile/rte_cfgfile.c +4 -0
index 9049fd9c2319..cec82c82ee20 100644
@@ -272,6 +272,10 @@ rte_cfgfile_create(int flags)
 	int i;
 	struct rte_cfgfile *cfg;
 
+	/* future proof flags usage */
+	if (flags & ~(CFG_FLAG_GLOBAL_SECTION | CFG_FLAG_EMPTY_VALUES))
+		return NULL;
+	
 	cfg = malloc(sizeof(*cfg));
 
 	if (cfg == NULL)
Signature · 1 line
2.20.1
#6 lore raw

v2 cover enforce checking on flag values in API's

In reply to Stephen Hemminger

Since the DPDK api's are lazy about checking for flag values it means the flags can never be extended in future releases without causing ABI breakage. This means we end up doing unnecessary symbol versioning just to work around applications that might pass in naughty bits.

This is the DPDK analog of the Linux kernel openat() problem. Openat api was added but since kernel did not check flags it ended up that another syscall openat2() was necessary before the flags could be used.

v2 - rebase and fix checkpatch warnings from RFC

Stephen Hemminger (4):
ring: future proof flag settings
hash: check flags on creation
stack: check flags on creation
cfgfile: check flags value

 lib/librte_cfgfile/rte_cfgfile.c  |  4 ++++
 lib/librte_hash/rte_cuckoo_hash.c |  9 +++++++++
 lib/librte_ring/rte_ring.c        | 10 ++++++++++
 lib/librte_stack/rte_stack.c      |  5 +++++
 4 files changed, 28 insertions(+)
Signature · 1 line
2.20.1
#7 lore raw

PATCH v2 1/4 ring: future proof flag settings

All API's should check that they support the flag values passed. These checks ensure that the extra bits can safely be used without risk of ABI breakage.

---
 lib/librte_ring/rte_ring.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/librte_ring/rte_ring.c +10 -0
index ebe5ccf0de68..70685121581f 100644
@@ -42,6 +42,9 @@ static struct rte_tailq_elem rte_ring_tailq = {
 };
 EAL_REGISTER_TAILQ(rte_ring_tailq)
 
+/* mask of all valid flag values to ring_create() */
+#define RING_F_MASK	0x007F
+
 /* true if x is a power of 2 */
 #define POWEROF2(x) ((((x)-1) & (x)) == 0)
 
@@ -197,6 +200,13 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 	RTE_BUILD_BUG_ON(offsetof(struct rte_ring_headtail, tail) !=
 		offsetof(struct rte_ring_rts_headtail, tail.val.pos));
 
+	/* future proof flags, only allow supported values */
+	if (flags & ~RING_F_MASK) {
+		RTE_LOG(ERR, RING,
+			"Unsupported flags requested %#x\n", flags);
+		return -EINVAL;
+	}
+
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));
 	ret = strlcpy(r->name, name, sizeof(r->name));
Signature · 1 line
2.20.1
#8 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ring: future proof flag settings

<snip>

Quoted 15 lines

All API's should check that they support the flag values passed. These checks ensure that the extra bits can safely be used without risk of ABI breakage.

---
 lib/librte_ring/rte_ring.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/librte_ring/rte_ring.c index renamed from lib/librte_ring/rte_ring.c +0 -0

ebe5ccf0de68..70685121581f 100644

lib/librte_ring/rte_ring.c static struct rte_tailq_elem rte_ring_tailq = { }; · line 45

Quoted 4 lines
lib/librte_ring/rte_ring.c +2 -0
@@ -42,6 +42,9 @@ static struct rte_tailq_elem rte_ring_tailq = {  };
 EAL_REGISTER_TAILQ(rte_ring_tailq)
 
+/* mask of all valid flag values to ring_create() */
+#define RING_F_MASK	0x007F

Is it better to construct this using the actual flag #defines?

Quoted 21 lines
lib/librte_ring/rte_ring.c +8 -0
+
 /* true if x is a power of 2 */
 #define POWEROF2(x) ((((x)-1) & (x)) == 0)
 
@@ -197,6 +200,13 @@ rte_ring_init(struct rte_ring *r, const char *name,
 unsigned count,
 	RTE_BUILD_BUG_ON(offsetof(struct rte_ring_headtail, tail) !=
 		offsetof(struct rte_ring_rts_headtail, tail.val.pos));
 
+	/* future proof flags, only allow supported values */
+	if (flags & ~RING_F_MASK) {
+		RTE_LOG(ERR, RING,
+			"Unsupported flags requested %#x\n", flags);
+		return -EINVAL;
+	}
+
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));

ret = strlcpy(r->name, name, sizeof(r->name));
--
2.20.1

#9 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ring: future proof flag settings

Quoted 19 lines · On Fri, 24 Apr 2020 18:07:15 +0000 Honnappa Nagarahalli…

<snip>

Quoted 17 lines

All API's should check that they support the flag values passed. These checks ensure that the extra bits can safely be used without risk of ABI breakage.

---
 lib/librte_ring/rte_ring.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/librte_ring/rte_ring.c index renamed from lib/librte_ring/rte_ring.c +0 -0

ebe5ccf0de68..70685121581f 100644

lib/librte_ring/rte_ring.c +0 -0
@@ -42,6 +42,9 @@ static struct rte_tailq_elem rte_ring_tailq = {  };
 EAL_REGISTER_TAILQ(rte_ring_tailq)
 
Quoted 3 lines

lib/librte_ring/rte_ring.c static struct rte_tailq_elem rte_ring_tailq = { · line 46

Quoted 2 lines
lib/librte_ring/rte_ring.c +2 -0
+/* mask of all valid flag values to ring_create() */
+#define RING_F_MASK	0x007F  

Is it better to construct this using the actual flag #defines?

sure, but it gets long

#10 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ring: future proof flag settings

Quoted 31 lines

-----Original Message-----
From: dev <[email protected]> On Behalf Of Stephen Hemminger
Sent: Friday, April 24, 2020 8:02 PM
To: Honnappa Nagarahalli <[email protected]>
Cc: [email protected]; nd <[email protected]>
Subject: Re: [dpdk-dev] [PATCH v2 1/4] ring: future proof flag settings

Quoted 19 lines · On Fri, 24 Apr 2020 18:07:15 +0000 Honnappa Nagarahalli…

<snip>

Quoted 17 lines

All API's should check that they support the flag values passed. These checks ensure that the extra bits can safely be used without risk of ABI breakage.

---
 lib/librte_ring/rte_ring.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
lib/librte_ring/rte_ring.c index renamed from lib/librte_ring/rte_ring.c +0 -0

ebe5ccf0de68..70685121581f 100644

lib/librte_ring/rte_ring.c +0 -0
@@ -42,6 +42,9 @@ static struct rte_tailq_elem rte_ring_tailq = {  };
 EAL_REGISTER_TAILQ(rte_ring_tailq)
 
Quoted 5 lines
Quoted 3 lines

lib/librte_ring/rte_ring.c static struct rte_tailq_elem rte_ring_tailq = { · line 46

Quoted 2 lines
lib/librte_ring/rte_ring.c +2 -0
+/* mask of all valid flag values to ring_create() */
+#define RING_F_MASK	0x007F

Is it better to construct this using the actual flag #defines?

sure, but it gets long

+1 to use public defines here.

#11 lore raw

PATCH v2 2/4 hash: check flags on creation

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_hash/rte_cuckoo_hash.c | 9 +++++++++
 1 file changed, 9 insertions(+)
lib/librte_hash/rte_cuckoo_hash.c +9 -0
index 6af8ca42e94f..ab9cd91b4955 100644
@@ -32,6 +32,9 @@
 #include "rte_hash.h"
 #include "rte_cuckoo_hash.h"
 
+/* Mask of all flags supported by this version */
+#define RTE_HASH_EXTRA_FLAGS_MASK 0x2f
+
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
 		CURRENT_BKT != NULL;                                          \
@@ -164,6 +167,12 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->extra_flag & ~RTE_HASH_EXTRA_FLAGS_MASK) {
+		rte_errno = EINVAL;
+		RTE_LOG(ERR, HASH, "rte_hash_create: unsupported extra flags\n");
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 1 line
2.20.1
#12 lore raw

PATCH v2 3/4 stack: check flags on creation

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_stack/rte_stack.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/librte_stack/rte_stack.c +5 -0
index d19824f00439..e58fa545fca4 100644
@@ -59,6 +59,11 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,
 	unsigned int sz;
 	int ret;
 
+	if (flags & ~(RTE_STACK_F_LF)) {
+		STACK_LOG_ERR("Unsupported stack flags %#x\n", flags);
+		return NULL;
+	}
+
 #ifdef RTE_ARCH_64
 	RTE_BUILD_BUG_ON(sizeof(struct rte_stack_lf_head) != 16);
 #else
Signature · 1 line
2.20.1
#13 lore raw

PATCH v2 4/4 cfgfile: check flags value

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_cfgfile/rte_cfgfile.c +4 -0
index 9049fd9c2319..714717dd9007 100644
@@ -272,6 +272,10 @@ rte_cfgfile_create(int flags)
 	int i;
 	struct rte_cfgfile *cfg;
 
+	/* future proof flags usage */
+	if (flags & ~(CFG_FLAG_GLOBAL_SECTION | CFG_FLAG_EMPTY_VALUES))
+		return NULL;
+
 	cfg = malloc(sizeof(*cfg));
 
 	if (cfg == NULL)
Signature · 1 line
2.20.1
#14 lore raw

v3 cover Enforce checking on flag values in API's

In reply to Stephen Hemminger

The DPDK API's are lax about checking for undefined flag values. This makes it impossible to add new bits to existing API's without causing ABI breakage. This means we end up doing unnecessary symbol versioning just to work around applications that might pass in naughty bits.

This is the DPDK analog of the Linux kernel openat() problem. Openat api was added but since kernel did not check flags it ended up that another syscall openat2() was necessary before the flags could be used.

v3 - define mask based on existing defines for ring and hash

Stephen Hemminger (4):
ring: future proof flag settings
hash: check flags on creation
stack: check flags on creation
cfgfile: check flags value

 lib/librte_cfgfile/rte_cfgfile.c  |  4 ++++
 lib/librte_hash/rte_cuckoo_hash.c | 14 ++++++++++++++
 lib/librte_ring/rte_ring.c        | 12 ++++++++++++
 lib/librte_stack/rte_stack.c      |  5 +++++
 4 files changed, 35 insertions(+)
Signature · 1 line
2.20.1
#15 lore raw

PATCH v3 1/4 ring: future proof flag settings

All API's should check that they support the flag values passed. These checks ensure that the extra bits can safely be used without risk of ABI breakage.

---
 lib/librte_ring/rte_ring.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ring/rte_ring.c +12 -0
index ebe5ccf0de68..e16dd45a82de 100644
@@ -42,6 +42,11 @@ static struct rte_tailq_elem rte_ring_tailq = {
 };
 EAL_REGISTER_TAILQ(rte_ring_tailq)
 
+/* mask of all valid flag values to ring_create() */
+#define RING_F_MASK (RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ | \
+		     RING_F_MP_RTS_ENQ | RING_F_MC_RTS_DEQ |	       \
+		     RING_F_MP_HTS_ENQ | RING_F_MC_HTS_DEQ )
+
 /* true if x is a power of 2 */
 #define POWEROF2(x) ((((x)-1) & (x)) == 0)
 
@@ -197,6 +202,13 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 	RTE_BUILD_BUG_ON(offsetof(struct rte_ring_headtail, tail) !=
 		offsetof(struct rte_ring_rts_headtail, tail.val.pos));
 
+	/* future proof flags, only allow supported values */
+	if (flags & ~RING_F_MASK) {
+		RTE_LOG(ERR, RING,
+			"Unsupported flags requested %#x\n", flags);
+		return -EINVAL;
+	}
+
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));
 	ret = strlcpy(r->name, name, sizeof(r->name));
Signature · 1 line
2.20.1
Reviewed-by on v3 1/4
#16 lore raw

Re: [dpdk-dev] [PATCH v3 1/4] ring: future proof flag settings

<snip>

Quoted 6 lines

All API's should check that they support the flag values passed. These checks ensure that the extra bits can safely be used without risk of ABI breakage.

Quoted 36 lines
---
 lib/librte_ring/rte_ring.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
lib/librte_ring/rte_ring.c index renamed from lib/librte_ring/rte_ring.c +0 -0

ebe5ccf0de68..e16dd45a82de 100644

lib/librte_ring/rte_ring.c +12 -0
@@ -42,6 +42,11 @@ static struct rte_tailq_elem rte_ring_tailq = {  };
 EAL_REGISTER_TAILQ(rte_ring_tailq)
 
+/* mask of all valid flag values to ring_create() */ #define
+RING_F_MASK (RING_F_SP_ENQ | RING_F_SC_DEQ | RING_F_EXACT_SZ | \
+		     RING_F_MP_RTS_ENQ | RING_F_MC_RTS_DEQ |	       \
+		     RING_F_MP_HTS_ENQ | RING_F_MC_HTS_DEQ )
+
 /* true if x is a power of 2 */
 #define POWEROF2(x) ((((x)-1) & (x)) == 0)
 
@@ -197,6 +202,13 @@ rte_ring_init(struct rte_ring *r, const char *name,
 unsigned count,
 	RTE_BUILD_BUG_ON(offsetof(struct rte_ring_headtail, tail) !=
 		offsetof(struct rte_ring_rts_headtail, tail.val.pos));
 
+	/* future proof flags, only allow supported values */
+	if (flags & ~RING_F_MASK) {
+		RTE_LOG(ERR, RING,
+			"Unsupported flags requested %#x\n", flags);
+		return -EINVAL;
+	}
+
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));

ret = strlcpy(r->name, name, sizeof(r->name));
--
2.20.1

#17 lore raw

PATCH v3 2/4 hash: check flags on creation

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_hash/rte_cuckoo_hash.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
lib/librte_hash/rte_cuckoo_hash.c +14 -0
index 38767a8a164f..d54bbb47edcb 100644
@@ -32,6 +32,14 @@
 #include "rte_hash.h"
 #include "rte_cuckoo_hash.h"
 
+/* Mask of all flags supported by this version */
+#define RTE_HASH_EXTRA_FLAGS_MASK (RTE_HASH_EXTRA_FLAGS_TRANS_MEM_SUPPORT | \
+				   RTE_HASH_EXTRA_FLAGS_MULTI_WRITER_ADD | \
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \
+				   RTE_HASH_EXTRA_FLAGS_EXT_TABLE |	\
+				   RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \
+				   RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)
+
 #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET)                            \
 	for (CURRENT_BKT = START_BUCKET;                                      \
 		CURRENT_BKT != NULL;                                          \
@@ -164,6 +172,12 @@ rte_hash_create(const struct rte_hash_parameters *params)
 		return NULL;
 	}
 
+	if (params->extra_flag & ~RTE_HASH_EXTRA_FLAGS_MASK) {
+		rte_errno = EINVAL;
+		RTE_LOG(ERR, HASH, "rte_hash_create: unsupported extra flags\n");
+		return NULL;
+	}
+
 	/* Validate correct usage of extra options */
 	if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) &&
 	    (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) {
Signature · 1 line
2.20.1
Acked-by on v3 2/4
#18 lore raw

Re: [dpdk-dev] [PATCH v3 2/4] hash: check flags on creation

Quoted 9 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, April 27, 2020 4:16 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Wang, Yipeng1 <[email protected]>; Gobriel, Sameh <[email protected]>; Richardson, Bruce <[email protected]>
Subject: [PATCH v3 2/4] hash: check flags on creation

Quoted 5 lines

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---

#19 lore raw

PATCH v3 3/4 stack: check flags on creation

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_stack/rte_stack.c | 5 +++++
 1 file changed, 5 insertions(+)
lib/librte_stack/rte_stack.c +5 -0
index d19824f00439..e58fa545fca4 100644
@@ -59,6 +59,11 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,
 	unsigned int sz;
 	int ret;
 
+	if (flags & ~(RTE_STACK_F_LF)) {
+		STACK_LOG_ERR("Unsupported stack flags %#x\n", flags);
+		return NULL;
+	}
+
 #ifdef RTE_ARCH_64
 	RTE_BUILD_BUG_ON(sizeof(struct rte_stack_lf_head) != 16);
 #else
Signature · 1 line
2.20.1
Acked-by on v3 3/4
#20 lore raw

Re: [dpdk-dev] [PATCH v3 3/4] stack: check flags on creation

Quoted 8 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, April 27, 2020 6:16 PM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Eads, Gage <[email protected]>; Olivier Matz <[email protected]>
Subject: [PATCH v3 3/4] stack: check flags on creation

Quoted 5 lines

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---

#21 lore raw

PATCH v3 4/4 cfgfile: check flags value

In reply to Stephen Hemminger

All API's should check that they support the flag values passed. If an application passes an invalid flag it could cause problems in later ABI.

---
 lib/librte_cfgfile/rte_cfgfile.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/librte_cfgfile/rte_cfgfile.c +4 -0
index 9049fd9c2319..714717dd9007 100644
@@ -272,6 +272,10 @@ rte_cfgfile_create(int flags)
 	int i;
 	struct rte_cfgfile *cfg;
 
+	/* future proof flags usage */
+	if (flags & ~(CFG_FLAG_GLOBAL_SECTION | CFG_FLAG_EMPTY_VALUES))
+		return NULL;
+
 	cfg = malloc(sizeof(*cfg));
 
 	if (cfg == NULL)
Signature · 1 line
2.20.1
#23 lore raw

Re: [dpdk-dev] [PATCH v3 0/4] Enforce checking on flag values in API's

In reply to Stephen Hemminger
Quoted 19 lines · Stephen Hemminger

The DPDK API's are lax about checking for undefined flag values. This makes it impossible to add new bits to existing API's without causing ABI breakage. This means we end up doing unnecessary symbol versioning just to work around applications that might pass in naughty bits.

This is the DPDK analog of the Linux kernel openat() problem. Openat api was added but since kernel did not check flags it ended up that another syscall openat2() was necessary before the flags could be used.

v3 - define mask based on existing defines for ring and hash

Stephen Hemminger (4):
ring: future proof flag settings
hash: check flags on creation
stack: check flags on creation
cfgfile: check flags value

Quoted 6 lines
 lib/librte_cfgfile/rte_cfgfile.c  |  4 ++++
 lib/librte_hash/rte_cuckoo_hash.c | 14 ++++++++++++++
 lib/librte_ring/rte_ring.c        | 12 ++++++++++++
 lib/librte_stack/rte_stack.c      |  5 +++++
 4 files changed, 35 insertions(+)

I think this is a good idea to do in DPDK

#24 lore raw

Re: [dpdk-dev] [PATCH v3 0/4] Enforce checking on flag values in API's

28/04/2020 12:28, Bruce Richardson:

Quoted 20 lines · Stephen Hemminger
Quoted 11 lines

The DPDK API's are lax about checking for undefined flag values. This makes it impossible to add new bits to existing API's without causing ABI breakage. This means we end up doing unnecessary symbol versioning just to work around applications that might pass in naughty bits.

This is the DPDK analog of the Linux kernel openat() problem. Openat api was added but since kernel did not check flags it ended up that another syscall openat2() was necessary before the flags could be used.

Quoted 8 lines

v3 - define mask based on existing defines for ring and hash

Stephen Hemminger (4):
ring: future proof flag settings
hash: check flags on creation
stack: check flags on creation
cfgfile: check flags value

Quoted 3 lines

I think this is a good idea to do in DPDK

Applied, thanks

#25 lore raw

Re: [dpdk-dev] [PATCH v3 0/4] Enforce checking on flag values in API's

In reply to Stephen Hemminger
Quoted 19 lines

The DPDK API's are lax about checking for undefined flag values. This makes it impossible to add new bits to existing API's without causing ABI breakage. This means we end up doing unnecessary symbol versioning just to work around applications that might pass in naughty bits.

This is the DPDK analog of the Linux kernel openat() problem. Openat api was added but since kernel did not check flags it ended up that another syscall openat2() was necessary before the flags could be used.

v3 - define mask based on existing defines for ring and hash

Stephen Hemminger (4):
ring: future proof flag settings
hash: check flags on creation
stack: check flags on creation
cfgfile: check flags value

Quoted 7 lines
 lib/librte_cfgfile/rte_cfgfile.c  |  4 ++++
 lib/librte_hash/rte_cuckoo_hash.c | 14 ++++++++++++++
 lib/librte_ring/rte_ring.c        | 12 ++++++++++++
 lib/librte_stack/rte_stack.c      |  5 +++++
 4 files changed, 35 insertions(+)

--

Series Acked-by: Konstantin Ananyev <[email protected]>

Quoted 1 line

2.20.1