diff options
author | Sasha Levin <sasha.levin@oracle.com> | 2013-12-07 17:26:27 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-15 18:28:47 -0500 |
commit | d90d9ff6cac64e701f27291ecef12fdc48606bb6 (patch) | |
tree | bc1c113caa56f26749ee1b226ca24117672c411e | |
parent | 90af0bf9303883865a8626f23b4b0ed60d4d10dc (diff) |
net: unix: allow set_peek_off to fail
[ Upstream commit 12663bfc97c8b3fdb292428105dd92d563164050 ]
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | include/linux/net.h | 2 | ||||
-rw-r--r-- | net/core/sock.c | 2 | ||||
-rw-r--r-- | net/unix/af_unix.c | 8 |
3 files changed, 8 insertions, 4 deletions
diff --git a/include/linux/net.h b/include/linux/net.h index 0c4ae5d94de9..65545ac6fb9c 100644 --- a/include/linux/net.h +++ b/include/linux/net.h | |||
@@ -180,7 +180,7 @@ struct proto_ops { | |||
180 | int offset, size_t size, int flags); | 180 | int offset, size_t size, int flags); |
181 | ssize_t (*splice_read)(struct socket *sock, loff_t *ppos, | 181 | ssize_t (*splice_read)(struct socket *sock, loff_t *ppos, |
182 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); | 182 | struct pipe_inode_info *pipe, size_t len, unsigned int flags); |
183 | void (*set_peek_off)(struct sock *sk, int val); | 183 | int (*set_peek_off)(struct sock *sk, int val); |
184 | }; | 184 | }; |
185 | 185 | ||
186 | #define DECLARE_SOCKADDR(type, dst, src) \ | 186 | #define DECLARE_SOCKADDR(type, dst, src) \ |
diff --git a/net/core/sock.c b/net/core/sock.c index 6565431b0e6d..50a345e5a26f 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -885,7 +885,7 @@ set_rcvbuf: | |||
885 | 885 | ||
886 | case SO_PEEK_OFF: | 886 | case SO_PEEK_OFF: |
887 | if (sock->ops->set_peek_off) | 887 | if (sock->ops->set_peek_off) |
888 | sock->ops->set_peek_off(sk, val); | 888 | ret = sock->ops->set_peek_off(sk, val); |
889 | else | 889 | else |
890 | ret = -EOPNOTSUPP; | 890 | ret = -EOPNOTSUPP; |
891 | break; | 891 | break; |
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index 8664ad0d5797..2ee993c7732a 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c | |||
@@ -529,13 +529,17 @@ static int unix_seqpacket_sendmsg(struct kiocb *, struct socket *, | |||
529 | static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *, | 529 | static int unix_seqpacket_recvmsg(struct kiocb *, struct socket *, |
530 | struct msghdr *, size_t, int); | 530 | struct msghdr *, size_t, int); |
531 | 531 | ||
532 | static void unix_set_peek_off(struct sock *sk, int val) | 532 | static int unix_set_peek_off(struct sock *sk, int val) |
533 | { | 533 | { |
534 | struct unix_sock *u = unix_sk(sk); | 534 | struct unix_sock *u = unix_sk(sk); |
535 | 535 | ||
536 | mutex_lock(&u->readlock); | 536 | if (mutex_lock_interruptible(&u->readlock)) |
537 | return -EINTR; | ||
538 | |||
537 | sk->sk_peek_off = val; | 539 | sk->sk_peek_off = val; |
538 | mutex_unlock(&u->readlock); | 540 | mutex_unlock(&u->readlock); |
541 | |||
542 | return 0; | ||
539 | } | 543 | } |
540 | 544 | ||
541 | 545 | ||