Skip to contentSkip to conversation

afpacket: fix critical issue reported by klocwork

PATCH In review Cunming Liang 3 participants 7 messages Feb 12, 2015 – Feb 25, 2015 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 afpacket: fix critical issue reported by klocwork

Klocwork report 'req' might be used uninitialized.
In some cases it can 'goto error' when '*internals' not been set. The result is unexpected checking the value of '*internals'.

---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_pmd_af_packet/rte_eth_af_packet.c +3 -1
index 1ffe1cd..185607d 100644
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;
 	struct pkt_rx_queue *rx_queue;
 	struct pkt_tx_queue *tx_queue;
 	int rc, qsockfd, tpver, discard;
 	unsigned int i, q, rdsize;
 	int fanout_arg __rte_unused, bypass __rte_unused;
 
+	*internals = NULL;
+
 	for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
 		pair = &kvlist->pairs[k_idx];
 		if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL)
Signature · 1 line
1.8.1.4

A message that is not in the archive (sent off-list or not yet received): 1423732089-6202-1-git-send-email-cunming.liang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw

Hi Cunming,

You would have more chance to have a review by CC'ing John. I checked your patch and have a comment below.

2015-02-12 17:08, Cunming Liang:

Quoted 14 lines

Klocwork report 'req' might be used uninitialized.
In some cases it can 'goto error' when '*internals' not been set. The result is unexpected checking the value of '*internals'.

---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/librte_pmd_af_packet/rte_eth_af_packet.c +0 -0
index 1ffe1cd..185607d 100644

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 442

Quoted 5 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +1 -1
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;

If *internals is set to NULL, there should be no case where req used and undefined.

Quoted 12 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +2 -0
 	struct pkt_rx_queue *rx_queue;
 	struct pkt_tx_queue *tx_queue;
 	int rc, qsockfd, tpver, discard;
 	unsigned int i, q, rdsize;
 	int fanout_arg __rte_unused, bypass __rte_unused;
 
+	*internals = NULL;
+
 	for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
 		pair = &kvlist->pairs[k_idx];
 		if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL)
#3 lore raw
Quoted 15 lines · Thomas Monjalon

Hi Cunming,

You would have more chance to have a review by CC'ing John. I checked your patch and have a comment below.

2015-02-12 17:08, Cunming Liang:

Quoted 9 lines

Klocwork report 'req' might be used uninitialized.
In some cases it can 'goto error' when '*internals' not been set. The result is unexpected checking the value of '*internals'.

---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 13 lines

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 442

Quoted 10 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +1 -1
index 1ffe1cd..185607d 100644
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;

If *internals is set to NULL, there should be no case where req used and undefined.

I agree -- it looks to me like req is protected by checking for *internals == NULL. I don't think this patch is necessary.

Quoted 16 lines
Quoted 12 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +2 -0
 	struct pkt_rx_queue *rx_queue;
 	struct pkt_tx_queue *tx_queue;
 	int rc, qsockfd, tpver, discard;
 	unsigned int i, q, rdsize;
 	int fanout_arg __rte_unused, bypass __rte_unused;
 
+	*internals = NULL;
+
 	for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
 		pair = &kvlist->pairs[k_idx];
 		if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL)
Signature · 2 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw
Quoted 21 lines

-----Original Message-----
From: John W. Linville [mailto:[email protected]]
Sent: Saturday, February 21, 2015 2:39 AM
To: Thomas Monjalon
Cc: Liang, Cunming; [email protected]; John Linville
Subject: Re: [dpdk-dev] [PATCH v1] afpacket: fix critical issue reported by klocwork

Quoted 10 lines · Thomas Monjalon

Hi Cunming,

You would have more chance to have a review by CC'ing John. I checked your patch and have a comment below.

2015-02-12 17:08, Cunming Liang:

Quoted 4 lines

Klocwork report 'req' might be used uninitialized.
In some cases it can 'goto error' when '*internals' not been set. The result is unexpected checking the value of '*internals'.

Quoted 19 lines
Quoted 6 lines

Review

Quoted 6 lines
---
 lib/librte_pmd_af_packet/rte_eth_af_packet.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/lib/librte_pmd_af_packet/rte_eth_af_packet.c

Quoted 12 lines

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 442

Quoted 9 lines

index 1ffe1cd..185607d 100644

lib/librte_pmd_af_packet/rte_eth_af_packet.c +1 -1
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;

If *internals is set to NULL, there should be no case where req used and undefined.

[LCM] Agree, so that's why I add '*internals = NULL' below as well.

Quoted 3 lines

I agree -- it looks to me like req is protected by checking for *internals == NULL. I don't think this patch is necessary.

[LCM] The major piece of the patch is add setting for '*internals=NULL;'.

Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +0 -0
 	struct pkt_rx_queue *rx_queue;
 	struct pkt_tx_queue *tx_queue;
 	int rc, qsockfd, tpver, discard;
 	unsigned int i, q, rdsize;
 	int fanout_arg __rte_unused, bypass __rte_unused;
 
