[PATCH -next 18/22] net: socket: add __compat_sys_recvfrom() helper; remove in-kernel call to compat syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __compat_sys_recvfrom() allows us to avoid
the internal calls to the compat_sys_recvfrom() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 net/compat.c | 23 ---
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/net/compat.c b/net/compat.c
index 9e0d030063ad..513adc8d0e0f 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -753,18 +753,25 @@ COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct 
compat_msghdr __user *, msg, uns
 flags | MSG_CMSG_COMPAT, false);
 }
 
+static inline long __compat_sys_recvfrom(int fd, void __user *buf,
+compat_size_t len, unsigned int flags,
+struct sockaddr __user *addr,
+int __user *addrlen)
+{
+   return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr,
+ addrlen);
+}
+
 COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, 
unsigned int, flags)
 {
-   return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, NULL,
- NULL);
+   return __compat_sys_recvfrom(fd, buf, len, flags, NULL, NULL);
 }
 
 COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, 
len,
   unsigned int, flags, struct sockaddr __user *, addr,
   int __user *, addrlen)
 {
-   return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr,
- addrlen);
+   return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen);
 }
 
 COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
@@ -845,11 +852,13 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user 
*, args)
   compat_ptr(a[4]), a[5]);
break;
case SYS_RECV:
-   ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]);
+   ret = __compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
+   NULL, NULL);
break;
case SYS_RECVFROM:
-   ret = compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
- compat_ptr(a[4]), compat_ptr(a[5]));
+   ret = __compat_sys_recvfrom(a0, compat_ptr(a1), a[2], a[3],
+   compat_ptr(a[4]),
+   compat_ptr(a[5]));
break;
case SYS_SHUTDOWN:
ret = __sys_shutdown(a0, a1);
-- 
2.16.2



[PATCH -next 01/22] net: socket: add __sys_recvfrom() helper; remove in-kernel call to syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __sys_recvfrom() allows us to avoid the
internal calls to the sys_recvfrom() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 include/linux/socket.h |  6 ++
 net/compat.c   |  3 ++-
 net/socket.c   | 21 +
 3 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 9286a5a8c60c..40cc93b91628 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -353,4 +353,10 @@ extern int __sys_recvmmsg(int fd, struct mmsghdr __user 
*mmsg, unsigned int vlen
  unsigned int flags, struct timespec *timeout);
 extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg,
  unsigned int vlen, unsigned int flags);
+
+/* helpers which do the actual work for syscalls */
+extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
+ unsigned int flags, struct sockaddr __user *addr,
+ int __user *addr_len);
+
 #endif /* _LINUX_SOCKET_H */
diff --git a/net/compat.c b/net/compat.c
index 22381719718c..2d8186c277b2 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -760,7 +760,8 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, 
buf, compat_size_t, len
   unsigned int, flags, struct sockaddr __user *, addr,
   int __user *, addrlen)
 {
-   return sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr, 
addrlen);
+   return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, addr,
+ addrlen);
 }
 
 COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
diff --git a/net/socket.c b/net/socket.c
index a93c99b518ca..712d99d8680f 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1767,10 +1767,8 @@ SYSCALL_DEFINE4(send, int, fd, void __user *, buff, 
size_t, len,
  * sender. We verify the buffers are writable and if needed move the
  * sender address from kernel to user space.
  */
-
-SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
-   unsigned int, flags, struct sockaddr __user *, addr,
-   int __user *, addr_len)
+int __sys_recvfrom(int fd, void __user *ubuf, size_t size, unsigned int flags,
+  struct sockaddr __user *addr, int __user *addr_len)
 {
struct socket *sock;
struct iovec iov;
@@ -1810,6 +1808,13 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, 
size_t, size,
return err;
 }
 
+SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
+   unsigned int, flags, struct sockaddr __user *, addr,
+   int __user *, addr_len)
+{
+   return __sys_recvfrom(fd, ubuf, size, flags, addr, addr_len);
+}
+
 /*
  * Receive a datagram from a socket.
  */
@@ -1817,7 +1822,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, 
size_t, size,
 SYSCALL_DEFINE4(recv, int, fd, void __user *, ubuf, size_t, size,
unsigned int, flags)
 {
-   return sys_recvfrom(fd, ubuf, size, flags, NULL, NULL);
+   return __sys_recvfrom(fd, ubuf, size, flags, NULL, NULL);
 }
 
 /*
@@ -2486,9 +2491,9 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
break;
case SYS_RECVFROM:
-   err = sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
-  (struct sockaddr __user *)a[4],
-  (int __user *)a[5]);
+   err = __sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
+(struct sockaddr __user *)a[4],
+(int __user *)a[5]);
break;
case SYS_SHUTDOWN:
err = sys_shutdown(a0, a1);
-- 
2.16.2



[PATCH -next 10/22] net: socket: add __sys_socketpair() helper; remove in-kernel call to syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __sys_socketpair() allows us to avoid the
internal calls to the sys_socketpair() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 include/linux/socket.h |  2 ++
 net/compat.c   |  2 +-
 net/socket.c   | 11 ---
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 9ba003e92fea..dbdddf0d079e 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -372,5 +372,7 @@ extern int __sys_getsockname(int fd, struct sockaddr __user 
*usockaddr,
 int __user *usockaddr_len);
 extern int __sys_getpeername(int fd, struct sockaddr __user *usockaddr,
 int __user *usockaddr_len);
+extern int __sys_socketpair(int family, int type, int protocol,
+   int __user *usockvec);
 
 #endif /* _LINUX_SOCKET_H */
diff --git a/net/compat.c b/net/compat.c
index 74017f618eb1..04db26316438 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -832,7 +832,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, 
args)
ret = __sys_getpeername(a0, compat_ptr(a1), compat_ptr(a[2]));
break;
case SYS_SOCKETPAIR:
-   ret = sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
+   ret = __sys_socketpair(a0, a1, a[2], compat_ptr(a[3]));
break;
case SYS_SEND:
ret = sys_send(a0, compat_ptr(a1), a[2], a[3]);
diff --git a/net/socket.c b/net/socket.c
index 007fb9483279..5861821f46f5 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1368,8 +1368,7 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, 
protocol)
  * Create a pair of connected sockets.
  */
 
-SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
-   int __user *, usockvec)
+int __sys_socketpair(int family, int type, int protocol, int __user *usockvec)
 {
struct socket *sock1, *sock2;
int fd1, fd2, err;
@@ -1454,6 +1453,12 @@ SYSCALL_DEFINE4(socketpair, int, family, int, type, int, 
protocol,
return err;
 }
 
+SYSCALL_DEFINE4(socketpair, int, family, int, type, int, protocol,
+   int __user *, usockvec)
+{
+   return __sys_socketpair(family, type, protocol, usockvec);
+}
+
 /*
  * Bind a name to a socket. Nothing much to do here since it's
  * the protocol's responsibility to handle the local address.
@@ -2521,7 +2526,7 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
  (int __user *)a[2]);
break;
case SYS_SOCKETPAIR:
-   err = sys_socketpair(a0, a1, a[2], (int __user *)a[3]);
+   err = __sys_socketpair(a0, a1, a[2], (int __user *)a[3]);
break;
case SYS_SEND:
err = sys_send(a0, (void __user *)a1, a[2], a[3]);
-- 
2.16.2



[PATCH -next 17/22] net: socket: replace call to sys_recv() with __sys_recvfrom()

2018-03-16 Thread Dominik Brodowski
sys_recv() merely expands the parameters to __sys_recvfrom() by NULL and
NULL. Open-code this in the two places which used sys_recv() as a wrapper
to __sys_recvfrom().

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 net/compat.c | 3 ++-
 net/socket.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/net/compat.c b/net/compat.c
index d55982ff5c59..9e0d030063ad 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -755,7 +755,8 @@ COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct 
compat_msghdr __user *, msg, uns
 
 COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, 
unsigned int, flags)
 {
-   return sys_recv(fd, buf, len, flags | MSG_CMSG_COMPAT);
+   return __sys_recvfrom(fd, buf, len, flags | MSG_CMSG_COMPAT, NULL,
+ NULL);
 }
 
 COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, buf, compat_size_t, 
len,
diff --git a/net/socket.c b/net/socket.c
index c4fb60be194b..34cf4b163f8f 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2566,7 +2566,8 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
   (struct sockaddr __user *)a[4], a[5]);
break;
case SYS_RECV:
-   err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
+   err = __sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
+NULL, NULL);
break;
case SYS_RECVFROM:
err = __sys_recvfrom(a0, (void __user *)a1, a[2], a[3],
-- 
2.16.2



[PATCH -next 13/22] net: socket: add __sys_getsockopt() helper; remove in-kernel call to syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __sys_getsockopt() allows us to avoid the
internal calls to the sys_getsockopt() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 net/socket.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 5dd2e39a6cd4..a05289b1f863 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1918,8 +1918,8 @@ SYSCALL_DEFINE5(setsockopt, int, fd, int, level, int, 
optname,
  * to pass a user mode parameter for the protocols to sort out.
  */
 
-SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,
-   char __user *, optval, int __user *, optlen)
+static int __sys_getsockopt(int fd, int level, int optname,
+   char __user *optval, int __user *optlen)
 {
int err, fput_needed;
struct socket *sock;
@@ -1944,6 +1944,12 @@ SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, 
optname,
return err;
 }
 
+SYSCALL_DEFINE5(getsockopt, int, fd, int, level, int, optname,
+   char __user *, optval, int __user *, optlen)
+{
+   return __sys_getsockopt(fd, level, optname, optval, optlen);
+}
+
 /*
  * Shutdown a socket.
  */
@@ -2563,8 +2569,8 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
break;
case SYS_GETSOCKOPT:
err =
-   sys_getsockopt(a0, a1, a[2], (char __user *)a[3],
-  (int __user *)a[4]);
+   __sys_getsockopt(a0, a1, a[2], (char __user *)a[3],
+(int __user *)a[4]);
break;
case SYS_SENDMSG:
err = sys_sendmsg(a0, (struct user_msghdr __user *)a1, a[2]);
-- 
2.16.2



[PATCH -next 02/22] net: socket: add __sys_sendto() helper; remove in-kernel call to syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __sys_sendto() allows us to avoid the
internal calls to the sys_sendto() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 include/linux/socket.h |  3 +++
 net/compat.c   |  3 ++-
 net/socket.c   | 19 ---
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 40cc93b91628..54b85abc7265 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -358,5 +358,8 @@ extern int __sys_sendmmsg(int fd, struct mmsghdr __user 
*mmsg,
 extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
  unsigned int flags, struct sockaddr __user *addr,
  int __user *addr_len);
+extern int __sys_sendto(int fd, void __user *buff, size_t len,
+   unsigned int flags, struct sockaddr __user *addr,
+   int addr_len);
 
 #endif /* _LINUX_SOCKET_H */
diff --git a/net/compat.c b/net/compat.c
index 2d8186c277b2..fc82982d9b84 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -838,7 +838,8 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, 
args)
ret = sys_send(a0, compat_ptr(a1), a[2], a[3]);
break;
case SYS_SENDTO:
-   ret = sys_sendto(a0, compat_ptr(a1), a[2], a[3], 
compat_ptr(a[4]), a[5]);
+   ret = __sys_sendto(a0, compat_ptr(a1), a[2], a[3],
+  compat_ptr(a[4]), a[5]);
break;
case SYS_RECV:
ret = compat_sys_recv(a0, compat_ptr(a1), a[2], a[3]);
diff --git a/net/socket.c b/net/socket.c
index 712d99d8680f..3f037a21ba5e 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1711,10 +1711,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr 
__user *, usockaddr,
  * space and check the user space data area is readable before invoking
  * the protocol.
  */
-
-SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
-   unsigned int, flags, struct sockaddr __user *, addr,
-   int, addr_len)
+int __sys_sendto(int fd, void __user *buff, size_t len, unsigned int flags,
+struct sockaddr __user *addr,  int addr_len)
 {
struct socket *sock;
struct sockaddr_storage address;
@@ -1752,6 +1750,13 @@ SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, 
size_t, len,
return err;
 }
 
+SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
+   unsigned int, flags, struct sockaddr __user *, addr,
+   int, addr_len)
+{
+   return __sys_sendto(fd, buff, len, flags, addr, addr_len);
+}
+
 /*
  * Send a datagram down a socket.
  */
@@ -1759,7 +1764,7 @@ SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, 
size_t, len,
 SYSCALL_DEFINE4(send, int, fd, void __user *, buff, size_t, len,
unsigned int, flags)
 {
-   return sys_sendto(fd, buff, len, flags, NULL, 0);
+   return __sys_sendto(fd, buff, len, flags, NULL, 0);
 }
 
 /*
@@ -2484,8 +2489,8 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
err = sys_send(a0, (void __user *)a1, a[2], a[3]);
break;
case SYS_SENDTO:
-   err = sys_sendto(a0, (void __user *)a1, a[2], a[3],
-(struct sockaddr __user *)a[4], a[5]);
+   err = __sys_sendto(a0, (void __user *)a1, a[2], a[3],
+  (struct sockaddr __user *)a[4], a[5]);
break;
case SYS_RECV:
err = sys_recv(a0, (void __user *)a1, a[2], a[3]);
-- 
2.16.2



[PATCH -next 15/22] net: socket: move check for forbid_cmsg_compat to __sys_...msg()

2018-03-16 Thread Dominik Brodowski
The non-compat codepaths for sys_...msg() verify that MSG_CMSG_COMPAT
is not set. By moving this check to the __sys_...msg() functions
(and making it dependent on a static flag passed to this function), we
can call the __sys...msg() functions instead of the syscall functions
in all cases. __sys_recvmmsg() does not need this trickery, as the
check is handled within the do_sys_recvmmsg() function internal to
net/socket.c.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 include/linux/socket.h | 13 +
 net/compat.c   |  8 +---
 net/socket.c   | 38 +++---
 3 files changed, 37 insertions(+), 22 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index cad120e4ed4b..e2b6bd4fe977 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -346,13 +346,18 @@ extern int put_cmsg(struct msghdr*, int level, int type, 
int len, void *data);
 
 struct timespec;
 
-/* The __sys_...msg variants allow MSG_CMSG_COMPAT */
-extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg, unsigned 
flags);
-extern long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned 
flags);
+/* The __sys_...msg variants allow MSG_CMSG_COMPAT iff
+ * forbid_cmsg_compat==false
+ */
+extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg,
+ unsigned int flags, bool forbid_cmsg_compat);
+extern long __sys_sendmsg(int fd, struct user_msghdr __user *msg,
+ unsigned int flags, bool forbid_cmsg_compat);
 extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int 
vlen,
  unsigned int flags, struct timespec *timeout);
 extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg,
- unsigned int vlen, unsigned int flags);
+ unsigned int vlen, unsigned int flags,
+ bool forbid_cmsg_compat);
 
 /* helpers which do the actual work for syscalls */
 extern int __sys_recvfrom(int fd, void __user *ubuf, size_t size,
diff --git a/net/compat.c b/net/compat.c
index f1ec23e9dfce..5caa48987bb2 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -736,19 +736,21 @@ static unsigned char nas[21] = {
 
 COMPAT_SYSCALL_DEFINE3(sendmsg, int, fd, struct compat_msghdr __user *, msg, 
unsigned int, flags)
 {
-   return __sys_sendmsg(fd, (struct user_msghdr __user *)msg, flags | 
MSG_CMSG_COMPAT);
+   return __sys_sendmsg(fd, (struct user_msghdr __user *)msg,
+flags | MSG_CMSG_COMPAT, false);
 }
 
 COMPAT_SYSCALL_DEFINE4(sendmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
   unsigned int, vlen, unsigned int, flags)
 {
return __sys_sendmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
- flags | MSG_CMSG_COMPAT);
+ flags | MSG_CMSG_COMPAT, false);
 }
 
 COMPAT_SYSCALL_DEFINE3(recvmsg, int, fd, struct compat_msghdr __user *, msg, 
unsigned int, flags)
 {
-   return __sys_recvmsg(fd, (struct user_msghdr __user *)msg, flags | 
MSG_CMSG_COMPAT);
+   return __sys_recvmsg(fd, (struct user_msghdr __user *)msg,
+flags | MSG_CMSG_COMPAT, false);
 }
 
 COMPAT_SYSCALL_DEFINE4(recv, int, fd, void __user *, buf, compat_size_t, len, 
unsigned int, flags)
diff --git a/net/socket.c b/net/socket.c
index 72cdaaeccb85..3dcace0ca3d9 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2137,12 +2137,16 @@ static int ___sys_sendmsg(struct socket *sock, struct 
user_msghdr __user *msg,
  * BSD sendmsg interface
  */
 
-long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned flags)
+long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned int flags,
+  bool forbid_cmsg_compat)
 {
int fput_needed, err;
struct msghdr msg_sys;
struct socket *sock;
 
+   if (forbid_cmsg_compat && (flags & MSG_CMSG_COMPAT))
+   return -EINVAL;
+
sock = sockfd_lookup_light(fd, &err, &fput_needed);
if (!sock)
goto out;
@@ -2156,9 +2160,7 @@ long __sys_sendmsg(int fd, struct user_msghdr __user 
*msg, unsigned flags)
 
 SYSCALL_DEFINE3(sendmsg, int, fd, struct user_msghdr __user *, msg, unsigned 
int, flags)
 {
-   if (flags & MSG_CMSG_COMPAT)
-   return -EINVAL;
-   return __sys_sendmsg(fd, msg, flags);
+   return __sys_sendmsg(fd, msg, flags, true);
 }
 
 /*
@@ -2166,7 +2168,7 @@ SYSCALL_DEFINE3(sendmsg, int, fd, struct user_msghdr 
__user *, msg, unsigned int
  */
 
 int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
-  unsigned int flags)
+  unsigned int flags, bool forbid_cmsg_compat)
 {
int fput_needed, err, datagrams;
struct socket *sock;
@@ -2176,6 +2178,9 @@ int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg, 
unsigned int vlen,
struct 

Re: arm64 kvm built with clang doesn't boot

2018-03-16 Thread Mark Rutland
On Fri, Mar 16, 2018 at 04:52:08PM +, Nick Desaulniers wrote:
> + Sami (Google), Takahiro (Linaro)
> 
> Just so I fully understand the problem enough to articulate it, we'd be
> looking for the compiler to keep the jump tables for speed (I would guess
> -fno-jump-tables would emit an if-else chain) but only emit relative jumps
> (not absolute jumps)?

Our main concern is that there is no absolute addressing. If that rules
out using a relative jump table, that's ok.

We want to avoid the fragility of collecting -f-no-* options as future
compiler transformations end up introducing absolute addressing.

Thanks,
Mark.


[PATCH -next 03/22] net: socket: add __sys_accept4() helper; remove in-kernel call to syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __sys_accept4() allows us to avoid the
internal calls to the sys_accept4() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 include/linux/socket.h |  2 ++
 net/compat.c   |  4 ++--
 net/socket.c   | 20 +---
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index 54b85abc7265..6a9840271676 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -361,5 +361,7 @@ extern int __sys_recvfrom(int fd, void __user *ubuf, size_t 
size,
 extern int __sys_sendto(int fd, void __user *buff, size_t len,
unsigned int flags, struct sockaddr __user *addr,
int addr_len);
+extern int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
+int __user *upeer_addrlen, int flags);
 
 #endif /* _LINUX_SOCKET_H */
diff --git a/net/compat.c b/net/compat.c
index fc82982d9b84..0ff9f7451b6f 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -823,7 +823,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, 
args)
ret = sys_listen(a0, a1);
break;
case SYS_ACCEPT:
-   ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0);
+   ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), 0);
break;
case SYS_GETSOCKNAME:
ret = sys_getsockname(a0, compat_ptr(a1), compat_ptr(a[2]));
@@ -873,7 +873,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, 
args)
  compat_ptr(a[4]));
break;
case SYS_ACCEPT4:
-   ret = sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
+   ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
break;
default:
ret = -EINVAL;
diff --git a/net/socket.c b/net/socket.c
index 3f037a21ba5e..45f6ea0d57a5 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -1519,8 +1519,8 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
  * clean when we restucture accept also.
  */
 
-SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
-   int __user *, upeer_addrlen, int, flags)
+int __sys_accept4(int fd, struct sockaddr __user *upeer_sockaddr,
+ int __user *upeer_addrlen, int flags)
 {
struct socket *sock, *newsock;
struct file *newfile;
@@ -1599,10 +1599,16 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr 
__user *, upeer_sockaddr,
goto out_put;
 }
 
+SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
+   int __user *, upeer_addrlen, int, flags)
+{
+   return __sys_accept4(fd, upeer_sockaddr, upeer_addrlen, flags);
+}
+
 SYSCALL_DEFINE3(accept, int, fd, struct sockaddr __user *, upeer_sockaddr,
int __user *, upeer_addrlen)
 {
-   return sys_accept4(fd, upeer_sockaddr, upeer_addrlen, 0);
+   return __sys_accept4(fd, upeer_sockaddr, upeer_addrlen, 0);
 }
 
 /*
@@ -2469,8 +2475,8 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
err = sys_listen(a0, a1);
break;
case SYS_ACCEPT:
-   err = sys_accept4(a0, (struct sockaddr __user *)a1,
- (int __user *)a[2], 0);
+   err = __sys_accept4(a0, (struct sockaddr __user *)a1,
+   (int __user *)a[2], 0);
break;
case SYS_GETSOCKNAME:
err =
@@ -2525,8 +2531,8 @@ SYSCALL_DEFINE2(socketcall, int, call, unsigned long 
__user *, args)
   (struct timespec __user *)a[4]);
break;
case SYS_ACCEPT4:
-   err = sys_accept4(a0, (struct sockaddr __user *)a1,
- (int __user *)a[2], a[3]);
+   err = __sys_accept4(a0, (struct sockaddr __user *)a1,
+   (int __user *)a[2], a[3]);
break;
default:
err = -EINVAL;
-- 
2.16.2



[PATCH -next 21/22] net: socket: add __compat_sys_recvmmsg() helper; remove in-kernel call to compat syscall

2018-03-16 Thread Dominik Brodowski
Using the net-internal helper __compat_sys_recvmmsg() allows us to avoid
the internal calls to the compat_sys_recvmmsg() syscall.

Cc: David S. Miller 
Cc: net...@vger.kernel.org
Signed-off-by: Dominik Brodowski 
---
 net/compat.c | 17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/compat.c b/net/compat.c
index cdf5b0c1b962..7b2ae42a1598 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -787,9 +787,9 @@ COMPAT_SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, 
buf, compat_size_t, len
return __compat_sys_recvfrom(fd, buf, len, flags, addr, addrlen);
 }
 
-COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
-  unsigned int, vlen, unsigned int, flags,
-  struct compat_timespec __user *, timeout)
+static int __compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
+unsigned int vlen, unsigned int flags,
+struct compat_timespec __user *timeout)
 {
int datagrams;
struct timespec ktspec;
@@ -809,6 +809,13 @@ COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct 
compat_mmsghdr __user *, mmsg,
return datagrams;
 }
 
+COMPAT_SYSCALL_DEFINE5(recvmmsg, int, fd, struct compat_mmsghdr __user *, mmsg,
+  unsigned int, vlen, unsigned int, flags,
+  struct compat_timespec __user *, timeout)
+{
+   return __compat_sys_recvmmsg(fd, mmsg, vlen, flags, timeout);
+}
+
 COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
 {
u32 a[AUDITSC_ARGS];
@@ -895,8 +902,8 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, 
args)
ret = compat_sys_recvmsg(a0, compat_ptr(a1), a[2]);
break;
case SYS_RECVMMSG:
-   ret = compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3],
- compat_ptr(a[4]));
+   ret = __compat_sys_recvmmsg(a0, compat_ptr(a1), a[2], a[3],
+   compat_ptr(a[4]));
break;
case SYS_ACCEPT4:
ret = __sys_accept4(a0, compat_ptr(a1), compat_ptr(a[2]), a[3]);
-- 
2.16.2



[PATCH 4.9 37/86] ALSA: hda: add dock and led support for HP ProBook 640 G2

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Dennis Wassenberg 

commit 099fd6ca0ad25bc19c5ade2ea4b25b8fadaa11b3 upstream.

This patch adds missing initialisation for HP 2013 UltraSlim Dock
Line-In/Out PINs and activates keyboard mute/micmute leds
for HP ProBook 640 G2

Signed-off-by: Dennis Wassenberg 
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_conexant.c |1 +
 1 file changed, 1 insertion(+)

--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -850,6 +850,7 @@ static const struct snd_pci_quirk cxt506
SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", 
CXT_FIXUP_ASPIRE_DMIC),
SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
+   SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),




[PATCH 4.9 36/86] ALSA: hda: add dock and led support for HP EliteBook 820 G3

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Dennis Wassenberg 

commit aea808172018ca01abf53db808323aed23281835 upstream.

This patch adds missing initialisation for HP 2013 UltraSlim Dock
Line-In/Out PINs and activates keyboard mute/micmute leds
for HP EliteBook 820 G3

Signed-off-by: Dennis Wassenberg 
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_conexant.c |1 +
 1 file changed, 1 insertion(+)

--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -849,6 +849,7 @@ static const struct snd_pci_quirk cxt506
SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", 
CXT_FIXUP_ASPIRE_DMIC),
SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", 
CXT_FIXUP_ASPIRE_DMIC),
SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
+   SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),




[PATCH 4.9 33/86] ALSA: hda/realtek - Make dock sound work on ThinkPad L570

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Dennis Wassenberg 

commit e4c07b3b66b7d6a24c2fe3b1ddeff5cd9b378b3a upstream.

One version of Lenovo Thinkpad T570 did not use ALC298
(like other Kaby Lake devices). Instead it uses ALC292.
In order to make the Lenovo dock working with that codec
the dock quirk for ALC292 will be used.

Signed-off-by: Dennis Wassenberg 
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_realtek.c |1 +
 1 file changed, 1 insertion(+)

--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -5801,6 +5801,7 @@ static const struct snd_pci_quirk alc269
SND_PCI_QUIRK(0x17aa, 0x2245, "Thinkpad T470", 
ALC298_FIXUP_TPT470_DOCK),
SND_PCI_QUIRK(0x17aa, 0x2246, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
SND_PCI_QUIRK(0x17aa, 0x2247, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
+   SND_PCI_QUIRK(0x17aa, 0x2249, "Thinkpad", ALC292_FIXUP_TPT460),
SND_PCI_QUIRK(0x17aa, 0x224b, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
SND_PCI_QUIRK(0x17aa, 0x224c, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
SND_PCI_QUIRK(0x17aa, 0x224d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),




[PATCH 4.9 28/86] x86/MCE: Serialize sysfs changes

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Seunghun Han 

commit b3b7c4795ccab5be71f080774c45bbbcc75c2aaf upstream.

The check_interval file in

  /sys/devices/system/machinecheck/machinecheck

directory is a global timer value for MCE polling. If it is changed by one
CPU, mce_restart() broadcasts the event to other CPUs to delete and restart
the MCE polling timer and __mcheck_cpu_init_timer() reinitializes the
mce_timer variable.

If more than one CPU writes a specific value to the check_interval file
concurrently, mce_timer is not protected from such concurrent accesses and
all kinds of explosions happen. Since only root can write to those sysfs
variables, the issue is not a big deal security-wise.

However, concurrent writes to these configuration variables is void of
reason so the proper thing to do is to serialize the access with a mutex.

Boris:

 - Make store_int_with_restart() use device_store_ulong() to filter out
   negative intervals
 - Limit min interval to 1 second
 - Correct locking
 - Massage commit message

Signed-off-by: Seunghun Han 
Signed-off-by: Borislav Petkov 
Signed-off-by: Thomas Gleixner 
Cc: Greg Kroah-Hartman 
Cc: Tony Luck 
Cc: linux-edac 
Cc: sta...@vger.kernel.org
Link: http://lkml.kernel.org/r/20180302202706.9434-1-kkama...@gmail.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/cpu/mcheck/mce.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -61,6 +61,9 @@ static DEFINE_MUTEX(mce_chrdev_read_mute
smp_load_acquire(&(p)); \
 })
 
+/* sysfs synchronization */
+static DEFINE_MUTEX(mce_sysfs_mutex);
+
 #define CREATE_TRACE_POINTS
 #include 
 
