Subject: linux 3.18.67 and patch-3.18.55-vs2.3.7.5.diff
From: Corey Wright <undefined@pobox.com>
Date: Sun, 27 Aug 2017 13:31:16 -0500
Sun, 27 Aug 2017 13:31:16 -0500
summary
-------

applying patch-3.18.55-vs2.3.7.5.diff to linux 3.18.67 results
in a number of failures which are resolved by the attached patches.

patch failures
--------------

```
patching file Makefile
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file Makefile.rej
...
patching file include/linux/pid.h
Hunk #1 FAILED at 8.
Hunk #2 succeeded at 172 (offset 2 lines).
1 out of 2 hunks FAILED -- saving rejects to file include/linux/pid.h.rej
...
patching file include/linux/sched.h
Hunk #1 succeeded at 1450 (offset 10 lines).
Hunk #2 succeeded at 1763 (offset 10 lines).
Hunk #3 succeeded at 1781 (offset 10 lines).
Hunk #4 FAILED at 1785.
1 out of 4 hunks FAILED -- saving rejects to file include/linux/sched.h.rej
...
patching file net/ipv6/tcp_ipv6.c
Hunk #2 FAILED at 165.
1 out of 2 hunks FAILED -- saving rejects to file net/ipv6/tcp_ipv6.c.rej
```

* Makefile
  * fails on any version other than original version (ie 3.18.55)
* net/ipv6/tcp_ipv6.c
  * fails due to upstream change introduced in 3.18.58
  * addressed by attached patch-3.18.55-58-vs2.3.7.5.diff
* include/linux/pid.h
* include/linux/sched.h
  * fails due to upstream change introduced in 3.18.67
  * addressed by attached patch-3.18.55-67-vs2.3.7.5.diff

attached patches
----------------

* patch-3.18.55-58-vs2.3.7.5.diff
  * same patch as i previously sent here, but with more comments
  * same change as herbert made in patch-4.1.42-vs2.3.8.6.diff
* patch-3.18.55-67-vs2.3.7.5.diff

instructions
------------

* acquire linux 3.18.67 source
* apply patch-3.18.55-vs2.3.7.5.diff
* apply patch-3.18.55-58-vs2.3.7.5.diff
* apply patch-3.18.55-67-vs2.3.7.5.diff

testing
-------

* testme.sh
* testfs.sh
* start, ssh into, update, and stop guest 
* start, ssh into, update, and stop lxc container
* deployed for 36 hours

disclaimer
----------

it works for me, but lacks independent review and testing.

corey
--
undefined@pobox.com


https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?h=linux-3.18.y&id=a360eb6f74b999a7546f2542c0d6483fdbb73461

Give preference to Linux-Vserver patch over upstream IPv4-mapped-to-IPv6 fix.

The upstream fix is only relevant for IPv6 loopback (ie mapping destination of
:: to ::ffff:127.0.0.1 or ::1 based on whether source is IPv4-mapped IPv6
address), which Linux-Vserver doesn't specifically support (eg
VSERVER_AUTO_LBACK is IPv4-only).

See https://lwn.net/Articles/688462/, section "Address mapping", for more
information on IPv4-mapped IPv6.

If socket has a Linux-Vserver network context, then handle as previous,
otherwise handle as per the upstream fix.

diff -urNp a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
--- a/net/ipv6/tcp_ipv6.c	2017-07-21 09:49:54.073001106 -0500
+++ b/net/ipv6/tcp_ipv6.c	2017-07-21 09:55:43.805534787 -0500
@@ -166,11 +166,17 @@ static int tcp_v6_connect(struct sock *s
 	 */
 
 	if (ipv6_addr_any(&usin->sin6_addr)) {
-		if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
-			ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
-					       &usin->sin6_addr);
+		struct nx_info *nxi =  sk->sk_nx_info;
+
+		if (nxi && nx_info_has_v6(nxi))
+			/* FIXME: remap lback? */
+			usin->sin6_addr = nxi->v6.ip;
 		else
-			usin->sin6_addr = in6addr_loopback;
+			if (ipv6_addr_v4mapped(&sk->sk_v6_rcv_saddr))
+				ipv6_addr_set_v4mapped(htonl(INADDR_LOOPBACK),
+						       &usin->sin6_addr);
+			else
+				usin->sin6_addr = in6addr_loopback;
 	}
 
 	addr_type = ipv6_addr_type(&usin->sin6_addr);


https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/commit/?h=linux-3.18.y&id=63407c4d1f9f64015974206e9bf40b318fdd74ee

1. Adjust to upstream adding an enum value to the end of the enum definition
   (where we also add one).

2. Continue to wrap the body of task_tgid_vnr() with vx_map_tgid(), similar to
   task_pid_vnr().

diff -urNpd linux-3.18.67-vs2.3.7.5~/include/linux/pid.h linux-3.18.67-vs2.3.7.5/include/linux/pid.h
--- linux-3.18.67-vs2.3.7.5~/include/linux/pid.h	2017-08-24 21:31:56.212586227 -0500
+++ linux-3.18.67-vs2.3.7.5/include/linux/pid.h	2017-08-25 10:02:42.851831581 -0500
@@ -10,7 +10,8 @@ enum pid_type
 	PIDTYPE_SID,
 	PIDTYPE_MAX,
 	/* only valid to __task_pid_nr_ns() */
-	__PIDTYPE_TGID
+	__PIDTYPE_TGID,
+	PIDTYPE_REALPID
 };
 
 /*
diff -urNpd linux-3.18.67-vs2.3.7.5~/include/linux/sched.h linux-3.18.67-vs2.3.7.5/include/linux/sched.h
--- linux-3.18.67-vs2.3.7.5~/include/linux/sched.h	2017-08-24 21:31:56.212586227 -0500
+++ linux-3.18.67-vs2.3.7.5/include/linux/sched.h	2017-08-25 10:13:28.925812909 -0500
@@ -1824,7 +1824,7 @@ static inline pid_t task_tgid_nr_ns(stru
 
 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
 {
-	return __task_pid_nr_ns(tsk, __PIDTYPE_TGID, NULL);
+	return vx_map_tgid(__task_pid_nr_ns(tsk, __PIDTYPE_TGID, NULL));
 }
 
 static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace
*ns)