Skip to content

Commit 2cf6bff

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: replace skb_make_writable with skb_ensure_writable
This converts all remaining users and then removes skb_make_writable. Suggested-by: Daniel Borkmann <[email protected]> Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent fb2eb1c commit 2cf6bff

File tree

5 files changed

+6
-33
lines changed

5 files changed

+6
-33
lines changed

include/linux/netfilter.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,6 @@ int compat_nf_getsockopt(struct sock *sk, u_int8_t pf, int optval,
336336
char __user *opt, int *len);
337337
#endif
338338

339-
/* Call this before modifying an existing packet: ensures it is
340-
modifiable and linear to the point you care about (writable_len).
341-
Returns true or false. */
342-
int skb_make_writable(struct sk_buff *skb, unsigned int writable_len);
343-
344339
struct flowi;
345340
struct nf_queue_entry;
346341

net/netfilter/core.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -536,28 +536,6 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state,
536536
}
537537
EXPORT_SYMBOL(nf_hook_slow);
538538

539-
540-
int skb_make_writable(struct sk_buff *skb, unsigned int writable_len)
541-
{
542-
if (writable_len > skb->len)
543-
return 0;
544-
545-
/* Not exclusive use of packet? Must copy. */
546-
if (!skb_cloned(skb)) {
547-
if (writable_len <= skb_headlen(skb))
548-
return 1;
549-
} else if (skb_clone_writable(skb, writable_len))
550-
return 1;
551-
552-
if (writable_len <= skb_headlen(skb))
553-
writable_len = 0;
554-
else
555-
writable_len -= skb_headlen(skb);
556-
557-
return !!__pskb_pull_tail(skb, writable_len);
558-
}
559-
EXPORT_SYMBOL(skb_make_writable);
560-
561539
/* This needs to be compiled in any case to avoid dependencies between the
562540
* nfnetlink_queue code and nf_conntrack.
563541
*/

net/netfilter/nf_synproxy_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ unsigned int synproxy_tstamp_adjust(struct sk_buff *skb,
196196
optoff = protoff + sizeof(struct tcphdr);
197197
optend = protoff + th->doff * 4;
198198

199-
if (!skb_make_writable(skb, optend))
199+
if (skb_ensure_writable(skb, optend))
200200
return 0;
201201

202202
while (optoff < optend) {

net/netfilter/nfnetlink_queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff)
863863
}
864864
skb_put(e->skb, diff);
865865
}
866-
if (!skb_make_writable(e->skb, data_len))
866+
if (skb_ensure_writable(e->skb, data_len))
867867
return -ENOMEM;
868868
skb_copy_to_linear_data(e->skb, data, data_len);
869869
e->skb->ip_summed = CHECKSUM_NONE;

net/netfilter/xt_DSCP.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dscp_tg(struct sk_buff *skb, const struct xt_action_param *par)
3434
u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
3535

3636
if (dscp != dinfo->dscp) {
37-
if (!skb_make_writable(skb, sizeof(struct iphdr)))
37+
if (skb_ensure_writable(skb, sizeof(struct iphdr)))
3838
return NF_DROP;
3939

4040
ipv4_change_dsfield(ip_hdr(skb),
@@ -52,7 +52,7 @@ dscp_tg6(struct sk_buff *skb, const struct xt_action_param *par)
5252
u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
5353

5454
if (dscp != dinfo->dscp) {
55-
if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
55+
if (skb_ensure_writable(skb, sizeof(struct ipv6hdr)))
5656
return NF_DROP;
5757

5858
ipv6_change_dsfield(ipv6_hdr(skb),
@@ -82,7 +82,7 @@ tos_tg(struct sk_buff *skb, const struct xt_action_param *par)
8282
nv = (orig & ~info->tos_mask) ^ info->tos_value;
8383

8484
if (orig != nv) {
85-
if (!skb_make_writable(skb, sizeof(struct iphdr)))
85+
if (skb_ensure_writable(skb, sizeof(struct iphdr)))
8686
return NF_DROP;
8787
iph = ip_hdr(skb);
8888
ipv4_change_dsfield(iph, 0, nv);
@@ -102,7 +102,7 @@ tos_tg6(struct sk_buff *skb, const struct xt_action_param *par)
102102
nv = (orig & ~info->tos_mask) ^ info->tos_value;
103103

104104
if (orig != nv) {
105-
if (!skb_make_writable(skb, sizeof(struct iphdr)))
105+
if (skb_ensure_writable(skb, sizeof(struct iphdr)))
106106
return NF_DROP;
107107
iph = ipv6_hdr(skb);
108108
ipv6_change_dsfield(iph, 0, nv);

0 commit comments

Comments
 (0)