Commit 6ee1d84b authored by David S. Miller's avatar David S. Miller

Merge branch 'skb-drop-reason-boundary'

Menglong Dong says:

====================
net: skb: check the boundrary of skb drop reason

In the commit 1330b6ef ("skb: make drop reason booleanable"),
SKB_NOT_DROPPED_YET is added to the enum skb_drop_reason, which makes
the invalid drop reason SKB_NOT_DROPPED_YET can leak to the kfree_skb
tracepoint. Once this happen (it happened, as 4th patch says), it can
cause NULL pointer in drop monitor and result in kernel panic.

Therefore, check the boundrary of drop reason in both kfree_skb_reason
(2th patch) and drop monitor (1th patch) to prevent such case happens
again.

Meanwhile, fix the invalid drop reason passed to kfree_skb_reason() in
tcp_v4_rcv() and tcp_v6_rcv().

Changes since v2:
1/4 - don't reset the reason and print the debug warning only (Jakub
      Kicinski)
4/4 - remove new lines between tags

Changes since v1:
- consider tcp_v6_rcv() in the 4th patch
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 3aba1030 f8319dfd
...@@ -510,7 +510,8 @@ enum skb_drop_reason { ...@@ -510,7 +510,8 @@ enum skb_drop_reason {
(name = SKB_DROP_REASON_##reason) (name = SKB_DROP_REASON_##reason)
#define SKB_DR_OR(name, reason) \ #define SKB_DR_OR(name, reason) \
do { \ do { \
if (name == SKB_DROP_REASON_NOT_SPECIFIED) \ if (name == SKB_DROP_REASON_NOT_SPECIFIED || \
name == SKB_NOT_DROPPED_YET) \
SKB_DR_SET(name, reason); \ SKB_DR_SET(name, reason); \
} while (0) } while (0)
......
...@@ -517,7 +517,7 @@ static void net_dm_packet_trace_kfree_skb_hit(void *ignore, ...@@ -517,7 +517,7 @@ static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
if (!nskb) if (!nskb)
return; return;
if ((unsigned int)reason >= SKB_DROP_REASON_MAX) if (unlikely(reason >= SKB_DROP_REASON_MAX || reason <= 0))
reason = SKB_DROP_REASON_NOT_SPECIFIED; reason = SKB_DROP_REASON_NOT_SPECIFIED;
cb = NET_DM_SKB_CB(nskb); cb = NET_DM_SKB_CB(nskb);
cb->reason = reason; cb->reason = reason;
......
...@@ -771,6 +771,8 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason) ...@@ -771,6 +771,8 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
if (!skb_unref(skb)) if (!skb_unref(skb))
return; return;
DEBUG_NET_WARN_ON_ONCE(reason <= 0 || reason >= SKB_DROP_REASON_MAX);
trace_kfree_skb(skb, __builtin_return_address(0), reason); trace_kfree_skb(skb, __builtin_return_address(0), reason);
__kfree_skb(skb); __kfree_skb(skb);
} }
......
...@@ -2101,6 +2101,7 @@ int tcp_v4_rcv(struct sk_buff *skb) ...@@ -2101,6 +2101,7 @@ int tcp_v4_rcv(struct sk_buff *skb)
} }
discard_it: discard_it:
SKB_DR_OR(drop_reason, NOT_SPECIFIED);
/* Discard frame. */ /* Discard frame. */
kfree_skb_reason(skb, drop_reason); kfree_skb_reason(skb, drop_reason);
return 0; return 0;
......
...@@ -1509,6 +1509,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -1509,6 +1509,7 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
discard: discard:
if (opt_skb) if (opt_skb)
__kfree_skb(opt_skb); __kfree_skb(opt_skb);
SKB_DR_OR(reason, NOT_SPECIFIED);
kfree_skb_reason(skb, reason); kfree_skb_reason(skb, reason);
return 0; return 0;
csum_err: csum_err:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment