netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: llc: fix use after free in llc_ui_recvmsg
@ 2013-12-30 22:40 Daniel Borkmann
  2014-01-03  0:31 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Borkmann @ 2013-12-30 22:40 UTC (permalink / raw)
  To: davem; +Cc: netdev, Stephen Hemminger, Arnaldo Carvalho de Melo

While commit 30a584d944fb 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: 30a584d944fb ("[LLX]: SOCK_DGRAM interface fixes")
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
---
 net/llc/af_llc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/llc/af_llc.c b/net/llc/af_llc.c
index 7b01b9f..c71b699 100644
--- a/net/llc/af_llc.c
+++ b/net/llc/af_llc.c
@@ -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;
@@ -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)
@@ -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);
 
-- 
1.7.11.7

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

* Re: [PATCH net] net: llc: fix use after free in llc_ui_recvmsg
  2013-12-30 22:40 [PATCH net] net: llc: fix use after free in llc_ui_recvmsg Daniel Borkmann
@ 2014-01-03  0:31 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2014-01-03  0:31 UTC (permalink / raw)
  To: dborkman; +Cc: netdev, stephen, acme

From: Daniel Borkmann <dborkman@redhat.com>
Date: Mon, 30 Dec 2013 23:40:50 +0100

> While commit 30a584d944fb 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: 30a584d944fb ("[LLX]: SOCK_DGRAM interface fixes")
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>

Applied and queued up for -stable, thanks!

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

end of thread, other threads:[~2014-01-03  0:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-30 22:40 [PATCH net] net: llc: fix use after free in llc_ui_recvmsg Daniel Borkmann
2014-01-03  0:31 ` David Miller

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).