Skip to contentSkip to conversation

eal: fix negative value incorrectly being used defect

PATCH Applied Cunming Liang 4 participants 4 messages Dec 11, 2015 – Dec 12, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: fix negative value incorrectly being used defect

In eal_intr_proc_rxtx_intr, negative value may be used as argument to a function expecting a positive value. If 'read' returns EAGAIN as example, the bytes_read updates to a negative value which continue be passed as argument for the next 'read'.

Coverity issue: 107115

927 do {
3. negative_return_fn: Function read(fd, &buf, bytes_read) returns a negative number.
4. var_assign: Assigning: signed variable bytes_read = read.
CID 107115 (#1 of 1): Argument cannot be negative
(NEGATIVE_RETURNS)9. negative_returns: bytes_read is passed to a parameter that cannot be negative.
928 bytes_read = read(fd, &buf, bytes_read);

Fixes c9f3ec1a0f3f ("eal/linux: add Rx interrupt control function")
---
 lib/librte_eal/linuxapp/eal/eal_interrupts.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
lib/librte_eal/linuxapp/eal/eal_interrupts.c +4 -3
index 470d6a1..06b26a9 100644
@@ -901,6 +901,7 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
 {
 	union rte_intr_read_buffer buf;
 	int bytes_read = 1;
+	int nbytes;
 
 	switch (intr_handle->type) {
 	case RTE_INTR_HANDLE_UIO:
@@ -925,15 +926,15 @@ eal_intr_proc_rxtx_intr(int fd, const struct rte_intr_handle *intr_handle)
 	 * for epoll_wait.
 	 */
 	do {
-		bytes_read = read(fd, &buf, bytes_read);
-		if (bytes_read < 0) {
+		nbytes = read(fd, &buf, bytes_read);
+		if (nbytes < 0) {
 			if (errno == EINTR || errno == EWOULDBLOCK ||
 			    errno == EAGAIN)
 				continue;
 			RTE_LOG(ERR, EAL,
 				"Error reading from fd %d: %s\n",
 				fd, strerror(errno));
-		} else if (bytes_read == 0)
+		} else if (nbytes == 0)
 			RTE_LOG(ERR, EAL, "Read nothing from fd %d\n", fd);
 		return;
 	} while (1);
Signature · 1 line
2.4.3
Acked-by on v1 1/1
#1 lore raw
Quoted 24 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Cunming Liang
Sent: Friday, December 11, 2015 1:49 AM
To: [email protected]
Subject: [dpdk-dev] [PATCH v1] eal: fix negative value incorrectly being used defect

In eal_intr_proc_rxtx_intr, negative value may be used as argument to a function expecting a positive value. If 'read' returns EAGAIN as example, the bytes_read updates to a negative value which continue be passed as argument for the next 'read'.

Coverity issue: 107115

927 do {
3. negative_return_fn: Function read(fd, &buf, bytes_read) returns a
negative number.
4. var_assign: Assigning: signed variable bytes_read = read. CID 107115 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)9. negative_returns: bytes_read is passed to a
parameter
that cannot be negative.
928 bytes_read = read(fd, &buf, bytes_read);

Quoted 3 lines
Fixes c9f3ec1a0f3f ("eal/linux: add Rx interrupt control function")
Acked-by on v1 1/1
#2 lore raw
In reply to Cunming Liang

Hello Cunming,

Quoted 17 lines · Cunming Liang

In eal_intr_proc_rxtx_intr, negative value may be used as argument to a function expecting a positive value. If 'read' returns EAGAIN as example, the bytes_read updates to a negative value which continue be passed as argument for the next 'read'.

Coverity issue: 107115

927 do {
3. negative_return_fn: Function read(fd, &buf, bytes_read) returns a
negative number.
4. var_assign: Assigning: signed variable bytes_read = read. CID 107115 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)9. negative_returns: bytes_read is passed to a
parameter
that cannot be negative.
928 bytes_read = read(fd, &buf, bytes_read);

Quoted 4 lines
Fixes c9f3ec1a0f3f ("eal/linux: add Rx interrupt control function")

Thanks.

Signature · 1 line
David Marchand
#3 lore raw

2015-12-11 15:54, David Marchand:

Quoted 22 lines

Hello Cunming,

Quoted 17 lines · Cunming Liang

In eal_intr_proc_rxtx_intr, negative value may be used as argument to a function expecting a positive value. If 'read' returns EAGAIN as example, the bytes_read updates to a negative value which continue be passed as argument for the next 'read'.

Coverity issue: 107115

927 do {
3. negative_return_fn: Function read(fd, &buf, bytes_read) returns a
negative number.
4. var_assign: Assigning: signed variable bytes_read = read. CID 107115 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)9. negative_returns: bytes_read is passed to a
parameter
that cannot be negative.
928 bytes_read = read(fd, &buf, bytes_read);

Quoted 6 lines
Quoted 4 lines
Fixes c9f3ec1a0f3f ("eal/linux: add Rx interrupt control function")

Applied, thanks