public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Amir Vadai <amir@vadai.me>
To: zhuyj <zyjzyj2000@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	netdev <netdev@vger.kernel.org>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Or Gerlitz <ogerlitz@mellanox.com>,
	Hadar Har-Zion <hadarh@mellanox.com>,
	Jiri Pirko <jiri@mellanox.com>
Subject: Re: [PATCH net V2] net/sched: pedit: make sure that offset is valid
Date: Tue, 29 Nov 2016 09:14:34 +0200	[thread overview]
Message-ID: <20161129071434.GA22491@office.localdomain> (raw)
In-Reply-To: <CAD=hENcSiWiH-9e6=gjn+wK4R6ZQsNa21R_w_eWzDtCxiUDNVQ@mail.gmail.com>

On Tue, Nov 29, 2016 at 10:32:05AM +0800, zhuyj wrote:
>  +       if (offset > 0 && offset > skb->len)
> 
> offset > skb->len is enough?
offset is signed and skb->len is unsigned. Therefore for example if
offset=-1 and skb->len=10, the actual comparison is 0xff...>10

> 
> On Mon, Nov 28, 2016 at 6:56 PM, Amir Vadai <amir@vadai.me> wrote:
> > Add a validation function to make sure offset is valid:
> > 1. Not below skb head (could happen when offset is negative).
> > 2. Validate both 'offset' and 'at'.
> >
> > Signed-off-by: Amir Vadai <amir@vadai.me>
> > ---
> > Hi Dave,
> >
> > Please pull to -stable branches.
> >
> > Changes from V0:
> > - Add a validation to the 'at' value (this is used as an offset too)
> > - Instead of validating the output of skb_header_pointer(), make sure that the
> >         offset is good before calling it.
> >
> > Thanks,
> > Amir
> >  net/sched/act_pedit.c | 24 ++++++++++++++++++++----
> >  1 file changed, 20 insertions(+), 4 deletions(-)
> >
> > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c
> > index b54d56d4959b..cf9b2fe8eac6 100644
> > --- a/net/sched/act_pedit.c
> > +++ b/net/sched/act_pedit.c
> > @@ -108,6 +108,17 @@ static void tcf_pedit_cleanup(struct tc_action *a, int bind)
> >         kfree(keys);
> >  }
> >
> > +static bool offset_valid(struct sk_buff *skb, int offset)
> > +{
> > +       if (offset > 0 && offset > skb->len)
> > +               return false;
> > +
> > +       if  (offset < 0 && -offset > skb_headroom(skb))
> > +               return false;
> > +
> > +       return true;
> > +}
> > +
> >  static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
> >                      struct tcf_result *res)
> >  {
> > @@ -134,6 +145,11 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
> >                         if (tkey->offmask) {
> >                                 char *d, _d;
> >
> > +                               if (!offset_valid(skb, off + tkey->at)) {
> > +                                       pr_info("tc filter pedit 'at' offset %d out of bounds\n",
> > +                                               off + tkey->at);
> > +                                       goto bad;
> > +                               }
> >                                 d = skb_header_pointer(skb, off + tkey->at, 1,
> >                                                        &_d);
> >                                 if (!d)
> > @@ -146,10 +162,10 @@ static int tcf_pedit(struct sk_buff *skb, const struct tc_action *a,
> >                                         " offset must be on 32 bit boundaries\n");
> >                                 goto bad;
> >                         }
> > -                       if (offset > 0 && offset > skb->len) {
> > -                               pr_info("tc filter pedit"
> > -                                       " offset %d can't exceed pkt length %d\n",
> > -                                      offset, skb->len);
> > +
> > +                       if (!offset_valid(skb, off + offset)) {
> > +                               pr_info("tc filter pedit offset %d out of bounds\n",
> > +                                       offset);
> >                                 goto bad;
> >                         }
> >
> > --
> > 2.10.2
> >

  reply	other threads:[~2016-11-29  7:14 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-28 10:56 [PATCH net V2] net/sched: pedit: make sure that offset is valid Amir Vadai
2016-11-29  2:32 ` zhuyj
2016-11-29  7:14   ` Amir Vadai [this message]
2016-11-29  9:27     ` zhuyj
2016-11-29 11:03       ` Amir Vadai
2016-11-30  0:46 ` David Miller

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=20161129071434.GA22491@office.localdomain \
    --to=amir@vadai.me \
    --cc=davem@davemloft.net \
    --cc=hadarh@mellanox.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=ogerlitz@mellanox.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=zyjzyj2000@gmail.com \
    /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