netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: unix: non blocking recvmsg() should not return -EINTR
@ 2014-03-26  1:42 Eric Dumazet
  2014-03-26 13:17 ` Rainer Weikusat
  2014-03-26 15:00 ` David Laight
  0 siblings, 2 replies; 25+ messages in thread
From: Eric Dumazet @ 2014-03-26  1:42 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Rainer Weikusat

From: Eric Dumazet <edumazet@google.com>

Some applications didn't expect recvmsg() on a non blocking socket
could return -EINTR. This possibility was added as a side effect
of commit b3ca9b02b00704 ("net: fix multithreaded signal handling in
unix recv routines").

To hit this bug, you need to be a bit unlucky, as the u->readlock
mutex is usually held for very small periods.

Fixes: b3ca9b02b00704 ("net: fix multithreaded signal handling in unix recv routines")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Rainer Weikusat <rweikusat@mobileactivedefense.com>
---
 net/unix/af_unix.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index ce6ec6c2f4de..94404f19f9de 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1787,8 +1787,11 @@ static int unix_dgram_recvmsg(struct kiocb *iocb, struct socket *sock,
 		goto out;
 
 	err = mutex_lock_interruptible(&u->readlock);
-	if (err) {
-		err = sock_intr_errno(sock_rcvtimeo(sk, noblock));
+	if (unlikely(err)) {
+		/* recvmsg() in non blocking mode is supposed to return -EAGAIN
+		 * sk_rcvtimeo is not honored by mutex_lock_interruptible()
+		 */
+		err = noblock ? -EAGAIN : -ERESTARTSYS;
 		goto out;
 	}
 
@@ -1913,6 +1916,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
 	struct unix_sock *u = unix_sk(sk);
 	DECLARE_SOCKADDR(struct sockaddr_un *, sunaddr, msg->msg_name);
 	int copied = 0;
+	int noblock = flags & MSG_DONTWAIT;
 	int check_creds = 0;
 	int target;
 	int err = 0;
@@ -1928,7 +1932,7 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
 		goto out;
 
 	target = sock_rcvlowat(sk, flags&MSG_WAITALL, size);
-	timeo = sock_rcvtimeo(sk, flags&MSG_DONTWAIT);
+	timeo = sock_rcvtimeo(sk, noblock);
 
 	/* Lock the socket to prevent queue disordering
 	 * while sleeps in memcpy_tomsg
@@ -1940,8 +1944,11 @@ static int unix_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
 	}
 
 	err = mutex_lock_interruptible(&u->readlock);
-	if (err) {
-		err = sock_intr_errno(timeo);
+	if (unlikely(err)) {
+		/* recvmsg() in non blocking mode is supposed to return -EAGAIN
+		 * sk_rcvtimeo is not honored by mutex_lock_interruptible()
+		 */
+		err = noblock ? -EAGAIN : -ERESTARTSYS;
 		goto out;
 	}
 

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2014-03-28 20:35 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-26  1:42 [PATCH] net: unix: non blocking recvmsg() should not return -EINTR Eric Dumazet
2014-03-26 13:17 ` Rainer Weikusat
2014-03-26 13:57   ` Rainer Weikusat
2014-03-26 14:09   ` Eric Dumazet
2014-03-26 14:25     ` Rainer Weikusat
2014-03-26 15:00 ` David Laight
2014-03-26 15:13   ` Rainer Weikusat
2014-03-26 15:25     ` Eric Dumazet
2014-03-26 15:33       ` Eric Dumazet
2014-03-26 19:46       ` Rainer Weikusat
2014-03-26 21:04         ` Rainer Weikusat
2014-03-27  9:36           ` David Laight
2014-03-27 12:40             ` Rainer Weikusat
2014-03-27 12:49               ` Jamal Hadi Salim
2014-03-27 13:02                 ` Rainer Weikusat
2014-03-27 12:53               ` David Laight
2014-03-27 13:29                 ` Rainer Weikusat
2014-03-26 21:05         ` David Miller
2014-03-26 21:21           ` Rainer Weikusat
2014-03-26 21:44             ` Eric Dumazet
2014-03-26 22:06               ` Rainer Weikusat
2014-03-26 22:35                 ` Eric Dumazet
2014-03-26 22:51                   ` Rainer Weikusat
2014-03-26 22:58                     ` Eric Dumazet
2014-03-28 20:35             ` Rainer Weikusat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).