From: jamal <hadi@cyberus.ca>
To: Changli Gao <xiaosuo@gmail.com>
Cc: Patrick McHardy <kaber@trash.net>,
"David S. Miller" <davem@davemloft.net>,
netdev@vger.kernel.org
Subject: Re: [PATCH] cls_flow: add sanity check for the packet length
Date: Wed, 04 Aug 2010 09:39:43 -0400 [thread overview]
Message-ID: <1280929183.5669.7.camel@bigi> (raw)
In-Reply-To: <1280905687-8463-1-git-send-email-xiaosuo@gmail.com>
On Wed, 2010-08-04 at 15:08 +0800, Changli Gao wrote:
> The packet length should be checked before the packet data is dereferenced.
>
> Signed-off-by: Changli Gao <xiaosuo@gmail.com>
> ---
> include/linux/skbuff.h | 6 ++--
> net/sched/cls_flow.c | 69 +++++++++++++++++++++++++++++++++----------------
> 2 files changed, 50 insertions(+), 25 deletions(-)
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index d20d9e7..3f0ac50 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -1210,12 +1210,12 @@ static inline unsigned char *pskb_pull(struct sk_buff *skb, unsigned int len)
> return unlikely(len > skb->len) ? NULL : __pskb_pull(skb, len);
> }
>
> -static inline int pskb_may_pull(struct sk_buff *skb, unsigned int len)
> +static inline bool pskb_may_pull(struct sk_buff *skb, unsigned int len)
> {
> if (likely(len <= skb_headlen(skb)))
> - return 1;
> + return true;
> if (unlikely(len > skb->len))
> - return 0;
> + return false;
> return __pskb_pull_tail(skb, len - skb_headlen(skb)) != NULL;
> }
Above is a different patch?
> diff --git a/net/sched/cls_flow.c b/net/sched/cls_flow.c
> index f73542d..d63a374 100644
> --- a/net/sched/cls_flow.c
> +++ b/net/sched/cls_flow.c
> @@ -65,37 +65,48 @@ static inline u32 addr_fold(void *addr)
> return (a & 0xFFFFFFFF) ^ (BITS_PER_LONG > 32 ? a >> 32 : 0);
> }
>
> -static u32 flow_get_src(const struct sk_buff *skb)
> +static inline bool flow_pskb_may_pull(struct sk_buff *skb, unsigned int len)
> +{
> + return pskb_may_pull(skb, skb_network_offset(skb) + len);
> +}
network_pskb_may_pull() would make it more generic (probably in
skbuff.h) and reused everywhere you need skb_network_offset
> +static u32 flow_get_src(struct sk_buff *skb)
> {
> switch (skb->protocol) {
> case htons(ETH_P_IP):
> - return ntohl(ip_hdr(skb)->saddr);
> + return flow_pskb_may_pull(skb, sizeof(struct iphdr)) ?
> + ntohl(ip_hdr(skb)->saddr) : 0;
> case htons(ETH_P_IPV6):
> - return ntohl(ipv6_hdr(skb)->saddr.s6_addr32[3]);
> + return flow_pskb_may_pull(skb, sizeof(struct ipv6hdr)) ?
> + ntohl(ipv6_hdr(skb)->saddr.s6_addr32[3]) : 0;
> default:
BTW - does returning zero above make sense or is returning the default below better?
> return addr_fold(skb->sk);
Same comment applies in all other switch statements..
cheers,
jamal
next prev parent reply other threads:[~2010-08-04 13:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-04 7:08 [PATCH] cls_flow: add sanity check for the packet length Changli Gao
2010-08-04 13:39 ` jamal [this message]
2010-08-04 13:51 ` Changli Gao
2010-08-04 14:18 ` jamal
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=1280929183.5669.7.camel@bigi \
--to=hadi@cyberus.ca \
--cc=davem@davemloft.net \
--cc=kaber@trash.net \
--cc=netdev@vger.kernel.org \
--cc=xiaosuo@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.