DPDK patches and discussions
 help / color / mirror / Atom feed
From: Rahul Bhansali <rbhansali@marvell.com>
To: Thomas Monjalon <thomas@monjalon.net>
Cc: "dev@dpdk.org" <dev@dpdk.org>,
	"david.marchand@redhat.com" <david.marchand@redhat.com>,
	Conor Walsh <conor.walsh@intel.com>
Subject: RE: [EXT] Re: [PATCH] examples/l3fwd: resolve stack buffer overflow issue
Date: Thu, 10 Mar 2022 09:38:53 +0000	[thread overview]
Message-ID: <CO6PR18MB38449200B546F8EB48316E59B80B9@CO6PR18MB3844.namprd18.prod.outlook.com> (raw)
In-Reply-To: <8029134.GJh79HuArf@thomas>



> -----Original Message-----
> From: Thomas Monjalon <thomas@monjalon.net>
> Sent: Thursday, March 10, 2022 12:37 AM
> To: Rahul Bhansali <rbhansali@marvell.com>
> Cc: dev@dpdk.org; david.marchand@redhat.com; Conor Walsh
> <conor.walsh@intel.com>
> Subject: Re: [EXT] Re: [PATCH] examples/l3fwd: resolve stack buffer overflow
> issue
> 
> 09/03/2022 16:24, Rahul Bhansali:
> > Hi Thomas,
> >
> > From: Thomas Monjalon <thomas@monjalon.net>
> > > 11/01/2022 13:50, Rahul Bhansali:
> > > >  		/* 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.
> 
> 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

> 
> > 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://urldefense.proofpoint.com/v2/url?u=https-3A__godbolt.org_z_4Ke
> > cqbsde&d=DwICAg&c=nKjWec2b6R0mOyPaz7xtfQ&r=bm7kwlFq6L5uO69sS-
> 08RKSWPEU
> > tAQMUQjqHDFDtmpY&m=3GLnWHKqJB7pB5Jc36-gFYv-q-
> 3lyEtAFIK3Zt_TMRHhsAGJPIM
> > sAYTAunXt-TCf&s=L93OhPE9w3nl-Tf16rsvJ_OIC9Jar3Q7Be6vX9KfKfc&e=
> >
> > >
> > > >  		j = 0;
> > > >  		switch (len % FWDSTEP) {
> > > >  		while (j < len) {
> 
> 
> 
> 


  reply	other threads:[~2022-03-10  9:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-11 12:50 Rahul Bhansali
2022-03-07  4:27 ` Rahul Bhansali
2022-03-07  6:45 ` Rahul Bhansali
2022-03-07 10:46   ` Walsh, Conor
2022-03-08 11:20 ` Thomas Monjalon
2022-03-09 15:24   ` [EXT] " Rahul Bhansali
2022-03-09 19:07     ` Thomas Monjalon
2022-03-10  9:38       ` Rahul Bhansali [this message]
2022-03-09 15:57 ` Ananyev, Konstantin
2022-03-14 22:16   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CO6PR18MB38449200B546F8EB48316E59B80B9@CO6PR18MB3844.namprd18.prod.outlook.com \
    --to=rbhansali@marvell.com \
    --cc=conor.walsh@intel.com \
    --cc=david.marchand@redhat.com \
    --cc=dev@dpdk.org \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).