@@ -31,33 +31,33 @@ static inline unsigned int optlen(const u_int8_t *opt, unsigned int offset)
31
31
static unsigned int
32
32
tcpoptstrip_mangle_packet (struct sk_buff * skb ,
33
33
const struct xt_action_param * par ,
34
- unsigned int tcphoff , unsigned int minlen )
34
+ unsigned int tcphoff )
35
35
{
36
36
const struct xt_tcpoptstrip_target_info * info = par -> targinfo ;
37
+ struct tcphdr * tcph , _th ;
37
38
unsigned int optl , i , j ;
38
- struct tcphdr * tcph ;
39
39
u_int16_t n , o ;
40
40
u_int8_t * opt ;
41
- int len , tcp_hdrlen ;
41
+ int tcp_hdrlen ;
42
42
43
43
/* This is a fragment, no TCP header is available */
44
44
if (par -> fragoff != 0 )
45
45
return XT_CONTINUE ;
46
46
47
- if (!skb_make_writable (skb , skb -> len ))
47
+ tcph = skb_header_pointer (skb , tcphoff , sizeof (_th ), & _th );
48
+ if (!tcph )
48
49
return NF_DROP ;
49
50
50
- len = skb -> len - tcphoff ;
51
- if (len < (int )sizeof (struct tcphdr ))
52
- return NF_DROP ;
53
-
54
- tcph = (struct tcphdr * )(skb_network_header (skb ) + tcphoff );
55
51
tcp_hdrlen = tcph -> doff * 4 ;
52
+ if (tcp_hdrlen < sizeof (struct tcphdr ))
53
+ return NF_DROP ;
56
54
57
- if (len < tcp_hdrlen )
55
+ if (skb_ensure_writable ( skb , tcphoff + tcp_hdrlen ) )
58
56
return NF_DROP ;
59
57
60
- opt = (u_int8_t * )tcph ;
58
+ /* must reload tcph, might have been moved */
59
+ tcph = (struct tcphdr * )(skb_network_header (skb ) + tcphoff );
60
+ opt = (u8 * )tcph ;
61
61
62
62
/*
63
63
* Walk through all TCP options - if we find some option to remove,
@@ -91,8 +91,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
91
91
static unsigned int
92
92
tcpoptstrip_tg4 (struct sk_buff * skb , const struct xt_action_param * par )
93
93
{
94
- return tcpoptstrip_mangle_packet (skb , par , ip_hdrlen (skb ),
95
- sizeof (struct iphdr ) + sizeof (struct tcphdr ));
94
+ return tcpoptstrip_mangle_packet (skb , par , ip_hdrlen (skb ));
96
95
}
97
96
98
97
#if IS_ENABLED (CONFIG_IP6_NF_MANGLE )
@@ -109,8 +108,7 @@ tcpoptstrip_tg6(struct sk_buff *skb, const struct xt_action_param *par)
109
108
if (tcphoff < 0 )
110
109
return NF_DROP ;
111
110
112
- return tcpoptstrip_mangle_packet (skb , par , tcphoff ,
113
- sizeof (* ipv6h ) + sizeof (struct tcphdr ));
111
+ return tcpoptstrip_mangle_packet (skb , par , tcphoff );
114
112
}
115
113
#endif
116
114
0 commit comments