diff mbox

net: unix: allow set_peek_off to fail

Message ID 1386455187-28597-1-git-send-email-sasha.levin@oracle.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Sasha Levin Dec. 7, 2013, 10:26 p.m. UTC
unix_dgram_recvmsg() will hold the readlock of the socket until recv
is complete.

In the same time, we may try to setsockopt(SO_PEEK_OFF) which will hang until
unix_dgram_recvmsg() will complete (which can take a while) without allowing
us to break out of it, triggering a hung task spew.

Instead, allow set_peek_off to fail, this way userspace will not hang.

Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 include/linux/net.h |    2 +-
 net/core/sock.c     |    2 +-
 net/unix/af_unix.c  |    8 ++++++--
 3 files changed, 8 insertions(+), 4 deletions(-)

Comments

Pavel Emelyanov Dec. 9, 2013, 7:32 a.m. UTC | #1
On 12/08/2013 02:26 AM, Sasha Levin wrote:
> unix_dgram_recvmsg() will hold the readlock of the socket until recv
> is complete.
> 
> In the same time, we may try to setsockopt(SO_PEEK_OFF) which will hang until
> unix_dgram_recvmsg() will complete (which can take a while) without allowing
> us to break out of it, triggering a hung task spew.
> 
> Instead, allow set_peek_off to fail, this way userspace will not hang.
> 
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>

Acked-by: Pavel Emelyanov <xemul@parallels.com>
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller Dec. 11, 2013, 2:45 a.m. UTC | #2
From: Pavel Emelyanov <xemul@parallels.com>
Date: Mon, 9 Dec 2013 11:32:46 +0400

> On 12/08/2013 02:26 AM, Sasha Levin wrote:
>> unix_dgram_recvmsg() will hold the readlock of the socket until recv
>> is complete.
>> 
>> In the same time, we may try to setsockopt(SO_PEEK_OFF) which will hang until
>> unix_dgram_recvmsg() will complete (which can take a while) without allowing
>> us to break out of it, triggering a hung task spew.
>> 
>> Instead, allow set_peek_off to fail, this way userspace will not hang.
>> 
>> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> 
> Acked-by: Pavel Emelyanov <xemul@parallels.com>

Applied and queued up for -stable, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/net.h b/include/linux/net.h
index 4bcee94..69be3e6 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -181,7 +181,7 @@  struct proto_ops {
 				      int offset, size_t size, int flags);
 	ssize_t 	(*splice_read)(struct socket *sock,  loff_t *ppos,
 				       struct pipe_inode_info *pipe, size_t len, unsigned int flags);
-	void		(*set_peek_off)(struct sock *sk, int val);
+	int		(*set_peek_off)(struct sock *sk, int val);
 };
 
 #define DECLARE_SOCKADDR(type, dst, src)	\
diff --git a/net/core/sock.c b/net/core/sock.c
index ab20ed9..5393b4b 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -882,7 +882,7 @@  set_rcvbuf:
 
 	case SO_PEEK_OFF:
 		if (sock->ops->set_peek_off)
-			sock->ops->set_peek_off(sk, val);
+			ret = sock->ops->set_peek_off(sk, val);
 		else
 			ret = -EOPNOTSUPP;
 		break;
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 01625cc..a0ca162 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -530,13 +530,17 @@  static int unix_seqpacket_sendmsg(struct kiocb *, struct socket *,
 static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *,
 				  struct msghdr *, size_t, int);
 
-static void unix_set_peek_off(struct sock *sk, int val)
+static int unix_set_peek_off(struct sock *sk, int val)
 {
 	struct unix_sock *u = unix_sk(sk);
 
-	mutex_lock(&u->readlock);
+	if (mutex_lock_interruptible(&u->readlock))
+		return -EINTR;
+
 	sk->sk_peek_off = val;
 	mutex_unlock(&u->readlock);
+
+	return 0;
 }