Quoted 10 lines

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 453

Quoted 6 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +2 -0
+	*internals = NULL;
+
 	for (k_idx = 0; k_idx < kvlist->count; k_idx++) {
 		pair = &kvlist->pairs[k_idx];
 		if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL)

--
John W. Linville Someday the world will need a hero, and you
[email protected] might be all we have. Be ready.

A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118DE679-E2R4CRU6q/[email protected]

#7 lore raw

2015-02-25 00:57, Liang, Cunming:

Quoted 15 lines

From: John W. Linville [mailto:[email protected]]

Quoted 13 lines · Thomas Monjalon
Quoted 12 lines

2015-02-12 17:08, Cunming Liang:

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 442

Quoted 8 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +1 -1
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;

If *internals is set to NULL, there should be no case where req used and undefined.

Quoted 6 lines

[LCM] Agree, so that's why I add '*internals = NULL' below as well.

Quoted 3 lines

I agree -- it looks to me like req is protected by checking for *internals == NULL. I don't think this patch is necessary.

[LCM] The major piece of the patch is add setting for '*internals=NULL;'.

Yes understood, but it is already initialized to NULL before calling rte_pmd_init_internals():
http://dpdk.org/browse/dpdk/tree/lib/librte_pmd_af_packet/rte_eth_af_packet.c#n706

#8 lore raw
Quoted 31 lines

-----Original Message-----
From: Thomas Monjalon [mailto:[email protected]]
Sent: Wednesday, February 25, 2015 4:46 PM
To: Liang, Cunming
Cc: John W. Linville; [email protected]; John Linville
Subject: Re: [dpdk-dev] [PATCH v1] afpacket: fix critical issue reported by klocwork

2015-02-25 00:57, Liang, Cunming:

Quoted 20 lines

From: John W. Linville [mailto:[email protected]]

Quoted 13 lines · Thomas Monjalon
Quoted 12 lines

2015-02-12 17:08, Cunming Liang:

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 442

Quoted 8 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +1 -1
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;

If *internals is set to NULL, there should be no case where req used and undefined.

[LCM] Agree, so that's why I add '*internals = NULL' below as well.

Quoted 3 lines

I agree -- it looks to me like req is protected by checking for *internals == NULL. I don't think this patch is necessary.

Quoted 6 lines
Quoted 1 line

[LCM] The major piece of the patch is add setting for '*internals=NULL;'.

Yes understood, but it is already initialized to NULL before calling rte_pmd_init_internals():
http://dpdk.org/browse/dpdk/tree/lib/librte_pmd_af_packet/rte_eth_af_packet
.c#n706

[LCM] I see, it's complained by klocwork.
So either adding 'internals=NULL' or adding some comments helps to avoid checking again on the next scanning. How do you think ?

A message that is not in the archive (sent off-list or not yet received): D0158A423229094DA7ABF71CF2FA0DA3118DED48-E2R4CRU6q/[email protected]

#10 lore raw

2015-02-25 09:52, Liang, Cunming:

Quoted 24 lines

From: Thomas Monjalon [mailto:[email protected]]

Quoted 23 lines

2015-02-25 00:57, Liang, Cunming:

Quoted 21 lines

From: John W. Linville [mailto:[email protected]]

Quoted 13 lines · Thomas Monjalon
Quoted 12 lines

2015-02-12 17:08, Cunming Liang:

lib/librte_pmd_af_packet/rte_eth_af_packet.c rte_pmd_init_internals(const char *name, · line 442

Quoted 8 lines
lib/librte_pmd_af_packet/rte_eth_af_packet.c +1 -1
@@ -439,13 +439,15 @@ rte_pmd_init_internals(const char *name,
 	size_t ifnamelen;
 	unsigned k_idx;
 	struct sockaddr_ll sockaddr;
-	struct tpacket_req *req;
+	struct tpacket_req *req = NULL;

If *internals is set to NULL, there should be no case where req used and undefined.

[LCM] Agree, so that's why I add '*internals = NULL' below as well.

Quoted 3 lines

I agree -- it looks to me like req is protected by checking for *internals == NULL. I don't think this patch is necessary.

[LCM] The major piece of the patch is add setting for '*internals=NULL;'.

Quoted 7 lines
Quoted 4 lines

Yes understood, but it is already initialized to NULL before calling rte_pmd_init_internals():
http://dpdk.org/browse/dpdk/tree/lib/librte_pmd_af_packet/rte_eth_af_packet
.c#n706

[LCM] I see, it's complained by klocwork.
So either adding 'internals=NULL' or adding some comments helps to avoid checking again on the next scanning. How do you think ?

No, we don't have to pollute the code for a tool.
You should check how to disable this false positive in your tool.