From: Greg KH <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
alan@lxorguk.ukuu.org.uk, Gao feng <gaofeng@cn.fujitsu.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [ 32/47] ipv6: fix incorrect ipsec fragment
Date: Thu, 07 Jun 2012 13:14:30 +0900 [thread overview]
Message-ID: <20120607041402.774327617@linuxfoundation.org> (raw)
In-Reply-To: <20120607041504.GA13819@kroah.com>
3.0-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao feng <gaofeng@cn.fujitsu.com>
[ Upstream commit 0c1833797a5a6ec23ea9261d979aa18078720b74 ]
Since commit ad0081e43a
"ipv6: Fragment locally generated tunnel-mode IPSec6 packets as needed"
the fragment of packets is incorrect.
because tunnel mode needs IPsec headers and trailer for all fragments,
while on transport mode it is sufficient to add the headers to the
first fragment and the trailer to the last.
so modify mtu and maxfraglen base on ipsec mode and if fragment is first
or last.
with my test,it work well(every fragment's size is the mtu)
and does not trigger slow fragment path.
Changes from v1:
though optimization, mtu_prev and maxfraglen_prev can be delete.
replace xfrm mode codes with dst_entry's new frag DST_XFRM_TUNNEL.
add fuction ip6_append_data_mtu to make codes clearer.
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/net/dst.h | 1
net/ipv6/ip6_output.c | 68 ++++++++++++++++++++++++++++++++++++-------------
net/xfrm/xfrm_policy.c | 3 ++
3 files changed, 54 insertions(+), 18 deletions(-)
--- a/include/net/dst.h
+++ b/include/net/dst.h
@@ -78,6 +78,7 @@ struct dst_entry {
#define DST_NOHASH 0x0008
#define DST_NOCACHE 0x0010
#define DST_NOCOUNT 0x0020
+#define DST_XFRM_TUNNEL 0x0100
union {
struct dst_entry *next;
struct rtable __rcu *rt_next;
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1194,6 +1194,29 @@ static inline struct ipv6_rt_hdr *ip6_rt
return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
}
+static void ip6_append_data_mtu(int *mtu,
+ int *maxfraglen,
+ unsigned int fragheaderlen,
+ struct sk_buff *skb,
+ struct rt6_info *rt)
+{
+ if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
+ if (skb == NULL) {
+ /* first fragment, reserve header_len */
+ *mtu = *mtu - rt->dst.header_len;
+
+ } else {
+ /*
+ * this fragment is not first, the headers
+ * space is regarded as data space.
+ */
+ *mtu = dst_mtu(rt->dst.path);
+ }
+ *maxfraglen = ((*mtu - fragheaderlen) & ~7)
+ + fragheaderlen - sizeof(struct frag_hdr);
+ }
+}
+
int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
int offset, int len, int odd, struct sk_buff *skb),
void *from, int length, int transhdrlen,
@@ -1203,7 +1226,7 @@ int ip6_append_data(struct sock *sk, int
struct inet_sock *inet = inet_sk(sk);
struct ipv6_pinfo *np = inet6_sk(sk);
struct inet_cork *cork;
- struct sk_buff *skb;
+ struct sk_buff *skb, *skb_prev = NULL;
unsigned int maxfraglen, fragheaderlen;
int exthdrlen;
int hh_len;
@@ -1260,8 +1283,12 @@ int ip6_append_data(struct sock *sk, int
inet->cork.fl.u.ip6 = *fl6;
np->cork.hop_limit = hlimit;
np->cork.tclass = tclass;
- mtu = np->pmtudisc == IPV6_PMTUDISC_PROBE ?
- rt->dst.dev->mtu : dst_mtu(rt->dst.path);
+ if (rt->dst.flags & DST_XFRM_TUNNEL)
+ mtu = np->pmtudisc == IPV6_PMTUDISC_PROBE ?
+ rt->dst.dev->mtu : dst_mtu(&rt->dst);
+ else
+ mtu = np->pmtudisc == IPV6_PMTUDISC_PROBE ?
+ rt->dst.dev->mtu : dst_mtu(rt->dst.path);
if (np->frag_size < mtu) {
if (np->frag_size)
mtu = np->frag_size;
@@ -1356,38 +1383,43 @@ int ip6_append_data(struct sock *sk, int
unsigned int fraglen;
unsigned int fraggap;
unsigned int alloclen;
- struct sk_buff *skb_prev;
alloc_new_skb:
- skb_prev = skb;
-
/* There's no room in the current skb */
- if (skb_prev)
- fraggap = skb_prev->len - maxfraglen;
+ if (skb)
+ fraggap = skb->len - maxfraglen;
else
fraggap = 0;
+ /* update mtu and maxfraglen if necessary */
+ if (skb == NULL || skb_prev == NULL)
+ ip6_append_data_mtu(&mtu, &maxfraglen,
+ fragheaderlen, skb, rt);
+
+ skb_prev = skb;
/*
* If remaining data exceeds the mtu,
* we know we need more fragment(s).
*/
datalen = length + fraggap;
- if (datalen > (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen)
- datalen = maxfraglen - fragheaderlen;
- fraglen = datalen + fragheaderlen;
+ if (datalen > (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen)
+ datalen = maxfraglen - fragheaderlen - rt->dst.trailer_len;
if ((flags & MSG_MORE) &&
!(rt->dst.dev->features&NETIF_F_SG))
alloclen = mtu;
else
alloclen = datalen + fragheaderlen;
- /*
- * The last fragment gets additional space at tail.
- * Note: we overallocate on fragments with MSG_MODE
- * because we have no idea if we're the last one.
- */
- if (datalen == length + fraggap)
- alloclen += rt->dst.trailer_len;
+ if (datalen != length + fraggap) {
+ /*
+ * this is not the last fragment, the trailer
+ * space is regarded as data space.
+ */
+ datalen += rt->dst.trailer_len;
+ }
+
+ alloclen += rt->dst.trailer_len;
+ fraglen = datalen + fragheaderlen;
/*
* We just reserve space for fragment header.
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -1917,6 +1917,9 @@ no_transform:
}
ok:
xfrm_pols_put(pols, drop_pols);
+ if (dst && dst->xfrm &&
+ dst->xfrm->props.mode == XFRM_MODE_TUNNEL)
+ dst->flags |= DST_XFRM_TUNNEL;
return dst;
nopol:
next prev parent reply other threads:[~2012-06-07 4:14 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-07 4:15 [ 00/47] 3.0.34-stable review Greg KH
2012-06-07 4:13 ` [ 01/47] SCSI: fix scsi_wait_scan Greg KH
2012-06-07 4:14 ` [ 02/47] SCSI: Fix dm-multipath starvation when scsi host is busy Greg KH
2012-06-07 4:14 ` [ 03/47] mm: consider all swapped back pages in used-once logic Greg KH
2012-06-07 4:14 ` [ 04/47] mm: pmd_read_atomic: fix 32bit PAE pmd walk vs pmd_populate SMP race condition Greg KH
2012-06-07 4:14 ` [ 05/47] iwlwifi: update BT traffic load states correctly Greg KH
2012-06-07 4:14 ` [ 06/47] cifs: fix oops while traversing open file list (try #4) Greg KH
2012-06-07 4:14 ` [ 07/47] PARISC: fix boot failure on 32-bit systems caused by branch stubs placed before .text Greg KH
2012-06-07 4:14 ` [ 08/47] PARISC: fix TLB fault path on PA2.0 narrow systems Greg KH
2012-06-07 4:14 ` [ 09/47] solos-pci: Fix DMA support Greg KH
2012-06-07 4:14 ` [ 10/47] mac80211: fix ADDBA declined after suspend with wowlan Greg KH
2012-06-07 4:14 ` [ 11/47] NFSv4: Map NFS4ERR_SHARE_DENIED into an EACCES error instead of EIO Greg KH
2012-06-07 4:14 ` [ 12/47] drm/radeon: fix XFX quirk Greg KH
2012-06-07 4:14 ` [ 13/47] drm/i915: properly handle interlaced bit for sdvo dtd conversion Greg KH
2012-06-07 4:14 ` [ 14/47] drm/i915: wait for a vblank to pass after tv detect Greg KH
2012-06-07 4:14 ` [ 15/47] Bluetooth: Add support for Broadcom BCM20702A0 Greg KH
2012-06-07 4:14 ` [ 16/47] Bluetooth: Add support for BCM20702A0 [0a5c:21e3] Greg KH
2012-06-07 4:14 ` [ 17/47] Bluetooth: btusb: Add vendor specific ID (0a5c 21f3) for BCM20702A0 Greg KH
2012-06-07 4:14 ` [ 18/47] Bluetooth: btusb: add support for BCM20702A0 [0a5c:21e6] Greg KH
2012-06-07 4:14 ` [ 19/47] Bluetooth: btusb: Add USB device ID "0a5c 21e8" Greg KH
2012-06-07 4:14 ` [ 20/47] Bluetooth: btusb: Add vendor specific ID (0489 e042) for BCM20702A0 Greg KH
2012-06-07 4:14 ` [ 21/47] Bluetooth: btusb: typo in Broadcom SoftSailing id Greg KH
2012-06-07 4:14 ` [ 22/47] Add Foxconn / Hon Hai IDs for btusb module Greg KH
2012-06-07 4:14 ` [ 23/47] Bluetooth: Add support for Foxconn/Hon Hai AR5BBU22 0489:E03C Greg KH
2012-06-07 4:14 ` [ 24/47] ALSA: usb-audio: fix rate_list memory leak Greg KH
2012-06-07 4:14 ` [ 25/47] vfs: umount_tree() might be called on subtree that had never made it Greg KH
2012-06-07 4:14 ` [ 26/47] mtd: nand: fix scan_read_raw_oob Greg KH
2012-06-07 4:14 ` [ 27/47] drm/radeon: properly program gart on rv740, juniper, cypress, barts, hemlock Greg KH
2012-06-07 4:14 ` [ 28/47] drm/radeon: fix HD6790, HD6570 backend programming Greg KH
2012-06-07 4:14 ` [ 29/47] drm/ttm: Fix spinlock imbalance Greg KH
2012-06-07 4:14 ` [ 30/47] ipv4: Do not use dead fib_info entries Greg KH
2012-06-07 4:14 ` [ 31/47] ipv4: fix the rcu race between free_fib_info and ip_route_output_slow Greg KH
2012-06-07 4:14 ` Greg KH [this message]
2012-06-07 4:14 ` [ 33/47] l2tp: fix oops in L2TP IP sockets for connect() AF_UNSPEC case Greg KH
2012-06-07 4:14 ` [ 34/47] pktgen: fix crash at module unload Greg KH
2012-06-07 4:14 ` [ 35/47] pktgen: fix module unload for good Greg KH
2012-06-07 4:14 ` [ 36/47] Revert "net: maintain namespace isolation between vlan and real device" Greg KH
2012-06-07 4:14 ` [ 37/47] sctp: check cached dst before using it Greg KH
2012-06-07 4:14 ` [ 38/47] skb: avoid unnecessary reallocations in __skb_cow Greg KH
2012-06-07 4:14 ` [ 39/47] xfrm: take net hdr len into account for esp payload size calculation Greg KH
2012-06-07 4:14 ` [ 40/47] ext4: force ro mount if ext4_setup_super() fails Greg KH
2012-06-07 4:14 ` [ 41/47] ext4: add missing save_error_info() to ext4_error() Greg KH
2012-06-07 4:14 ` [ 42/47] ext4: dont trash state flags in EXT4_IOC_SETFLAGS Greg KH
2012-06-07 4:14 ` [ 43/47] ext4: add ext4_mb_unload_buddy in the error path Greg KH
2012-06-07 4:14 ` [ 44/47] ext4: remove mb_groups before tearing down the buddy_cache Greg KH
2012-06-07 4:14 ` [ 45/47] drm/radeon/kms: add new BTC PCI ids Greg KH
2012-06-07 4:14 ` [ 46/47] ACPI battery: only refresh the sysfs files when pertinent information changes Greg KH
2012-06-07 4:14 ` [ 47/47] wl1251: fix oops on early interrupt Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120607041402.774327617@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@davemloft.net \
--cc=gaofeng@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).