examples/l3fwd: resolve stack buffer overflow issue
PATCH 1/1 examples/l3fwd: resolve stack buffer overflow issue
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Function send_packetsx4() tries to access out of bound data from rte_mbuf and fill it into TX buffer even in the case where no pending packets (len = 0).
Performance impact:- No
ASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address 0xffffe2c0dcf0 at pc 0x0000005e791c bp 0xffffe2c0d7e0 sp 0xffffe2c0d800 READ of size 8 at 0xffffe2c0dcf0 thread T0
#0 0x5e7918 in send_packetsx4 ../examples/l3fwd/l3fwd_common.h:251 #1 0x5e7918 in send_packets_multi ../examples/l3fwd/l3fwd_neon.h:226
--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)
examples/l3fwd/l3fwd_common.h +4 -0
@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; + j =0 ;switch (len %FWDSTEP ) {while (j < len) {
@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], } } +exit: qconf->tx_mbufs[port].len = len; }
Signature · 1 line
2.25.1
Hi Thomas,
Below patch is pending for review and merge. Can you please check it ?
http://patches.dpdk.org/project/dpdk/list/?series=21124
Regards,
Rahul
-----Original Message-----
From: Rahul Bhansali <[email protected]>
Sent: Tuesday, January 11, 2022 6:20 PM
To: [email protected]; [email protected]; [email protected]
Cc: Rahul Bhansali <[email protected]>
Subject: [PATCH] examples/l3fwd: resolve stack buffer overflow issue
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Function send_packetsx4() tries to access out of bound data from rte_mbuf and fill it into TX buffer even in the case where no pending packets (len = 0). Performance impact:- No
ASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0 at pc 0x0000005e791c bp 0xffffe2c0d7e0 sp 0xffffe2c0d800 READ of size 8 at 0xffffe2c0dcf0 thread T0
#0 0x5e7918 in send_packetsx4 ../examples/l3fwd/l3fwd_common.h:251
#1 0x5e7918 in send_packets_multi ../examples/l3fwd/l3fwd_neon.h:226
--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)
examples/l3fwd/l3fwd_common.h +4 -0
@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; + j =0 ;switch (len %FWDSTEP ) {while (j < len) {
@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], } } +exit: qconf->tx_mbufs[port].len = len; }
--
2.25.1
Ping..
-----Original Message-----
From: Rahul Bhansali <[email protected]>
Sent: Tuesday, January 11, 2022 6:20 PM
To: [email protected]; [email protected]; [email protected]
Cc: Rahul Bhansali <[email protected]>
Subject: [PATCH] examples/l3fwd: resolve stack buffer overflow issue
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Function send_packetsx4() tries to access out of bound data from rte_mbuf and fill it into TX buffer even in the case where no pending packets (len = 0). Performance impact:- No
ASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0 at pc 0x0000005e791c bp 0xffffe2c0d7e0 sp 0xffffe2c0d800 READ of size 8 at 0xffffe2c0dcf0 thread T0
#0 0x5e7918 in send_packetsx4 ../examples/l3fwd/l3fwd_common.h:251
#1 0x5e7918 in send_packets_multi ../examples/l3fwd/l3fwd_neon.h:226
--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)
examples/l3fwd/l3fwd_common.h +4 -0
@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; + j =0 ;switch (len %FWDSTEP ) {while (j < len) {
@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], } } +exit: qconf->tx_mbufs[port].len = len; }
--
2.25.1
Walsh, Conor
Reviewed-byHi Rahul,
I must have forgot to put my tag on this because I thought I reviewed it already. I reviewed and tested it again this morning.
Thanks,
Quoted 60 lines
-----Original Message-----
From: Rahul Bhansali <[email protected]>
Sent: Monday 7 March 2022 06:45
To: Rahul Bhansali <[email protected]>; [email protected]; Walsh, Conor <[email protected]>; [email protected]
Subject: RE: [PATCH] examples/l3fwd: resolve stack buffer overflow issuePing..
-----Original Message-----
From: Rahul Bhansali <[email protected]>
Sent: Tuesday, January 11, 2022 6:20 PM
To: [email protected]; [email protected]; [email protected]
Cc: Rahul Bhansali <[email protected]>
Subject: [PATCH] examples/l3fwd: resolve stack buffer overflow issueThis patch fixes the stack buffer overflow error reported from AddressSanitizer.
Functionsend_packetsx4()tries to access out of bound data fromrte_mbufand fill it into TX buffer even in the case where no pending packets (len = 0). Performance impact:- NoASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0at pc0x0000005e791cbp0xffffe2c0d7e0sp0xffffe2c0d800READ of size 8 at0xffffe2c0dcf0thread T0
#00x5e7918insend_packetsx4../examples/l3fwd/l3fwd_common.h:251#10x5e7918insend_packets_multi../examples/l3fwd/l3fwd_neon.h:226Signed-off-by Rahul Bhansali <[email protected]>--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)(quoted diff) +0
-0
b/examples/l3fwd/l3fwd_common.hindex7d83ff641a..de77711f88100644examples/l3fwd/l3fwd_common.h +3
-0@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; + j =0 ;switch (len %FWDSTEP ) {examples/l3fwd/l3fwd_common.h +1
-1while (j < len) {@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], } } +exit: qconf->tx_mbufs[port].len = len; } --2.25.1
11/01/2022 13:50, Rahul Bhansali:
Quoted 7 lines
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Functionsend_packetsx4()tries to access out of bound data fromrte_mbufand fill it into TX buffer even in the case where no pending packets (len = 0).
Performance impact:- No
Quoted 6 lines
ASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0at pc0x0000005e791cbp0xffffe2c0d7e0sp0xffffe2c0d800READ of size 8 at0xffffe2c0dcf0thread T0
#00x5e7918insend_packetsx4../examples/l3fwd/l3fwd_common.h:251#10x5e7918insend_packets_multi../examples/l3fwd/l3fwd_neon.h:226
This code comes from below commit, so these tags are missing:
Quoted 10 lines
Signed-off-by Rahul Bhansali <[email protected]>--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)examples/l3fwd/l3fwd_common.h +0
-0
examples/l3fwd/l3fwd_common.h send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], · line 241
Quoted 6 lines
examples/l3fwd/l3fwd_common.h +3
-0@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; +
I don't understand how it can fix something.
There is already "while (j < len)" with j and len being 0, the loop should not be effective in this case.
Quoted 10 lines
examples/l3fwd/l3fwd_common.h +1
-0j =0 ;switch (len %FWDSTEP ) {while (j < len) {@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], } } +exit: qconf->tx_mbufs[port].len = len; }
Hi Thomas,
Quoted 43 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Tuesday, March 8, 2022 4:51 PM
To: Rahul Bhansali <[email protected]>
Cc: [email protected]; [email protected]; Conor Walsh <[email protected]>
Subject: [EXT] Re: [PATCH] examples/l3fwd: resolve stack buffer overflow issueExternal Email
----------------------------------------------------------------------
11/01/2022 13:50, Rahul Bhansali:Quoted 7 lines
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Functionsend_packetsx4()tries to access out of bound data fromrte_mbufand fill it into TX buffer even in the case where no pending packets (len = 0).
Performance impact:- NoQuoted 6 lines
ASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0at pc0x0000005e791cbp0xffffe2c0d7e0sp0xffffe2c0d800READ of size 8 at0xffffe2c0dcf0thread T0
#00x5e7918insend_packetsx4../examples/l3fwd/l3fwd_common.h:251#10x5e7918insend_packets_multi../examples/l3fwd/l3fwd_neon.h:226This code comes from below commit, so these tags are missing:
Fixes 96ff445371e0 ("examples/l3fwd: reorganise and optimize LPM codepath")
Cc: [email protected]Quoted 12 lines
Signed-off-by Rahul Bhansali <[email protected]>--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)(quoted diff) +0
-0
b/examples/l3fwd/l3fwd_common.hindex7d83ff641a..de77711f88100644examples/l3fwd/l3fwd_common.h +0
-0@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],
Quoted 9 lines
examples/l3fwd/l3fwd_common.h send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], · line 241
Quoted 5 lines
examples/l3fwd/l3fwd_common.h +3
-0/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; +I don't understand how it can fix something.
There is already "while (j < len)" with j and len being 0, the loop should not be effective in this case.
This Switch will execute Case statement first even before considering the while condition or anything else before case statement. While condition will be executed only after all switch cases are executed. Hence in case of len = 0 and n > 28, it is throwing stack buffer overflow error.
Below is sample code to simulate the while loop behavior inside switch. Checked it for both x86 and arm64.
https://godbolt.org/z/4Kecqbsde
Quoted 14 lines
examples/l3fwd/l3fwd_common.h send_packetsx4(struct lcore_conf *qconf, uint16_t
Quoted 5 lines
examples/l3fwd/l3fwd_common.h +0
-0j =0 ;switch (len %FWDSTEP ) {examples/l3fwd/l3fwd_common.h +0
-0while (j < len) {@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_tport, struct
rte_mbuf*m[],Quoted 6 lines
examples/l3fwd/l3fwd_common.h +1
-0} } +exit: qconf->tx_mbufs[port].len = len; }
09/03/2022 16:24, Rahul Bhansali:
Quoted 14 lines
Hi Thomas,
From: Thomas Monjalon <[email protected]>
Quoted 10 lines
11/01/2022 13:50, Rahul Bhansali:
examples/l3fwd/l3fwd_common.h send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], · line 241
Quoted 5 lines
examples/l3fwd/l3fwd_common.h +3
-0/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; +I don't understand how it can fix something.
There is already "while (j < len)" with j and len being 0, the loop should not be effective in this case.
Quoted 1 line
This Switch will execute Case statement first even before considering the while condition or anything else before case statement. While condition will be executed only after all switch cases are executed.
I don't know this construct. Is it part of the C standard? We learn something everyday :)
Quoted 9 lines
Hence in case of len = 0 and n > 28, it is throwing stack buffer overflow error.
Below is sample code to simulate the while loop behavior inside switch. Checked it for both x86 and arm64.
https://godbolt.org/z/4KecqbsdeQuoted 4 lines
Quoted 4 lines
examples/l3fwd/l3fwd_common.h +0
-0j =0 ;switch (len %FWDSTEP ) {while (j < len) {
Quoted 26 lines
-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Thursday, March 10, 2022 12:37 AM
To: Rahul Bhansali <[email protected]>
Cc: [email protected]; [email protected]; Conor Walsh <[email protected]>
Subject: Re: [EXT] Re: [PATCH] examples/l3fwd: resolve stack buffer overflow issue09/03/2022 16:24, Rahul Bhansali:
Quoted 14 lines
Hi Thomas,
From: Thomas Monjalon <[email protected]>
Quoted 10 lines
11/01/2022 13:50, Rahul Bhansali:
examples/l3fwd/l3fwd_common.h send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], · line 241
Quoted 5 lines
examples/l3fwd/l3fwd_common.h +3
-0/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; +I don't understand how it can fix something.
There is already "while (j < len)" with j and len being 0, the loop should not be effective in this case.
Quoted 6 lines
Quoted 1 line
This Switch will execute Case statement first even before considering the while
condition or anything else before case statement. While condition will be executed only after all switch cases are executed.
I don't know this construct. Is it part of the C standard? We learn something everyday :)
Yeah, this is new learning for me as well 😊
It’s the way switch works and make it faster than If-else conditions executions by directly transferring control to respective case first and then do rest of the things. Ref document: https://docs.microsoft.com/en-us/cpp/c-language/switch-statement-c?view=msvc-170
Quoted 20 lines
Quoted 4 lines
Hence in case of len = 0 and n > 28, it is throwing stack buffer overflow error.
Below is sample code to simulate the while loop behavior inside switch.
Checked it for both x86 and arm64.
Quoted 2 lines
https://urldefense.proofpoint.com/v2/url?u=https-3A__godbolt.org_z_4Ke
cqbsde&d=DwICAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=bm7kwlFq6L5uO69sS-08RKSWPEU
Quoted 1 line
tAQMUQjqHDFDtmpY&m=3GLnWHKqJB7pB5Jc36-gFYv-q-
3lyEtAFIK3Zt_TMRHhsAGJPIM
Quoted 6 lines
sAYTAunXt-TCf&s=L93OhPE9w3nl-Tf16rsvJ_OIC9Jar3Q7Be6vX9KfKfc&e=
Quoted 4 lines
Quoted 4 lines
examples/l3fwd/l3fwd_common.h +0
-0j =0 ;switch (len %FWDSTEP ) {while (j < len) {
Quoted 34 lines
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Functionsend_packetsx4()tries to access out of bound data fromrte_mbufand fill it into TX buffer even in the case where no pending packets (len = 0).
Performance impact:- NoASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0at pc0x0000005e791cbp0xffffe2c0d7e0sp0xffffe2c0d800READ of size 8 at0xffffe2c0dcf0thread T0
#00x5e7918insend_packetsx4../examples/l3fwd/l3fwd_common.h:251#10x5e7918insend_packets_multi../examples/l3fwd/l3fwd_neon.h:226Signed-off-by Rahul Bhansali <[email protected]>--- examples/l3fwd/l3fwd_common.h | 4 ++++ 1 file changed, 4 insertions(+)examples/l3fwd/l3fwd_common.h +3
-0@@ -236,6 +236,9 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],/* copy rest of the packets into the TX buffer. */ len = num - n; +if (len ==0 ) + goto exit; + j =0 ;switch (len %FWDSTEP ) {while (j < len) {
examples/l3fwd/l3fwd_common.h send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[],
Quoted 8 lines
examples/l3fwd/l3fwd_common.h +1
-1@@ -258,6 +261,7 @@ send_packetsx4(struct lcore_conf *qconf, uint16_t port, struct rte_mbuf *m[], } } +exit: qconf->tx_mbufs[port].len = len; } --
Quoted 1 line
2.25.1
Thomas Monjalon
AppliedQuoted 14 lines
Quoted 14 lines
This patch fixes the stack buffer overflow error reported from AddressSanitizer.
Functionsend_packetsx4()tries to access out of bound data fromrte_mbufand fill it into TX buffer even in the case where no pending packets (len = 0).
Performance impact:- NoASAN error report:-
==819==ERROR: AddressSanitizer: stack-buffer-overflow on address0xffffe2c0dcf0at pc0x0000005e791cbp0xffffe2c0d7e0sp0xffffe2c0d800READ of size 8 at0xffffe2c0dcf0thread T0
#00x5e7918insend_packetsx4../examples/l3fwd/l3fwd_common.h:251#10x5e7918insend_packets_multi../examples/l3fwd/l3fwd_neon.h:226
Quoted 3 lines
Quoted 1 line
Signed-off-by Rahul Bhansali <[email protected]>Reviewed-by Conor Walsh <[email protected]>
Applied, thanks.