diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-10-21 19:27:46 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-10-22 05:59:53 -0400 |
commit | deea84b0ae3d26b41502ae0a39fe7fe134e703d0 (patch) | |
tree | 4730d75c6e2edf50b0e61087178baa9092647b94 /include/linux | |
parent | bfb85c9f753a7172bd962e8717118191dfd612cc (diff) |
[NET]: Fix SKB_WITH_OVERHEAD calculation
The calculation in SKB_WITH_OVERHEAD is incorrect in that it can cause
an overflow across a page boundary which is what it's meant to prevent.
In particular, the header length (X) should not be lumped together with
skb_shared_info. The latter needs to be aligned properly while the header
has no choice but to sit in front of wherever the payload is.
Therefore the correct calculation is to take away the aligned size of
skb_shared_info, and then subtract the header length. The resulting
quantity L satisfies the following inequality:
SKB_DATA_ALIGN(L + X) + sizeof(struct skb_shared_info) <= PAGE_SIZE
This is the quantity used by alloc_skb to do the actual allocation.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/skbuff.h | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index f93f22b3d2ff..369f60a4797d 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
@@ -41,8 +41,7 @@ | |||
41 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ | 41 | #define SKB_DATA_ALIGN(X) (((X) + (SMP_CACHE_BYTES - 1)) & \ |
42 | ~(SMP_CACHE_BYTES - 1)) | 42 | ~(SMP_CACHE_BYTES - 1)) |
43 | #define SKB_WITH_OVERHEAD(X) \ | 43 | #define SKB_WITH_OVERHEAD(X) \ |
44 | (((X) - sizeof(struct skb_shared_info)) & \ | 44 | ((X) - SKB_DATA_ALIGN(sizeof(struct skb_shared_info))) |
45 | ~(SMP_CACHE_BYTES - 1)) | ||
46 | #define SKB_MAX_ORDER(X, ORDER) \ | 45 | #define SKB_MAX_ORDER(X, ORDER) \ |
47 | SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) | 46 | SKB_WITH_OVERHEAD((PAGE_SIZE << (ORDER)) - (X)) |
48 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) | 47 | #define SKB_MAX_HEAD(X) (SKB_MAX_ORDER((X), 0)) |