Skip to content

Commit

Permalink
net: llc: fix use after free in llc_ui_recvmsg
Browse files Browse the repository at this point in the history
While commit 30a584d fixes datagram interface in LLC, a use
after free bug has been introduced for SOCK_STREAM sockets that do
not make use of MSG_PEEK.

The flow is as follow ...

  if (!(flags & MSG_PEEK)) {
    ...
    sk_eat_skb(sk, skb, false);
    ...
  }
  ...
  if (used + offset < skb->len)
    continue;

... where sk_eat_skb() calls __kfree_skb(). Therefore, cache
original length and work on skb_len to check partial reads.

Fixes: 30a584d ("[LLX]: SOCK_DGRAM interface fixes")
Signed-off-by: Daniel Borkmann <[email protected]>
Cc: Stephen Hemminger <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Daniel Borkmann authored and davem330 committed Jan 3, 2014
1 parent 6cd4ce0 commit 4d231b7
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions net/llc/af_llc.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
unsigned long cpu_flags;
size_t copied = 0;
u32 peek_seq = 0;
u32 *seq;
u32 *seq, skb_len;
unsigned long used;
int target; /* Read at least this many bytes */
long timeo;
Expand Down Expand Up @@ -812,6 +812,7 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
}
continue;
found_ok_skb:
skb_len = skb->len;
/* Ok so how much can we use? */
used = skb->len - offset;
if (len < used)
Expand Down Expand Up @@ -844,7 +845,7 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
}

/* Partial read */
if (used + offset < skb->len)
if (used + offset < skb_len)
continue;
} while (len > 0);

Expand Down

0 comments on commit 4d231b7

Please sign in to comment.