@@ -2308,6 +2311,7 @@ static ssize_t set_ignore_ce(struct devi
if (kstrtou64(buf, 0, &new) < 0)
return -EINVAL;
 
+   mutex_lock(&mce_sysfs_mutex);
if (mca_cfg.ignore_ce ^ !!new) {
if (new) {
/* disable ce features */
@@ -2320,6 +2324,8 @@ static ssize_t set_ignore_ce(struct devi
on_each_cpu(mce_enable_ce, (void *)1, 1);
}
}
+   mutex_unlock(&mce_sysfs_mutex);
+
return size;
 }
 
@@ -2332,6 +2338,7 @@ static ssize_t set_cmci_disabled(struct
if (kstrtou64(buf, 0, &new) < 0)
return -EINVAL;
 
+   mutex_lock(&mce_sysfs_mutex);
if (mca_cfg.cmci_disabled ^ !!new) {
if (new) {
/* disable cmci */
@@ -2343,6 +2350,8 @@ static ssize_t set_cmci_disabled(struct
on_each_cpu(mce_enable_ce, NULL, 1);
}
}
+   mutex_unlock(&mce_sysfs_mutex);
+
return size;
 }
 
@@ -2350,8 +2359,19 @@ static ssize_t store_int_with_restart(st
  struct device_attribute *attr,
  const char *buf, size_t size)
 {
-   ssize_t ret = device_store_int(s, attr, buf, size);
+   unsigned long old_check_interval = check_interval;
+   ssize_t ret = device_store_ulong(s, attr, buf, size);
+
+   if (check_interval == old_check_interval)
+   return ret;
+
+   if (check_interval < 1)
+   check_interval = 1;
+
+   mutex_lock(&mce_sysfs_mutex);
mce_restart();
+   mutex_unlock(&mce_sysfs_mutex);
+
return ret;
 }
 




[PATCH 4.9 32/86] ALSA: hda/realtek - Fix dock line-out volume on Dell Precision 7520

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Takashi Iwai 

commit e312a869cd726c698a75caca0d9e5c22fd3f1534 upstream.

The dock line-out pin (NID 0x17 of ALC3254 codec) on Dell Precision
7520 may route to three different DACs, 0x02, 0x03 and 0x06.  The
first two DACS have the volume amp controls while the last one
doesn't.  And unfortunately, the auto-parser assigns this pin to DAC3,
resulting in the non-working volume control for the line out.

Fix it by disabling the routing to DAC3 on the corresponding pin.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=199029
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_realtek.c |   16 
 1 file changed, 16 insertions(+)

--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -4760,6 +4760,16 @@ static void alc298_fixup_speaker_volume(
}
 }
 
+/* disable DAC3 (0x06) selection on NID 0x17 as it has no volume amp control */
+static void alc295_fixup_disable_dac3(struct hda_codec *codec,
+ const struct hda_fixup *fix, int action)
+{
+   if (action == HDA_FIXUP_ACT_PRE_PROBE) {
+   hda_nid_t conn[2] = { 0x02, 0x03 };
+   snd_hda_override_conn_list(codec, 0x17, 2, conn);
+   }
+}
+
 /* Hook to update amp GPIO4 for automute */
 static void alc280_hp_gpio4_automute_hook(struct hda_codec *codec,
  struct hda_jack_callback *jack)
@@ -4909,6 +4919,7 @@ enum {
ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY,
ALC255_FIXUP_DELL_SPK_NOISE,
ALC225_FIXUP_DELL1_MIC_NO_PRESENCE,
+   ALC295_FIXUP_DISABLE_DAC3,
ALC280_FIXUP_HP_HEADSET_MIC,
ALC221_FIXUP_HP_FRONT_MIC,
ALC292_FIXUP_TPT460,
@@ -5601,6 +5612,10 @@ static const struct hda_fixup alc269_fix
.chained = true,
.chain_id = ALC298_FIXUP_DELL_AIO_MIC_NO_PRESENCE,
},
+   [ALC295_FIXUP_DISABLE_DAC3] = {
+   .type = HDA_FIXUP_FUNC,
+   .v.func = alc295_fixup_disable_dac3,
+   },
[ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER] = {
.type = HDA_FIXUP_PINS,
.v.pins = (const struct hda_pintbl[]) {
@@ -5664,6 +5679,7 @@ static const struct snd_pci_quirk alc269
SND_PCI_QUIRK(0x1028, 0x0725, "Dell Inspiron 3162", 
ALC255_FIXUP_DELL_SPK_NOISE),
SND_PCI_QUIRK(0x1028, 0x075b, "Dell XPS 13 9360", 
ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
SND_PCI_QUIRK(0x1028, 0x075d, "Dell AIO", ALC298_FIXUP_SPK_VOLUME),
+   SND_PCI_QUIRK(0x1028, 0x07b0, "Dell Precision 7520", 
ALC295_FIXUP_DISABLE_DAC3),
SND_PCI_QUIRK(0x1028, 0x0798, "Dell Inspiron 17 7000 Gaming", 
ALC256_FIXUP_DELL_INSPIRON_7559_SUBWOOFER),
SND_PCI_QUIRK(0x1028, 0x082a, "Dell XPS 13 9360", 
ALC256_FIXUP_DELL_XPS_13_HEADPHONE_NOISE),
SND_PCI_QUIRK(0x1028, 0x164a, "Dell", 
ALC293_FIXUP_DELL1_MIC_NO_PRESENCE),




[PATCH 4.9 31/86] ALSA: hda/realtek: Limit mic boost on T480

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Benjamin Berg 

commit 85981dfd6b0a0fd9ed87ca4a525981b67c21f098 upstream.

The internal mic boost on the T480 is too high. Fix this by applying the
ALC269_FIXUP_LIMIT_INT_MIC_BOOST fixup to the machine to limit the gain.

Signed-off-by: Benjamin Berg 
Tested-by: Benjamin Berg 
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_realtek.c |1 +
 1 file changed, 1 insertion(+)

--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -5788,6 +5788,7 @@ static const struct snd_pci_quirk alc269
SND_PCI_QUIRK(0x17aa, 0x224b, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
SND_PCI_QUIRK(0x17aa, 0x224c, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
SND_PCI_QUIRK(0x17aa, 0x224d, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
+   SND_PCI_QUIRK(0x17aa, 0x225d, "Thinkpad T480", 
ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
SND_PCI_QUIRK(0x17aa, 0x30bb, "ThinkCentre AIO", 
ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
SND_PCI_QUIRK(0x17aa, 0x30e2, "ThinkCentre AIO", 
ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),
SND_PCI_QUIRK(0x17aa, 0x3112, "ThinkCentre AIO", 
ALC233_FIXUP_LENOVO_LINE2_MIC_HOTKEY),




[PATCH 4.9 26/86] bcache: fix crashes in duplicate cache device register

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Tang Junhui 

commit cc40daf91bdddbba72a4a8cd0860640e06668309 upstream.

Kernel crashed when register a duplicate cache device, the call trace is
bellow:
[  417.643790] CPU: 1 PID: 16886 Comm: bcache-register Tainted: G
   W  OE4.15.5-amd64-preempt-sysrq-20171018 #2
[  417.643861] Hardware name: LENOVO 20ERCTO1WW/20ERCTO1WW, BIOS
N1DET41W (1.15 ) 12/31/2015
[  417.643870] RIP: 0010:bdevname+0x13/0x1e
[  417.643876] RSP: 0018:a3aa9138fd38 EFLAGS: 00010282
[  417.643884] RAX:  RBX: 8c8f2f2f8000 RCX: d6701f8
c7edf
[  417.643890] RDX: a3aa9138fd88 RSI: a3aa9138fd88 RDI: 000
0
[  417.643895] RBP: a3aa9138fde0 R08: a3aa9138fae8 R09: 000
1850e
[  417.643901] R10: 8c8eed34b271 R11: 8c8eed34b250 R12: 000
0
[  417.643906] R13: d6701f78f940 R14: 8c8f38f8 R15: 8c8ea7d
9
[  417.643913] FS:  7fde7e66f500() GS:8c8f6144() knlGS:

[  417.643919] CS:  0010 DS:  ES:  CR0: 80050033
[  417.643925] CR2: 0314 CR3: 0007e6fa0001 CR4: 003
606e0
[  417.643931] DR0:  DR1:  DR2: 000
0
[  417.643938] DR3:  DR6: fffe0ff0 DR7: 000
00400
[  417.643946] Call Trace:
[  417.643978]  register_bcache+0x1117/0x1270 [bcache]
[  417.643994]  ? slab_pre_alloc_hook+0x15/0x3c
[  417.644001]  ? slab_post_alloc_hook.isra.44+0xa/0x1a
[  417.644013]  ? kernfs_fop_write+0xf6/0x138
[  417.644020]  kernfs_fop_write+0xf6/0x138
[  417.644031]  __vfs_write+0x31/0xcc
[  417.644043]  ? current_kernel_time64+0x10/0x36
[  417.644115]  ? __audit_syscall_entry+0xbf/0xe3
[  417.644124]  vfs_write+0xa5/0xe2
[  417.644133]  SyS_write+0x5c/0x9f
[  417.644144]  do_syscall_64+0x72/0x81
[  417.644161]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
[  417.644169] RIP: 0033:0x7fde7e1c1974
[  417.644175] RSP: 002b:7fff13009a38 EFLAGS: 0246 ORIG_RAX: 000
1
[  417.644183] RAX: ffda RBX: 01658280 RCX: 7fde7e1c
1974
[  417.644188] RDX: 000a RSI: 01658280 RDI: 
0001
[  417.644193] RBP: 000a R08: 0003 R09: 
0077
[  417.644198] R10: 089e R11: 0246 R12: 
0001
[  417.644203] R13: 000a R14: 7fff R15: 

[  417.644213] Code: c7 c2 83 6f ee 98 be 20 00 00 00 48 89 df e8 6c 27 3b 0
0 48 89 d8 5b c3 0f 1f 44 00 00 48 8b 47 70 48 89 f2 48 8b bf 80 00 00 00 <8
b> b0 14 03 00 00 e9 73 ff ff ff 0f 1f 44 00 00 48 8b 47 40 39
[  417.644302] RIP: bdevname+0x13/0x1e RSP: a3aa9138fd38
[  417.644306] CR2: 0314

When registering duplicate cache device in register_cache(), after failure
on calling register_cache_set(), bch_cache_release() will be called, then
bdev will be freed, so bdevname(bdev, name) caused kernel crash.

Since bch_cache_release() will free bdev, so in this patch we make sure
bdev being freed if register_cache() fail, and do not free bdev again in
register_bcache() when register_cache() fail.

Signed-off-by: Tang Junhui 
Reported-by: Marc MERLIN 
Tested-by: Michael Lyle 
Reviewed-by: Michael Lyle 
Cc: 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/md/bcache/super.c |   16 ++--
 1 file changed, 10 insertions(+), 6 deletions(-)

--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1182,7 +1182,7 @@ static void register_bdev(struct cache_s
 
return;
 err:
-   pr_notice("error opening %s: %s", bdevname(bdev, name), err);
+   pr_notice("error %s: %s", bdevname(bdev, name), err);
bcache_device_stop(&dc->disk);
 }
 
@@ -1853,6 +1853,8 @@ static int register_cache(struct cache_s
const char *err = NULL; /* must be set for any error case */
int ret = 0;
 
+   bdevname(bdev, name);
+
memcpy(&ca->sb, sb, sizeof(struct cache_sb));
ca->bdev = bdev;
ca->bdev->bd_holder = ca;
@@ -1863,11 +1865,12 @@ static int register_cache(struct cache_s
ca->sb_bio.bi_io_vec[0].bv_page = sb_page;
get_page(sb_page);
 
-   if (blk_queue_discard(bdev_get_queue(ca->bdev)))
+   if (blk_queue_discard(bdev_get_queue(bdev)))
ca->discard = CACHE_DISCARD(&ca->sb);
 
ret = cache_alloc(ca);
if (ret != 0) {
+   blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
if (ret == -ENOMEM)
err = "cache_alloc(): -ENOMEM";
else
@@ -1890,14 +1893,14 @@ static int register_cache(struct cache_s
goto out;
}
 
-   pr_info("registered cache device %s", bdevname(bdev, name));
+   pr_info("registered cache device %s", name);
 
 out:
kobject_put(&ca->kobj);
 
 err:
if (err)
-   pr_notice("

[PATCH 4.9 10/86] drm/radeon: Fix deadlock on runtime suspend

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Lukas Wunner 

commit 15734feff2bdac24aa3266c437cffa42851990e3 upstream.

radeon's ->runtime_suspend hook calls drm_kms_helper_poll_disable(),
which waits for the output poll worker to finish if it's running.

The output poll worker meanwhile calls pm_runtime_get_sync() in
radeon's ->detect hooks, which waits for the ongoing suspend to finish,
causing a deadlock.

Fix by not acquiring a runtime PM ref if the ->detect hooks are called
in the output poll worker's context.  This is safe because the poll
worker is only enabled while runtime active and we know that
->runtime_suspend waits for it to finish.

Stack trace for posterity:

  INFO: task kworker/0:3:31847 blocked for more than 120 seconds
  Workqueue: events output_poll_execute [drm_kms_helper]
  Call Trace:
   schedule+0x3c/0x90
   rpm_resume+0x1e2/0x690
   __pm_runtime_resume+0x3f/0x60
   radeon_lvds_detect+0x39/0xf0 [radeon]
   output_poll_execute+0xda/0x1e0 [drm_kms_helper]
   process_one_work+0x14b/0x440
   worker_thread+0x48/0x4a0

  INFO: task kworker/2:0:10493 blocked for more than 120 seconds.
  Workqueue: pm pm_runtime_work
  Call Trace:
   schedule+0x3c/0x90
   schedule_timeout+0x1b3/0x240
   wait_for_common+0xc2/0x180
   wait_for_completion+0x1d/0x20
   flush_work+0xfc/0x1a0
   __cancel_work_timer+0xa5/0x1d0
   cancel_delayed_work_sync+0x13/0x20
   drm_kms_helper_poll_disable+0x1f/0x30 [drm_kms_helper]
   radeon_pmops_runtime_suspend+0x3d/0xa0 [radeon]
   pci_pm_runtime_suspend+0x61/0x1a0
   vga_switcheroo_runtime_suspend+0x21/0x70
   __rpm_callback+0x32/0x70
   rpm_callback+0x24/0x80
   rpm_suspend+0x12b/0x640
   pm_runtime_work+0x6f/0xb0
   process_one_work+0x14b/0x440
   worker_thread+0x48/0x4a0

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94147
Fixes: 10ebc0bc0934 ("drm/radeon: add runtime PM support (v2)")
Cc: sta...@vger.kernel.org # v3.13+: 27d4ee03078a: workqueue: Allow retrieval 
of current task's work struct
Cc: sta...@vger.kernel.org # v3.13+: 25c058ccaf2e: drm: Allow determining if 
current task is output poll worker
Cc: Ismo Toijala 
Cc: Alex Deucher 
Cc: Dave Airlie 
Reviewed-by: Lyude Paul 
Signed-off-by: Lukas Wunner 
Link: 
https://patchwork.freedesktop.org/patch/msgid/64ea02c44f91dda19bc563902b97bbc699040392.1518338789.git.lu...@wunner.de
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/radeon/radeon_connectors.c |   74 +++--
 1 file changed, 49 insertions(+), 25 deletions(-)

--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -897,9 +897,11 @@ radeon_lvds_detect(struct drm_connector
enum drm_connector_status ret = connector_status_disconnected;
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
if (encoder) {
struct radeon_encoder *radeon_encoder = 
to_radeon_encoder(encoder);
@@ -922,8 +924,12 @@ radeon_lvds_detect(struct drm_connector
/* check acpi lid status ??? */
 
radeon_connector_update_scratch_regs(connector, ret);
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
+
return ret;
 }
 
@@ -1037,9 +1043,11 @@ radeon_vga_detect(struct drm_connector *
enum drm_connector_status ret = connector_status_disconnected;
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
encoder = radeon_best_single_encoder(connector);
if (!encoder)
@@ -1106,8 +1114,10 @@ radeon_vga_detect(struct drm_connector *
radeon_connector_update_scratch_regs(connector, ret);
 
 out:
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
 
return ret;
 }
@@ -1171,9 +1181,11 @@ radeon_tv_detect(struct drm_connector *c
if (!radeon_connector->dac_load_detect)
return ret;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   ret

[PATCH 4.9 24/86] kbuild: Handle builtin dtb file names containing hyphens

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: James Hogan 

commit 55fe6da9efba102866e2fb5b40b04b6a4b26c19e upstream.

cmd_dt_S_dtb constructs the assembly source to incorporate a devicetree
FDT (that is, the .dtb file) as binary data in the kernel image. This
assembly source contains labels before and after the binary data. The
label names incorporate the file name of the corresponding .dtb file.
Hyphens are not legal characters in labels, so .dtb files built into the
kernel with hyphens in the file name result in errors like the
following:

bcm3368-netgear-cvg834g.dtb.S: Assembler messages:
bcm3368-netgear-cvg834g.dtb.S:5: Error: : no such section
bcm3368-netgear-cvg834g.dtb.S:5: Error: junk at end of line, first unrecognized 
character is `-'
bcm3368-netgear-cvg834g.dtb.S:6: Error: unrecognized opcode 
`__dtb_bcm3368-netgear-cvg834g_begin:'
bcm3368-netgear-cvg834g.dtb.S:8: Error: unrecognized opcode 
`__dtb_bcm3368-netgear-cvg834g_end:'
bcm3368-netgear-cvg834g.dtb.S:9: Error: : no such section
bcm3368-netgear-cvg834g.dtb.S:9: Error: junk at end of line, first unrecognized 
character is `-'

Fix this by updating cmd_dt_S_dtb to transform all hyphens from the file
name to underscores when constructing the labels.

As of v4.16-rc2, 1139 .dts files across ARM64, ARM, MIPS and PowerPC
contain hyphens in their names, but the issue only currently manifests
on Broadcom MIPS platforms, as that is the only place where such files
are built into the kernel. For example when CONFIG_DT_NETGEAR_CVG834G=y,
or on BMIPS kernels when the dtbs target is used (in the latter case it
admittedly shouldn't really build all the dtb.o files, but thats a
separate issue).

Fixes: 695835511f96 ("MIPS: BMIPS: rename bcm96358nb4ser to 
bcm6358-neufbox4-sercom")
Signed-off-by: James Hogan 
Reviewed-by: Frank Rowand 
Cc: Rob Herring 
Cc: Michal Marek 
Cc: Ralf Baechle 
Cc: Florian Fainelli 
Cc: Kevin Cernekee 
Cc:  # 4.9+
Signed-off-by: Masahiro Yamada 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/Makefile.lib |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -290,11 +290,11 @@ cmd_dt_S_dtb= 
\
echo '\#include ';   \
echo '.section .dtb.init.rodata,"a"';   \
echo '.balign STRUCT_ALIGNMENT';\
-   echo '.global __dtb_$(*F)_begin';   \
-   echo '__dtb_$(*F)_begin:';  \
+   echo '.global __dtb_$(subst -,_,$(*F))_begin';  \
+   echo '__dtb_$(subst -,_,$(*F))_begin:'; \
echo '.incbin "$<" ';   \
-   echo '__dtb_$(*F)_end:';\
-   echo '.global __dtb_$(*F)_end'; \
+   echo '__dtb_$(subst -,_,$(*F))_end:';   \
+   echo '.global __dtb_$(subst -,_,$(*F))_end';\
echo '.balign STRUCT_ALIGNMENT';\
 ) > $@
 




[PATCH 4.9 27/86] bcache: dont attach backing with duplicate UUID

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Michael Lyle 

commit 86755b7a96faed57f910f9e6b8061e019ac1ec08 upstream.

This can happen e.g. during disk cloning.

This is an incomplete fix: it does not catch duplicate UUIDs earlier
when things are still unattached.  It does not unregister the device.
Further changes to cope better with this are planned but conflict with
Coly's ongoing improvements to handling device errors.  In the meantime,
one can manually stop the device after this has happened.

Attempts to attach a duplicate device result in:

[  136.372404] loop: module loaded
[  136.424461] bcache: register_bdev() registered backing device loop0
[  136.424464] bcache: bch_cached_dev_attach() Tried to attach loop0 but 
duplicate UUID already attached

My test procedure is:

  dd if=/dev/sdb1 of=imgfile bs=1024 count=262144
  losetup -f imgfile

Signed-off-by: Michael Lyle 
Reviewed-by: Tang Junhui 
Cc: 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/md/bcache/super.c |   11 +++
 1 file changed, 11 insertions(+)

--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -937,6 +937,7 @@ int bch_cached_dev_attach(struct cached_
uint32_t rtime = cpu_to_le32(get_seconds());
struct uuid_entry *u;
char buf[BDEVNAME_SIZE];
+   struct cached_dev *exist_dc, *t;
 
bdevname(dc->bdev, buf);
 
@@ -960,6 +961,16 @@ int bch_cached_dev_attach(struct cached_
return -EINVAL;
}
 
+   /* Check whether already attached */
+   list_for_each_entry_safe(exist_dc, t, &c->cached_devs, list) {
+   if (!memcmp(dc->sb.uuid, exist_dc->sb.uuid, 16)) {
+   pr_err("Tried to attach %s but duplicate UUID already 
attached",
+   buf);
+
+   return -EINVAL;
+   }
+   }
+
u = uuid_find(c, dc->sb.uuid);
 
if (u &&




[PATCH 4.9 23/86] KVM: s390: fix memory overwrites when not using SCA entries

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: David Hildenbrand 

commit f07afa0462b76a5b9c4f3a43d5ac24fdb86a90c2 upstream.

Even if we don't have extended SCA support, we can have more than 64 CPUs
if we don't enable any HW features that might use the SCA entries.

Now, this works just fine, but we missed a return, which is why we
would actually store the SCA entries. If we have more than 64 CPUs, this
means writing outside of the basic SCA - bad.

Let's fix this. This allows > 64 CPUs when running nested (under vSIE)
without random crashes.

Fixes: a6940674c384 ("KVM: s390: allow 255 VCPUs when sca entries aren't used")
Reported-by: Christian Borntraeger 
Tested-by: Christian Borntraeger 
Signed-off-by: David Hildenbrand 
Message-Id: <20180306132758.21034-1-da...@redhat.com>
Cc: sta...@vger.kernel.org
Reviewed-by: Cornelia Huck 
Signed-off-by: Christian Borntraeger 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/s390/kvm/kvm-s390.c |1 +
 1 file changed, 1 insertion(+)

--- a/arch/s390/kvm/kvm-s390.c
+++ b/arch/s390/kvm/kvm-s390.c
@@ -1601,6 +1601,7 @@ static void sca_add_vcpu(struct kvm_vcpu
/* we still need the basic sca for the ipte control */
vcpu->arch.sie_block->scaoh = (__u32)(((__u64)sca) >> 32);
vcpu->arch.sie_block->scaol = (__u32)(__u64)sca;
+   return;
}
read_lock(&vcpu->kvm->arch.sca_lock);
if (vcpu->kvm->arch.use_esca) {




[PATCH 4.9 21/86] loop: Fix lost writes caused by missing flag

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Ross Zwisler 

commit 1d037577c323e5090ce281e96bc313ab2eee5be2 upstream.

The following commit:

commit aa4d86163e4e ("block: loop: switch to VFS ITER_BVEC")

replaced __do_lo_send_write(), which used ITER_KVEC iterators, with
lo_write_bvec() which uses ITER_BVEC iterators.  In this change, though,
the WRITE flag was lost:

-   iov_iter_kvec(&from, ITER_KVEC | WRITE, &kvec, 1, len);
+   iov_iter_bvec(&i, ITER_BVEC, bvec, 1, bvec->bv_len);

This flag is necessary for the DAX case because we make decisions based on
whether or not the iterator is a READ or a WRITE in dax_iomap_actor() and
in dax_iomap_rw().

We end up going through this path in configurations where we combine a PMEM
device with 4k sectors, a loopback device and DAX.  The consequence of this
missed flag is that what we intend as a write actually turns into a read in
the DAX code, so no data is ever written.

The very simplest test case is to create a loopback device and try and
write a small string to it, then hexdump a few bytes of the device to see
if the write took.  Without this patch you read back all zeros, with this
you read back the string you wrote.

For XFS this causes us to fail or panic during the following xfstests:

xfs/074 xfs/078 xfs/216 xfs/217 xfs/250

For ext4 we have a similar issue where writes never happen, but we don't
currently have any xfstests that use loopback and show this issue.

Fix this by restoring the WRITE flag argument to iov_iter_bvec().  This
causes the xfstests to all pass.

Cc: Al Viro 
Cc: sta...@vger.kernel.org
Fixes: commit aa4d86163e4e ("block: loop: switch to VFS ITER_BVEC")
Reviewed-by: Christoph Hellwig 
Reviewed-by: Ming Lei 
Signed-off-by: Ross Zwisler 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/block/loop.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -263,7 +263,7 @@ static int lo_write_bvec(struct file *fi
struct iov_iter i;
ssize_t bw;
 
-   iov_iter_bvec(&i, ITER_BVEC, bvec, 1, bvec->bv_len);
+   iov_iter_bvec(&i, ITER_BVEC | WRITE, bvec, 1, bvec->bv_len);
 
file_start_write(file);
bw = vfs_iter_write(file, &i, ppos);




Re: arm64 kvm built with clang doesn't boot

2018-03-16 Thread Marc Zyngier
On 16/03/18 16:52, Nick Desaulniers wrote:

[dropping kernel-dynamic-to...@google.com which keeps bouncing]

> Is this in regards to: commit "arm64: Add ARM_SMCCC_ARCH_WORKAROUND_1 BP
> hardening support"? Has anyone tried to upstream a fix for this?  We
> probably want to be very explicit with register widths here.
What do you mean? The current code is as strict as it gets, and
explicitly tells the compiler to use the right register width, based on
the SMC call parameter types.

Thanks,

M.
-- 
Jazz is not dead. It just smells funny...


[PATCH 4.9 18/86] MIPS: ath25: Check for kzalloc allocation failure

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

commit 1b22b4b28fd5fbc51855219e3238b3ab81da8466 upstream.

Currently there is no null check on a failed allocation of board_data,
and hence a null pointer dereference will occurr. Fix this by checking
for the out of memory null pointer.

Fixes: a7473717483e ("MIPS: ath25: add board configuration detection")
Signed-off-by: Colin Ian King 
Cc: Ralf Baechle 
Cc: linux-m...@linux-mips.org
Cc:  # 3.19+
Patchwork: https://patchwork.linux-mips.org/patch/18657/
Signed-off-by: James Hogan 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/ath25/board.c |2 ++
 1 file changed, 2 insertions(+)

--- a/arch/mips/ath25/board.c
+++ b/arch/mips/ath25/board.c
@@ -135,6 +135,8 @@ int __init ath25_find_config(phys_addr_t
}
 
board_data = kzalloc(BOARD_CONFIG_BUFSZ, GFP_KERNEL);
+   if (!board_data)
+   goto error;
ath25_board.config = (struct ath25_boarddata *)board_data;
memcpy_fromio(board_data, bcfg, 0x100);
if (broken_boarddata) {




[PATCH 4.9 00/86] 4.9.88-stable review

2018-03-16 Thread Greg Kroah-Hartman
This is the start of the stable review cycle for the 4.9.88 release.
There are 86 patches in this series, all will be posted as a response
to this one.  If anyone has any issues with these being applied, please
let me know.

Responses should be made by Sun Mar 18 15:22:47 UTC 2018.
Anything received after that time might be too late.

The whole patch series can be found in one patch at:

https://www.kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.9.88-rc1.gz
or in the git tree and branch at:

git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git 
linux-4.9.y
and the diffstat can be found below.

thanks,

greg k-h

-
Pseudo-Shortlog of commits:

Greg Kroah-Hartman 
Linux 4.9.88-rc1

Koen Vandeputte 
PCI: dwc: Fix enumeration end when reaching root subordinate

Greentime Hu 
earlycon: add reg-offset to physical address before mapping

Sebastian Andrzej Siewior 
serial: core: mark port as initialized in autoconfig

Nikola Ciprich 
serial: 8250_pci: Add Brainboxes UC-260 4 port serial device

Xinyong 
usb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb()

Pete Zaitcev 
usb: usbmon: Read text within supplied buffer size

Danilo Krummrich 
usb: quirks: add control message delay for 1b1c:1b20

Colin Ian King 
usbip: vudc: fix null pointer dereference on udc->lock

Teijo Kinnunen 
USB: storage: Add JMicron bridge 152d:2567 to unusual_devs.h

Joel Fernandes 
staging: android: ashmem: Fix lockdep issue during llseek

Frank Mori Hess 
staging: comedi: fix comedi_nsamples_left.

Oliver Neukum 
uas: fix comparison for error code

Jonas Danielsson 
tty/serial: atmel: add new version check for usart

Ulrich Hecht 
serial: sh-sci: prevent lockup on full TTY buffers

Hans de Goede 
ASoC: rt5651: Fix regcache sync errors on resume

Fabio Estevam 
ASoC: sgtl5000: Fix suspend/resume

H.J. Lu 
x86: Treat R_X86_64_PLT32 as R_X86_64_PC32

Josh Poimboeuf 
x86/module: Detect and skip invalid relocations

Trond Myklebust 
NFS: Fix unstable write completion

Trond Myklebust 
NFS: Fix an incorrect type in struct nfs_direct_req

Quinn Tran 
scsi: qla2xxx: Replace fcport alloc with qla2x00_alloc_fcport

Clay McClure 
ubi: Fix race condition between ubi volume creation and udev

Tahsin Erdogan 
ext4: inplace xattr block update fails to deduplicate blocks

Florian Westphal 
netfilter: x_tables: pack percpu counter allocations

Florian Westphal 
netfilter: x_tables: pass xt_counters struct to counter allocator

Florian Westphal 
netfilter: x_tables: pass xt_counters struct instead of packet counter

Florian Westphal 
netfilter: ipv6: fix use-after-free Write in nf_nat_ipv6_manip_pkt

Florian Westphal 
netfilter: bridge: ebt_among: add missing match size checks

Florian Westphal 
netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets

Eric Dumazet 
netfilter: IDLETIMER: be syzkaller friendly

Paolo Abeni 
netfilter: nat: cope with negative port range

Paolo Abeni 
netfilter: x_tables: fix missing timer initialization in xt_LED

Florian Westphal 
netfilter: add back stackpointer size checks

Philipp Zabel 
tc358743: fix register i2c_rd/wr function fix

Dmitry Torokhov 
Input: tca8418_keypad - remove double read of key event register

Arnd Bergmann 
ARM: omap2: hide omap3_save_secure_ram on non-OMAP3 builds

Jerry Hoemann 
watchdog: hpwdt: Remove legacy NMI sourcing.

Arnd Bergmann 
watchdog: hpwdt: fix unused variable warning

Jerry Hoemann 
watchdog: hpwdt: Check source of NMI

Jerry Hoemann 
watchdog: hpwdt: SMBIOS check

Peter Zijlstra 
x86/paravirt, objtool: Annotate indirect calls

Ingo Molnar 
x86/speculation: Move firmware_restrict_branch_speculation_*() from C to CPP

Peter Zijlstra 
x86/boot, objtool: Annotate indirect jump in secondary_startup_64()

Peter Zijlstra 
x86/speculation, objtool: Annotate indirect calls/jumps for objtool

David Woodhouse 
x86/retpoline: Support retpoline builds with Clang

David Woodhouse 
x86/speculation: Use IBRS if available before calling into firmware

David Woodhouse 
Revert "x86/retpoline: Simplify vmexit_fill_RSB()"

Dan Williams 
nospec: Include  dependency

Dan Williams 
nospec: Kill array_index_nospec_mask_check()

Dennis Wassenberg 
ALSA: hda: add dock and led support for HP ProBook 640 G2

Dennis Wassenberg 
ALSA: hda: add dock and led support for HP EliteBook 820 G3

Takashi Iwai 
ALSA: seq: More protection for concurrent write and ioctl races

Takashi Iwai 
ALSA: seq: Don't allow resizing pool in use

Dennis Wassenberg 
ALSA: hda/realtek - Make dock sound work on ThinkPad L570

Takashi Iwai 
ALSA: hda/realtek - Fix dock line-out volume on Dell Precision 7520

Benjamin Berg 
ALSA: hda/realtek: Limit mic boost on T480

Konrad Rzeszutek Wilk 
x86/spectre_v2: Don't check microcode versions when run

[PATCH 4.9 06/86] drm/i915: Always call to intel_display_set_init_power() in resume_early.

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Maarten Lankhorst 

commit d13a8479f3584613b6aacbb793eae64578b8f69a upstream.

intel_power_domains_init_hw() calls set_init_power, but when using
runtime power management this call is skipped. This prevents hw readout
from taking place.

Signed-off-by: Maarten Lankhorst 
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=104172
Link: 
https://patchwork.freedesktop.org/patch/msgid/20180116155324.75120-1-maarten.lankho...@linux.intel.com
Fixes: bc87229f323e ("drm/i915/skl: enable PC9/10 power states during 
suspend-to-idle")
Cc: Nivedita Swaminathan 
Cc: Imre Deak 
Cc: Patrik Jakobsson 
Cc: Jani Nikula 
Cc: Joonas Lahtinen 
Cc: Rodrigo Vivi 
Cc:  # v4.5+
Reviewed-by: Imre Deak 
(cherry picked from commit ac25dfed15d470d7f23dd817e965b54aa3f94a1e)
Signed-off-by: Rodrigo Vivi 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/i915/i915_drv.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1703,6 +1703,8 @@ static int i915_drm_resume_early(struct
if (IS_BROXTON(dev_priv) ||
!(dev_priv->suspended_to_idle && dev_priv->csr.dmc_payload))
intel_power_domains_init_hw(dev_priv, true);
+   else
+   intel_display_set_init_power(dev_priv, true);
 
enable_rpm_wakeref_asserts(dev_priv);
 




[PATCH 4.9 19/86] MIPS: OCTEON: irq: Check for null return on kzalloc allocation

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

commit 902f4d067a50ccf645a58dd5fb1d113b6e0f9b5b upstream.

The allocation of host_data is not null checked, leading to a null
pointer dereference if the allocation fails. Fix this by adding a null
check and return with -ENOMEM.

Fixes: 64b139f97c01 ("MIPS: OCTEON: irq: add CIB and other fixes")
Signed-off-by: Colin Ian King 
Acked-by: David Daney 
Cc: Ralf Baechle 
Cc: "Steven J. Hill" 
Cc: linux-m...@linux-mips.org
Cc:  # 4.0+
Patchwork: https://patchwork.linux-mips.org/patch/18658/
Signed-off-by: James Hogan 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/cavium-octeon/octeon-irq.c |2 ++
 1 file changed, 2 insertions(+)

--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -2277,6 +2277,8 @@ static int __init octeon_irq_init_cib(st
}
 
host_data = kzalloc(sizeof(*host_data), GFP_KERNEL);
+   if (!host_data)
+   return -ENOMEM;
raw_spin_lock_init(&host_data->lock);
 
addr = of_get_address(ciu_node, 0, NULL, NULL);




[PATCH 4.9 02/86] RDMA/ucma: Check that user doesnt overflow QP state

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Leon Romanovsky 

commit a5880b84430316e3e1c1f5d23aa32ec6000cc717 upstream.

The QP state is limited and declared in enum ib_qp_state,
but ucma user was able to supply any possible (u32) value.

Reported-by: syzbot+0df1ab766f8924b1e...@syzkaller.appspotmail.com
Fixes: 75216638572f ("RDMA/cma: Export rdma cm interface to userspace")
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/infiniband/core/ucma.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1139,6 +1139,9 @@ static ssize_t ucma_init_qp_attr(struct
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
return -EFAULT;
 
+   if (cmd.qp_state > IB_QPS_ERR)
+   return -EINVAL;
+
ctx = ucma_get_ctx(file, cmd.id);
if (IS_ERR(ctx))
return PTR_ERR(ctx);




[PATCH 4.4 39/63] netfilter: bridge: ebt_among: add missing match size checks

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit c4585a2823edf4d1326da44d1524ecbfda26bb37 upstream.

ebt_among is special, it has a dynamic match size and is exempt
from the central size checks.

Therefore it must check that the size of the match structure
provided from userspace is sane by making sure em->match_size
is at least the minimum size of the expected structure.

The module has such a check, but its only done after accessing
a structure that might be out of bounds.

tested with: ebtables -A INPUT ... \
--among-dst fe:fe:fe:fe:fe:fe
--among-dst fe:fe:fe:fe:fe:fe --among-src 
fe:fe:fe:fe:ff:f,fe:fe:fe:fe:fe:fb,fe:fe:fe:fe:fc:fd,fe:fe:fe:fe:fe:fd,fe:fe:fe:fe:fe:fe
--among-src 
fe:fe:fe:fe:ff:f,fe:fe:fe:fe:fe:fa,fe:fe:fe:fe:fe:fd,fe:fe:fe:fe:fe:fe,fe:fe:fe:fe:fe:fe

Reported-by: 
Signed-off-by: Florian Westphal 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/bridge/netfilter/ebt_among.c |   21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

--- a/net/bridge/netfilter/ebt_among.c
+++ b/net/bridge/netfilter/ebt_among.c
@@ -172,18 +172,35 @@ ebt_among_mt(const struct sk_buff *skb,
return true;
 }
 
+static bool poolsize_invalid(const struct ebt_mac_wormhash *w)
+{
+   return w && w->poolsize >= (INT_MAX / sizeof(struct 
ebt_mac_wormhash_tuple));
+}
+
 static int ebt_among_mt_check(const struct xt_mtchk_param *par)
 {
const struct ebt_among_info *info = par->matchinfo;
const struct ebt_entry_match *em =
container_of(par->matchinfo, const struct ebt_entry_match, 
data);
-   int expected_length = sizeof(struct ebt_among_info);
+   unsigned int expected_length = sizeof(struct ebt_among_info);
const struct ebt_mac_wormhash *wh_dst, *wh_src;
int err;
 
+   if (expected_length > em->match_size)
+   return -EINVAL;
+
wh_dst = ebt_among_wh_dst(info);
-   wh_src = ebt_among_wh_src(info);
+   if (poolsize_invalid(wh_dst))
+   return -EINVAL;
+
expected_length += ebt_mac_wormhash_size(wh_dst);
+   if (expected_length > em->match_size)
+   return -EINVAL;
+
+   wh_src = ebt_among_wh_src(info);
+   if (poolsize_invalid(wh_src))
+   return -EINVAL;
+
expected_length += ebt_mac_wormhash_size(wh_src);
 
if (em->match_size != EBT_ALIGN(expected_length)) {




Re: [PATCH v8 42/42] ARM: dts: da850: Add clocks

2018-03-16 Thread David Lechner

On 03/15/2018 09:52 PM, David Lechner wrote:

This adds clock provider nodes for da850 and wires them up to all of the
devices.

Signed-off-by: David Lechner 
---


...

This is the mcasp0: mcasp@10 node...


@@ -560,6 +720,7 @@
dmas = <&edma0 1 1>,
<&edma0 0 1>;
dma-names = "tx", "rx";
+   clocks = <&psc1 7>;


After some testing, it looks like it needs to be:

+   power-domains = <&psc1 7>;

instead of

+   clocks = <&psc1 7>;


};
  
  		lcdc: display@213000 {


[PATCH 4.4 48/63] NFS: Fix an incorrect type in struct nfs_direct_req

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Trond Myklebust 

commit d9ee65539d3eabd9ade46cca1780e3309ad0f907 upstream.

The start offset needs to be of type loff_t.

Fixed: 5fadeb47dcc5c ("nfs: count DIO good bytes correctly with mirroring")
Cc: sta...@vger.kernel.org # v4.0+
Signed-off-by: Trond Myklebust 
Signed-off-by: Greg Kroah-Hartman 

---
 fs/nfs/direct.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -86,9 +86,9 @@ struct nfs_direct_req {
struct nfs_direct_mirror mirrors[NFS_PAGEIO_DESCRIPTOR_MIRROR_MAX];
int mirror_count;
 
+   loff_t  io_start;   /* Start offset for I/O */
ssize_t count,  /* bytes actually processed */
bytes_left, /* bytes left to be sent */
-   io_start,   /* start of IO */
error;  /* any reported error */
struct completion   completion; /* wait for i/o completion */
 




[tip:perf/core 1/2] drivers//perf/qcom_l2_pmu.c:598:13: error: invalid storage class for function 'l2_cache_event_start'

2018-03-16 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf/core
head:   bbb68468641547d56c83012670bcaf77f3dacd64
commit: 7eb709f29593aced51901cb53565477762800722 [1/2] perf: Fix sibling 
iteration
config: arm64-allyesconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 7eb709f29593aced51901cb53565477762800722
# save the attached .config to linux build tree
make.cross ARCH=arm64 

All error/warnings (new ones prefixed by >>):

   drivers//perf/qcom_l2_pmu.c: In function 'l2_cache_event_init':
>> drivers//perf/qcom_l2_pmu.c:598:13: error: invalid storage class for 
>> function 'l2_cache_event_start'
static void l2_cache_event_start(struct perf_event *event, int flags)
^~~~
>> drivers//perf/qcom_l2_pmu.c:598:1: warning: ISO C90 forbids mixed 
>> declarations and code [-Wdeclaration-after-statement]
static void l2_cache_event_start(struct perf_event *event, int flags)
^~
>> drivers//perf/qcom_l2_pmu.c:629:13: error: invalid storage class for 
>> function 'l2_cache_event_stop'
static void l2_cache_event_stop(struct perf_event *event, int flags)
^~~
>> drivers//perf/qcom_l2_pmu.c:645:12: error: invalid storage class for 
>> function 'l2_cache_event_add'
static int l2_cache_event_add(struct perf_event *event, int flags)
   ^~
>> drivers//perf/qcom_l2_pmu.c:672:13: error: invalid storage class for 
>> function 'l2_cache_event_del'
static void l2_cache_event_del(struct perf_event *event, int flags)
^~
>> drivers//perf/qcom_l2_pmu.c:687:13: error: invalid storage class for 
>> function 'l2_cache_event_read'
static void l2_cache_event_read(struct perf_event *event)
^~~
>> drivers//perf/qcom_l2_pmu.c:692:16: error: invalid storage class for 
>> function 'l2_cache_pmu_cpumask_show'
static ssize_t l2_cache_pmu_cpumask_show(struct device *dev,
   ^
   In file included from include/linux/kobject.h:20:0,
from include/linux/device.h:16,
from include/linux/acpi.h:27,
from drivers//perf/qcom_l2_pmu.c:12:
>> drivers//perf/qcom_l2_pmu.c:702:28: error: initializer element is not 
>> constant
  __ATTR(cpumask, S_IRUGO, l2_cache_pmu_cpumask_show, NULL);
   ^
   include/linux/sysfs.h:104:10: note: in definition of macro '__ATTR'
 .show = _show,  \
 ^
   drivers//perf/qcom_l2_pmu.c:702:28: note: (near initialization for 
'l2_cache_pmu_cpumask_attr.show')
  __ATTR(cpumask, S_IRUGO, l2_cache_pmu_cpumask_show, NULL);
   ^
   include/linux/sysfs.h:104:10: note: in definition of macro '__ATTR'
 .show = _show,  \
 ^
   In file included from drivers//perf/qcom_l2_pmu.c:24:0:
>> drivers//perf/qcom_l2_pmu.c:714:17: error: invalid storage class for 
>> function 'l2_code_show'
PMU_FORMAT_ATTR(l2_code,   "config:4-11");
^
   include/linux/perf_event.h:1377:1: note: in definition of macro 
'PMU_FORMAT_ATTR'
_name##_show(struct device *dev, \
^
   In file included from include/linux/kobject.h:20:0,
from include/linux/device.h:16,
from include/linux/acpi.h:27,
from drivers//perf/qcom_l2_pmu.c:12:
   drivers//perf/qcom_l2_pmu.c:714:17: error: initializer element is not 
constant
PMU_FORMAT_ATTR(l2_code,   "config:4-11");
^
   include/linux/sysfs.h:117:10: note: in definition of macro '__ATTR_RO'
 .show = _name##_show,  \
 ^
>> drivers//perf/qcom_l2_pmu.c:714:1: note: in expansion of macro 
>> 'PMU_FORMAT_ATTR'
PMU_FORMAT_ATTR(l2_code,   "config:4-11");
^~~
   drivers//perf/qcom_l2_pmu.c:714:17: note: (near initialization for 
'format_attr_l2_code.show')
PMU_FORMAT_ATTR(l2_code,   "config:4-11");
^
   include/linux/sysfs.h:117:10: note: in definition of macro '__ATTR_RO'
 .show = _name##_show,  \
 ^
>> drivers//perf/qcom_l2_pmu.c:714:1: note: in expansion of macro 
>> 'PMU_FORMAT_ATTR'
PMU_FORMAT_ATTR(l2_code,   "config:4-11");
^~~
   In file included from drivers//perf/qcom_l2_pmu.c:24:0:
>> drivers//perf/qcom_l2_pmu.c:715:17: error: invalid storage class for 
>> function 'l2_group_show'
PMU_FORMAT_ATTR(l2_group,  "config:0-3");
^
   include/linux/perf_event.h:1377:1: note: in definition of macro 
'PMU_FORMAT_ATTR'
_name##_show(struct device *dev, \
^
   In file included from include/linux/kobject.h:20:0,
from include/linux/device

[PATCH 4.9 01/86] RDMA/ucma: Limit possible option size

2018-03-16 Thread Greg Kroah-Hartman
4.9-stable review patch.  If anyone has any objections, please let me know.

--

From: Leon Romanovsky 

commit 6a21dfc0d0db7b7e0acedce67ca533a6eb19283c upstream.

Users of ucma are supposed to provide size of option level,
in most paths it is supposed to be equal to u8 or u16, but
it is not the case for the IB path record, where it can be
multiple of struct ib_path_rec_data.

This patch takes simplest possible approach and prevents providing
values more than possible to allocate.

Reported-by: syzbot+a38b0e9f694c379ca...@syzkaller.appspotmail.com
Fixes: 7ce86409adcd ("RDMA/ucma: Allow user space to set service type")
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/infiniband/core/ucma.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1275,6 +1275,9 @@ static ssize_t ucma_set_option(struct uc
if (IS_ERR(ctx))
return PTR_ERR(ctx);
 
+   if (unlikely(cmd.optval > KMALLOC_MAX_SIZE))
+   return -EINVAL;
+
optval = memdup_user((void __user *) (unsigned long) cmd.optval,
 cmd.optlen);
if (IS_ERR(optval)) {




[PATCH 4.4 46/63] ubi: Fix race condition between ubi volume creation and udev

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Clay McClure 

commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream.

Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi
device creation and udev"), we should make the volume active before
registering it.

Signed-off-by: Clay McClure 
Cc: 
Signed-off-by: Richard Weinberger 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/mtd/ubi/vmt.c |   15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -265,6 +265,12 @@ int ubi_create_volume(struct ubi_device
vol->last_eb_bytes = vol->usable_leb_size;
}
 
+   /* Make volume "available" before it becomes accessible via sysfs */
+   spin_lock(&ubi->volumes_lock);
+   ubi->volumes[vol_id] = vol;
+   ubi->vol_count += 1;
+   spin_unlock(&ubi->volumes_lock);
+
/* Register character device for the volume */
cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
vol->cdev.owner = THIS_MODULE;
@@ -304,11 +310,6 @@ int ubi_create_volume(struct ubi_device
if (err)
goto out_sysfs;
 
-   spin_lock(&ubi->volumes_lock);
-   ubi->volumes[vol_id] = vol;
-   ubi->vol_count += 1;
-   spin_unlock(&ubi->volumes_lock);
-
ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED);
self_check_volumes(ubi);
return err;
@@ -328,6 +329,10 @@ out_sysfs:
 out_cdev:
cdev_del(&vol->cdev);
 out_mapping:
+   spin_lock(&ubi->volumes_lock);
+   ubi->volumes[vol_id] = NULL;
+   ubi->vol_count -= 1;
+   spin_unlock(&ubi->volumes_lock);
if (do_free)
kfree(vol->eba_tbl);
 out_acc:




[PATCH 4.4 43/63] netfilter: x_tables: pass xt_counters struct to counter allocator

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit f28e15bacedd444608e25421c72eb2cf4527c9ca upstream.

Keeps some noise away from a followup patch.

Signed-off-by: Florian Westphal 
Acked-by: Eric Dumazet 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/netfilter/x_tables.h |   27 +--
 net/ipv4/netfilter/arp_tables.c|5 +
 net/ipv4/netfilter/ip_tables.c |5 +
 net/ipv6/netfilter/ip6_tables.c|5 +
 net/netfilter/x_tables.c   |   30 ++
 5 files changed, 34 insertions(+), 38 deletions(-)

--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -369,32 +369,7 @@ static inline unsigned long ifname_compa
 }
 
 
-/* On SMP, ip(6)t_entry->counters.pcnt holds address of the
- * real (percpu) counter.  On !SMP, its just the packet count,
- * so nothing needs to be done there.
- *
- * xt_percpu_counter_alloc returns the address of the percpu
- * counter, or 0 on !SMP. We force an alignment of 16 bytes
- * so that bytes/packets share a common cache line.
- *
- * Hence caller must use IS_ERR_VALUE to check for error, this
- * allows us to return 0 for single core systems without forcing
- * callers to deal with SMP vs. NONSMP issues.
- */
-static inline unsigned long xt_percpu_counter_alloc(void)
-{
-   if (nr_cpu_ids > 1) {
-   void __percpu *res = __alloc_percpu(sizeof(struct xt_counters),
-   sizeof(struct xt_counters));
-
-   if (res == NULL)
-   return -ENOMEM;
-
-   return (__force unsigned long) res;
-   }
-
-   return 0;
-}
+bool xt_percpu_counter_alloc(struct xt_counters *counters);
 void xt_percpu_counter_free(struct xt_counters *cnt);
 
 static inline struct xt_counters *
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -515,13 +515,10 @@ find_check_entry(struct arpt_entry *e, c
 {
struct xt_entry_target *t;
struct xt_target *target;
-   unsigned long pcnt;
int ret;
 
-   pcnt = xt_percpu_counter_alloc();
-   if (IS_ERR_VALUE(pcnt))
+   if (!xt_percpu_counter_alloc(&e->counters))
return -ENOMEM;
-   e->counters.pcnt = pcnt;
 
t = arpt_get_target(e);
target = xt_request_find_target(NFPROTO_ARP, t->u.user.name,
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -657,12 +657,9 @@ find_check_entry(struct ipt_entry *e, st
unsigned int j;
struct xt_mtchk_param mtpar;
struct xt_entry_match *ematch;
-   unsigned long pcnt;
 
-   pcnt = xt_percpu_counter_alloc();
-   if (IS_ERR_VALUE(pcnt))
+   if (!xt_percpu_counter_alloc(&e->counters))
return -ENOMEM;
-   e->counters.pcnt = pcnt;
 
j = 0;
mtpar.net   = net;
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -670,12 +670,9 @@ find_check_entry(struct ip6t_entry *e, s
unsigned int j;
struct xt_mtchk_param mtpar;
struct xt_entry_match *ematch;
-   unsigned long pcnt;
 
-   pcnt = xt_percpu_counter_alloc();
-   if (IS_ERR_VALUE(pcnt))
+   if (!xt_percpu_counter_alloc(&e->counters))
return -ENOMEM;
-   e->counters.pcnt = pcnt;
 
j = 0;
mtpar.net   = net;
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1592,6 +1592,36 @@ void xt_proto_fini(struct net *net, u_in
 }
 EXPORT_SYMBOL_GPL(xt_proto_fini);
 
+/**
+ * xt_percpu_counter_alloc - allocate x_tables rule counter
+ *
+ * @counter: pointer to counter struct inside the ip(6)/arpt_entry struct
+ *
+ * On SMP, the packet counter [ ip(6)t_entry->counters.pcnt ] will then
+ * contain the address of the real (percpu) counter.
+ *
+ * Rule evaluation needs to use xt_get_this_cpu_counter() helper
+ * to fetch the real percpu counter.
+ *
+ * returns false on error.
+ */
+bool xt_percpu_counter_alloc(struct xt_counters *counter)
+{
+   void __percpu *res;
+
+   if (nr_cpu_ids <= 1)
+   return true;
+
+   res = __alloc_percpu(sizeof(struct xt_counters),
+sizeof(struct xt_counters));
+   if (!res)
+   return false;
+
+   counter->pcnt = (__force unsigned long)res;
+   return true;
+}
+EXPORT_SYMBOL_GPL(xt_percpu_counter_alloc);
+
 void xt_percpu_counter_free(struct xt_counters *counters)
 {
unsigned long pcnt = counters->pcnt;




[PATCH 4.4 42/63] netfilter: x_tables: pass xt_counters struct instead of packet counter

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit 4d31eef5176df06f218201bc9c0ce40babb41660 upstream.

On SMP we overload the packet counter (unsigned long) to contain
percpu offset.  Hide this from callers and pass xt_counters address
instead.

Preparation patch to allocate the percpu counters in page-sized batch
chunks.

Signed-off-by: Florian Westphal 
Acked-by: Eric Dumazet 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/netfilter/x_tables.h |6 +-
 net/ipv4/netfilter/arp_tables.c|4 ++--
 net/ipv4/netfilter/ip_tables.c |4 ++--
 net/ipv6/netfilter/ip6_tables.c|5 ++---
 net/netfilter/x_tables.c   |9 +
 5 files changed, 16 insertions(+), 12 deletions(-)

--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -395,11 +395,7 @@ static inline unsigned long xt_percpu_co
 
return 0;
 }
-static inline void xt_percpu_counter_free(u64 pcnt)
-{
-   if (nr_cpu_ids > 1)
-   free_percpu((void __percpu *) (unsigned long) pcnt);
-}
+void xt_percpu_counter_free(struct xt_counters *cnt);
 
 static inline struct xt_counters *
 xt_get_this_cpu_counter(struct xt_counters *cnt)
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -540,7 +540,7 @@ find_check_entry(struct arpt_entry *e, c
 err:
module_put(t->u.kernel.target->me);
 out:
-   xt_percpu_counter_free(e->counters.pcnt);
+   xt_percpu_counter_free(&e->counters);
 
return ret;
 }
@@ -628,7 +628,7 @@ static inline void cleanup_entry(struct
if (par.target->destroy != NULL)
par.target->destroy(&par);
module_put(par.target->me);
-   xt_percpu_counter_free(e->counters.pcnt);
+   xt_percpu_counter_free(&e->counters);
 }
 
 /* Checks and translates the user-supplied table segment (held in
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -701,7 +701,7 @@ find_check_entry(struct ipt_entry *e, st
cleanup_match(ematch, net);
}
 
-   xt_percpu_counter_free(e->counters.pcnt);
+   xt_percpu_counter_free(&e->counters);
 
return ret;
 }
@@ -797,7 +797,7 @@ cleanup_entry(struct ipt_entry *e, struc
if (par.target->destroy != NULL)
par.target->destroy(&par);
module_put(par.target->me);
-   xt_percpu_counter_free(e->counters.pcnt);
+   xt_percpu_counter_free(&e->counters);
 }
 
 /* Checks and translates the user-supplied table segment (held in
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -713,7 +713,7 @@ find_check_entry(struct ip6t_entry *e, s
cleanup_match(ematch, net);
}
 
-   xt_percpu_counter_free(e->counters.pcnt);
+   xt_percpu_counter_free(&e->counters);
 
return ret;
 }
@@ -808,8 +808,7 @@ static void cleanup_entry(struct ip6t_en
if (par.target->destroy != NULL)
par.target->destroy(&par);
module_put(par.target->me);
-
-   xt_percpu_counter_free(e->counters.pcnt);
+   xt_percpu_counter_free(&e->counters);
 }
 
 /* Checks and translates the user-supplied table segment (held in
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -1592,6 +1592,15 @@ void xt_proto_fini(struct net *net, u_in
 }
 EXPORT_SYMBOL_GPL(xt_proto_fini);
 
+void xt_percpu_counter_free(struct xt_counters *counters)
+{
+   unsigned long pcnt = counters->pcnt;
+
+   if (nr_cpu_ids > 1)
+   free_percpu((void __percpu *)pcnt);
+}
+EXPORT_SYMBOL_GPL(xt_percpu_counter_free);
+
 static int __net_init xt_net_init(struct net *net)
 {
int i;




[PATCH 4.4 44/63] netfilter: x_tables: pack percpu counter allocations

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit ae0ac0ed6fcf5af3be0f63eb935f483f44a402d2 upstream.

instead of allocating each xt_counter individually, allocate 4k chunks
and then use these for counter allocation requests.

This should speed up rule evaluation by increasing data locality,
also speeds up ruleset loading because we reduce calls to the percpu
allocator.

As Eric points out we can't use PAGE_SIZE, page_allocator would fail on
arches with 64k page size.

Suggested-by: Eric Dumazet 
Signed-off-by: Florian Westphal 
Acked-by: Eric Dumazet 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/netfilter/x_tables.h |7 ++-
 net/ipv4/netfilter/arp_tables.c|9 ++---
 net/ipv4/netfilter/ip_tables.c |9 ++---
 net/ipv6/netfilter/ip6_tables.c|9 ++---
 net/netfilter/x_tables.c   |   34 +-
 5 files changed, 49 insertions(+), 19 deletions(-)

--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -368,8 +368,13 @@ static inline unsigned long ifname_compa
return ret;
 }
 
+struct xt_percpu_counter_alloc_state {
+   unsigned int off;
+   const char __percpu *mem;
+};
 
-bool xt_percpu_counter_alloc(struct xt_counters *counters);
+bool xt_percpu_counter_alloc(struct xt_percpu_counter_alloc_state *state,
+struct xt_counters *counter);
 void xt_percpu_counter_free(struct xt_counters *cnt);
 
 static inline struct xt_counters *
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -511,13 +511,14 @@ static inline int check_target(struct ar
 }
 
 static inline int
-find_check_entry(struct arpt_entry *e, const char *name, unsigned int size)
+find_check_entry(struct arpt_entry *e, const char *name, unsigned int size,
+struct xt_percpu_counter_alloc_state *alloc_state)
 {
struct xt_entry_target *t;
struct xt_target *target;
int ret;
 
-   if (!xt_percpu_counter_alloc(&e->counters))
+   if (!xt_percpu_counter_alloc(alloc_state, &e->counters))
return -ENOMEM;
 
t = arpt_get_target(e);
@@ -634,6 +635,7 @@ static inline void cleanup_entry(struct
 static int translate_table(struct xt_table_info *newinfo, void *entry0,
   const struct arpt_replace *repl)
 {
+   struct xt_percpu_counter_alloc_state alloc_state = { 0 };
struct arpt_entry *iter;
unsigned int *offsets;
unsigned int i;
@@ -707,7 +709,8 @@ static int translate_table(struct xt_tab
/* Finally, each sanity check must pass */
i = 0;
xt_entry_foreach(iter, entry0, newinfo->size) {
-   ret = find_check_entry(iter, repl->name, repl->size);
+   ret = find_check_entry(iter, repl->name, repl->size,
+  &alloc_state);
if (ret != 0)
break;
++i;
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -649,7 +649,8 @@ static int check_target(struct ipt_entry
 
 static int
 find_check_entry(struct ipt_entry *e, struct net *net, const char *name,
-unsigned int size)
+unsigned int size,
+struct xt_percpu_counter_alloc_state *alloc_state)
 {
struct xt_entry_target *t;
struct xt_target *target;
@@ -658,7 +659,7 @@ find_check_entry(struct ipt_entry *e, st
struct xt_mtchk_param mtpar;
struct xt_entry_match *ematch;
 
-   if (!xt_percpu_counter_alloc(&e->counters))
+   if (!xt_percpu_counter_alloc(alloc_state, &e->counters))
return -ENOMEM;
 
j = 0;
@@ -803,6 +804,7 @@ static int
 translate_table(struct net *net, struct xt_table_info *newinfo, void *entry0,
const struct ipt_replace *repl)
 {
+   struct xt_percpu_counter_alloc_state alloc_state = { 0 };
struct ipt_entry *iter;
unsigned int *offsets;
unsigned int i;
@@ -872,7 +874,8 @@ translate_table(struct net *net, struct
/* Finally, each sanity check must pass */
i = 0;
xt_entry_foreach(iter, entry0, newinfo->size) {
-   ret = find_check_entry(iter, net, repl->name, repl->size);
+   ret = find_check_entry(iter, net, repl->name, repl->size,
+  &alloc_state);
if (ret != 0)
break;
++i;
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -662,7 +662,8 @@ static int check_target(struct ip6t_entr
 
 static int
 find_check_entry(struct ip6t_entry *e, struct net *net, const char *name,
-unsigned int size)
+unsigned int size,
+struct xt_percpu_counter_alloc_state *alloc_state)
 {
struct xt_entry_tar

Re: [PATCH v6 0/5] Add coupled regulators mechanism

2018-03-16 Thread Tony Lindgren
* Maciej Purski  [180312 12:24]:
> On 03/09/2018 04:58 PM, Tony Lindgren wrote:
> > * Mark Brown  [180309 12:43]:
> > > On Fri, Mar 09, 2018 at 01:22:02PM +0100, Maciej Purski wrote:
> > > 
> > > > I would like to kindly ask Fabio Estevam and Tony Lindgren to test the 
> > > > patch
> > > > series on their boards.
> > 
> > I gave it a quick try and this set still causes at least mmc0
> > to fail for me.
>
> Thanks. Here's a small patch, which adds some debugs. Maybe they will reveal,
> where the problem is.

Sorry for the delay, now back from ELC. I tried applying this on
top of Linux next + your six patches but it fails to apply. Do
I need something else too?

Regards,

Tony


> diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
> index f1f11cf..0e80ba5 100644
> --- a/drivers/regulator/core.c
> +++ b/drivers/regulator/core.c
> @@ -2280,7 +2280,6 @@ int regulator_enable(struct regulator *regulator)
>  {
>   struct regulator_dev *rdev = regulator->rdev;
>   int ret = 0;
> - int ret2;
> 
>   if (rdev->coupling_desc.n_resolved != rdev->coupling_desc.n_coupled) {
>   rdev_err(rdev, "not all coupled regulators registered\n");
> @@ -2298,15 +2297,9 @@ int regulator_enable(struct regulator *regulator)
> 
>   regulator_lock_dependent(rdev);
>   ret = _regulator_enable(rdev);
> - ret2 = regulator_balance_voltage(rdev, PM_SUSPEND_ON);
> + regulator_balance_voltage(rdev, PM_SUSPEND_ON);
>   regulator_unlock_dependent(rdev);
> 
> - if (ret2 != 0) {
> - rdev_err(rdev,
> - "balancing failed when trying to enable regulator: %d",
> - ret2);
> - }
> -
>   if (ret != 0 && rdev->supply)
>   regulator_disable(rdev->supply);
> 
> @@ -3149,7 +3142,7 @@ static int regulator_set_voltage_rdev(struct 
> regulator_dev *rdev, int min_uV,
>   ret = regulator_set_voltage_unlocked(rdev->supply,
>   best_supply_uV, INT_MAX, state);
>   if (ret)
> - dev_err(&rdev->dev, "Failed to decrease supply voltage: 
> %d\n",
> + dev_warn(&rdev->dev, "Failed to decrease supply 
> voltage: %d\n",
>   ret);
>   /* No need to fail here */
>   ret = 0;
> @@ -3332,11 +3325,8 @@ static int regulator_balance_voltage(struct 
> regulator_dev *rdev,
>   ret = regulator_set_voltage_rdev(best_rdev, best_uV,
>best_uV, state);
> 
> - if (ret < 0) {
> - rdev_err(rdev,
> - "Failed to set voltage with error: %d", ret);
> + if (ret < 0)
>   goto out;
> - }
>   }
> 
>  out:
> 
> 


Re: [PATCH 0/2] net: phy: relax error checking when creating sysfs link netdev->phydev

2018-03-16 Thread Andrew Lunn
On Wed, Mar 14, 2018 at 05:26:22PM -0500, Grygorii Strashko wrote:
> Some ethernet drivers (like TI CPSW) may connect and manage >1 Net PHYs per
> one netdevice, as result such drivers will produce warning during system
> boot and fail to connect second phy to netdevice when PHYLIB framework
> will try to create sysfs link netdev->phydev for second PHY
> in phy_attach_direct(), because sysfs link with the same name has been
> created already for the first PHY.
> As result, second CPSW external port will became unusable.
> This issue was introduced by commits:
> 5568363f0cb3 ("net: phy: Create sysfs reciprocal links for 
> attached_dev/phydev"
> a3995460491d ("net: phy: Relax error checking on sysfs_create_link()"

I wonder if it would be better to add a flag to the phydev that
indicates it is the second PHY connected to a MAC? Add a bit to
phydrv->mdiodrv.flags. If that bit is set, don't create the sysfs
file.

For 99% of MAC drivers, having two PHYs is an error, so we want to aid
debug by reporting the sysfs error.

  Andrew


Re: [PATCH 8/9] x86/dumpstack: Save first regs set for the executive summary

2018-03-16 Thread Linus Torvalds
On Fri, Mar 16, 2018 at 4:48 AM, Borislav Petkov  wrote:
> On Thu, Mar 15, 2018 at 02:01:32PM -0500, Josh Poimboeuf wrote:
>> no_context() has the following line, right before it calls oops_end():
>>
>>   /* Executive summary in case the body of the oops scrolled away */
>>   printk(KERN_DEFAULT "CR2: %016lx\n", address);
>>
>> I think that line can now be removed, since the executive summary
>> __show_regs() will include CR2.
>
> Good idea. Done.

N!

Guys, %cr2 CAN AND DOES CHANGE!

The reason we do that

printk(KERN_DEFAULT "CR2: %016lx\n", address);

is because WE ARE NOT PRINTING OUT THE CURRENT CR2 REGISTER!

This is really damn important.

The "address" register contains the CR2 value as it was read *very*
early in the page fault case, before we enabled interrupts, and before
we did various random things that can cause further page faults and
change CR2!

So the executive summary that does __show_regs() may end up showing
something completely different than the actual faulting address,
because we might have taken a vmalloc-space exception in the meantime,
for example.

Do *NOT* get rid of that thing.

You're better off getting rid of the CR2 line from __show_regs(),
because it can be dangerously confusing. It's not actually part of the
saved register state at all, it's something entirely different. It's
like showing the current eflags rather than the eflags saved on the
faulting stack.

 Linus


Re: [RESEND PATCH v2] sched/fair: Remove check in idle_balance against migration_cost

2018-03-16 Thread Rohit Jain

Hi Peter,

On 03/16/2018 07:35 AM, Peter Zijlstra wrote:

On Wed, Mar 14, 2018 at 11:36:47AM -0700, Rohit Jain wrote:

Signed-off-by: Rohit Jain 

Signed-off-by: Rohit Jain 

Surely you only need a single on of those.


Oh wow! I don't know how I missed this :) Thanks!


---
  kernel/sched/fair.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index 5eb3ffc..569ea83 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -8804,8 +8804,7 @@ static int idle_balance(struct rq *this_rq, struct 
rq_flags *rf)
 */
rq_unpin_lock(this_rq, rf);
  
-	if (this_rq->avg_idle < sysctl_sched_migration_cost ||

-   !this_rq->rd->overload) {
+   if (!this_rq->rd->overload) {
rcu_read_lock();
sd = rcu_dereference_check_sched_domain(this_rq->sd);
if (sd)

I don't think that actually works right on the current tree. In
particular look at commit:

   31e77c93e432 ("sched/fair: Update blocked load when newly idle")


OK. I see from LKML the code has moved.

However, when I clone from 
https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/

I cannot see the commit.


[PATCH 4.4 61/63] usb: gadget: f_fs: Fix use-after-free in ffs_fs_kill_sb()

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Xinyong 

commit 1a087f032111a88e826877449dfb93ceb22b78b9 upstream.

When I debug a kernel crash issue in funcitonfs, found ffs_data.ref
overflowed, While functionfs is unmounting, ffs_data is put twice.

Commit 43938613c6fd ("drivers, usb: convert ffs_data.ref from atomic_t to
refcount_t") can avoid refcount overflow, but that is risk some situations.
So no need put ffs data in ffs_fs_kill_sb, already put in ffs_data_closed.

The issue can be reproduced in Mediatek mt6763 SoC, ffs for ADB device.
KASAN enabled configuration reports use-after-free errro.

BUG: KASAN: use-after-free in refcount_dec_and_test+0x14/0xe0 at addr 
ffc0579386a0
Read of size 4 by task umount/4650

BUG kmalloc-512 (Tainted: PW  O   ): kasan: bad access detected
-

INFO: Allocated in ffs_fs_mount+0x194/0x844 age=22856 cpu=2 pid=566
alloc_debug_processing+0x1ac/0x1e8
___slab_alloc.constprop.63+0x640/0x648
__slab_alloc.isra.57.constprop.62+0x24/0x34
kmem_cache_alloc_trace+0x1a8/0x2bc
ffs_fs_mount+0x194/0x844
mount_fs+0x6c/0x1d0
vfs_kern_mount+0x50/0x1b4
do_mount+0x258/0x1034
INFO: Freed in ffs_data_put+0x25c/0x320 age=0 cpu=3 pid=4650
free_debug_processing+0x22c/0x434
__slab_free+0x2d8/0x3a0
kfree+0x254/0x264
ffs_data_put+0x25c/0x320
ffs_data_closed+0x124/0x15c
ffs_fs_kill_sb+0xb8/0x110
deactivate_locked_super+0x6c/0x98
deactivate_super+0xb0/0xbc
INFO: Object 0xffc057938600 @offset=1536 fp=0x  (null)
..
Call trace:
[] dump_backtrace+0x0/0x250
[] show_stack+0x14/0x1c
[] dump_stack+0xa0/0xc8
[] print_trailer+0x158/0x260
[] object_err+0x3c/0x40
[] kasan_report_error+0x2a8/0x754
[] kasan_report+0x5c/0x60
[] __asan_load4+0x70/0x88
[] refcount_dec_and_test+0x14/0xe0
[] ffs_data_put+0x80/0x320
[] ffs_fs_kill_sb+0xc8/0x110
[] deactivate_locked_super+0x6c/0x98
[] deactivate_super+0xb0/0xbc
[] cleanup_mnt+0x64/0xec
[] __cleanup_mnt+0x10/0x18
[] task_work_run+0xcc/0x124
[] do_notify_resume+0x60/0x70
[] work_pending+0x10/0x14

Cc: sta...@vger.kernel.org
Signed-off-by: Xinyong 
Signed-off-by: Felipe Balbi 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/gadget/function/f_fs.c |1 -
 1 file changed, 1 deletion(-)

--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -1333,7 +1333,6 @@ ffs_fs_kill_sb(struct super_block *sb)
if (sb->s_fs_info) {
ffs_release_dev(sb->s_fs_info);
ffs_data_closed(sb->s_fs_info);
-   ffs_data_put(sb->s_fs_info);
}
 }
 




[PATCH 4.4 62/63] serial: 8250_pci: Add Brainboxes UC-260 4 port serial device

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Nikola Ciprich 

commit 9f2068f35729948bde84d87a40d135015911345d upstream.

Add PCI ids for two variants of Brainboxes UC-260 quad port
PCI serial cards.

Suggested-by: Andy Shevchenko 
Signed-off-by: Nikola Ciprich 
Cc: stable 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/tty/serial/8250/8250_pci.c |   11 +++
 1 file changed, 11 insertions(+)

--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -5300,6 +5300,17 @@ static struct pci_device_id serial_pci_t
PCI_ANY_ID, PCI_ANY_ID, 0, 0,/* 135a.0dc0 */
pbn_b2_4_115200 },
/*
+* BrainBoxes UC-260
+*/
+   {   PCI_VENDOR_ID_INTASHIELD, 0x0D21,
+   PCI_ANY_ID, PCI_ANY_ID,
+   PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0x00,
+   pbn_b2_4_115200 },
+   {   PCI_VENDOR_ID_INTASHIELD, 0x0E34,
+   PCI_ANY_ID, PCI_ANY_ID,
+PCI_CLASS_COMMUNICATION_MULTISERIAL << 8, 0x00,
+   pbn_b2_4_115200 },
+   /*
 * Perle PCI-RAS cards
 */
{   PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,




[PATCH 4.4 63/63] fixup: sctp: verify size of a new chunk in _sctp_make_chunk()

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Greg Kroah-Hartman 

Ben writes:
> > +   int chunklen;
> > +
> > +   chunklen = sizeof(*chunk_hdr) + paylen;
> 
> I think this length still needs to be rounded up (with WORD_ROUND here,
> instead of SCTP_PAD4 upstream).

So here's a fix for this problem.


Reported-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 

---
 net/sctp/sm_make_chunk.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1369,7 +1369,7 @@ static struct sctp_chunk *_sctp_make_chu
struct sock *sk;
int chunklen;
 
-   chunklen = sizeof(*chunk_hdr) + paylen;
+   chunklen = WORD_ROUND(sizeof(*chunk_hdr) + paylen);
if (chunklen > SCTP_MAX_CHUNK_LEN)
goto nodata;
 




[PATCH 4.4 59/63] USB: usbmon: remove assignment from IS_ERR argument

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Julia Lawall 

commit 46c236dc7d1212d7417e6fb0317f91c44c719322 upstream.

The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)

// 
@@
expression e1,e2;
statement S1,S2;
@@

+e1 = e2;
if (IS_ERR(
e1
-   = e2
   )) S1 else S2
// 

Signed-off-by: Julia Lawall 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/mon/mon_text.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -386,7 +386,8 @@ static ssize_t mon_text_read_t(struct fi
struct mon_event_text *ep;
struct mon_text_ptr ptr;
 
-   if (IS_ERR(ep = mon_text_read_wait(rp, file)))
+   ep = mon_text_read_wait(rp, file);
+   if (IS_ERR(ep))
return PTR_ERR(ep);
mutex_lock(&rp->printf_lock);
ptr.cnt = 0;
@@ -413,7 +414,8 @@ static ssize_t mon_text_read_u(struct fi
struct mon_event_text *ep;
struct mon_text_ptr ptr;
 
-   if (IS_ERR(ep = mon_text_read_wait(rp, file)))
+   ep = mon_text_read_wait(rp, file);
+   if (IS_ERR(ep))
return PTR_ERR(ep);
mutex_lock(&rp->printf_lock);
ptr.cnt = 0;




[PATCH 4.4 58/63] usb: quirks: add control message delay for 1b1c:1b20

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Danilo Krummrich 

commit cb88a0588717ba6c756cb5972d75766b273a6817 upstream.

Corsair Strafe RGB keyboard does not respond to usb control messages
sometimes and hence generates timeouts.

Commit de3af5bf259d ("usb: quirks: add delay init quirk for Corsair
Strafe RGB keyboard") tried to fix those timeouts by adding
USB_QUIRK_DELAY_INIT.

Unfortunately, even with this quirk timeouts of usb_control_msg()
can still be seen, but with a lower frequency (approx. 1 out of 15):

[   29.103520] usb 1-8: string descriptor 0 read error: -110
[   34.363097] usb 1-8: can't set config #1, error -110

Adding further delays to different locations where usb control
messages are issued just moves the timeouts to other locations,
e.g.:

[   35.400533] usbhid 1-8:1.0: can't add hid device: -110
[   35.401014] usbhid: probe of 1-8:1.0 failed with error -110

The only way to reliably avoid those issues is having a pause after
each usb control message. In approx. 200 boot cycles no more timeouts
were seen.

Addionaly, keep USB_QUIRK_DELAY_INIT as it turned out to be necessary
to have the delay in hub_port_connect() after hub_port_init().

The overall boot time seems not to be influenced by these additional
delays, even on fast machines and lightweight distributions.

Fixes: de3af5bf259d ("usb: quirks: add delay init quirk for Corsair Strafe RGB 
keyboard")
Cc: sta...@vger.kernel.org
Signed-off-by: Danilo Krummrich 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/core/message.c |4 
 drivers/usb/core/quirks.c  |3 ++-
 include/linux/usb/quirks.h |3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)

--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -147,6 +147,10 @@ int usb_control_msg(struct usb_device *d
 
ret = usb_internal_control_msg(dev, pipe, dr, data, size, timeout);
 
+   /* Linger a bit, prior to the next control message. */
+   if (dev->quirks & USB_QUIRK_DELAY_CTRL_MSG)
+   msleep(200);
+
kfree(dr);
 
return ret;
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -229,7 +229,8 @@ static const struct usb_device_id usb_qu
{ USB_DEVICE(0x1b1c, 0x1b13), .driver_info = USB_QUIRK_DELAY_INIT },
 
/* Corsair Strafe RGB */
-   { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT },
+   { USB_DEVICE(0x1b1c, 0x1b20), .driver_info = USB_QUIRK_DELAY_INIT |
+ USB_QUIRK_DELAY_CTRL_MSG },
 
/* Corsair K70 LUX */
{ USB_DEVICE(0x1b1c, 0x1b36), .driver_info = USB_QUIRK_DELAY_INIT },
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -56,4 +56,7 @@
  */
 #define USB_QUIRK_LINEAR_FRAME_INTR_BINTERVAL  BIT(11)
 
+/* Device needs a pause after every control message. */
+#define USB_QUIRK_DELAY_CTRL_MSG   BIT(13)
+
 #endif /* __LINUX_USB_QUIRKS_H */




[PATCH 4.4 57/63] USB: storage: Add JMicron bridge 152d:2567 to unusual_devs.h

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Teijo Kinnunen 

commit 5126a504b63d82785eaece3a9c30c660b313785a upstream.

This USB-SATA controller seems to be similar with JMicron bridge
152d:2566 already on the list. Adding it here fixes "Invalid
field in cdb" errors.

Signed-off-by: Teijo Kinnunen 
Cc: sta...@vger.kernel.org
Acked-by: Alan Stern 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/storage/unusual_devs.h |7 +++
 1 file changed, 7 insertions(+)

--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -2142,6 +2142,13 @@ UNUSUAL_DEV(  0x22b8, 0x3010, 0x0001, 0x
USB_SC_DEVICE, USB_PR_DEVICE, NULL,
US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
 
+/* Reported by Teijo Kinnunen  */
+UNUSUAL_DEV(  0x152d, 0x2567, 0x0117, 0x0117,
+   "JMicron",
+   "USB to ATA/ATAPI Bridge",
+   USB_SC_DEVICE, USB_PR_DEVICE, NULL,
+   US_FL_BROKEN_FUA ),
+
 /* Reported-by George Cherian  */
 UNUSUAL_DEV(0x152d, 0x9561, 0x, 0x,
"JMicron",




[PATCH 4.4 55/63] staging: comedi: fix comedi_nsamples_left.

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Frank Mori Hess 

commit a42ae5905140c324362fe5036ae1dbb16e4d359c upstream.

A rounding error was causing comedi_nsamples_left to
return the wrong value when nsamples was not a multiple
of the scan length.

Cc:  # v4.4+
Signed-off-by: Frank Mori Hess 
Reviewed-by: Ian Abbott 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/staging/comedi/drivers.c |3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- a/drivers/staging/comedi/drivers.c
+++ b/drivers/staging/comedi/drivers.c
@@ -484,8 +484,7 @@ unsigned int comedi_nsamples_left(struct
struct comedi_cmd *cmd = &async->cmd;
 
if (cmd->stop_src == TRIG_COUNT) {
-   unsigned int nscans = nsamples / cmd->scan_end_arg;
-   unsigned int scans_left = __comedi_nscans_left(s, nscans);
+   unsigned int scans_left = __comedi_nscans_left(s, 
cmd->stop_arg);
unsigned int scan_pos =
comedi_bytes_to_samples(s, async->scan_progress);
unsigned long long samples_left = 0;




[PATCH 4.4 56/63] staging: android: ashmem: Fix lockdep issue during llseek

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Joel Fernandes 

commit cb57469c9573f6018cd1302953dd45d6e05aba7b upstream.

ashmem_mutex create a chain of dependencies like so:

(1)
mmap syscall ->
  mmap_sem ->  (acquired)
  ashmem_mmap
  ashmem_mutex (try to acquire)
  (block)

(2)
llseek syscall ->
  ashmem_llseek ->
  ashmem_mutex ->  (acquired)
  inode_lock ->
  inode->i_rwsem (try to acquire)
  (block)

(3)
getdents ->
  iterate_dir ->
  inode_lock ->
  inode->i_rwsem   (acquired)
  copy_to_user ->
  mmap_sem (try to acquire)

There is a lock ordering created between mmap_sem and inode->i_rwsem
causing a lockdep splat [2] during a syzcaller test, this patch fixes
the issue by unlocking the mutex earlier. Functionally that's Ok since
we don't need to protect vfs_llseek.

[1] https://patchwork.kernel.org/patch/10185031/
[2] https://lkml.org/lkml/2018/1/10/48

Acked-by: Todd Kjos 
Cc: Arve Hjonnevag 
Cc: sta...@vger.kernel.org
Reported-by: syzbot+8ec30bb7bf1a981a2...@syzkaller.appspotmail.com
Signed-off-by: Joel Fernandes 
Acked-by: Greg Hackmann 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/staging/android/ashmem.c |   15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

--- a/drivers/staging/android/ashmem.c
+++ b/drivers/staging/android/ashmem.c
@@ -330,24 +330,23 @@ static loff_t ashmem_llseek(struct file
mutex_lock(&ashmem_mutex);
 
if (asma->size == 0) {
-   ret = -EINVAL;
-   goto out;
+   mutex_unlock(&ashmem_mutex);
+   return -EINVAL;
}
 
if (!asma->file) {
-   ret = -EBADF;
-   goto out;
+   mutex_unlock(&ashmem_mutex);
+   return -EBADF;
}
 
+   mutex_unlock(&ashmem_mutex);
+
ret = vfs_llseek(asma->file, offset, origin);
if (ret < 0)
-   goto out;
+   return ret;
 
/** Copy f_pos from backing file, since f_ops->llseek() sets it */
file->f_pos = asma->file->f_pos;
-
-out:
-   mutex_unlock(&ashmem_mutex);
return ret;
 }
 




[PATCH 4.4 52/63] serial: sh-sci: prevent lockup on full TTY buffers

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Ulrich Hecht 

commit 7842055bfce4bf0170d0f61df8b2add8399697be upstream.

When the TTY buffers fill up to the configured maximum, a system lockup
occurs:

[  598.820128] INFO: rcu_preempt detected stalls on CPUs/tasks:
[  598.825796]  0-...!: (1 GPs behind) idle=5a6/2/0 softirq=1974/1974 fqs=1
[  598.832577]  (detected by 3, t=62517 jiffies, g=296, c=295, q=126)
[  598.838755] Task dump for CPU 0:
[  598.841977] swapper/0   R  running task0 0  0 0x0022
[  598.849023] Call trace:
[  598.851476]  __switch_to+0x98/0xb0
[  598.854870](null)

This can be prevented by doing a dummy read of the RX data register.

This issue affects both HSCIF and SCIF ports. Reported for R-Car H3 ES2.0;
reproduced and fixed on H3 ES1.1. Probably affects other R-Car platforms
as well.

Reported-by: Yoshihiro Shimoda 
Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Cc: stable 
Tested-by: Nguyen Viet Dung 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/tty/serial/sh-sci.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -847,6 +847,8 @@ static void sci_receive_chars(struct uar
/* Tell the rest of the system the news. New characters! */
tty_flip_buffer_push(tport);
} else {
+   /* TTY buffers full; read from RX reg to prevent lockup */
+   serial_port_in(port, SCxRDR);
serial_port_in(port, SCxSR); /* dummy read */
sci_clear_SCxSR(port, SCxSR_RDxF_CLEAR(port));
}




[PATCH 4.4 50/63] x86/module: Detect and skip invalid relocations

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Josh Poimboeuf 

commit eda9cec4c9a12208a6f69fbe68f72a6311d50032 upstream.

There have been some cases where external tooling (e.g., kpatch-build)
creates a corrupt relocation which targets the wrong address.  This is a
silent failure which can corrupt memory in unexpected places.

On x86, the bytes of data being overwritten by relocations are always
initialized to zero beforehand.  Use that knowledge to add sanity checks
to detect such cases before they corrupt memory.

Signed-off-by: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: j...@kernel.org
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/37450d6c6225e54db107fba447ce9e56e5f758e9.1509713553.git.jpoim...@redhat.com
[ Restructured the messages, as it's unclear whether the relocation or the 
target is corrupted. ]
Signed-off-by: Ingo Molnar 
Cc: Matthias Kaehlcke 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/module.c |   13 +
 1 file changed, 13 insertions(+)

--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -170,19 +170,27 @@ int apply_relocate_add(Elf64_Shdr *sechd
case R_X86_64_NONE:
break;
case R_X86_64_64:
+   if (*(u64 *)loc != 0)
+   goto invalid_relocation;
*(u64 *)loc = val;
break;
case R_X86_64_32:
+   if (*(u32 *)loc != 0)
+   goto invalid_relocation;
*(u32 *)loc = val;
if (val != *(u32 *)loc)
goto overflow;
break;
case R_X86_64_32S:
+   if (*(s32 *)loc != 0)
+   goto invalid_relocation;
*(s32 *)loc = val;
if ((s64)val != *(s32 *)loc)
goto overflow;
break;
case R_X86_64_PC32:
+   if (*(u32 *)loc != 0)
+   goto invalid_relocation;
val -= (u64)loc;
*(u32 *)loc = val;
 #if 0
@@ -198,6 +206,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
}
return 0;
 
+invalid_relocation:
+   pr_err("x86/modules: Skipping invalid relocation target, existing value 
is nonzero for type %d, loc %p, val %Lx\n",
+  (int)ELF64_R_TYPE(rel[i].r_info), loc, val);
+   return -ENOEXEC;
+
 overflow:
pr_err("overflow in relocation type %d val %Lx\n",
   (int)ELF64_R_TYPE(rel[i].r_info), val);




[PATCH 4.4 49/63] Revert "ARM: dts: LogicPD Torpedo: Fix I2C1 pinmux"

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Greg Kroah-Hartman 

This reverts commit c86bfc7b7b01c4b98c29a39bd60e61fa8e337ebf which was
commit 74402055a2d3ec998a1ded599e86185a27d9bbf4 upstream.

The backport merged incorrectly, so I'm dropping it.

Reported-by: Ben Hutchings 
Cc: Adam Ford 
Cc: Tony Lindgren 
Signed-off-by: Greg Kroah-Hartman 


---
 arch/arm/boot/dts/logicpd-torpedo-som.dtsi |8 
 1 file changed, 8 deletions(-)

--- a/arch/arm/boot/dts/logicpd-torpedo-som.dtsi
+++ b/arch/arm/boot/dts/logicpd-torpedo-som.dtsi
@@ -90,8 +90,6 @@
 };
 
 &i2c1 {
-   pinctrl-names = "default";
-   pinctrl-0 = <&i2c1_pins>;
clock-frequency = <260>;
 
twl: twl@48 {
@@ -148,12 +146,6 @@
OMAP3630_CORE2_IOPAD(0x25da, PIN_INPUT_PULLUP | 
MUX_MODE2)   /* etk_ctl.sdmmc3_cmd */
>;
};
-   i2c1_pins: pinmux_i2c1_pins {
-   pinctrl-single,pins = <
-   OMAP3_CORE1_IOPAD(0x21ba, PIN_INPUT | MUX_MODE0)
/* i2c1_scl.i2c1_scl */
-   OMAP3_CORE1_IOPAD(0x21bc, PIN_INPUT | MUX_MODE0)
/* i2c1_sda.i2c1_sda */
-   >;
-   };
 };
 
 #include "twl4030.dtsi"




[PATCH 4.4 54/63] uas: fix comparison for error code

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Oliver Neukum 

commit 9a513c905bb95bef79d96feb08621c1ec8d8c4bb upstream.

A typo broke the comparison.

Fixes: cbeef22fd611 ("usb: uas: unconditionally bring back host after reset")
Signed-off-by: Oliver Neukum 
CC: sta...@kernel.org
Acked-by: Hans de Goede 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/usb/storage/uas.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -1052,7 +1052,7 @@ static int uas_post_reset(struct usb_int
return 0;
 
err = uas_configure_endpoints(devinfo);
-   if (err && err != ENODEV)
+   if (err && err != -ENODEV)
shost_printk(KERN_ERR, shost,
 "%s: alloc streams error %d after reset",
 __func__, err);




[PATCH 4.4 18/63] kbuild: Handle builtin dtb file names containing hyphens

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: James Hogan 

commit 55fe6da9efba102866e2fb5b40b04b6a4b26c19e upstream.

cmd_dt_S_dtb constructs the assembly source to incorporate a devicetree
FDT (that is, the .dtb file) as binary data in the kernel image. This
assembly source contains labels before and after the binary data. The
label names incorporate the file name of the corresponding .dtb file.
Hyphens are not legal characters in labels, so .dtb files built into the
kernel with hyphens in the file name result in errors like the
following:

bcm3368-netgear-cvg834g.dtb.S: Assembler messages:
bcm3368-netgear-cvg834g.dtb.S:5: Error: : no such section
bcm3368-netgear-cvg834g.dtb.S:5: Error: junk at end of line, first unrecognized 
character is `-'
bcm3368-netgear-cvg834g.dtb.S:6: Error: unrecognized opcode 
`__dtb_bcm3368-netgear-cvg834g_begin:'
bcm3368-netgear-cvg834g.dtb.S:8: Error: unrecognized opcode 
`__dtb_bcm3368-netgear-cvg834g_end:'
bcm3368-netgear-cvg834g.dtb.S:9: Error: : no such section
bcm3368-netgear-cvg834g.dtb.S:9: Error: junk at end of line, first unrecognized 
character is `-'

Fix this by updating cmd_dt_S_dtb to transform all hyphens from the file
name to underscores when constructing the labels.

As of v4.16-rc2, 1139 .dts files across ARM64, ARM, MIPS and PowerPC
contain hyphens in their names, but the issue only currently manifests
on Broadcom MIPS platforms, as that is the only place where such files
are built into the kernel. For example when CONFIG_DT_NETGEAR_CVG834G=y,
or on BMIPS kernels when the dtbs target is used (in the latter case it
admittedly shouldn't really build all the dtb.o files, but thats a
separate issue).

Fixes: 695835511f96 ("MIPS: BMIPS: rename bcm96358nb4ser to 
bcm6358-neufbox4-sercom")
Signed-off-by: James Hogan 
Reviewed-by: Frank Rowand 
Cc: Rob Herring 
Cc: Michal Marek 
Cc: Ralf Baechle 
Cc: Florian Fainelli 
Cc: Kevin Cernekee 
Cc:  # 4.9+
Signed-off-by: Masahiro Yamada 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/Makefile.lib |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -270,11 +270,11 @@ cmd_dt_S_dtb= 
\
echo '\#include ';   \
echo '.section .dtb.init.rodata,"a"';   \
echo '.balign STRUCT_ALIGNMENT';\
-   echo '.global __dtb_$(*F)_begin';   \
-   echo '__dtb_$(*F)_begin:';  \
+   echo '.global __dtb_$(subst -,_,$(*F))_begin';  \
+   echo '__dtb_$(subst -,_,$(*F))_begin:'; \
echo '.incbin "$<" ';   \
-   echo '__dtb_$(*F)_end:';\
-   echo '.global __dtb_$(*F)_end'; \
+   echo '__dtb_$(subst -,_,$(*F))_end:';   \
+   echo '.global __dtb_$(subst -,_,$(*F))_end';\
echo '.balign STRUCT_ALIGNMENT';\
 ) > $@
 




[PATCH 4.4 09/63] drm/amdgpu: Fix deadlock on runtime suspend

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Lukas Wunner 

commit aa0aad57909eb321746325951d66af88a83bc956 upstream.

amdgpu's ->runtime_suspend hook calls drm_kms_helper_poll_disable(),
which waits for the output poll worker to finish if it's running.

The output poll worker meanwhile calls pm_runtime_get_sync() in
amdgpu's ->detect hooks, which waits for the ongoing suspend to finish,
causing a deadlock.

Fix by not acquiring a runtime PM ref if the ->detect hooks are called
in the output poll worker's context.  This is safe because the poll
worker is only enabled while runtime active and we know that
->runtime_suspend waits for it to finish.

Fixes: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")
Cc: sta...@vger.kernel.org # v4.2+: 27d4ee03078a: workqueue: Allow retrieval of 
current task's work struct
Cc: sta...@vger.kernel.org # v4.2+: 25c058ccaf2e: drm: Allow determining if 
current task is output poll worker
Cc: Alex Deucher 
Tested-by: Mike Lothian 
Reviewed-by: Lyude Paul 
Signed-off-by: Lukas Wunner 
Link: 
https://patchwork.freedesktop.org/patch/msgid/4c9bf72aacae1eef062bd134cd112e0770a7f121.1518338789.git.lu...@wunner.de
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c |   58 -
 1 file changed, 38 insertions(+), 20 deletions(-)

--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c
@@ -739,9 +739,11 @@ amdgpu_connector_lvds_detect(struct drm_
enum drm_connector_status ret = connector_status_disconnected;
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
if (encoder) {
struct amdgpu_encoder *amdgpu_encoder = 
to_amdgpu_encoder(encoder);
@@ -760,8 +762,12 @@ amdgpu_connector_lvds_detect(struct drm_
/* check acpi lid status ??? */
 
amdgpu_connector_update_scratch_regs(connector, ret);
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
+
return ret;
 }
 
@@ -862,9 +868,11 @@ amdgpu_connector_vga_detect(struct drm_c
enum drm_connector_status ret = connector_status_disconnected;
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
encoder = amdgpu_connector_best_single_encoder(connector);
if (!encoder)
@@ -918,8 +926,10 @@ amdgpu_connector_vga_detect(struct drm_c
amdgpu_connector_update_scratch_regs(connector, ret);
 
 out:
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
 
return ret;
 }
@@ -981,9 +991,11 @@ amdgpu_connector_dvi_detect(struct drm_c
enum drm_connector_status ret = connector_status_disconnected;
bool dret = false, broken_edid = false;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
if (!force && amdgpu_connector_check_hpd_status_unchanged(connector)) {
ret = connector->status;
@@ -1108,8 +1120,10 @@ out:
amdgpu_connector_update_scratch_regs(connector, ret);
 
 exit:
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
 
return ret;
 }
@@ -1351,9 +1365,11 @@ amdgpu_connector_dp_detect(struct drm_co
struct drm_encoder *encoder = 
amdgpu_connector_best_single_encoder(connector);
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_

[PATCH 4.4 17/63] loop: Fix lost writes caused by missing flag

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Ross Zwisler 

commit 1d037577c323e5090ce281e96bc313ab2eee5be2 upstream.

The following commit:

commit aa4d86163e4e ("block: loop: switch to VFS ITER_BVEC")

replaced __do_lo_send_write(), which used ITER_KVEC iterators, with
lo_write_bvec() which uses ITER_BVEC iterators.  In this change, though,
the WRITE flag was lost:

-   iov_iter_kvec(&from, ITER_KVEC | WRITE, &kvec, 1, len);
+   iov_iter_bvec(&i, ITER_BVEC, bvec, 1, bvec->bv_len);

This flag is necessary for the DAX case because we make decisions based on
whether or not the iterator is a READ or a WRITE in dax_iomap_actor() and
in dax_iomap_rw().

We end up going through this path in configurations where we combine a PMEM
device with 4k sectors, a loopback device and DAX.  The consequence of this
missed flag is that what we intend as a write actually turns into a read in
the DAX code, so no data is ever written.

The very simplest test case is to create a loopback device and try and
write a small string to it, then hexdump a few bytes of the device to see
if the write took.  Without this patch you read back all zeros, with this
you read back the string you wrote.

For XFS this causes us to fail or panic during the following xfstests:

xfs/074 xfs/078 xfs/216 xfs/217 xfs/250

For ext4 we have a similar issue where writes never happen, but we don't
currently have any xfstests that use loopback and show this issue.

Fix this by restoring the WRITE flag argument to iov_iter_bvec().  This
causes the xfstests to all pass.

Cc: Al Viro 
Cc: sta...@vger.kernel.org
Fixes: commit aa4d86163e4e ("block: loop: switch to VFS ITER_BVEC")
Reviewed-by: Christoph Hellwig 
Reviewed-by: Ming Lei 
Signed-off-by: Ross Zwisler 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/block/loop.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -263,7 +263,7 @@ static int lo_write_bvec(struct file *fi
struct iov_iter i;
ssize_t bw;
 
-   iov_iter_bvec(&i, ITER_BVEC, bvec, 1, bvec->bv_len);
+   iov_iter_bvec(&i, ITER_BVEC | WRITE, bvec, 1, bvec->bv_len);
 
file_start_write(file);
bw = vfs_iter_write(file, &i, ppos);




[PATCH 4.4 15/63] MIPS: OCTEON: irq: Check for null return on kzalloc allocation

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Colin Ian King 

commit 902f4d067a50ccf645a58dd5fb1d113b6e0f9b5b upstream.

The allocation of host_data is not null checked, leading to a null
pointer dereference if the allocation fails. Fix this by adding a null
check and return with -ENOMEM.

Fixes: 64b139f97c01 ("MIPS: OCTEON: irq: add CIB and other fixes")
Signed-off-by: Colin Ian King 
Acked-by: David Daney 
Cc: Ralf Baechle 
Cc: "Steven J. Hill" 
Cc: linux-m...@linux-mips.org
Cc:  # 4.0+
Patchwork: https://patchwork.linux-mips.org/patch/18658/
Signed-off-by: James Hogan 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/cavium-octeon/octeon-irq.c |2 ++
 1 file changed, 2 insertions(+)

--- a/arch/mips/cavium-octeon/octeon-irq.c
+++ b/arch/mips/cavium-octeon/octeon-irq.c
@@ -2246,6 +2246,8 @@ static int __init octeon_irq_init_cib(st
}
 
host_data = kzalloc(sizeof(*host_data), GFP_KERNEL);
+   if (!host_data)
+   return -ENOMEM;
raw_spin_lock_init(&host_data->lock);
 
addr = of_get_address(ciu_node, 0, NULL, NULL);




[PATCH 4.4 16/63] Input: matrix_keypad - fix race when disabling interrupts

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Zhang Bo 

commit ea4f7bd2aca9f68470e9aac0fc9432fd180b1fe7 upstream.

If matrix_keypad_stop() is executing and the keypad interrupt is triggered,
disable_row_irqs() may be called by both matrix_keypad_interrupt() and
matrix_keypad_stop() at the same time, causing interrupts to be disabled
twice and the keypad being "stuck" after resuming.

Take lock when setting keypad->stopped to ensure that ISR will not race
with matrix_keypad_stop() disabling interrupts.

Signed-off-by: Zhang Bo 
Cc: sta...@vger.kernel.org
Signed-off-by: Dmitry Torokhov 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/input/keyboard/matrix_keypad.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -216,8 +216,10 @@ static void matrix_keypad_stop(struct in
 {
struct matrix_keypad *keypad = input_get_drvdata(dev);
 
+   spin_lock_irq(&keypad->lock);
keypad->stopped = true;
-   mb();
+   spin_unlock_irq(&keypad->lock);
+
flush_work(&keypad->work.work);
/*
 * matrix_keypad_scan() will leave IRQs enabled;




Re: [PATCH v5 03/11] perf/x86/intel/pt: Introduce a new function to get the capability of Intel PT

2018-03-16 Thread Paolo Bonzini
On 04/03/2018 13:07, Luwei Kang wrote:
> +u32 pt_cap_get_ex(u32 *caps, enum pt_capabilities cap)
> +{
> + struct pt_cap_desc *cd = &pt_caps[cap];
> + u32 c = caps[cd->leaf * PT_CPUID_REGS_NUM + cd->reg];
> + unsigned int shift = __ffs(cd->mask);
> +
> + return (c & cd->mask) >> shift;
> +}
> +EXPORT_SYMBOL_GPL(pt_cap_get_ex);
> +

You should change pt_cap_get to use this function.  Also, "_ex" is not a
very common suffix, so perhaps you can call it __pt_cap_get.

I don't have any other comments on patches 1-3, so when you resend we
can ask the x86 maintainers for approval.

Thanks,

Paolo


[PATCH 4.4 13/63] MIPS: BMIPS: Do not mask IPIs during suspend

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Justin Chen 

commit 06a3f0c9f2725f5d7c63c4203839373c9bd00c28 upstream.

Commit a3e6c1eff548 ("MIPS: IRQ: Fix disable_irq on CPU IRQs") fixes an
issue where disable_irq did not actually disable the irq. The bug caused
our IPIs to not be disabled, which actually is the correct behavior.

With the addition of commit a3e6c1eff548 ("MIPS: IRQ: Fix disable_irq on
CPU IRQs"), the IPIs were getting disabled going into suspend, thus
schedule_ipi() was not being called. This caused deadlocks where
schedulable task were not being scheduled and other cpus were waiting
for them to do something.

Add the IRQF_NO_SUSPEND flag so an irq_disable will not be called on the
IPIs during suspend.

Signed-off-by: Justin Chen 
Fixes: a3e6c1eff548 ("MIPS: IRQ: Fix disabled_irq on CPU IRQs")
Cc: Florian Fainelli 
Cc: linux-m...@linux-mips.org
Cc: sta...@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/17385/
[jho...@kernel.org: checkpatch: wrap long lines and fix commit refs]
Signed-off-by: James Hogan 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/mips/kernel/smp-bmips.c |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/arch/mips/kernel/smp-bmips.c
+++ b/arch/mips/kernel/smp-bmips.c
@@ -166,11 +166,11 @@ static void bmips_prepare_cpus(unsigned
return;
}
 
-   if (request_irq(IPI0_IRQ, bmips_ipi_interrupt, IRQF_PERCPU,
-   "smp_ipi0", NULL))
+   if (request_irq(IPI0_IRQ, bmips_ipi_interrupt,
+   IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi0", NULL))
panic("Can't request IPI0 interrupt");
-   if (request_irq(IPI1_IRQ, bmips_ipi_interrupt, IRQF_PERCPU,
-   "smp_ipi1", NULL))
+   if (request_irq(IPI1_IRQ, bmips_ipi_interrupt,
+   IRQF_PERCPU | IRQF_NO_SUSPEND, "smp_ipi1", NULL))
panic("Can't request IPI1 interrupt");
 }
 




[PATCH 4.4 37/63] netfilter: IDLETIMER: be syzkaller friendly

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Eric Dumazet 

commit cfc2c740533368b96e2be5e0a4e8c3cace7d9814 upstream.

We had one report from syzkaller [1]

First issue is that INIT_WORK() should be done before mod_timer()
or we risk timer being fired too soon, even with a 1 second timer.

Second issue is that we need to reject too big info->timeout
to avoid overflows in msecs_to_jiffies(info->timeout * 1000), or
risk looping, if result after overflow is 0.

[1]
WARNING: CPU: 1 PID: 5129 at kernel/workqueue.c:1444 __queue_work+0xdf4/0x1230 
kernel/workqueue.c:1444
Kernel panic - not syncing: panic_on_warn set ...

CPU: 1 PID: 5129 Comm: syzkaller159866 Not tainted 4.16.0-rc1+ #230
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 
01/01/2011
Call Trace:
 
 __dump_stack lib/dump_stack.c:17 [inline]
 dump_stack+0x194/0x257 lib/dump_stack.c:53
 panic+0x1e4/0x41c kernel/panic.c:183
 __warn+0x1dc/0x200 kernel/panic.c:547
 report_bug+0x211/0x2d0 lib/bug.c:184
 fixup_bug.part.11+0x37/0x80 arch/x86/kernel/traps.c:178
 fixup_bug arch/x86/kernel/traps.c:247 [inline]
 do_error_trap+0x2d7/0x3e0 arch/x86/kernel/traps.c:296
 do_invalid_op+0x1b/0x20 arch/x86/kernel/traps.c:315
 invalid_op+0x22/0x40 arch/x86/entry/entry_64.S:988
RIP: 0010:__queue_work+0xdf4/0x1230 kernel/workqueue.c:1444
RSP: 0018:8801db507538 EFLAGS: 00010006
RAX: 8801aeb46080 RBX: 8801db530200 RCX: 81481404
RDX: 0100 RSI: 86b42640 RDI: 0082
RBP: 8801db507758 R08: 11003b6a0de5 R09: 000c
R10: 8801db5073f0 R11: 0020 R12: 11003b6a0eb6
R13: 8801b1067ae0 R14: 01f8 R15: dc00
 queue_work_on+0x16a/0x1c0 kernel/workqueue.c:1488
 queue_work include/linux/workqueue.h:488 [inline]
 schedule_work include/linux/workqueue.h:546 [inline]
 idletimer_tg_expired+0x44/0x60 net/netfilter/xt_IDLETIMER.c:116
 call_timer_fn+0x228/0x820 kernel/time/timer.c:1326
 expire_timers kernel/time/timer.c:1363 [inline]
 __run_timers+0x7ee/0xb70 kernel/time/timer.c:1666
 run_timer_softirq+0x4c/0x70 kernel/time/timer.c:1692
 __do_softirq+0x2d7/0xb85 kernel/softirq.c:285
 invoke_softirq kernel/softirq.c:365 [inline]
 irq_exit+0x1cc/0x200 kernel/softirq.c:405
 exiting_irq arch/x86/include/asm/apic.h:541 [inline]
 smp_apic_timer_interrupt+0x16b/0x700 arch/x86/kernel/apic/apic.c:1052
 apic_timer_interrupt+0xa9/0xb0 arch/x86/entry/entry_64.S:829
 
RIP: 0010:arch_local_irq_restore arch/x86/include/asm/paravirt.h:777 [inline]
RIP: 0010:__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:160 
[inline]
RIP: 0010:_raw_spin_unlock_irqrestore+0x5e/0xba kernel/locking/spinlock.c:184
RSP: 0018:8801c20173c8 EFLAGS: 0282 ORIG_RAX: ff12
RAX: dc00 RBX: 0282 RCX: 0006
RDX: 10d592cd RSI: 110035d68d23 RDI: 0282
RBP: 8801c20173d8 R08: 110038402e47 R09: 
R10:  R11:  R12: 8820e5c8
R13: 8801b1067ad8 R14: 8801aea7c268 R15: 8801aea7c278
 __debug_object_init+0x235/0x1040 lib/debugobjects.c:378
 debug_object_init+0x17/0x20 lib/debugobjects.c:391
 __init_work+0x2b/0x60 kernel/workqueue.c:506
 idletimer_tg_create net/netfilter/xt_IDLETIMER.c:152 [inline]
 idletimer_tg_checkentry+0x691/0xb00 net/netfilter/xt_IDLETIMER.c:213
 xt_check_target+0x22c/0x7d0 net/netfilter/x_tables.c:850
 check_target net/ipv6/netfilter/ip6_tables.c:533 [inline]
 find_check_entry.isra.7+0x935/0xcf0 net/ipv6/netfilter/ip6_tables.c:575
 translate_table+0xf52/0x1690 net/ipv6/netfilter/ip6_tables.c:744
 do_replace net/ipv6/netfilter/ip6_tables.c:1160 [inline]
 do_ip6t_set_ctl+0x370/0x5f0 net/ipv6/netfilter/ip6_tables.c:1686
 nf_sockopt net/netfilter/nf_sockopt.c:106 [inline]
 nf_setsockopt+0x67/0xc0 net/netfilter/nf_sockopt.c:115
 ipv6_setsockopt+0x10b/0x130 net/ipv6/ipv6_sockglue.c:927
 udpv6_setsockopt+0x45/0x80 net/ipv6/udp.c:1422
 sock_common_setsockopt+0x95/0xd0 net/core/sock.c:2976
 SYSC_setsockopt net/socket.c:1850 [inline]
 SyS_setsockopt+0x189/0x360 net/socket.c:1829
 do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287

Fixes: 0902b469bd25 ("netfilter: xtables: idletimer target implementation")
Signed-off-by: Eric Dumazet 
Reported-by: syzkaller 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/netfilter/xt_IDLETIMER.c |9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- a/net/netfilter/xt_IDLETIMER.c
+++ b/net/netfilter/xt_IDLETIMER.c
@@ -147,11 +147,11 @@ static int idletimer_tg_create(struct id
(unsigned long) info->timer);
info->timer->refcnt = 1;
 
+   INIT_WORK(&info->timer->work, idletimer_tg_work);
+
mod_timer(&info->timer->timer,
  msecs_to_jiffies(info->timeout * 1000) + jiffies);
 
-   INIT_WORK(&info->timer->work, idletimer_tg_work);
-
return 0;
 

[PATCH 4.4 35/63] netfilter: x_tables: fix missing timer initialization in xt_LED

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Paolo Abeni 

commit 10414014bc085aac9f787a5890b33b5605fbcfc4 upstream.

syzbot reported that xt_LED may try to use the ledinternal->timer
without previously initializing it:

[ cut here ]
kernel BUG at kernel/time/timer.c:958!
invalid opcode:  [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 1 PID: 1826 Comm: kworker/1:2 Not tainted 4.15.0+ #306
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
Workqueue: ipv6_addrconf addrconf_dad_work
RIP: 0010:__mod_timer kernel/time/timer.c:958 [inline]
RIP: 0010:mod_timer+0x7d6/0x13c0 kernel/time/timer.c:1102
RSP: 0018:8801d24fe9f8 EFLAGS: 00010293
RAX: 8801d25246c0 RBX: 8801aec6cb50 RCX: 816052c6
RDX:  RSI: fffbd14b RDI: 8801aec6cb68
RBP: 8801d24fec98 R08:  R09: 11003a49fd6c
R10: 8801d24feb28 R11: 0005 R12: dc00
R13: 8801d24fec70 R14: fffbd14b R15: 8801af608f90
FS:  () GS:8801db50() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 206d6fd0 CR3: 06a22001 CR4: 001606e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400
Call Trace:
  led_tg+0x1db/0x2e0 net/netfilter/xt_LED.c:75
  ip6t_do_table+0xc2a/0x1a30 net/ipv6/netfilter/ip6_tables.c:365
  ip6table_raw_hook+0x65/0x80 net/ipv6/netfilter/ip6table_raw.c:42
  nf_hook_entry_hookfn include/linux/netfilter.h:120 [inline]
  nf_hook_slow+0xba/0x1a0 net/netfilter/core.c:483
  nf_hook.constprop.27+0x3f6/0x830 include/linux/netfilter.h:243
  NF_HOOK include/linux/netfilter.h:286 [inline]
  ndisc_send_skb+0xa51/0x1370 net/ipv6/ndisc.c:491
  ndisc_send_ns+0x38a/0x870 net/ipv6/ndisc.c:633
  addrconf_dad_work+0xb9e/0x1320 net/ipv6/addrconf.c:4008
  process_one_work+0xbbf/0x1af0 kernel/workqueue.c:2113
  worker_thread+0x223/0x1990 kernel/workqueue.c:2247
  kthread+0x33c/0x400 kernel/kthread.c:238
  ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:429
Code: 85 2a 0b 00 00 4d 8b 3c 24 4d 85 ff 75 9f 4c 8b bd 60 fd ff ff e8 bb
57 10 00 65 ff 0d 94 9a a1 7e e9 d9 fc ff ff e8 aa 57 10 00 <0f> 0b e8 a3
57 10 00 e9 14 fb ff ff e8 99 57 10 00 4c 89 bd 70
RIP: __mod_timer kernel/time/timer.c:958 [inline] RSP: 8801d24fe9f8
RIP: mod_timer+0x7d6/0x13c0 kernel/time/timer.c:1102 RSP: 8801d24fe9f8
---[ end trace f661ab06f5dd8b3d ]---

The ledinternal struct can be shared between several different
xt_LED targets, but the related timer is currently initialized only
if the first target requires it. Fix it by unconditionally
initializing the timer struct.

v1 -> v2: call del_timer_sync() unconditionally, too.

Fixes: 268cb38e1802 ("netfilter: x_tables: add LED trigger target")
Reported-by: syzbot+10c98dc5725c6c8fc...@syzkaller.appspotmail.com
Signed-off-by: Paolo Abeni 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/netfilter/xt_LED.c |   12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

--- a/net/netfilter/xt_LED.c
+++ b/net/netfilter/xt_LED.c
@@ -141,10 +141,11 @@ static int led_tg_check(const struct xt_
goto exit_alloc;
}
 
-   /* See if we need to set up a timer */
-   if (ledinfo->delay > 0)
-   setup_timer(&ledinternal->timer, led_timeout_callback,
-   (unsigned long)ledinternal);
+   /* Since the letinternal timer can be shared between multiple targets,
+* always set it up, even if the current target does not need it
+*/
+   setup_timer(&ledinternal->timer, led_timeout_callback,
+   (unsigned long)ledinternal);
 
list_add_tail(&ledinternal->list, &xt_led_triggers);
 
@@ -181,8 +182,7 @@ static void led_tg_destroy(const struct
 
list_del(&ledinternal->list);
 
-   if (ledinfo->delay > 0)
-   del_timer_sync(&ledinternal->timer);
+   del_timer_sync(&ledinternal->timer);
 
led_trigger_unregister(&ledinternal->netfilter_led_trigger);
 




[PATCH 4.4 36/63] netfilter: nat: cope with negative port range

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Paolo Abeni 

commit db57ccf0f2f4624b4c4758379f8165277504fbd7 upstream.

syzbot reported a division by 0 bug in the netfilter nat code:

divide error:  [#1] SMP KASAN
Dumping ftrace buffer:
(ftrace buffer empty)
Modules linked in:
CPU: 1 PID: 4168 Comm: syzkaller034710 Not tainted 4.16.0-rc1+ #309
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS
Google 01/01/2011
RIP: 0010:nf_nat_l4proto_unique_tuple+0x291/0x530
net/netfilter/nf_nat_proto_common.c:88
RSP: 0018:8801b2466778 EFLAGS: 00010246
RAX: f153 RBX: 8801b2466dd8 RCX: 8801b2466c7c
RDX:  RSI: 8801b2466c58 RDI: 8801db5293ac
RBP: 8801b24667d8 R08: 8801b8ba6dc0 R09: 88af5900
R10: 8801b24666f0 R11:  R12: 2990f153
R13: 0001 R14:  R15: 8801b2466c7c
FS:  017e3880() GS:8801db50() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 208fdfe4 CR3: 0001b5340002 CR4: 001606e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400
Call Trace:
  dccp_unique_tuple+0x40/0x50 net/netfilter/nf_nat_proto_dccp.c:30
  get_unique_tuple+0xc28/0x1c10 net/netfilter/nf_nat_core.c:362
  nf_nat_setup_info+0x1c2/0xe00 net/netfilter/nf_nat_core.c:406
  nf_nat_redirect_ipv6+0x306/0x730 net/netfilter/nf_nat_redirect.c:124
  redirect_tg6+0x7f/0xb0 net/netfilter/xt_REDIRECT.c:34
  ip6t_do_table+0xc2a/0x1a30 net/ipv6/netfilter/ip6_tables.c:365
  ip6table_nat_do_chain+0x65/0x80 net/ipv6/netfilter/ip6table_nat.c:41
  nf_nat_ipv6_fn+0x594/0xa80 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c:302
  nf_nat_ipv6_local_fn+0x33/0x5d0
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c:407
  ip6table_nat_local_fn+0x2c/0x40 net/ipv6/netfilter/ip6table_nat.c:69
  nf_hook_entry_hookfn include/linux/netfilter.h:120 [inline]
  nf_hook_slow+0xba/0x1a0 net/netfilter/core.c:483
  nf_hook include/linux/netfilter.h:243 [inline]
  NF_HOOK include/linux/netfilter.h:286 [inline]
  ip6_xmit+0x10ec/0x2260 net/ipv6/ip6_output.c:277
  inet6_csk_xmit+0x2fc/0x580 net/ipv6/inet6_connection_sock.c:139
  dccp_transmit_skb+0x9ac/0x10f0 net/dccp/output.c:142
  dccp_connect+0x369/0x670 net/dccp/output.c:564
  dccp_v6_connect+0xe17/0x1bf0 net/dccp/ipv6.c:946
  __inet_stream_connect+0x2d4/0xf00 net/ipv4/af_inet.c:620
  inet_stream_connect+0x58/0xa0 net/ipv4/af_inet.c:684
  SYSC_connect+0x213/0x4a0 net/socket.c:1639
  SyS_connect+0x24/0x30 net/socket.c:1620
  do_syscall_64+0x282/0x940 arch/x86/entry/common.c:287
  entry_SYSCALL_64_after_hwframe+0x26/0x9b
RIP: 0033:0x441c69
RSP: 002b:7ffe50cc0be8 EFLAGS: 0217 ORIG_RAX: 002a
RAX: ffda RBX:  RCX: 00441c69
RDX: 001c RSI: 208fdfe4 RDI: 0003
RBP: 006cc018 R08:  R09: 
R10: 0538 R11: 0217 R12: 00403590
R13: 00403620 R14:  R15: 
Code: 48 89 f0 83 e0 07 83 c0 01 38 d0 7c 08 84 d2 0f 85 46 02 00 00 48 8b
45 c8 44 0f b7 20 e8 88 97 04 fd 31 d2 41 0f b7 c4 4c 89 f9 <41> f7 f6 48
c1 e9 03 48 b8 00 00 00 00 00 fc ff df 0f b6 0c 01
RIP: nf_nat_l4proto_unique_tuple+0x291/0x530
net/netfilter/nf_nat_proto_common.c:88 RSP: 8801b2466778

The problem is that currently we don't have any check on the
configured port range. A port range == -1 triggers the bug, while
other negative values may require a very long time to complete the
following loop.

This commit addresses the issue swapping the two ends on negative
ranges. The check is performed in nf_nat_l4proto_unique_tuple() since
the nft nat loads the port values from nft registers at runtime.

v1 -> v2: use the correct 'Fixes' tag
v2 -> v3: update commit message, drop unneeded READ_ONCE()

Fixes: 5b1158e909ec ("[NETFILTER]: Add NAT support for nf_conntrack")
Reported-by: syzbot+8012e198bd037f487...@syzkaller.appspotmail.com
Signed-off-by: Paolo Abeni 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/netfilter/nf_nat_proto_common.c |7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

--- a/net/netfilter/nf_nat_proto_common.c
+++ b/net/netfilter/nf_nat_proto_common.c
@@ -41,7 +41,7 @@ void nf_nat_l4proto_unique_tuple(const s
 const struct nf_conn *ct,
 u16 *rover)
 {
-   unsigned int range_size, min, i;
+   unsigned int range_size, min, max, i;
__be16 *portptr;
u_int16_t off;
 
@@ -71,7 +71,10 @@ void nf_nat_l4proto_unique_tuple(const s
}
} else {
min = ntohs(range->min_proto.all);
-   range_size = ntohs(range->max_proto.all) - min + 1;
+   max = ntohs(range->max_proto.all);
+  

[PATCH 4.4 34/63] netfilter: add back stackpointer size checks

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit 57ebd808a97d7c5b1e1afb937c2db22beba3c1f8 upstream.

The rationale for removing the check is only correct for rulesets
generated by ip(6)tables.

In iptables, a jump can only occur to a user-defined chain, i.e.
because we size the stack based on number of user-defined chains we
cannot exceed stack size.

However, the underlying binary format has no such restriction,
and the validation step only ensures that the jump target is a
valid rule start point.

IOW, its possible to build a rule blob that has no user-defined
chains but does contain a jump.

If this happens, no jump stack gets allocated and crash occurs
because no jumpstack was allocated.

Fixes: 7814b6ec6d0d6 ("netfilter: xtables: don't save/restore jumpstack offset")
Reported-by: syzbot+e783f671527912cd9...@syzkaller.appspotmail.com
Signed-off-by: Florian Westphal 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/ipv4/netfilter/arp_tables.c |4 
 net/ipv4/netfilter/ip_tables.c  |4 
 net/ipv6/netfilter/ip6_tables.c |4 
 3 files changed, 12 insertions(+)

--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -329,6 +329,10 @@ unsigned int arpt_do_table(struct sk_buf
}
if (table_base + v
!= arpt_next_entry(e)) {
+   if (unlikely(stackidx >= private->stacksize)) {
+   verdict = NF_DROP;
+   break;
+   }
jumpstack[stackidx++] = e;
}
 
--- a/net/ipv4/netfilter/ip_tables.c
+++ b/net/ipv4/netfilter/ip_tables.c
@@ -408,6 +408,10 @@ ipt_do_table(struct sk_buff *skb,
}
if (table_base + v != ipt_next_entry(e) &&
!(e->ip.flags & IPT_F_GOTO)) {
+   if (unlikely(stackidx >= private->stacksize)) {
+   verdict = NF_DROP;
+   break;
+   }
jumpstack[stackidx++] = e;
pr_debug("Pushed %p into pos %u\n",
 e, stackidx - 1);
--- a/net/ipv6/netfilter/ip6_tables.c
+++ b/net/ipv6/netfilter/ip6_tables.c
@@ -425,6 +425,10 @@ ip6t_do_table(struct sk_buff *skb,
}
if (table_base + v != ip6t_next_entry(e) &&
!(e->ipv6.flags & IP6T_F_GOTO)) {
+   if (unlikely(stackidx >= private->stacksize)) {
+   verdict = NF_DROP;
+   break;
+   }
jumpstack[stackidx++] = e;
}
 




Re: [PATCH v5 0/2] Remove false-positive VLAs when using max()

2018-03-16 Thread Linus Torvalds
On Fri, Mar 16, 2018 at 4:47 AM, Florian Weimer  wrote:
>
> If you want to catch stack frames which have unbounded size,
> -Werror=stack-usage=1000 or -Werror=vla-larger-than=1000 (with the constant
> adjusted as needed) might be the better approach.

No, we want to catch *variable* stack sizes.

Does "-Werror=vla-larger-than=0" perhaps work for that? No, because
the stupid compiler says that is "meaningless".

And no, using "-Werror=vla-larger-than=1" doesn't work either, because
the moronic compiler continues to think that "vla" is about the
_type_, not the code:

   t.c: In function ‘test’:
   t.c:6:6: error: argument to variable-length array is too large
[-Werror=vla-larger-than=]
 int array[(1,100)];

Gcc people are crazy.

Is there really no way to just say "shut up about the stupid _syntax_
issue that is entirely irrelevant, and give us the _code_ issue".

 Linus


[PATCH 4.4 32/63] Input: tca8418_keypad - remove double read of key event register

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Dmitry Torokhov 

commit 9dd46c02532a6bed6240101ecf4bbc407f8c6adf upstream.

There is no need to tread the same register twice in a row.

Fixes: ea4348c8462a ("Input: tca8418_keypad - hide gcc-4.9 -Wmaybe-un ...")
Signed-off-by: Dmitry Torokhov 
Cc: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/input/keyboard/tca8418_keypad.c |2 --
 1 file changed, 2 deletions(-)

--- a/drivers/input/keyboard/tca8418_keypad.c
+++ b/drivers/input/keyboard/tca8418_keypad.c
@@ -189,8 +189,6 @@ static void tca8418_read_keypad(struct t
input_event(input, EV_MSC, MSC_SCAN, code);
input_report_key(input, keymap[code], state);
 
-   /* Read for next loop */
-   error = tca8418_read_byte(keypad_data, REG_KEY_EVENT_A, ®);
} while (1);
 
input_sync(input);




[PATCH 4.4 30/63] netfilter: nfnetlink_queue: fix timestamp attribute

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit a7f1884554b81bd68cd435d72f09a3527629ac43 upstream.

Since 4.4 we erronously use timestamp of the netlink skb (which is zero).

Bugzilla: https://bugzilla.netfilter.org/show_bug.cgi?id=1066
Fixes: b28b1e826f818c30ea7 ("netfilter: nfnetlink_queue: use y2038 safe 
timestamp")
Signed-off-by: Florian Westphal 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/netfilter/nfnetlink_queue.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -501,7 +501,7 @@ nfqnl_build_packet_message(struct net *n
 
if (entskb->tstamp.tv64) {
struct nfqnl_msg_packet_timestamp ts;
-   struct timespec64 kts = ktime_to_timespec64(skb->tstamp);
+   struct timespec64 kts = ktime_to_timespec64(entskb->tstamp);
 
ts.sec = cpu_to_be64(kts.tv_sec);
ts.usec = cpu_to_be64(kts.tv_nsec / NSEC_PER_USEC);




[PATCH 4.4 29/63] watchdog: hpwdt: fix unused variable warning

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Arnd Bergmann 

commit aeebc6ba88ba3758ad95467ff6191fabf2074c13 upstream.

The new hpwdt_my_nmi() function is used conditionally, which produces
a harmless warning in some configurations:

drivers/watchdog/hpwdt.c:478:12: error: 'hpwdt_my_nmi' defined but not used 
[-Werror=unused-function]

This moves it inside of the #ifdef that protects its caller, to silence
the warning.

Fixes: 621174a92851 ("watchdog: hpwdt: Check source of NMI")
Signed-off-by: Arnd Bergmann 
Reviewed-by: Jerry Hoemann 
Reviewed-by: Guenter Roeck 
Signed-off-by: Guenter Roeck 
Signed-off-by: Wim Van Sebroeck 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/watchdog/hpwdt.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -474,12 +474,12 @@ static int hpwdt_time_left(void)
return TICKS_TO_SECS(ioread16(hpwdt_timer_reg));
 }
 
+#ifdef CONFIG_HPWDT_NMI_DECODING
 static int hpwdt_my_nmi(void)
 {
return ioread8(hpwdt_nmistat) & 0x6;
 }
 
-#ifdef CONFIG_HPWDT_NMI_DECODING
 /*
  * NMI Handler
  */




Re: [PATCH v5 11/11] KVM: x86: Disable Intel Processor Trace when VMXON in L1 guest

2018-03-16 Thread Paolo Bonzini
On 04/03/2018 13:07, Luwei Kang wrote:
> + if (pt_mode == PT_MODE_HOST_GUEST) {

This would be vmx_pt_supported(), but I think it's better to remove that
function and just test pt_mode == PT_MODE_HOST_GUEST everywhere (or !=).

Paolo

> + vmx->pt_desc.guest.ctl = 0;
> + vmcs_write64(GUEST_IA32_RTIT_CTL, 0);
> + pt_set_intercept_for_msr(vmx, 1);
> + }
> +



[PATCH 4.4 31/63] ARM: omap2: hide omap3_save_secure_ram on non-OMAP3 builds

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Arnd Bergmann 

commit 863204cfdae98626a92535ac928ad79f4d6b74ff upstream.

In configurations without CONFIG_OMAP3 but with secure RAM support,
we now run into a link failure:

arch/arm/mach-omap2/omap-secure.o: In function `omap3_save_secure_ram':
omap-secure.c:(.text+0x130): undefined reference to `save_secure_ram_context'

The omap3_save_secure_ram() function is only called from the OMAP34xx
power management code, so we can simply hide that function in the
appropriate #ifdef.

Fixes: d09220a887f7 ("ARM: OMAP2+: Fix SRAM virt to phys translation for 
save_secure_ram_context")
Acked-by: Tony Lindgren 
Tested-by: Dan Murphy 
Signed-off-by: Arnd Bergmann 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/arm/mach-omap2/omap-secure.c |2 ++
 1 file changed, 2 insertions(+)

--- a/arch/arm/mach-omap2/omap-secure.c
+++ b/arch/arm/mach-omap2/omap-secure.c
@@ -73,6 +73,7 @@ phys_addr_t omap_secure_ram_mempool_base
return omap_secure_memblock_base;
 }
 
+#if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_PM)
 u32 omap3_save_secure_ram(void __iomem *addr, int size)
 {
u32 ret;
@@ -91,6 +92,7 @@ u32 omap3_save_secure_ram(void __iomem *
 
return ret;
 }
+#endif
 
 /**
  * rx51_secure_dispatcher: Routine to dispatch secure PPA API calls




[PATCH 4.4 27/63] watchdog: hpwdt: SMBIOS check

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Jerry Hoemann 

commit c42cbe41727a138905a28f8e0b00c147be77ee93 upstream.

This corrects:
commit cce78da76601 ("watchdog: hpwdt: Add check for UEFI bits")

The test on HPE SMBIOS extension type 219 record "Misc Features"
bits for UEFI support is incorrect.  The definition of the Misc Features
bits in the HPE SMBIOS OEM Extensions specification (and related
firmware) was changed to use a different pair of bits to
represent UEFI supported.  Howerver, a corresponding change
to Linux was missed.

Current code/platform work because the iCRU test is working.
But purpose of cce78da766 is to ensure correct functionality
on future systems where iCRU isn't supported.

Signed-off-by: Jerry Hoemann 
Reviewed-by: Guenter Roeck 
Signed-off-by: Guenter Roeck 
Signed-off-by: Wim Van Sebroeck 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/watchdog/hpwdt.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/drivers/watchdog/hpwdt.c
+++ b/drivers/watchdog/hpwdt.c
@@ -700,7 +700,7 @@ static void dmi_find_icru(const struct d
smbios_proliant_ptr = (struct smbios_proliant_info *) dm;
if (smbios_proliant_ptr->misc_features & 0x01)
is_icru = 1;
-   if (smbios_proliant_ptr->misc_features & 0x408)
+   if (smbios_proliant_ptr->misc_features & 0x1400)
is_uefi = 1;
}
 }




[PATCH 4.4 26/63] nospec: Include dependency

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Dan Williams 

commit eb6174f6d1be16b19cfa43dac296bfed003ce1a6 upstream.

The nospec.h header expects the per-architecture header file
 to optionally define array_index_mask_nospec(). Include
that dependency to prevent inadvertent fallback to the default
array_index_mask_nospec() implementation.

The default implementation may not provide a full mitigation
on architectures that perform data value speculation.

Reported-by: Christian Borntraeger 
Signed-off-by: Dan Williams 
Cc: Andy Lutomirski 
Cc: Arjan van de Ven 
Cc: Borislav Petkov 
Cc: Dave Hansen 
Cc: David Woodhouse 
Cc: Greg Kroah-Hartman 
Cc: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: linux-a...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/151881605404.17395.1341935530792574707.st...@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Ingo Molnar 
Signed-off-by: Greg Kroah-Hartman 

---
 include/linux/nospec.h |1 +
 1 file changed, 1 insertion(+)

--- a/include/linux/nospec.h
+++ b/include/linux/nospec.h
@@ -5,6 +5,7 @@
 
 #ifndef _LINUX_NOSPEC_H
 #define _LINUX_NOSPEC_H
+#include 
 
 /**
  * array_index_mask_nospec() - generate a ~0 mask when index < size, 0 
otherwise




[PATCH 4.4 25/63] ALSA: hda: add dock and led support for HP ProBook 640 G2

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Dennis Wassenberg 

commit 099fd6ca0ad25bc19c5ade2ea4b25b8fadaa11b3 upstream.

This patch adds missing initialisation for HP 2013 UltraSlim Dock
Line-In/Out PINs and activates keyboard mute/micmute leds
for HP ProBook 640 G2

Signed-off-by: Dennis Wassenberg 
Cc: 
Signed-off-by: Takashi Iwai 
Signed-off-by: Greg Kroah-Hartman 

---
 sound/pci/hda/patch_conexant.c |1 +
 1 file changed, 1 insertion(+)

--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -850,6 +850,7 @@ static const struct snd_pci_quirk cxt506
SND_PCI_QUIRK(0x1025, 0x054f, "Acer Aspire 4830T", 
CXT_FIXUP_ASPIRE_DMIC),
SND_PCI_QUIRK(0x103c, 0x8079, "HP EliteBook 840 G3", CXT_FIXUP_HP_DOCK),
SND_PCI_QUIRK(0x103c, 0x807C, "HP EliteBook 820 G3", CXT_FIXUP_HP_DOCK),
+   SND_PCI_QUIRK(0x103c, 0x80FD, "HP ProBook 640 G2", CXT_FIXUP_HP_DOCK),
SND_PCI_QUIRK(0x103c, 0x8174, "HP Spectre x360", CXT_FIXUP_HP_SPECTRE),
SND_PCI_QUIRK(0x103c, 0x8115, "HP Z1 Gen3", CXT_FIXUP_HP_GATE_MIC),
SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),




Re: [PATCH v5 0/2] Remove false-positive VLAs when using max()

2018-03-16 Thread Florian Weimer

On 03/16/2018 06:29 PM, Linus Torvalds wrote:


Gcc people are crazy.


End of discussion from me.  This is not acceptable.

Florian


Re: [PATCH][RFC] kernel.h: provide array iterator

2018-03-16 Thread Rasmus Villemoes
On 2018-03-15 11:00, Kieran Bingham wrote:
> Simplify array iteration with a helper to iterate each entry in an array.
> Utilise the existing ARRAY_SIZE macro to identify the length of the array
> and pointer arithmetic to process each item as a for loop.
> 
> Signed-off-by: Kieran Bingham 
> ---
>  include/linux/kernel.h | 10 ++
>  1 file changed, 10 insertions(+)
> 
> The use of static arrays to store data is a common use case throughout the
> kernel. Along with that is the obvious need to iterate that data.
> 
> In fact there are just shy of 5000 instances of iterating a static array:
>   git grep "for .*ARRAY_SIZE" | wc -l
>   4943
> 
> When working on the UVC driver - I found that I needed to split one such
> iteration into two parts, and at the same time felt that this could be
> refactored to be cleaner / easier to read. 

About that, it would be helpful if you first converted to the new
iterator, so that one can more easily see they are equivalent. And then
split in two, adding the flush_workqueue call. Or do it the other way
around. But please don't mix the two in one patch, especially not if
it's supposed to act as an example of how to use the new helper.

> I do however worry that this simple short patch might not be desired or could
> also be heavily bikeshedded due to it's potential wide spread use (though
> perhaps that would be a good thing to have more users) ...  but here it is,
> along with an example usage below which is part of a separate series.

I think it can be useful, and it does have the must_be_array protection
built in, so code doesn't silently break if one changes from a
fixed-size allocation to e.g. a kmalloc-based one. Just don't attempt a
tree-wide mass conversion, but obviously starting to make use of it when
refactoring code anyway is fine.

And now, the bikeshedding you expected :)

> diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> index ce51455e2adf..95d7dae248b7 100644
> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -70,6 +70,16 @@
>   */
>  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + 
> __must_be_array(arr))
>  
> +/**
> + * for_each_array_element - Iterate all items in an array
> + * @elem: pointer of array type for iteration cursor

Hm, "pointer of array type" sounds wrong; it's not a "pointer to array".
But "pointer of array elements' type" is clumsy. Maybe just "@elem:
iteration cursor" is clear enough.

> + * @array: array to be iterated
> + */
> +#define for_each_array_element(elem, array) \
> + for (elem = &(array)[0]; \
> +  elem < &(array)[ARRAY_SIZE(array)]; \
> +  ++elem)
> +

Please parenthesize elem as well.

Rasmus


[PATCH 4.4 20/63] x86/MCE: Serialize sysfs changes

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Seunghun Han 

commit b3b7c4795ccab5be71f080774c45bbbcc75c2aaf upstream.

The check_interval file in

  /sys/devices/system/machinecheck/machinecheck

directory is a global timer value for MCE polling. If it is changed by one
CPU, mce_restart() broadcasts the event to other CPUs to delete and restart
the MCE polling timer and __mcheck_cpu_init_timer() reinitializes the
mce_timer variable.

If more than one CPU writes a specific value to the check_interval file
concurrently, mce_timer is not protected from such concurrent accesses and
all kinds of explosions happen. Since only root can write to those sysfs
variables, the issue is not a big deal security-wise.

However, concurrent writes to these configuration variables is void of
reason so the proper thing to do is to serialize the access with a mutex.

Boris:

 - Make store_int_with_restart() use device_store_ulong() to filter out
   negative intervals
 - Limit min interval to 1 second
 - Correct locking
 - Massage commit message

Signed-off-by: Seunghun Han 
Signed-off-by: Borislav Petkov 
Signed-off-by: Thomas Gleixner 
Cc: Greg Kroah-Hartman 
Cc: Tony Luck 
Cc: linux-edac 
Cc: sta...@vger.kernel.org
Link: http://lkml.kernel.org/r/20180302202706.9434-1-kkama...@gmail.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/cpu/mcheck/mce.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -60,6 +60,9 @@ static DEFINE_MUTEX(mce_chrdev_read_mute
smp_load_acquire(&(p)); \
 })
 
+/* sysfs synchronization */
+static DEFINE_MUTEX(mce_sysfs_mutex);
+
 #define CREATE_TRACE_POINTS
 #include 
 
@@ -2220,6 +2223,7 @@ static ssize_t set_ignore_ce(struct devi
if (kstrtou64(buf, 0, &new) < 0)
return -EINVAL;
 
+   mutex_lock(&mce_sysfs_mutex);
if (mca_cfg.ignore_ce ^ !!new) {
if (new) {
/* disable ce features */
@@ -2232,6 +2236,8 @@ static ssize_t set_ignore_ce(struct devi
on_each_cpu(mce_enable_ce, (void *)1, 1);
}
}
+   mutex_unlock(&mce_sysfs_mutex);
+
return size;
 }
 
@@ -2244,6 +2250,7 @@ static ssize_t set_cmci_disabled(struct
if (kstrtou64(buf, 0, &new) < 0)
return -EINVAL;
 
+   mutex_lock(&mce_sysfs_mutex);
if (mca_cfg.cmci_disabled ^ !!new) {
if (new) {
/* disable cmci */
@@ -2255,6 +2262,8 @@ static ssize_t set_cmci_disabled(struct
on_each_cpu(mce_enable_ce, NULL, 1);
}
}
+   mutex_unlock(&mce_sysfs_mutex);
+
return size;
 }
 
@@ -2262,8 +2271,19 @@ static ssize_t store_int_with_restart(st
  struct device_attribute *attr,
  const char *buf, size_t size)
 {
-   ssize_t ret = device_store_int(s, attr, buf, size);
+   unsigned long old_check_interval = check_interval;
+   ssize_t ret = device_store_ulong(s, attr, buf, size);
+
+   if (check_interval == old_check_interval)
+   return ret;
+
+   if (check_interval < 1)
+   check_interval = 1;
+
+   mutex_lock(&mce_sysfs_mutex);
mce_restart();
+   mutex_unlock(&mce_sysfs_mutex);
+
return ret;
 }
 




Re: arc_usr_cmpxchg and preemption

2018-03-16 Thread Alexey Brodkin
Hi Peter, Vineet,

On Wed, 2018-03-14 at 18:53 +0100, Peter Zijlstra wrote:
> On Wed, Mar 14, 2018 at 09:58:19AM -0700, Vineet Gupta wrote:
> 
> > Well it is broken wrt the semantics the syscall is supposed to provide.
> > Preemption disabling is what prevents a concurrent thread from coming in and
> > modifying the same location (Imagine a variable which is being cmpxchg
> > concurrently by 2 threads).
> > 
> > One approach is to do it the MIPS way, emulate the llsc flag - set it under
> > preemption disabled section and clear it in switch_to
> 
> *shudder*... just catch the -EFAULT, force the write fault and retry.

More I look at this initially quite simple thing more it looks like
a can of worms...

> Something like:
> 
> int sys_cmpxchg(u32 __user *user_ptr, u32 old, u32 new)
> {

That functions is supposed to return old value stored in memory.
At least that's how it is used in case of ARC and M68K.

Remember there's already libc that relies on that established API
and we cannot just change it... even though it might be a good idea.
For example return "errno" and pass old value via pointer in an argument.
But now I guess it's better to use what we have now.

>   u32 val;
>   int ret;
> 
> again:
>   ret = 0;
> 
>   preempt_disable();
>   val = get_user(user_ptr);

What if get_user() fails?
In Peter's implementation we will return 0, in Vineet's
we will return -EFAULT... and who knows what kind of unexpected behavior happens
further down the line in user-space... so I think it would be safer to kill
the process then.

And that's my take:
-->8
int sys_cmpxchg(u32 __user *user_ptr, u32 old, u32 new)
{
u32 val;
int ret;

again:
ret = 0;

preempt_disable();

ret = get_user(val, user_ptr);
if(ret == -EFAULT) {
struct page *page;

preempt_enable();
ret = get_user_pages_fast((unsigned long)user_ptr, 1, 1, &page);
if (ret < 0) {
force_sig(SIGSEGV, current);
return ret;
}

put_page(page);
goto again;
}

if (val == old)
ret = put_user(new, user_ptr);

preempt_enable();

if (ret == -EFAULT) {
struct page *page;

ret = get_user_pages_fast((unsigned long)user_ptr, 1, 1, &page);
if (ret < 0) {
force_sig(SIGSEGV, current);
return ret;
}

put_page(page);
goto again;
}

return ret;
}
-->8

-Alexey

[PATCH 4.4 19/63] bcache: dont attach backing with duplicate UUID

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Michael Lyle 

commit 86755b7a96faed57f910f9e6b8061e019ac1ec08 upstream.

This can happen e.g. during disk cloning.

This is an incomplete fix: it does not catch duplicate UUIDs earlier
when things are still unattached.  It does not unregister the device.
Further changes to cope better with this are planned but conflict with
Coly's ongoing improvements to handling device errors.  In the meantime,
one can manually stop the device after this has happened.

Attempts to attach a duplicate device result in:

[  136.372404] loop: module loaded
[  136.424461] bcache: register_bdev() registered backing device loop0
[  136.424464] bcache: bch_cached_dev_attach() Tried to attach loop0 but 
duplicate UUID already attached

My test procedure is:

  dd if=/dev/sdb1 of=imgfile bs=1024 count=262144
  losetup -f imgfile

Signed-off-by: Michael Lyle 
Reviewed-by: Tang Junhui 
Cc: 
Signed-off-by: Jens Axboe 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/md/bcache/super.c |   11 +++
 1 file changed, 11 insertions(+)

--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -935,6 +935,7 @@ int bch_cached_dev_attach(struct cached_
uint32_t rtime = cpu_to_le32(get_seconds());
struct uuid_entry *u;
char buf[BDEVNAME_SIZE];
+   struct cached_dev *exist_dc, *t;
 
bdevname(dc->bdev, buf);
 
@@ -958,6 +959,16 @@ int bch_cached_dev_attach(struct cached_
return -EINVAL;
}
 
+   /* Check whether already attached */
+   list_for_each_entry_safe(exist_dc, t, &c->cached_devs, list) {
+   if (!memcmp(dc->sb.uuid, exist_dc->sb.uuid, 16)) {
+   pr_err("Tried to attach %s but duplicate UUID already 
attached",
+   buf);
+
+   return -EINVAL;
+   }
+   }
+
u = uuid_find(c, dc->sb.uuid);
 
if (u &&




[PATCH 4.4 10/63] drm/amdgpu: Notify sbios device ready before send request

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Rex Zhu 

commit 1bced75f4ab04bec55aecb57d99435dc6d0ae5a0 upstream.

it is required if a platform supports PCIe root complex
core voltage reduction. After receiving this notification,
SBIOS can apply default PCIe root complex power policy.

Reviewed-by: Alex Deucher 
Signed-off-by: Rex Zhu 
Signed-off-by: Alex Deucher 
Cc: sta...@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
@@ -585,6 +585,9 @@ int amdgpu_acpi_pcie_performance_request
size_t size;
u32 retry = 3;
 
+   if (amdgpu_acpi_pcie_notify_device_ready(adev))
+   return -EINVAL;
+
/* Get the device handle */
handle = ACPI_HANDLE(&adev->pdev->dev);
if (!handle)




[PATCH 4.4 08/63] drm/radeon: Fix deadlock on runtime suspend

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Lukas Wunner 

commit 15734feff2bdac24aa3266c437cffa42851990e3 upstream.

radeon's ->runtime_suspend hook calls drm_kms_helper_poll_disable(),
which waits for the output poll worker to finish if it's running.

The output poll worker meanwhile calls pm_runtime_get_sync() in
radeon's ->detect hooks, which waits for the ongoing suspend to finish,
causing a deadlock.

Fix by not acquiring a runtime PM ref if the ->detect hooks are called
in the output poll worker's context.  This is safe because the poll
worker is only enabled while runtime active and we know that
->runtime_suspend waits for it to finish.

Stack trace for posterity:

  INFO: task kworker/0:3:31847 blocked for more than 120 seconds
  Workqueue: events output_poll_execute [drm_kms_helper]
  Call Trace:
   schedule+0x3c/0x90
   rpm_resume+0x1e2/0x690
   __pm_runtime_resume+0x3f/0x60
   radeon_lvds_detect+0x39/0xf0 [radeon]
   output_poll_execute+0xda/0x1e0 [drm_kms_helper]
   process_one_work+0x14b/0x440
   worker_thread+0x48/0x4a0

  INFO: task kworker/2:0:10493 blocked for more than 120 seconds.
  Workqueue: pm pm_runtime_work
  Call Trace:
   schedule+0x3c/0x90
   schedule_timeout+0x1b3/0x240
   wait_for_common+0xc2/0x180
   wait_for_completion+0x1d/0x20
   flush_work+0xfc/0x1a0
   __cancel_work_timer+0xa5/0x1d0
   cancel_delayed_work_sync+0x13/0x20
   drm_kms_helper_poll_disable+0x1f/0x30 [drm_kms_helper]
   radeon_pmops_runtime_suspend+0x3d/0xa0 [radeon]
   pci_pm_runtime_suspend+0x61/0x1a0
   vga_switcheroo_runtime_suspend+0x21/0x70
   __rpm_callback+0x32/0x70
   rpm_callback+0x24/0x80
   rpm_suspend+0x12b/0x640
   pm_runtime_work+0x6f/0xb0
   process_one_work+0x14b/0x440
   worker_thread+0x48/0x4a0

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=94147
Fixes: 10ebc0bc0934 ("drm/radeon: add runtime PM support (v2)")
Cc: sta...@vger.kernel.org # v3.13+: 27d4ee03078a: workqueue: Allow retrieval 
of current task's work struct
Cc: sta...@vger.kernel.org # v3.13+: 25c058ccaf2e: drm: Allow determining if 
current task is output poll worker
Cc: Ismo Toijala 
Cc: Alex Deucher 
Cc: Dave Airlie 
Reviewed-by: Lyude Paul 
Signed-off-by: Lukas Wunner 
Link: 
https://patchwork.freedesktop.org/patch/msgid/64ea02c44f91dda19bc563902b97bbc699040392.1518338789.git.lu...@wunner.de
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/radeon/radeon_connectors.c |   74 +++--
 1 file changed, 49 insertions(+), 25 deletions(-)

--- a/drivers/gpu/drm/radeon/radeon_connectors.c
+++ b/drivers/gpu/drm/radeon/radeon_connectors.c
@@ -891,9 +891,11 @@ radeon_lvds_detect(struct drm_connector
enum drm_connector_status ret = connector_status_disconnected;
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
if (encoder) {
struct radeon_encoder *radeon_encoder = 
to_radeon_encoder(encoder);
@@ -916,8 +918,12 @@ radeon_lvds_detect(struct drm_connector
/* check acpi lid status ??? */
 
radeon_connector_update_scratch_regs(connector, ret);
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
+
return ret;
 }
 
@@ -1020,9 +1026,11 @@ radeon_vga_detect(struct drm_connector *
enum drm_connector_status ret = connector_status_disconnected;
int r;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   return connector_status_disconnected;
+   if (!drm_kms_helper_is_poll_worker()) {
+   r = pm_runtime_get_sync(connector->dev->dev);
+   if (r < 0)
+   return connector_status_disconnected;
+   }
 
encoder = radeon_best_single_encoder(connector);
if (!encoder)
@@ -1089,8 +1097,10 @@ radeon_vga_detect(struct drm_connector *
radeon_connector_update_scratch_regs(connector, ret);
 
 out:
-   pm_runtime_mark_last_busy(connector->dev->dev);
-   pm_runtime_put_autosuspend(connector->dev->dev);
+   if (!drm_kms_helper_is_poll_worker()) {
+   pm_runtime_mark_last_busy(connector->dev->dev);
+   pm_runtime_put_autosuspend(connector->dev->dev);
+   }
 
return ret;
 }
@@ -1153,9 +1163,11 @@ radeon_tv_detect(struct drm_connector *c
if (!radeon_connector->dac_load_detect)
return ret;
 
-   r = pm_runtime_get_sync(connector->dev->dev);
-   if (r < 0)
-   ret

[PATCH 4.4 03/63] RDMA/mlx5: Fix integer overflow while resizing CQ

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Leon Romanovsky 

commit 28e9091e3119933c38933cb8fc48d5618eb784c8 upstream.

The user can provide very large cqe_size which will cause to integer
overflow as it can be seen in the following UBSAN warning:

===
UBSAN: Undefined behaviour in drivers/infiniband/hw/mlx5/cq.c:1192:53
signed integer overflow:
64870 * 65536 cannot be represented in type 'int'
CPU: 0 PID: 267 Comm: syzkaller605279 Not tainted 4.15.0+ #90 Hardware
name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014
Call Trace:
 dump_stack+0xde/0x164
 ? dma_virt_map_sg+0x22c/0x22c
 ubsan_epilogue+0xe/0x81
 handle_overflow+0x1f3/0x251
 ? __ubsan_handle_negate_overflow+0x19b/0x19b
 ? lock_acquire+0x440/0x440
 mlx5_ib_resize_cq+0x17e7/0x1e40
 ? cyc2ns_read_end+0x10/0x10
 ? native_read_msr_safe+0x6c/0x9b
 ? cyc2ns_read_end+0x10/0x10
 ? mlx5_ib_modify_cq+0x220/0x220
 ? sched_clock_cpu+0x18/0x200
 ? lookup_get_idr_uobject+0x200/0x200
 ? rdma_lookup_get_uobject+0x145/0x2f0
 ib_uverbs_resize_cq+0x207/0x3e0
 ? ib_uverbs_ex_create_cq+0x250/0x250
 ib_uverbs_write+0x7f9/0xef0
 ? cyc2ns_read_end+0x10/0x10
 ? print_irqtrace_events+0x280/0x280
 ? ib_uverbs_ex_create_cq+0x250/0x250
 ? uverbs_devnode+0x110/0x110
 ? sched_clock_cpu+0x18/0x200
 ? do_raw_spin_trylock+0x100/0x100
 ? __lru_cache_add+0x16e/0x290
 __vfs_write+0x10d/0x700
 ? uverbs_devnode+0x110/0x110
 ? kernel_read+0x170/0x170
 ? sched_clock_cpu+0x18/0x200
 ? security_file_permission+0x93/0x260
 vfs_write+0x1b0/0x550
 SyS_write+0xc7/0x1a0
 ? SyS_read+0x1a0/0x1a0
 ? trace_hardirqs_on_thunk+0x1a/0x1c
 entry_SYSCALL_64_fastpath+0x1e/0x8b
RIP: 0033:0x433549
RSP: 002b:7ffe63bd1ea8 EFLAGS: 0217
===

Cc: syzkaller 
Cc:  # 3.13
Fixes: bde51583f49b ("IB/mlx5: Add support for resize CQ")
Reported-by: Noa Osherovich 
Reviewed-by: Yishai Hadas 
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/infiniband/hw/mlx5/cq.c |7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

--- a/drivers/infiniband/hw/mlx5/cq.c
+++ b/drivers/infiniband/hw/mlx5/cq.c
@@ -972,7 +972,12 @@ static int resize_user(struct mlx5_ib_de
if (ucmd.reserved0 || ucmd.reserved1)
return -EINVAL;
 
-   umem = ib_umem_get(context, ucmd.buf_addr, entries * ucmd.cqe_size,
+   /* check multiplication overflow */
+   if (ucmd.cqe_size && SIZE_MAX / ucmd.cqe_size <= entries - 1)
+   return -EINVAL;
+
+   umem = ib_umem_get(context, ucmd.buf_addr,
+  (size_t)ucmd.cqe_size * entries,
   IB_ACCESS_LOCAL_WRITE, 1);
if (IS_ERR(umem)) {
err = PTR_ERR(umem);




Re: [PATCH 0/2] net: phy: relax error checking when creating sysfs link netdev->phydev

2018-03-16 Thread Florian Fainelli


On 03/16/2018 10:22 AM, Andrew Lunn wrote:
> On Wed, Mar 14, 2018 at 05:26:22PM -0500, Grygorii Strashko wrote:
>> Some ethernet drivers (like TI CPSW) may connect and manage >1 Net PHYs per
>> one netdevice, as result such drivers will produce warning during system
>> boot and fail to connect second phy to netdevice when PHYLIB framework
>> will try to create sysfs link netdev->phydev for second PHY
>> in phy_attach_direct(), because sysfs link with the same name has been
>> created already for the first PHY.
>> As result, second CPSW external port will became unusable.
>> This issue was introduced by commits:
>> 5568363f0cb3 ("net: phy: Create sysfs reciprocal links for 
>> attached_dev/phydev"
>> a3995460491d ("net: phy: Relax error checking on sysfs_create_link()"
> 
> I wonder if it would be better to add a flag to the phydev that
> indicates it is the second PHY connected to a MAC? Add a bit to
> phydrv->mdiodrv.flags. If that bit is set, don't create the sysfs
> file.

We could indeed do that, I am fine with Grygorii's approach though in
making the creation more silent and non fatal.

> 
> For 99% of MAC drivers, having two PHYs is an error, so we want to aid
> debug by reporting the sysfs error.
That is true, either way is fine with me, really.
-- 
Florian


[PATCH 4.4 06/63] drm: Allow determining if current task is output poll worker

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Lukas Wunner 

commit 25c058ccaf2ebbc3e250ec1e199e161f91fe27d4 upstream.

Introduce a helper to determine if the current task is an output poll
worker.

This allows us to fix a long-standing deadlock in several DRM drivers
wherein the ->runtime_suspend callback waits for the output poll worker
to finish and the worker in turn calls a ->detect callback which waits
for runtime suspend to finish.  The ->detect callback is invoked from
multiple call sites and waiting for runtime suspend to finish is the
correct thing to do except if it's executing in the context of the
worker.

v2: Expand kerneldoc to specifically mention deadlock between
output poll worker and autosuspend worker as use case. (Lyude)

Cc: Dave Airlie 
Cc: Ben Skeggs 
Cc: Alex Deucher 
Reviewed-by: Lyude Paul 
Signed-off-by: Lukas Wunner 
Link: 
https://patchwork.freedesktop.org/patch/msgid/3549ce32e7f1467102e70d3e9cbf70c46bfe108e.1518593424.git.lu...@wunner.de
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/gpu/drm/drm_probe_helper.c |   20 
 include/drm/drm_crtc_helper.h  |1 +
 2 files changed, 21 insertions(+)

--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -412,6 +412,26 @@ out:
 }
 
 /**
+ * drm_kms_helper_is_poll_worker - is %current task an output poll worker?
+ *
+ * Determine if %current task is an output poll worker.  This can be used
+ * to select distinct code paths for output polling versus other contexts.
+ *
+ * One use case is to avoid a deadlock between the output poll worker and
+ * the autosuspend worker wherein the latter waits for polling to finish
+ * upon calling drm_kms_helper_poll_disable(), while the former waits for
+ * runtime suspend to finish upon calling pm_runtime_get_sync() in a
+ * connector ->detect hook.
+ */
+bool drm_kms_helper_is_poll_worker(void)
+{
+   struct work_struct *work = current_work();
+
+   return work && work->func == output_poll_execute;
+}
+EXPORT_SYMBOL(drm_kms_helper_is_poll_worker);
+
+/**
  * drm_kms_helper_poll_disable - disable output polling
  * @dev: drm_device
  *
--- a/include/drm/drm_crtc_helper.h
+++ b/include/drm/drm_crtc_helper.h
@@ -241,5 +241,6 @@ extern void drm_kms_helper_hotplug_event
 extern void drm_kms_helper_poll_disable(struct drm_device *dev);
 extern void drm_kms_helper_poll_enable(struct drm_device *dev);
 extern void drm_kms_helper_poll_enable_locked(struct drm_device *dev);
+extern bool drm_kms_helper_is_poll_worker(void);
 
 #endif




[PATCH 4.4 02/63] RDMA/ucma: Check that user doesnt overflow QP state

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Leon Romanovsky 

commit a5880b84430316e3e1c1f5d23aa32ec6000cc717 upstream.

The QP state is limited and declared in enum ib_qp_state,
but ucma user was able to supply any possible (u32) value.

Reported-by: syzbot+0df1ab766f8924b1e...@syzkaller.appspotmail.com
Fixes: 75216638572f ("RDMA/cma: Export rdma cm interface to userspace")
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/infiniband/core/ucma.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1138,6 +1138,9 @@ static ssize_t ucma_init_qp_attr(struct
if (copy_from_user(&cmd, inbuf, sizeof(cmd)))
return -EFAULT;
 
+   if (cmd.qp_state > IB_QPS_ERR)
+   return -EINVAL;
+
ctx = ucma_get_ctx(file, cmd.id);
if (IS_ERR(ctx))
return PTR_ERR(ctx);




[PATCH v6 3/3] arm64: dts: renesas: Add LVDS decoder to R-Car V3M Eagle

2018-03-16 Thread Jacopo Mondi
The R-Car V3M Eagle board includes a transparent THC63LVD1024 LVDS
decoder, connected to the on-chip LVDS encoder output on one side
and to HDMI encoder ADV7511w on the other one.

As the decoder does not need any configuration it has been so-far
omitted from DTS. Now that a driver is available, describe it in DT
as well.

Signed-off-by: Jacopo Mondi 
Reviewed-by: Andrzej Hajda 

---

List of patch dependencies, as of renesas-drivers-2018-03-13-v4.16-rc5:

- [PATCH v2 0/5] arm64: dts: renesas: r8a77970: enable HDMI output
   which includes DU, LVDS and FCPD enablement from:
  [PATCH v2 0/5] Add R8A77970/V3MSK LVDS/HDMI support
- [PATCH v4] v4l: vsp1: Fix video output on R8A77970

Patches to be applied on top of
"arm64: dts: renesas: eagle: add HDMI output using the ADV7511W"

Thanks
   j
---
 arch/arm64/boot/dts/renesas/r8a77970-eagle.dts | 33 +++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/boot/dts/renesas/r8a77970-eagle.dts 
b/arch/arm64/boot/dts/renesas/r8a77970-eagle.dts
index c0fd144..69f43b8 100644
--- a/arch/arm64/boot/dts/renesas/r8a77970-eagle.dts
+++ b/arch/arm64/boot/dts/renesas/r8a77970-eagle.dts
@@ -42,6 +42,33 @@
};
};
};
+
+   thc63lvd1024: lvds-decoder {
+   compatible = "thine,thc63lvd1024";
+
+   ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   port@0 {
+   reg = <0>;
+
+   thc63lvd1024_in_0: endpoint {
+   remote-endpoint = <&lvds0_out>;
+   };
+   };
+
+   port@2{
+   reg = <2>;
+
+   thc63lvd1024_out_2: endpoint {
+   remote-endpoint = <&adv7511_in>;
+   };
+
+   };
+
+   };
+   };
 };
 
 &avb {
@@ -98,7 +125,7 @@
port@0 {
reg = <0>;
adv7511_in: endpoint {
-   remote-endpoint = <&lvds0_out>;
+   remote-endpoint = <&thc63lvd1024_out_2>;
};
};
 
@@ -152,8 +179,8 @@
 
ports {
port@1 {
-   endpoint {
-   remote-endpoint = <&adv7511_in>;
+   lvds0_out: endpoint {
+   remote-endpoint = <&thc63lvd1024_in_0>;
};
};
};
-- 
2.7.4



[PATCH 4.4 04/63] scsi: qla2xxx: Fix NULL pointer crash due to active timer for ABTS

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: himanshu.madh...@cavium.com 

commit 1514839b366417934e2f1328edb50ed1e8a719f5 upstream.

This patch fixes NULL pointer crash due to active timer running for abort
IOCB.

>From crash dump analysis it was discoverd that get_next_timer_interrupt()
encountered a corrupted entry on the timer list.

 #9 [95e1f6f0fd40] page_fault at 914fe8f8
[exception RIP: get_next_timer_interrupt+440]
RIP: 90ea3088  RSP: 95e1f6f0fdf0  RFLAGS: 00010013
RAX: 95e1f6451028  RBX: 000218e2389e5f40  RCX: 0001232ad600
RDX: 0001  RSI: 95e1f6f0fdf0  RDI: 01232ad6
RBP: 95e1f6f0fe40   R8: 95e1f6451188   R9: 0001
R10: 0016  R11: 0016  R12: 0001232ad5f6
R13: 95e1f645  R14: 95e1f6f0fdf8  R15: 95e1f6f0fe10
ORIG_RAX:   CS: 0010  SS: 0018

Looking at the assembly of get_next_timer_interrupt(), address came
from %r8 (95e1f6451188) which is pointing to list_head with single
entry at 95e5ff621178.

 0x90ea307a :  mov(%r8),%rdx
 0x90ea307d :  cmp%r8,%rdx
 0x90ea3080 :  je 
0x90ea30a7 
 0x90ea3082 :  nopw   0x0(%rax,%rax,1)
 0x90ea3088 :  testb  $0x1,0x18(%rdx)

 crash> rd 95e1f6451188 10
 95e1f6451188:  95e5ff621178 95e5ff621178   x.b.x.b.
 95e1f6451198:  95e1f6451198 95e1f6451198   ..E...E.
 95e1f64511a8:  95e1f64511a8 95e1f64511a8   ..E...E.
 95e1f64511b8:  95e77cf509a0 95e77cf509a0   ...|...|
 95e1f64511c8:  95e1f64511c8 95e1f64511c8   ..E...E.

 crash> rd 95e5ff621178 10
 95e5ff621178:  0001 95e15936aa00   ..6Y
 95e5ff621188:      
 95e5ff621198:  00a0 0010   
 95e5ff6211a8:  95e5ff621198 000c   ..b.
 95e5ff6211b8:  0f58 95e751f8d720   X... ..Q

 95e5ff621178 belongs to freed mempool object at 95e5ff621080.

 CACHENAME OBJSIZE  ALLOCATED TOTAL  SLABS  
SSIZE
 95dc7fd74d00 mnt_cache384  19785 24948594
16k
   SLAB  MEMORYNODE  TOTAL  ALLOCATED  FREE
   dc5dabfd8800  95e5ff62 1 42 2913
   FREE / [ALLOCATED]
95e5ff621080  (cpu 6 cache)

Examining the contents of that memory reveals a pointer to a constant string
in the driver, "abort\0", which is set by qla24xx_async_abort_cmd().

 crash> rd c059277c 20
 c059277c:  6e490074726f6261 0074707572726574   abort.Interrupt.
 c059278c:  00676e696c6c6f50 6920726576697244   Polling.Driver i
 c059279c:  646f6d207325206e 6974736554000a65   n %s mode..Testi
 c05927ac:  636976656420676e 786c252074612065   ng device at %lx
 c05927bc:  6b63656843000a2e 646f727020676e69   ...Checking prod
 c05927cc:  6f20444920746375 0a2e706968632066   uct ID of chip..
 c05927dc:  5120646e756f4600 204130303232414c   .Found QLA2200A
 c05927ec:  43000a2e70696843 20676e696b636568   Chip...Checking
 c05927fc:  65786f626c69616d 6c636e69000a2e73   mailboxes...incl
 c059280c:  756e696c2f656475 616d2d616d642f78   ude/linux/dma-ma

 crash> struct -ox srb_iocb
 struct srb_iocb {
   union {
   struct {...} logio;
   struct {...} els_logo;
   struct {...} tmf;
   struct {...} fxiocb;
   struct {...} abt;
   struct ct_arg ctarg;
   struct {...} mbx;
   struct {...} nack;
[0x0 ] } u;
[0xb8] struct timer_list timer;
[0x108] void (*timeout)(void *);
 }
 SIZE: 0x110

 crash> ! bc
 ibase=16
 obase=10
 B8+40
 F8

The object is a srb_t, and at offset 0xf8 within that structure
(i.e. 95e5ff621080 + f8 -> 95e5ff621178) is a struct timer_list.

Cc:  #4.4+
Fixes: 4440e46d5db7 ("[SCSI] qla2xxx: Add IOCB Abort command asynchronous 
handling.")
Signed-off-by: Himanshu Madhani 
Reviewed-by: Johannes Thumshirn 
Signed-off-by: Martin K. Petersen 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/scsi/qla2xxx/qla_init.c |1 +
 1 file changed, 1 insertion(+)

--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -365,6 +365,7 @@ qla24xx_abort_sp_done(void *data, void *
srb_t *sp = (srb_t *)ptr;
struct srb_iocb *abt = &sp->u.iocb_cmd;
 
+   del_timer(&sp->u.iocb_cmd.timer);
complete(&abt->u.abt.comp);
 }
 




[PATCH 4.4 01/63] RDMA/ucma: Limit possible option size

2018-03-16 Thread Greg Kroah-Hartman
4.4-stable review patch.  If anyone has any objections, please let me know.

--

From: Leon Romanovsky 

commit 6a21dfc0d0db7b7e0acedce67ca533a6eb19283c upstream.

Users of ucma are supposed to provide size of option level,
in most paths it is supposed to be equal to u8 or u16, but
it is not the case for the IB path record, where it can be
multiple of struct ib_path_rec_data.

This patch takes simplest possible approach and prevents providing
values more than possible to allocate.

Reported-by: syzbot+a38b0e9f694c379ca...@syzkaller.appspotmail.com
Fixes: 7ce86409adcd ("RDMA/ucma: Allow user space to set service type")
Signed-off-by: Leon Romanovsky 
Signed-off-by: Doug Ledford 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/infiniband/core/ucma.c |3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -1274,6 +1274,9 @@ static ssize_t ucma_set_option(struct uc
if (IS_ERR(ctx))
return PTR_ERR(ctx);
 
+   if (unlikely(cmd.optval > KMALLOC_MAX_SIZE))
+   return -EINVAL;
+
optval = memdup_user((void __user *) (unsigned long) cmd.optval,
 cmd.optlen);
if (IS_ERR(optval)) {




[PATCH 3.18 17/25] serial: sh-sci: prevent lockup on full TTY buffers

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Ulrich Hecht 

commit 7842055bfce4bf0170d0f61df8b2add8399697be upstream.

When the TTY buffers fill up to the configured maximum, a system lockup
occurs:

[  598.820128] INFO: rcu_preempt detected stalls on CPUs/tasks:
[  598.825796]  0-...!: (1 GPs behind) idle=5a6/2/0 softirq=1974/1974 fqs=1
[  598.832577]  (detected by 3, t=62517 jiffies, g=296, c=295, q=126)
[  598.838755] Task dump for CPU 0:
[  598.841977] swapper/0   R  running task0 0  0 0x0022
[  598.849023] Call trace:
[  598.851476]  __switch_to+0x98/0xb0
[  598.854870](null)

This can be prevented by doing a dummy read of the RX data register.

This issue affects both HSCIF and SCIF ports. Reported for R-Car H3 ES2.0;
reproduced and fixed on H3 ES1.1. Probably affects other R-Car platforms
as well.

Reported-by: Yoshihiro Shimoda 
Signed-off-by: Ulrich Hecht 
Reviewed-by: Geert Uytterhoeven 
Cc: stable 
Tested-by: Nguyen Viet Dung 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/tty/serial/sh-sci.c |2 ++
 1 file changed, 2 insertions(+)

--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -736,6 +736,8 @@ static void sci_receive_chars(struct uar
/* Tell the rest of the system the news. New characters! */
tty_flip_buffer_push(tport);
} else {
+   /* TTY buffers full; read from RX reg to prevent lockup */
+   serial_port_in(port, SCxRDR);
serial_port_in(port, SCxSR); /* dummy read */
serial_port_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
}




[PATCH 3.18 15/25] x86/module: Detect and skip invalid relocations

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Josh Poimboeuf 

commit eda9cec4c9a12208a6f69fbe68f72a6311d50032 upstream.

There have been some cases where external tooling (e.g., kpatch-build)
creates a corrupt relocation which targets the wrong address.  This is a
silent failure which can corrupt memory in unexpected places.

On x86, the bytes of data being overwritten by relocations are always
initialized to zero beforehand.  Use that knowledge to add sanity checks
to detect such cases before they corrupt memory.

Signed-off-by: Josh Poimboeuf 
Cc: Linus Torvalds 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Cc: j...@kernel.org
Cc: live-patch...@vger.kernel.org
Link: 
http://lkml.kernel.org/r/37450d6c6225e54db107fba447ce9e56e5f758e9.1509713553.git.jpoim...@redhat.com
[ Restructured the messages, as it's unclear whether the relocation or the 
target is corrupted. ]
Signed-off-by: Ingo Molnar 
Cc: Matthias Kaehlcke 
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/module.c |   13 +
 1 file changed, 13 insertions(+)

--- a/arch/x86/kernel/module.c
+++ b/arch/x86/kernel/module.c
@@ -167,19 +167,27 @@ int apply_relocate_add(Elf64_Shdr *sechd
case R_X86_64_NONE:
break;
case R_X86_64_64:
+   if (*(u64 *)loc != 0)
+   goto invalid_relocation;
*(u64 *)loc = val;
break;
case R_X86_64_32:
+   if (*(u32 *)loc != 0)
+   goto invalid_relocation;
*(u32 *)loc = val;
if (val != *(u32 *)loc)
goto overflow;
break;
case R_X86_64_32S:
+   if (*(s32 *)loc != 0)
+   goto invalid_relocation;
*(s32 *)loc = val;
if ((s64)val != *(s32 *)loc)
goto overflow;
break;
case R_X86_64_PC32:
+   if (*(u32 *)loc != 0)
+   goto invalid_relocation;
val -= (u64)loc;
*(u32 *)loc = val;
 #if 0
@@ -195,6 +203,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
}
return 0;
 
+invalid_relocation:
+   pr_err("x86/modules: Skipping invalid relocation target, existing value 
is nonzero for type %d, loc %p, val %Lx\n",
+  (int)ELF64_R_TYPE(rel[i].r_info), loc, val);
+   return -ENOEXEC;
+
 overflow:
pr_err("overflow in relocation type %d val %Lx\n",
   (int)ELF64_R_TYPE(rel[i].r_info), val);




[PATCH 3.18 14/25] scripts: recordmcount: break hardlinks

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Russell King 

commit dd39a26538e37f6c6131e829a4a510787e43c783 upstream.

recordmcount edits the file in-place, which can cause problems when
using ccache in hardlink mode.  Arrange for recordmcount to break a
hardlinked object.

Link: http://lkml.kernel.org/r/e1a7mvt-et...@rmk-pc.arm.linux.org.uk

Cc: sta...@vger.kernel.org # 2.6.37+
Signed-off-by: Russell King 
Signed-off-by: Steven Rostedt 
Cc: Arnd Bergmann 
Signed-off-by: Greg Kroah-Hartman 

---
 scripts/recordmcount.c |   14 ++
 1 file changed, 14 insertions(+)

--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -201,6 +201,20 @@ static void *mmap_file(char const *fname
addr = umalloc(sb.st_size);
uread(fd_map, addr, sb.st_size);
}
+   if (sb.st_nlink != 1) {
+   /* file is hard-linked, break the hard link */
+   close(fd_map);
+   if (unlink(fname) < 0) {
+   perror(fname);
+   fail_file();
+   }
+   fd_map = open(fname, O_RDWR | O_CREAT, sb.st_mode);
+   if (fd_map < 0) {
+   perror(fname);
+   fail_file();
+   }
+   uwrite(fd_map, addr, sb.st_size);
+   }
return addr;
 }
 




[PATCH 3.18 13/25] ubi: Fix race condition between ubi volume creation and udev

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Clay McClure 

commit a51a0c8d213594bc094cb8e54aad0cb6d7f7b9a6 upstream.

Similar to commit 714fb87e8bc0 ("ubi: Fix race condition between ubi
device creation and udev"), we should make the volume active before
registering it.

Signed-off-by: Clay McClure 
Cc: 
Signed-off-by: Richard Weinberger 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/mtd/ubi/vmt.c |   15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -308,6 +308,12 @@ int ubi_create_volume(struct ubi_device
vol->last_eb_bytes = vol->usable_leb_size;
}
 
+   /* Make volume "available" before it becomes accessible via sysfs */
+   spin_lock(&ubi->volumes_lock);
+   ubi->volumes[vol_id] = vol;
+   ubi->vol_count += 1;
+   spin_unlock(&ubi->volumes_lock);
+
/* Register character device for the volume */
cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
vol->cdev.owner = THIS_MODULE;
@@ -350,11 +356,6 @@ int ubi_create_volume(struct ubi_device
if (err)
goto out_sysfs;
 
-   spin_lock(&ubi->volumes_lock);
-   ubi->volumes[vol_id] = vol;
-   ubi->vol_count += 1;
-   spin_unlock(&ubi->volumes_lock);
-
ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED);
self_check_volumes(ubi);
return err;
@@ -374,6 +375,10 @@ out_sysfs:
 out_cdev:
cdev_del(&vol->cdev);
 out_mapping:
+   spin_lock(&ubi->volumes_lock);
+   ubi->volumes[vol_id] = NULL;
+   ubi->vol_count -= 1;
+   spin_unlock(&ubi->volumes_lock);
if (do_free)
kfree(vol->eba_tbl);
 out_acc:




[PATCH 3.18 12/25] netfilter: ipv6: fix use-after-free Write in nf_nat_ipv6_manip_pkt

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit b078556aecd791b0e5cb3a59f4c3a14273b52121 upstream.

l4proto->manip_pkt() can cause reallocation of skb head so pointer
to the ipv6 header must be reloaded.

Reported-and-tested-by: 
Fixes: 58a317f1061c89 ("netfilter: ipv6: add IPv6 NAT support")
Signed-off-by: Florian Westphal 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c |4 
 1 file changed, 4 insertions(+)

--- a/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
+++ b/net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
@@ -99,6 +99,10 @@ static bool nf_nat_ipv6_manip_pkt(struct
!l4proto->manip_pkt(skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff,
target, maniptype))
return false;
+
+   /* must reload, offset might have changed */
+   ipv6h = (void *)skb->data + iphdroff;
+
 manip_addr:
if (maniptype == NF_NAT_MANIP_SRC)
ipv6h->saddr = target->src.u3.in6;




[PATCH 3.18 11/25] netfilter: bridge: ebt_among: add missing match size checks

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Florian Westphal 

commit c4585a2823edf4d1326da44d1524ecbfda26bb37 upstream.

ebt_among is special, it has a dynamic match size and is exempt
from the central size checks.

Therefore it must check that the size of the match structure
provided from userspace is sane by making sure em->match_size
is at least the minimum size of the expected structure.

The module has such a check, but its only done after accessing
a structure that might be out of bounds.

tested with: ebtables -A INPUT ... \
--among-dst fe:fe:fe:fe:fe:fe
--among-dst fe:fe:fe:fe:fe:fe --among-src 
fe:fe:fe:fe:ff:f,fe:fe:fe:fe:fe:fb,fe:fe:fe:fe:fc:fd,fe:fe:fe:fe:fe:fd,fe:fe:fe:fe:fe:fe
--among-src 
fe:fe:fe:fe:ff:f,fe:fe:fe:fe:fe:fa,fe:fe:fe:fe:fe:fd,fe:fe:fe:fe:fe:fe,fe:fe:fe:fe:fe:fe

Reported-by: 
Signed-off-by: Florian Westphal 
Signed-off-by: Pablo Neira Ayuso 
Signed-off-by: Greg Kroah-Hartman 

---
 net/bridge/netfilter/ebt_among.c |   21 +++--
 1 file changed, 19 insertions(+), 2 deletions(-)

--- a/net/bridge/netfilter/ebt_among.c
+++ b/net/bridge/netfilter/ebt_among.c
@@ -172,18 +172,35 @@ ebt_among_mt(const struct sk_buff *skb,
return true;
 }
 
+static bool poolsize_invalid(const struct ebt_mac_wormhash *w)
+{
+   return w && w->poolsize >= (INT_MAX / sizeof(struct 
ebt_mac_wormhash_tuple));
+}
+
 static int ebt_among_mt_check(const struct xt_mtchk_param *par)
 {
const struct ebt_among_info *info = par->matchinfo;
const struct ebt_entry_match *em =
container_of(par->matchinfo, const struct ebt_entry_match, 
data);
-   int expected_length = sizeof(struct ebt_among_info);
+   unsigned int expected_length = sizeof(struct ebt_among_info);
const struct ebt_mac_wormhash *wh_dst, *wh_src;
int err;
 
+   if (expected_length > em->match_size)
+   return -EINVAL;
+
wh_dst = ebt_among_wh_dst(info);
-   wh_src = ebt_among_wh_src(info);
+   if (poolsize_invalid(wh_dst))
+   return -EINVAL;
+
expected_length += ebt_mac_wormhash_size(wh_dst);
+   if (expected_length > em->match_size)
+   return -EINVAL;
+
+   wh_src = ebt_among_wh_src(info);
+   if (poolsize_invalid(wh_src))
+   return -EINVAL;
+
expected_length += ebt_mac_wormhash_size(wh_src);
 
if (em->match_size != EBT_ALIGN(expected_length)) {




[PATCH 3.18 25/25] fixup: sctp: verify size of a new chunk in _sctp_make_chunk()

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Greg Kroah-Hartman 

Ben writes:
> > +   int chunklen;
> > +
> > +   chunklen = sizeof(*chunk_hdr) + paylen;
> 
> I think this length still needs to be rounded up (with WORD_ROUND here,
> instead of SCTP_PAD4 upstream).

So here's a fix for this problem.


Reported-by: Ben Hutchings 
Signed-off-by: Greg Kroah-Hartman 

---
 net/sctp/sm_make_chunk.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1369,7 +1369,7 @@ static struct sctp_chunk *_sctp_make_chu
struct sock *sk;
int chunklen;
 
-   chunklen = sizeof(*chunk_hdr) + paylen;
+   chunklen = WORD_ROUND(sizeof(*chunk_hdr) + paylen);
if (chunklen > SCTP_MAX_CHUNK_LEN)
goto nodata;
 




[PATCH 3.18 04/25] x86/MCE: Serialize sysfs changes

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Seunghun Han 

commit b3b7c4795ccab5be71f080774c45bbbcc75c2aaf upstream.

The check_interval file in

  /sys/devices/system/machinecheck/machinecheck

directory is a global timer value for MCE polling. If it is changed by one
CPU, mce_restart() broadcasts the event to other CPUs to delete and restart
the MCE polling timer and __mcheck_cpu_init_timer() reinitializes the
mce_timer variable.

If more than one CPU writes a specific value to the check_interval file
concurrently, mce_timer is not protected from such concurrent accesses and
all kinds of explosions happen. Since only root can write to those sysfs
variables, the issue is not a big deal security-wise.

However, concurrent writes to these configuration variables is void of
reason so the proper thing to do is to serialize the access with a mutex.

Boris:

 - Make store_int_with_restart() use device_store_ulong() to filter out
   negative intervals
 - Limit min interval to 1 second
 - Correct locking
 - Massage commit message

Signed-off-by: Seunghun Han 
Signed-off-by: Borislav Petkov 
Signed-off-by: Thomas Gleixner 
Cc: Greg Kroah-Hartman 
Cc: Tony Luck 
Cc: linux-edac 
Cc: sta...@vger.kernel.org
Link: http://lkml.kernel.org/r/20180302202706.9434-1-kkama...@gmail.com
Signed-off-by: Greg Kroah-Hartman 

---
 arch/x86/kernel/cpu/mcheck/mce.c |   22 +-
 1 file changed, 21 insertions(+), 1 deletion(-)

--- a/arch/x86/kernel/cpu/mcheck/mce.c
+++ b/arch/x86/kernel/cpu/mcheck/mce.c
@@ -56,6 +56,9 @@ static DEFINE_MUTEX(mce_chrdev_read_mute
  rcu_read_lock_sched_held() || \
  lockdep_is_held(&mce_chrdev_read_mutex))
 
+/* sysfs synchronization */
+static DEFINE_MUTEX(mce_sysfs_mutex);
+
 #define CREATE_TRACE_POINTS
 #include 
 
@@ -2183,6 +2186,7 @@ static ssize_t set_ignore_ce(struct devi
if (kstrtou64(buf, 0, &new) < 0)
return -EINVAL;
 
+   mutex_lock(&mce_sysfs_mutex);
if (mca_cfg.ignore_ce ^ !!new) {
if (new) {
/* disable ce features */
@@ -2195,6 +2199,8 @@ static ssize_t set_ignore_ce(struct devi
on_each_cpu(mce_enable_ce, (void *)1, 1);
}
}
+   mutex_unlock(&mce_sysfs_mutex);
+
return size;
 }
 
@@ -2207,6 +2213,7 @@ static ssize_t set_cmci_disabled(struct
if (kstrtou64(buf, 0, &new) < 0)
return -EINVAL;
 
+   mutex_lock(&mce_sysfs_mutex);
if (mca_cfg.cmci_disabled ^ !!new) {
if (new) {
/* disable cmci */
@@ -2218,6 +2225,8 @@ static ssize_t set_cmci_disabled(struct
on_each_cpu(mce_enable_ce, NULL, 1);
}
}
+   mutex_unlock(&mce_sysfs_mutex);
+
return size;
 }
 
@@ -2225,8 +2234,19 @@ static ssize_t store_int_with_restart(st
  struct device_attribute *attr,
  const char *buf, size_t size)
 {
-   ssize_t ret = device_store_int(s, attr, buf, size);
+   unsigned long old_check_interval = check_interval;
+   ssize_t ret = device_store_ulong(s, attr, buf, size);
+
+   if (check_interval == old_check_interval)
+   return ret;
+
+   if (check_interval < 1)
+   check_interval = 1;
+
+   mutex_lock(&mce_sysfs_mutex);
mce_restart();
+   mutex_unlock(&mce_sysfs_mutex);
+
return ret;
 }
 




[PATCH 3.18 03/25] Input: matrix_keypad - fix race when disabling interrupts

2018-03-16 Thread Greg Kroah-Hartman
3.18-stable review patch.  If anyone has any objections, please let me know.

--

From: Zhang Bo 

commit ea4f7bd2aca9f68470e9aac0fc9432fd180b1fe7 upstream.

If matrix_keypad_stop() is executing and the keypad interrupt is triggered,
disable_row_irqs() may be called by both matrix_keypad_interrupt() and
matrix_keypad_stop() at the same time, causing interrupts to be disabled
twice and the keypad being "stuck" after resuming.

Take lock when setting keypad->stopped to ensure that ISR will not race
with matrix_keypad_stop() disabling interrupts.

Signed-off-by: Zhang Bo 
Cc: sta...@vger.kernel.org
Signed-off-by: Dmitry Torokhov 
Signed-off-by: Greg Kroah-Hartman 

---
 drivers/input/keyboard/matrix_keypad.c |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/drivers/input/keyboard/matrix_keypad.c
+++ b/drivers/input/keyboard/matrix_keypad.c
@@ -216,8 +216,10 @@ static void matrix_keypad_stop(struct in
 {
struct matrix_keypad *keypad = input_get_drvdata(dev);
 
+   spin_lock_irq(&keypad->lock);
keypad->stopped = true;
-   mb();
+   spin_unlock_irq(&keypad->lock);
+
flush_work(&keypad->work.work);
/*
 * matrix_keypad_scan() will leave IRQs enabled;




Re: [PATCH 8/9] x86/dumpstack: Save first regs set for the executive summary

2018-03-16 Thread Josh Poimboeuf
On Fri, Mar 16, 2018 at 10:22:29AM -0700, Linus Torvalds wrote:
> On Fri, Mar 16, 2018 at 4:48 AM, Borislav Petkov  wrote:
> > On Thu, Mar 15, 2018 at 02:01:32PM -0500, Josh Poimboeuf wrote:
> >> no_context() has the following line, right before it calls oops_end():
> >>
> >>   /* Executive summary in case the body of the oops scrolled away */
> >>   printk(KERN_DEFAULT "CR2: %016lx\n", address);
> >>
> >> I think that line can now be removed, since the executive summary
> >> __show_regs() will include CR2.
> >
> > Good idea. Done.
> 
> N!
> 
> Guys, %cr2 CAN AND DOES CHANGE!
> 
> The reason we do that
> 
> printk(KERN_DEFAULT "CR2: %016lx\n", address);
> 
> is because WE ARE NOT PRINTING OUT THE CURRENT CR2 REGISTER!

Good point.  I missed the fact that no_context() isn't printing the
current CR2.

> This is really damn important.
> 
> The "address" register contains the CR2 value as it was read *very*
> early in the page fault case, before we enabled interrupts, and before
> we did various random things that can cause further page faults and
> change CR2!
> 
> So the executive summary that does __show_regs() may end up showing
> something completely different than the actual faulting address,
> because we might have taken a vmalloc-space exception in the meantime,
> for example.
> 
> Do *NOT* get rid of that thing.
> 
> You're better off getting rid of the CR2 line from __show_regs(),
> because it can be dangerously confusing. It's not actually part of the
> saved register state at all, it's something entirely different. It's
> like showing the current eflags rather than the eflags saved on the
> faulting stack.

True, it's probably best to remove it.  The only time we need CR2's
value is presumably when it would have already been printed in
no_context(), and so it primarily just adds confusion as you said.

-- 
Josh


[PATCH v2] staging: typec: rt1711h typec chip driver

2018-03-16 Thread ShuFan Lee
From: ShuFan Lee 

Richtek RT1711H Type-C chip driver that works with
Type-C Port Controller Manager to provide USB PD and
USB Type-C functionalities.
Add definition of TCPC_CC_STATUS_TOGGLING.

Signed-off-by: ShuFan Lee 
---
 drivers/staging/typec/Kconfig |   8 +
 drivers/staging/typec/Makefile|   1 +
 drivers/staging/typec/tcpci.h |   1 +
 drivers/staging/typec/tcpci_rt1711h.c | 329 ++
 4 files changed, 339 insertions(+)
 create mode 100644 drivers/staging/typec/tcpci_rt1711h.c

 changelogs between v1 and v2
 - use gpiod_* instead of gpio_*

diff --git a/drivers/staging/typec/Kconfig b/drivers/staging/typec/Kconfig
index 5359f556d203..3aa981fbc8f5 100644
--- a/drivers/staging/typec/Kconfig
+++ b/drivers/staging/typec/Kconfig
@@ -9,6 +9,14 @@ config TYPEC_TCPCI
help
  Type-C Port Controller driver for TCPCI-compliant controller.
 
+config TYPEC_RT1711H
+   tristate "Richtek RT1711H Type-C chip driver"
+   select TYPEC_TCPCI
+   help
+ Richtek RT1711H Type-C chip driver that works with
+ Type-C Port Controller Manager to provide USB PD and USB
+ Type-C functionalities.
+
 endif
 
 endmenu
diff --git a/drivers/staging/typec/Makefile b/drivers/staging/typec/Makefile
index 53d649abcb53..7803d485e1b3 100644
--- a/drivers/staging/typec/Makefile
+++ b/drivers/staging/typec/Makefile
@@ -1 +1,2 @@
 obj-$(CONFIG_TYPEC_TCPCI)  += tcpci.o
+obj-$(CONFIG_TYPEC_RT1711H)+= tcpci_rt1711h.o
diff --git a/drivers/staging/typec/tcpci.h b/drivers/staging/typec/tcpci.h
index 34c865f0dcf6..303ebde26546 100644
--- a/drivers/staging/typec/tcpci.h
+++ b/drivers/staging/typec/tcpci.h
@@ -59,6 +59,7 @@
 #define TCPC_POWER_CTRL_VCONN_ENABLE   BIT(0)
 
 #define TCPC_CC_STATUS 0x1d
+#define TCPC_CC_STATUS_TOGGLINGBIT(5)
 #define TCPC_CC_STATUS_TERMBIT(4)
 #define TCPC_CC_STATUS_CC2_SHIFT   2
 #define TCPC_CC_STATUS_CC2_MASK0x3
diff --git a/drivers/staging/typec/tcpci_rt1711h.c 
b/drivers/staging/typec/tcpci_rt1711h.c
new file mode 100644
index ..12afac363d6d
--- /dev/null
+++ b/drivers/staging/typec/tcpci_rt1711h.c
@@ -0,0 +1,329 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018, Richtek Technology Corporation
+ *
+ * Richtek RT1711H Type-C Chip Driver
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "tcpci.h"
+
+#define RT1711H_RTCTRL80x9B
+
+/* Autoidle timeout = (tout * 2 + 1) * 6.4ms */
+#define RT1711H_RTCTRL8_SET(ck300, ship_off, auto_idle, tout) \
+   (((ck300) << 7) | ((ship_off) << 5) | \
+   ((auto_idle) << 3) | ((tout) & 0x07))
+
+#define RT1711H_RTCTRL11   0x9E
+
+/* I2C timeout = (tout + 1) * 12.5ms */
+#define RT1711H_RTCTRL11_SET(en, tout) \
+(((en) << 7) | ((tout) & 0x0F))
+
+#define RT1711H_RTCTRL13   0xA0
+#define RT1711H_RTCTRL14   0xA1
+#define RT1711H_RTCTRL15   0xA2
+#define RT1711H_RTCTRL16   0xA3
+
+struct rt1711h_chip {
+   struct tcpci_data data;
+   struct tcpci *tcpci;
+   struct device *dev;
+   int irq;
+};
+
+static int rt1711h_read16(struct rt1711h_chip *chip, unsigned int reg, u16 
*val)
+{
+   return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
+}
+
+static int rt1711h_write16(struct rt1711h_chip *chip, unsigned int reg, u16 
val)
+{
+   return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16));
+}
+
+static int rt1711h_read8(struct rt1711h_chip *chip, unsigned int reg, u8 *val)
+{
+   return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8));
+}
+
+static int rt1711h_write8(struct rt1711h_chip *chip, unsigned int reg, u8 val)
+{
+   return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8));
+}
+
+static const struct regmap_config rt1711h_regmap_config = {
+   .reg_bits = 8,
+   .val_bits = 8,
+
+   .max_register = 0xFF, /* 0x80 .. 0xFF are vendor defined */
+};
+
+static struct rt1711h_chip *tdata_to_rt1711h(struct tcpci_data *tdata)
+{
+   return container_of(tdata, struct rt1711h_chip, data);
+}
+
+static int rt1711h_init(struct tcpci *tcpci, struct tcpci_data *tdata)
+{
+   int ret;
+   struct rt1711h_chip *chip = tdata_to_rt1711h(tdata);
+
+   /* CK 300K from 320K, shipping off, auto_idle enable, tout = 32ms */
+   ret = rt1711h_write8(chip, RT1711H_RTCTRL8,
+RT1711H_RTCTRL8_SET(0, 1, 1, 2));
+   if (ret < 0)
+   return ret;
+
+   /* I2C reset : (val + 1) * 12.5ms */
+   ret = rt1711h_write8(chip, RT1711H_RTCTRL11,
+RT1711H_RTCTRL11_SET(1, 0x0F));
+   if (ret < 0)
+   return ret;
+
+   /* tTCPCfilter : (26.7 * val) us */
+   ret = rt1711h_write8(chip, RT1711H_RTCTRL14, 0x0F);
+   if (ret < 0)
+   return ret;
+
+   /* 

RE: [PATCH v4 3/4] PCI: hv: Remove hbus->enum_sem

2018-03-16 Thread Dexuan Cui
> From: Lorenzo Pieralisi 
> Sent: Friday, March 16, 2018 03:54
> ...
> Dexuan,
> while applying/updating these patches I notice this one may be squashed
> into: https://patchwork.ozlabs.org/patch/886266/
> 
> since they logically belong in the same patch. Are you OK with me doing
> that ? Is my reading correct ?
> Lorenzo

I'm OK. 
I used two patches
[PATCH v4 1/2] PCI: hv: Serialize the present and eject work items
[PATCH v4 3/4] PCI: hv: Remove hbus->enum_sem
only because the first fixed a real issue and hence IMO should go into
stable kernels, and the second is only a cleanup patch, which doesn't
need go into stable kernels.

Either way is ok to me. 
Please feel free to do whatever you think is better. :-)

Thanks,
-- Dexuan



Re: [RESEND PATCH v2] sched/fair: Remove check in idle_balance against migration_cost

2018-03-16 Thread Peter Zijlstra
On Fri, Mar 16, 2018 at 10:21:54AM -0700, Rohit Jain wrote:
> Hi Peter,
> 
> On 03/16/2018 07:35 AM, Peter Zijlstra wrote:
> > On Wed, Mar 14, 2018 at 11:36:47AM -0700, Rohit Jain wrote:
> > > Signed-off-by: Rohit Jain 
> > > 
> > > Signed-off-by: Rohit Jain 
> > Surely you only need a single on of those.
> 
> Oh wow! I don't know how I missed this :) Thanks!

> However, when I clone from
> https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git/
> I cannot see the commit.

You need to look at:

  https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/

my queue.git is the sporadic push of my quilt tree on top of that.


<    1   2   3   4   5   6   7   8   9   10   >