提交 55b3280d 编写于 作者: H Hoang Le 提交者: David S. Miller

tipc: fix skb truesize/datasize ratio control

In commit d618d09a ("tipc: enforce valid ratio between skb truesize
and contents") we introduced a test for ensuring that the condition
truesize/datasize <= 4 is true for a received buffer. Unfortunately this
test has two problems.

- Because of the integer arithmetics the test
  if (skb->truesize / buf_roundup_len(skb) > 4) will miss all
  ratios [4 < ratio < 5], which was not the intention.
- The buffer returned by skb_copy() inherits skb->truesize of the
  original buffer, which doesn't help the situation at all.

In this commit, we change the ratio condition and replace skb_copy()
with a call to skb_copy_expand() to finally get this right.
Acked-by: NJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: NJon Maloy <jon.maloy@ericsson.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 eb53f7af
...@@ -208,8 +208,8 @@ bool tipc_msg_validate(struct sk_buff **_skb) ...@@ -208,8 +208,8 @@ bool tipc_msg_validate(struct sk_buff **_skb)
int msz, hsz; int msz, hsz;
/* Ensure that flow control ratio condition is satisfied */ /* Ensure that flow control ratio condition is satisfied */
if (unlikely(skb->truesize / buf_roundup_len(skb) > 4)) { if (unlikely(skb->truesize / buf_roundup_len(skb) >= 4)) {
skb = skb_copy(skb, GFP_ATOMIC); skb = skb_copy_expand(skb, BUF_HEADROOM, 0, GFP_ATOMIC);
if (!skb) if (!skb)
return false; return false;
kfree_skb(*_skb); kfree_skb(*_skb);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册