netfilter: remove skb_make_writable helper
Subsystems (4)
Florian Westphal
maintainercover netfilter: remove skb_make_writable helper
This series removes skb_make_writable. All users are converted to skb_ensure_writable.
In Hindsight, skb_ensure_writable() should never have been added to the tree, and instead we should have moved skb_make_writable to the core.
What happened instead that skb_ensure_writable was added to OVS, then moved to core, then extended in functionality until the point it has the same effect and same pre and post-conditions as skb_make_writable.
So, remove skb_make_writable and use the new function everywhere. Patch 1 has a more detailed explanation/walkthrough of the two functions and their pre and post-conditions.
Florian Westphal (8):
netfilter: bridge: convert skb_make_writable to skb_ensure_writable
netfilter: ipvs: prefer skb_ensure_writable
netfilter: conntrack, nat: prefer skb_ensure_writable
netfilter: ipv4: prefer skb_ensure_writable
netfilter: nf_tables: prefer skb_ensure_writable
netfilter: xt_HL: prefer skb_ensure_writable
netfilter: tcpmss, optstrip: prefer skb_ensure_writable
netfilter: replace skb_make_writable with skb_ensure_writable
include/linux/netfilter.h | 5 ----- net/bridge/netfilter/ebt_dnat.c | 2 +- net/bridge/netfilter/ebt_redirect.c | 2 +- net/bridge/netfilter/ebt_snat.c | 2 +- net/ipv4/netfilter/arpt_mangle.c | 2 +- net/ipv4/netfilter/ipt_ECN.c | 4 ++-- net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_snmp_basic_main.c | 2 +- net/netfilter/core.c | 22 ---------------------- net/netfilter/ipvs/ip_vs_app.c | 4 ++-- net/netfilter/ipvs/ip_vs_core.c | 4 ++-- net/netfilter/ipvs/ip_vs_ftp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_sctp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_tcp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_udp.c | 4 ++-- net/netfilter/ipvs/ip_vs_xmit.c | 12 ++++++------ net/netfilter/nf_conntrack_proto_sctp.c | 2 +- net/netfilter/nf_conntrack_seqadj.c | 4 ++-- net/netfilter/nf_nat_helper.c | 4 ++-- net/netfilter/nf_nat_proto.c | 24 ++++++++++++------------ net/netfilter/nf_nat_sip.c | 2 +- net/netfilter/nf_synproxy_core.c | 2 +- net/netfilter/nfnetlink_queue.c | 2 +- net/netfilter/nft_exthdr.c | 3 ++- net/netfilter/nft_payload.c | 6 +++--- net/netfilter/xt_DSCP.c | 8 ++++---- net/netfilter/xt_HL.c | 4 ++-- net/netfilter/xt_TCPMSS.c | 2 +- net/netfilter/xt_TCPOPTSTRIP.c | 28 +++++++++++++--------------- 29 files changed, 71 insertions(+), 99 deletions(-)
Florian Westphal
maintainerPATCH 1/8 netfilter: bridge: convert skb_make_writable to skb_ensure_writable
Back in the day, skb_ensure_writable did not exist. By now, both functions have the same precondition:
I. skb_make_writable will test in this order:
1. wlen > skb->len -> error
2. if not cloned and wlen <= headlen -> OK
3. If cloned and wlen bytes of clone writeable -> OK
After those checks, skb is either not cloned but needs to pull from nonlinear area, or writing to head would also alter data of another clone.
In both cases skb_make_writable will then call __pskb_pull_tail, which will kmalloc a new memory area to use for skb->head.
IOW, after successful skb_make_writable call, the requested length is in linear area and can be modified, even if skb was cloned.
II. skb_ensure_writable will do this instead:
1. call pskb_may_pull. This handles case 1 above. After this, wlen is in linear area, but skb might be cloned.
2. return if skb is not cloned
3. return if wlen byte of clone are writeable.
4. fully copy the skb.
So post-conditions are the same:
*len bytes are writeable in linear area without altering any payload data of a clone, all header pointers might have been changed.
Only differences are that skb_ensure_writable is in the core, whereas skb_make_writable lives in netfilter core and the inverted return value. skb_make_writable returns 0 on error, whereas skb_ensure_writable returns negative value.
For the normal cases performance is similar:
A. skb is not cloned and in linear area:
pskb_may_pull is inline helper, so neither function copies.
B. skb is cloned, write is in linear area and clone is writeable:
both funcions return with step 3.
This series removes skb_make_writable from the kernel.
While at it, pass the needed value instead, its less confusing that way:
There is no special-handling of "0-length" argument in either skb_make_writable or skb_ensure_writable.
bridge already makes sure ethernet header is in linear area, only purpose of the make_writable() is is to copy skb->head in case of cloned skbs.
--- net/bridge/netfilter/ebt_dnat.c | 2 +- net/bridge/netfilter/ebt_redirect.c | 2 +- net/bridge/netfilter/ebt_snat.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
net/bridge/netfilter/ebt_dnat.c +1 -1
@@ -21,7 +21,7 @@ ebt_dnat_tg(struct sk_buff *skb, const struct xt_action_param *par)const struct ebt_nat_info *info = par->targinfo;struct net_device *dev; -if (!skb_make_writable (skb,0 )) +if (skb_ensure_writable (skb,ETH_ALEN ))return EBT_DROP ;ether_addr_copy (eth_hdr (skb)->h_dest, info->mac);
net/bridge/netfilter/ebt_redirect.c +1 -1
@@ -20,7 +20,7 @@ ebt_redirect_tg(struct sk_buff *skb, const struct xt_action_param *par) {const struct ebt_redirect_info *info = par->targinfo; -if (!skb_make_writable (skb,0 )) +if (skb_ensure_writable (skb,ETH_ALEN ))return EBT_DROP ;if (xt_hooknum (par) !=NF_BR_BROUTING )
net/bridge/netfilter/ebt_snat.c +1 -1
@@ -21,7 +21,7 @@ ebt_snat_tg(struct sk_buff *skb, const struct xt_action_param *par) {const struct ebt_nat_info *info = par->targinfo; -if (!skb_make_writable (skb,0 )) +if (skb_ensure_writable (skb,ETH_ALEN *2 ))return EBT_DROP ;ether_addr_copy (eth_hdr (skb)->h_source, info->mac);
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 2/8 netfilter: ipvs: prefer skb_ensure_writable
In reply to Florian WestphalIt does the same thing, use it instead so we can remove skb_make_writable.
--- net/netfilter/ipvs/ip_vs_app.c | 4 ++-- net/netfilter/ipvs/ip_vs_core.c | 4 ++-- net/netfilter/ipvs/ip_vs_ftp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_sctp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_tcp.c | 4 ++-- net/netfilter/ipvs/ip_vs_proto_udp.c | 4 ++-- net/netfilter/ipvs/ip_vs_xmit.c | 12 ++++++------ 7 files changed, 18 insertions(+), 18 deletions(-)
net/netfilter/ipvs/ip_vs_app.c +2 -2
@@ -363,7 +363,7 @@ static inline int app_tcp_pkt_out(struct ip_vs_conn *cp, struct sk_buff *skb,struct tcphdr *th;__u32 seq; -if (!skb_make_writable (skb, tcp_offset +sizeof (*th))) +if (skb_ensure_writable (skb, tcp_offset +sizeof (*th)))return 0 ; th = (struct tcphdr *)(skb_network_header (skb) + tcp_offset);
@@ -440,7 +440,7 @@ static inline int app_tcp_pkt_in(struct ip_vs_conn *cp, struct sk_buff *skb,struct tcphdr *th;__u32 seq; -if (!skb_make_writable (skb, tcp_offset +sizeof (*th))) +if (skb_ensure_writable (skb, tcp_offset +sizeof (*th)))return 0 ; th = (struct tcphdr *)(skb_network_header (skb) + tcp_offset);
net/netfilter/ipvs/ip_vs_core.c +2 -2
@@ -897,7 +897,7 @@ static int handle_response_icmp(int af, struct sk_buff *skb,if (IPPROTO_TCP == protocol ||IPPROTO_UDP == protocol ||IPPROTO_SCTP == protocol) offset +=2 *sizeof (__u16); -if (!skb_make_writable (skb, offset)) +if (skb_ensure_writable (skb, offset)) goto out;#ifdef CONFIG_IP_VS_IPV6
@@ -1287,7 +1287,7 @@ handle_response(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,IP_VS_DBG_PKT (11 , af, pp, skb, iph->off,"Outgoing packet" ); -if (!skb_make_writable (skb, iph->len)) +if (skb_ensure_writable (skb, iph->len)) goto drop;/* mangle the packet */
net/netfilter/ipvs/ip_vs_ftp.c +2 -2
@@ -273,7 +273,7 @@ static int ip_vs_ftp_out(struct ip_vs_app *app, struct ip_vs_conn *cp,return 1 ;/* Linear packets are much easier to deal with. */ -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb, skb->len))return 0 ;if (cp->app_data == (void *)IP_VS_FTP_PASV ) {
@@ -439,7 +439,7 @@ static int ip_vs_ftp_in(struct ip_vs_app *app, struct ip_vs_conn *cp,return 1 ;/* Linear packets are much easier to deal with. */ -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb, skb->len))return 0 ; data = data_start =ip_vs_ftp_data_ptr (skb, ipvsh);
net/netfilter/ipvs/ip_vs_proto_sctp.c +2 -2
@@ -101,7 +101,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,#endif /* csum_check requires unshared skb */ -if (!skb_make_writable (skb, sctphoff +sizeof (*sctph))) +if (skb_ensure_writable (skb, sctphoff +sizeof (*sctph)))return 0 ;if (unlikely (cp->app !=NULL )) {
@@ -148,7 +148,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,#endif /* csum_check requires unshared skb */ -if (!skb_make_writable (skb, sctphoff +sizeof (*sctph))) +if (skb_ensure_writable (skb, sctphoff +sizeof (*sctph)))return 0 ;if (unlikely (cp->app !=NULL )) {
net/netfilter/ipvs/ip_vs_proto_tcp.c +2 -2
@@ -163,7 +163,7 @@ tcp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, oldlen = skb->len - tcphoff;/* csum_check requires unshared skb */ -if (!skb_make_writable (skb, tcphoff+sizeof (*tcph))) +if (skb_ensure_writable (skb, tcphoff +sizeof (*tcph)))return 0 ;if (unlikely (cp->app !=NULL )) {
@@ -241,7 +241,7 @@ tcp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, oldlen = skb->len - tcphoff;/* csum_check requires unshared skb */ -if (!skb_make_writable (skb, tcphoff+sizeof (*tcph))) +if (skb_ensure_writable (skb, tcphoff +sizeof (*tcph)))return 0 ;if (unlikely (cp->app !=NULL )) {
net/netfilter/ipvs/ip_vs_proto_udp.c +2 -2
@@ -153,7 +153,7 @@ udp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, oldlen = skb->len - udphoff;/* csum_check requires unshared skb */ -if (!skb_make_writable (skb, udphoff+sizeof (*udph))) +if (skb_ensure_writable (skb, udphoff +sizeof (*udph)))return 0 ;if (unlikely (cp->app !=NULL )) {
@@ -236,7 +236,7 @@ udp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp, oldlen = skb->len - udphoff;/* csum_check requires unshared skb */ -if (!skb_make_writable (skb, udphoff+sizeof (*udph))) +if (skb_ensure_writable (skb, udphoff +sizeof (*udph)))return 0 ;if (unlikely (cp->app !=NULL )) {
net/netfilter/ipvs/ip_vs_xmit.c +6 -6
@@ -279,7 +279,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, }/* don't propagate ttl change to cloned packets */ -if (!skb_make_writable (skb,sizeof (struct ipv6hdr ))) +if (skb_ensure_writable (skb,sizeof (struct ipv6hdr )))return false;ipv6_hdr (skb)->hop_limit--;
@@ -294,7 +294,7 @@ static inline bool decrement_ttl(struct netns_ipvs *ipvs, }/* don't propagate ttl change to cloned packets */ -if (!skb_make_writable (skb,sizeof (struct iphdr ))) +if (skb_ensure_writable (skb,sizeof (struct iphdr )))return false;/* Decrease ttl */
@@ -796,7 +796,7 @@ ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, }/* copy-on-write the packet before mangling it */ -if (!skb_make_writable (skb,sizeof (struct iphdr ))) +if (skb_ensure_writable (skb,sizeof (struct iphdr ))) goto tx_error;if (skb_cow (skb, rt->dst.dev->hard_header_len))
@@ -885,7 +885,7 @@ ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, }/* copy-on-write the packet before mangling it */ -if (!skb_make_writable (skb,sizeof (struct ipv6hdr ))) +if (skb_ensure_writable (skb,sizeof (struct ipv6hdr ))) goto tx_error;if (skb_cow (skb, rt->dst.dev->hard_header_len))
@@ -1404,7 +1404,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp, }/* copy-on-write the packet before mangling it */ -if (!skb_make_writable (skb, offset)) +if (skb_ensure_writable (skb, offset)) goto tx_error;if (skb_cow (skb, rt->dst.dev->hard_header_len))
@@ -1493,7 +1493,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp, }/* copy-on-write the packet before mangling it */ -if (!skb_make_writable (skb, offset)) +if (skb_ensure_writable (skb, offset)) goto tx_error;if (skb_cow (skb, rt->dst.dev->hard_header_len))
Signature · 1 line
2.21.0
Re: [PATCH nf-next 2/8] netfilter: ipvs: prefer skb_ensure_writable
Quoted 3 lines · Florian Westphal
It does the same thing, use it instead so we can remove
skb_make_writable.Signed-off-by Florian Westphal <[email protected]>
Florian Westphal
maintainerPATCH 3/8 netfilter: conntrack, nat: prefer skb_ensure_writable
In reply to Florian Westphallike previous patches -- convert conntrack to use the core helper.
--- net/netfilter/nf_conntrack_proto_sctp.c | 2 +- net/netfilter/nf_conntrack_seqadj.c | 4 ++-- net/netfilter/nf_nat_helper.c | 4 ++-- net/netfilter/nf_nat_proto.c | 24 ++++++++++++------------ 4 files changed, 17 insertions(+), 17 deletions(-)
net/netfilter/nf_conntrack_proto_sctp.c +1 -1
@@ -339,7 +339,7 @@ static bool sctp_error(struct sk_buff *skb,if (state->hook ==NF_INET_PRE_ROUTING && state->net->ct.sysctl_checksum && skb->ip_summed ==CHECKSUM_NONE ) { -if (!skb_make_writable (skb, dataoff +sizeof (struct sctphdr ))) { +if (skb_ensure_writable (skb, dataoff +sizeof (*sh))) { logmsg ="nf_ct_sctp: failed to read header " ; goto out_invalid; }
net/netfilter/nf_conntrack_seqadj.c +2 -2
@@ -125,7 +125,7 @@ static unsigned int nf_ct_sack_adjust(struct sk_buff *skb, optoff = protoff +sizeof (struct tcphdr ); optend = protoff + tcph->doff *4 ; -if (!skb_make_writable (skb, optend)) +if (skb_ensure_writable (skb, optend))return 0 ; tcph = (void *)skb->data + protoff;
@@ -175,7 +175,7 @@ int nf_ct_seq_adjust(struct sk_buff *skb, this_way = &seqadj->seq[dir]; other_way = &seqadj->seq[!dir]; -if (!skb_make_writable (skb, protoff +sizeof (*tcph))) +if (skb_ensure_writable (skb, protoff +sizeof (*tcph)))return 0 ; tcph = (void *)skb->data + protoff;
net/netfilter/nf_nat_helper.c +2 -2
@@ -98,7 +98,7 @@ bool __nf_nat_mangle_tcp_packet(struct sk_buff *skb,struct tcphdr *tcph;int oldlen, datalen; -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb, skb->len))return false; if (rep_len > match_len &&
@@ -148,7 +148,7 @@ nf_nat_mangle_udp_packet(struct sk_buff *skb,struct udphdr *udph;int datalen, oldlen; -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb, skb->len))return false; if (rep_len > match_len &&
net/netfilter/nf_nat_proto.c +12 -12
@@ -73,7 +73,7 @@ static bool udp_manip_pkt(struct sk_buff *skb,struct udphdr *hdr;bool do_csum; -if (!skb_make_writable (skb, hdroff +sizeof (*hdr))) +if (skb_ensure_writable (skb, hdroff +sizeof (*hdr)))return false; hdr = (struct udphdr *)(skb->data + hdroff);
@@ -91,7 +91,7 @@ static bool udplite_manip_pkt(struct sk_buff *skb,#ifdef CONFIG_NF_CT_PROTO_UDPLITE struct udphdr *hdr; -if (!skb_make_writable (skb, hdroff +sizeof (*hdr))) +if (skb_ensure_writable (skb, hdroff +sizeof (*hdr)))return false; hdr = (struct udphdr *)(skb->data + hdroff);
@@ -117,7 +117,7 @@ sctp_manip_pkt(struct sk_buff *skb,if (skb->len >= hdroff +sizeof (*hdr)) hdrsize =sizeof (*hdr); -if (!skb_make_writable (skb, hdroff + hdrsize)) +if (skb_ensure_writable (skb, hdroff + hdrsize))return false; hdr = (struct sctphdr *)(skb->data + hdroff);
@@ -158,7 +158,7 @@ tcp_manip_pkt(struct sk_buff *skb,if (skb->len >= hdroff +sizeof (struct tcphdr )) hdrsize =sizeof (struct tcphdr ); -if (!skb_make_writable (skb, hdroff + hdrsize)) +if (skb_ensure_writable (skb, hdroff + hdrsize))return false; hdr = (struct tcphdr *)(skb->data + hdroff);
@@ -198,7 +198,7 @@ dccp_manip_pkt(struct sk_buff *skb,if (skb->len >= hdroff +sizeof (struct dccp_hdr )) hdrsize =sizeof (struct dccp_hdr ); -if (!skb_make_writable (skb, hdroff + hdrsize)) +if (skb_ensure_writable (skb, hdroff + hdrsize))return false; hdr = (struct dccp_hdr *)(skb->data + hdroff);
@@ -232,7 +232,7 @@ icmp_manip_pkt(struct sk_buff *skb, {struct icmphdr *hdr; -if (!skb_make_writable (skb, hdroff +sizeof (*hdr))) +if (skb_ensure_writable (skb, hdroff +sizeof (*hdr)))return false; hdr = (struct icmphdr *)(skb->data + hdroff);
@@ -250,7 +250,7 @@ icmpv6_manip_pkt(struct sk_buff *skb, {struct icmp6hdr *hdr; -if (!skb_make_writable (skb, hdroff +sizeof (*hdr))) +if (skb_ensure_writable (skb, hdroff +sizeof (*hdr)))return false; hdr = (struct icmp6hdr *)(skb->data + hdroff);
@@ -278,7 +278,7 @@ gre_manip_pkt(struct sk_buff *skb,/* pgreh includes two optional 32bit fields which are not required * to be there. That's where the magic '8' comes from */ -if (!skb_make_writable (skb, hdroff +sizeof (*pgreh) -8 )) +if (skb_ensure_writable (skb, hdroff +sizeof (*pgreh) -8 ))return false; greh = (void *)skb->data + hdroff;
@@ -350,7 +350,7 @@ static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb,struct iphdr *iph;unsigned int hdroff; -if (!skb_make_writable (skb, iphdroff +sizeof (*iph))) +if (skb_ensure_writable (skb, iphdroff +sizeof (*iph)))return false; iph = (void *)skb->data + iphdroff;
@@ -381,7 +381,7 @@ static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb,int hdroff;u8 nexthdr; -if (!skb_make_writable (skb, iphdroff +sizeof (*ipv6h))) +if (skb_ensure_writable (skb, iphdroff +sizeof (*ipv6h)))return false; ipv6h = (void *)skb->data + iphdroff;
@@ -565,7 +565,7 @@ int nf_nat_icmp_reply_translation(struct sk_buff *skb,WARN_ON (ctinfo !=IP_CT_RELATED && ctinfo !=IP_CT_RELATED_REPLY ); -if (!skb_make_writable (skb, hdrlen +sizeof (*inside))) +if (skb_ensure_writable (skb, hdrlen +sizeof (*inside)))return 0 ;if (nf_ip_checksum (skb, hooknum, hdrlen,0 ))return 0 ;
@@ -787,7 +787,7 @@ int nf_nat_icmpv6_reply_translation(struct sk_buff *skb,WARN_ON (ctinfo !=IP_CT_RELATED && ctinfo !=IP_CT_RELATED_REPLY ); -if (!skb_make_writable (skb, hdrlen +sizeof (*inside))) +if (skb_ensure_writable (skb, hdrlen +sizeof (*inside)))return 0 ;if (nf_ip6_checksum (skb, hooknum, hdrlen,IPPROTO_ICMPV6 ))return 0 ;
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 4/8 netfilter: ipv4: prefer skb_ensure_writable
In reply to Florian Westphal.. so skb_make_writable can be removed soon.
--- net/ipv4/netfilter/arpt_mangle.c | 2 +- net/ipv4/netfilter/ipt_ECN.c | 4 ++-- net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_snmp_basic_main.c | 2 +- net/netfilter/nf_nat_sip.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-)
net/ipv4/netfilter/arpt_mangle.c +1 -1
@@ -16,7 +16,7 @@ target(struct sk_buff *skb, const struct xt_action_param *par)unsigned char *arpptr;int pln, hln; -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb, skb->len))return NF_DROP ; arp =arp_hdr (skb);
net/ipv4/netfilter/ipt_ECN.c +2 -2
@@ -32,7 +32,7 @@ set_ect_ip(struct sk_buff *skb, const struct ipt_ECN_info *einfo)if ((iph->tos &IPT_ECN_IP_MASK ) != (einfo->ip_ect &IPT_ECN_IP_MASK )) {__u8 oldtos; -if (!skb_make_writable (skb,sizeof (struct iphdr ))) +if (skb_ensure_writable (skb,sizeof (struct iphdr )))return false; iph =ip_hdr (skb); oldtos = iph->tos;
@@ -61,7 +61,7 @@ set_ect_tcp(struct sk_buff *skb, const struct ipt_ECN_info *einfo) tcph->cwr == einfo->proto.tcp.cwr))return true; -if (!skb_make_writable (skb,ip_hdrlen (skb) +sizeof (*tcph))) +if (skb_ensure_writable (skb,ip_hdrlen (skb) +sizeof (*tcph)))return false; tcph = (void *)ip_hdr (skb) +ip_hdrlen (skb);
net/ipv4/netfilter/nf_nat_h323.c +1 -1
@@ -59,7 +59,7 @@ static int set_addr(struct sk_buff *skb, unsigned int protoff,net_notice_ratelimited ("nf_nat_h323: nf_nat_mangle_udp_packet error\n" );return -1 ; } -/* nf_nat_mangle_udp_packet uses skb_make_writable() to copy +/* nf_nat_mangle_udp_packet uses skb_ensure_writable() to copy * or pull everything in a linear buffer, so we can safely * use the skb pointers now */ *data = skb->data +ip_hdrlen (skb) +sizeof (struct udphdr );
net/ipv4/netfilter/nf_nat_snmp_basic_main.c +1 -1
@@ -196,7 +196,7 @@ static int help(struct sk_buff *skb, unsigned int protoff,return NF_DROP ; } -if (!skb_make_writable (skb, skb->len)) { +if (skb_ensure_writable (skb, skb->len)) {nf_ct_helper_log (skb, ct,"cannot mangle packet" );return NF_DROP ; }
net/netfilter/nf_nat_sip.c +1 -1
@@ -285,7 +285,7 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,if (dir ==IP_CT_DIR_REPLY && ct_sip_info->forced_dport) {struct udphdr *uh; -if (!skb_make_writable (skb, skb->len)) { +if (skb_ensure_writable (skb, skb->len)) {nf_ct_helper_log (skb, ct,"cannot mangle packet" );return NF_DROP ; }
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 5/8 netfilter: nf_tables: prefer skb_ensure_writable
In reply to Florian Westphal.. so skb_make_writable can be removed.
--- net/netfilter/nft_exthdr.c | 3 ++- net/netfilter/nft_payload.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
net/netfilter/nft_exthdr.c +2 -1
@@ -156,7 +156,8 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,if (i + optl > tcphdr_len || priv->len + priv->offset > optl)return ; -if (!skb_make_writable (pkt->skb, pkt->xt.thoff + i + priv->len)) +if (skb_ensure_writable (pkt->skb, + pkt->xt.thoff + i + priv->len))return ; tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff,
net/netfilter/nft_payload.c +3 -3
@@ -243,7 +243,7 @@ static int nft_payload_l4csum_update(const struct nft_pktinfo *pkt, tsum)); } -if (!skb_make_writable (skb, l4csum_offset +sizeof (sum)) || +if (skb_ensure_writable (skb, l4csum_offset +sizeof (sum)) ||skb_store_bits (skb, l4csum_offset, &sum,sizeof (sum)) <0 )return -1 ;
@@ -259,7 +259,7 @@ static int nft_payload_csum_inet(struct sk_buff *skb, const u32 *src,return -1 ;nft_csum_replace (&sum, fsum, tsum); -if (!skb_make_writable (skb, csum_offset +sizeof (sum)) || +if (skb_ensure_writable (skb, csum_offset +sizeof (sum)) ||skb_store_bits (skb, csum_offset, &sum,sizeof (sum)) <0 )return -1 ;
@@ -312,7 +312,7 @@ static void nft_payload_set_eval(const struct nft_expr *expr, goto err; } -if (!skb_make_writable (skb,max (offset + priv->len,0 )) || +if (skb_ensure_writable (skb,max (offset + priv->len,0 )) ||skb_store_bits (skb, offset, src, priv->len) <0 ) goto err;
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 6/8 netfilter: xt_HL: prefer skb_ensure_writable
In reply to Florian WestphalAlso, make the argument to be only the needed size of the header we're altering, no need to pull in the full packet into linear area.
--- net/netfilter/xt_HL.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/xt_HL.c +2 -2
@@ -32,7 +32,7 @@ ttl_tg(struct sk_buff *skb, const struct xt_action_param *par)const struct ipt_TTL_info *info = par->targinfo;int new_ttl; -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb,sizeof (*iph)))return NF_DROP ; iph =ip_hdr (skb);
@@ -72,7 +72,7 @@ hl_tg6(struct sk_buff *skb, const struct xt_action_param *par)const struct ip6t_HL_info *info = par->targinfo;int new_hl; -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb,sizeof (*ip6h)))return NF_DROP ; ip6h =ipv6_hdr (skb);
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 7/8 netfilter: tcpmss, optstrip: prefer skb_ensure_writable
In reply to Florian WestphalThis also changes optstrip to only make the tcp header writeable rather than the entire packet.
--- net/netfilter/xt_TCPMSS.c | 2 +- net/netfilter/xt_TCPOPTSTRIP.c | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-)
net/netfilter/xt_TCPMSS.c +1 -1
@@ -89,7 +89,7 @@ tcpmss_mangle_packet(struct sk_buff *skb,if (par->fragoff !=0 )return 0 ; -if (!skb_make_writable (skb, skb->len)) +if (skb_ensure_writable (skb, skb->len))return -1 ; len = skb->len - tcphoff;
net/netfilter/xt_TCPOPTSTRIP.c +13 -15
@@ -31,33 +31,33 @@ static inline unsigned int optlen(const u_int8_t *opt, unsigned int offset)static unsigned int tcpoptstrip_mangle_packet (struct sk_buff *skb,const struct xt_action_param *par, -unsigned int tcphoff,unsigned int minlen) +unsigned int tcphoff) {const struct xt_tcpoptstrip_target_info *info = par->targinfo; +struct tcphdr *tcph, _th;unsigned int optl, i, j; -struct tcphdr *tcph;u_int16_t n, o;u_int8_t *opt; -int len, tcp_hdrlen; +int tcp_hdrlen;/* This is a fragment, no TCP header is available */ if (par->fragoff !=0 )return XT_CONTINUE ; -if (!skb_make_writable (skb, skb->len)) + tcph =skb_header_pointer (skb, tcphoff,sizeof (_th), &_th); +if (!tcph)return NF_DROP ; - len = skb->len - tcphoff; -if (len < (int )sizeof (struct tcphdr )) -return NF_DROP ; - - tcph = (struct tcphdr *)(skb_network_header (skb) + tcphoff); tcp_hdrlen = tcph->doff *4 ; +if (tcp_hdrlen <sizeof (struct tcphdr )) +return NF_DROP ; -if (len < tcp_hdrlen) +if (skb_ensure_writable (skb, tcphoff + tcp_hdrlen))return NF_DROP ; - opt = (u_int8_t *)tcph; +/* must reload tcph, might have been moved */ + tcph = (struct tcphdr *)(skb_network_header (skb) + tcphoff); + opt = (u8 *)tcph;/* * Walk through all TCP options - if we find some option to remove,
@@ -91,8 +91,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,static unsigned int tcpoptstrip_tg4 (struct sk_buff *skb,const struct xt_action_param *par) { -return tcpoptstrip_mangle_packet (skb, par,ip_hdrlen (skb), -sizeof (struct iphdr ) +sizeof (struct tcphdr )); +return tcpoptstrip_mangle_packet (skb, par,ip_hdrlen (skb)); }#if IS_ENABLED (CONFIG_IP6_NF_MANGLE )
@@ -109,8 +108,7 @@ tcpoptstrip_tg6(struct sk_buff *skb, const struct xt_action_param *par)if (tcphoff <0 )return NF_DROP ; -return tcpoptstrip_mangle_packet (skb, par, tcphoff, - sizeof(*ipv6h) + sizeof(struct tcphdr)); + return tcpoptstrip_mangle_packet(skb, par, tcphoff); }#endif
Signature · 1 line
2.21.0
Florian Westphal
maintainerPATCH 8/8 netfilter: replace skb_make_writable with skb_ensure_writable
In reply to Florian WestphalThis converts all remaining users and then removes skb_make_writable.
--- include/linux/netfilter.h | 5 ----- net/netfilter/core.c | 22 ---------------------- net/netfilter/nf_synproxy_core.c | 2 +- net/netfilter/nfnetlink_queue.c | 2 +- net/netfilter/xt_DSCP.c | 8 ++++---- 5 files changed, 6 insertions(+), 33 deletions(-)
include/linux/netfilter.h +0 -5
@@ -336,11 +336,6 @@ int compat_nf_getsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt, int *len);#endif -/* Call this before modifying an existing packet: ensures it is -modifiable and linear to the point you care about (writable_len). -Returns true or false. */ -int skb_make_writable (struct sk_buff *skb,unsigned int writable_len); -struct flowi ;struct nf_queue_entry ;
net/netfilter/core.c +0 -22
@@ -536,28 +536,6 @@ int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state, }EXPORT_SYMBOL (nf_hook_slow); - -int skb_make_writable (struct sk_buff *skb,unsigned int writable_len) -{ -if (writable_len > skb->len) -return 0 ; - -/* Not exclusive use of packet? Must copy. */ -if (!skb_cloned (skb)) { -if (writable_len <=skb_headlen (skb)) -return 1 ; - }else if (skb_clone_writable (skb, writable_len)) -return 1 ; - -if (writable_len <=skb_headlen (skb)) - writable_len =0 ; -else - writable_len -=skb_headlen (skb); - -return !!__pskb_pull_tail (skb, writable_len); -} -EXPORT_SYMBOL (skb_make_writable); -/* This needs to be compiled in any case to avoid dependencies between the * nfnetlink_queue code and nf_conntrack. */
net/netfilter/nf_synproxy_core.c +1 -1
@@ -196,7 +196,7 @@ unsigned int synproxy_tstamp_adjust(struct sk_buff *skb, optoff = protoff +sizeof (struct tcphdr ); optend = protoff + th->doff *4 ; -if (!skb_make_writable (skb, optend)) +if (skb_ensure_writable (skb, optend))return 0 ;while (optoff < optend) {
net/netfilter/nfnetlink_queue.c +1 -1
@@ -863,7 +863,7 @@ nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff) }skb_put (e->skb, diff); } -if (!skb_make_writable (e->skb, data_len)) +if (skb_ensure_writable (e->skb, data_len))return -ENOMEM ;skb_copy_to_linear_data (e->skb, data, data_len); e->skb->ip_summed =CHECKSUM_NONE ;
net/netfilter/xt_DSCP.c +4 -4
@@ -34,7 +34,7 @@ dscp_tg(struct sk_buff *skb, const struct xt_action_param *par)u_int8_t dscp =ipv4_get_dsfield (ip_hdr (skb)) >>XT_DSCP_SHIFT ;if (dscp != dinfo->dscp) { -if (!skb_make_writable (skb,sizeof (struct iphdr ))) +if (skb_ensure_writable (skb,sizeof (struct iphdr )))return NF_DROP ; ipv4_change_dsfield(ip_hdr(skb),
@@ -52,7 +52,7 @@ dscp_tg6(struct sk_buff *skb, const struct xt_action_param *par)u_int8_t dscp =ipv6_get_dsfield (ipv6_hdr (skb)) >>XT_DSCP_SHIFT ;if (dscp != dinfo->dscp) { -if (!skb_make_writable (skb,sizeof (struct ipv6hdr ))) +if (skb_ensure_writable (skb,sizeof (struct ipv6hdr )))return NF_DROP ; ipv6_change_dsfield(ipv6_hdr(skb),
@@ -82,7 +82,7 @@ tos_tg(struct sk_buff *skb, const struct xt_action_param *par) nv = (orig & ~info->tos_mask) ^ info->tos_value;if (orig != nv) { -if (!skb_make_writable (skb,sizeof (struct iphdr ))) +if (skb_ensure_writable (skb,sizeof (struct iphdr )))return NF_DROP ; iph =ip_hdr (skb);ipv4_change_dsfield (iph,0 , nv);
@@ -102,7 +102,7 @@ tos_tg6(struct sk_buff *skb, const struct xt_action_param *par) nv = (orig & ~info->tos_mask) ^ info->tos_value;if (orig != nv) { -if (!skb_make_writable (skb,sizeof (struct iphdr ))) +if (skb_ensure_writable (skb,sizeof (struct iphdr )))return NF_DROP ; iph =ipv6_hdr (skb);ipv6_change_dsfield (iph,0 , nv);
Signature · 1 line
2.21.0
Pablo Neira Ayuso
maintainerQuoted 2 lines · Florian Westphal
This series removes
skb_make_writable. All users are converted toskb_ensure_writable.
Series applied.