mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH] Cipso: cipso_v4_optptr enter infinite loop
       [not found] <1501471381-12808-1-git-send-email-yujuan.qi@mediatek.com>
@ 2017-07-31 20:13 ` Paul Moore
  2017-08-01 22:31 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Moore @ 2017-07-31 20:13 UTC (permalink / raw)
  To: Yujuan Qi
  Cc: David S. Miller, Casey Schaufler, netdev, linux-mediatek,
	linux-kernel, Ryder Lee

On Sun, Jul 30, 2017 at 11:23 PM, Yujuan Qi <yujuan.qi@mediatek.com> wrote:
> From: "yujuan.qi" <yujuan.qi@mediatek.com>
>
> in for(),if((optlen > 0) && (optptr[1] == 0)), enter infinite loop.
>
> Test: receive a packet which the ip length > 20 and the first byte of ip option is 0, produce this issue
>
> Signed-off-by: yujuan.qi <yujuan.qi@mediatek.com>
> ---
>  net/ipv4/cipso_ipv4.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)

Considering I gave you the code below I should probably ack it, right? ;)

Acked-by: Paul Moore <paul@paul-moore.com>

> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index ae20616..0d1e07d 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -1523,9 +1523,17 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb)
>         int taglen;
>
>         for (optlen = iph->ihl*4 - sizeof(struct iphdr); optlen > 0; ) {
> -               if (optptr[0] == IPOPT_CIPSO)
> +               switch (optptr[0]) {
> +               case IPOPT_CIPSO:
>                         return optptr;
> -               taglen = optptr[1];
> +               case IPOPT_END:
> +                       return NULL;
> +               case IPOPT_NOOP:
> +                       taglen = 1;
> +                       break;
> +               default:
> +                       taglen = optptr[1];
> +               }
>                 optlen -= taglen;
>                 optptr += taglen;
>         }

-- 
paul moore
security @ redhat

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Cipso: cipso_v4_optptr enter infinite loop
       [not found] <1501471381-12808-1-git-send-email-yujuan.qi@mediatek.com>
  2017-07-31 20:13 ` [PATCH] Cipso: cipso_v4_optptr enter infinite loop Paul Moore
@ 2017-08-01 22:31 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2017-08-01 22:31 UTC (permalink / raw)
  To: yujuan.qi; +Cc: pmoore, casey, netdev, linux-mediatek, linux-kernel, ryder.lee

From: Yujuan Qi <yujuan.qi@mediatek.com>
Date: Mon, 31 Jul 2017 11:23:01 +0800

> From: "yujuan.qi" <yujuan.qi@mediatek.com>
> 
> in for(),if((optlen > 0) && (optptr[1] == 0)), enter infinite loop.
> 
> Test: receive a packet which the ip length > 20 and the first byte of ip option is 0, produce this issue
> 
> Signed-off-by: yujuan.qi <yujuan.qi@mediatek.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Cipso: cipso_v4_optptr enter infinite loop
       [not found] <1501241408-19129-1-git-send-email-yujuan.qi@mediatek.com>
@ 2017-07-28 15:12 ` Paul Moore
  0 siblings, 0 replies; 3+ messages in thread
From: Paul Moore @ 2017-07-28 15:12 UTC (permalink / raw)
  To: Yujuan Qi
  Cc: David S. Miller, Casey Schaufler, netdev, linux-mediatek,
	linux-kernel, Ryder Lee

On Fri, Jul 28, 2017 at 7:30 AM, Yujuan Qi <yujuan.qi@mediatek.com> wrote:
> From: "yujuan.qi" <yujuan.qi@mediatek.com>
>
> in for(),if((optlen > 0) && (optptr[1] == 0)), enter infinite loop.
>
> Test: receive a packet which the ip length > 20 and the first byte of ip option is 0, produce this issue
>
> Signed-off-by: yujuan.qi <yujuan.qi@mediatek.com>
> ---
>  net/ipv4/cipso_ipv4.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/net/ipv4/cipso_ipv4.c b/net/ipv4/cipso_ipv4.c
> index ae20616..b3d97c7 100644
> --- a/net/ipv4/cipso_ipv4.c
> +++ b/net/ipv4/cipso_ipv4.c
> @@ -1528,6 +1528,8 @@ unsigned char *cipso_v4_optptr(const struct sk_buff *skb)
>                 taglen = optptr[1];
>                 optlen -= taglen;
>                 optptr += taglen;
> +               if (!taglen)
> +                       break;
>         }
>
>         return NULL;

Thanks for catching this and submitting a patch.  Unfortunately
checking taglen/optptr[1] isn't going to help with the NOP and EOL
options as they are single byte options.  I think a for-loop like the
following, or something similar, is probably the better solution:

  for (optlen = iph->ihl*4 - sizeof(struct iphdr); optlen > 0; ) {
         switch (optptr[0]) {
         case IPOPT_CIPSO:
                 return optptr;
         case IPOPT_END:
                 return NULL;
         case IPOPT_NOOP:
                 taglen = 1;
                 break;
         default:
                 taglen = optptr[1];
         }
         optlen -= taglen;
         optptr += taglen;
  }

-- 
paul moore
security @ redhat

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-08-01 22:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1501471381-12808-1-git-send-email-yujuan.qi@mediatek.com>
2017-07-31 20:13 ` [PATCH] Cipso: cipso_v4_optptr enter infinite loop Paul Moore
2017-08-01 22:31 ` David Miller
     [not found] <1501241408-19129-1-git-send-email-yujuan.qi@mediatek.com>
2017-07-28 15:12 ` Paul Moore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®