Subject: [PATCH 1/5] fix send buffer check

From: Hideo AOKI <[email-masked]>
Date: Mon, 29 Oct 2007 17:22:53 -0400

This patch introduces sndbuf size check before memory allocation for
send buffer.

--
Hideo Aoki
Hitachi Computer Products (America) Inc.

Signed-off-by: Satoshi Oshima <[email-masked]>
Signed-off-by: Hideo Aoki <[email-masked]>

 ip_output.c |    5 +++++
 1 file changed, 5 insertions(+)

diff -pruN linux-2.6.24-rc1/net/ipv4/ip_output.c linux-2.6.24-rc1-mem003-ipv4-dev-p1/net/ipv4/ip_output.c
--- linux-2.6.24-rc1/net/ipv4/ip_output.c	2007-10-24 11:34:34.000000000 -0400
+++ linux-2.6.24-rc1-mem003-ipv4-dev-p1/net/ipv4/ip_output.c	2007-10-24 11:46:43.000000000 -0400
@@ -1004,6 +1004,11 @@ alloc_new_skb:
 					frag = &skb_shinfo(skb)->frags[i];
 				}
 			} else if (i < MAX_SKB_FRAGS) {
+				if (atomic_read(&sk->sk_wmem_alloc) + PAGE_SIZE
+				    > 2 * sk->sk_sndbuf) {
+					err = -ENOBUFS;
+					goto error;
+				}
 				if (copy > PAGE_SIZE)
 					copy = PAGE_SIZE;
 				page = alloc_pages(sk->sk_allocation, 0);