Comments

We got system OOM while running some UDP netperf testing on the loopback
device. The case is multiple senders sent stream UDP packets to a single
receiver via loopback on local host. Of course, the receiver is not able
to handle all the packets in time. But we surprisingly found that these
packets were not discarded due to the receiver's sk->sk_rcvbuf limit.
Instead, they are kept queuing to sk->sk_backlog and finally ate up all
the memory. We believe this is a secure hole that a none privileged user
can crash the system.
The root cause for this problem is, when the receiver is doing
__release_sock() (i.e. after userspace recv, kernel udp_recvmsg ->
skb_free_datagram_locked -> release_sock), it moves skbs from backlog to
sk_receive_queue with the softirq enabled. In the above case, multiple
busy senders will almost make it an endless loop. The skbs in the
backlog end up eat all the system memory.
The patch fixed this problem by adding accounting for the socket
backlog. So that the backlog size can be restricted by protocol's choice
(i.e. UDP).
Reported-by: Alex Shi <alex.shi@intel.com>
Cc: David Miller <davem@davemloft.net>
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: Zhu Yi <yi.zhu@intel.com>
---
V2: remove atomic operation for sk_backlog.len
limit UDP backlog size to 2*sk->sk_rcvbuf
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

From: Zhu Yi <yi.zhu@intel.com>
Date: Fri, 26 Feb 2010 17:27:44 +0800
> We got system OOM while running some UDP netperf testing on the loopback> device. The case is multiple senders sent stream UDP packets to a single> receiver via loopback on local host. Of course, the receiver is not able> to handle all the packets in time. But we surprisingly found that these> packets were not discarded due to the receiver's sk->sk_rcvbuf limit.> Instead, they are kept queuing to sk->sk_backlog and finally ate up all> the memory. We believe this is a secure hole that a none privileged user> can crash the system.> > The root cause for this problem is, when the receiver is doing> __release_sock() (i.e. after userspace recv, kernel udp_recvmsg ->> skb_free_datagram_locked -> release_sock), it moves skbs from backlog to> sk_receive_queue with the softirq enabled. In the above case, multiple> busy senders will almost make it an endless loop. The skbs in the> backlog end up eat all the system memory.> > The patch fixed this problem by adding accounting for the socket> backlog. So that the backlog size can be restricted by protocol's choice> (i.e. UDP).> > Reported-by: Alex Shi <alex.shi@intel.com>> Cc: David Miller <davem@davemloft.net>> Cc: Eric Dumazet <eric.dumazet@gmail.com>> Signed-off-by: Zhu Yi <yi.zhu@intel.com>
So remind me why TCP, or any other non-UDP protocol, won't
intrinsically have this problem too?
It seems pretty trivial to do with any protocol, especially remotely,
with a packet generator. The code in TCP, for example, which queues
to the backlog, doesn't care about sequence numbers or anything like
that.
So you could spray a machine with the same TCP frame over and over
again, as fast as possible, as long as it matches the socket identity.
And in this way fill up the backlog endlessly and OOM the system.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

On Fri, 2010-02-26 at 20:05 +0800, David Miller wrote:
> So remind me why TCP, or any other non-UDP protocol, won't> intrinsically have this problem too?
If TCP ACKs are not received, the (closed) remote window prevents the
TCP sender to send more frames.
> It seems pretty trivial to do with any protocol, especially remotely,> with a packet generator. The code in TCP, for example, which queues> to the backlog, doesn't care about sequence numbers or anything like> that.> > So you could spray a machine with the same TCP frame over and over> again, as fast as possible, as long as it matches the socket identity.> > And in this way fill up the backlog endlessly and OOM the system.
Yeah, I only considered about the normal case, that is the TCP frames
are built and managed in the kernel. If a user does frame generation
himself, yes, the same problem could happen potentially for all
protocols using backlog.
Thanks,
-yi
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html

From: Zhu Yi <yi.zhu@intel.com>
Date: Mon, 01 Mar 2010 10:08:48 +0800
> Yeah, I only considered about the normal case, that is the TCP frames> are built and managed in the kernel.
You're not even considering the kernel case completely. It's just as
easy to modify the kernel to maliciously send frames in this way.
> If a user does frame generation himself, yes, the same problem could> happen potentially for all protocols using backlog.
We need the protection for every protocol, please implement your
changes this way.
Thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html