Commit 9905eed4 authored by David S. Miller's avatar David S. Miller

Merge branch 'af_unix-OOB-fixes'

Kuniyuki Iwashima says:

====================
af_unix: Fix some OOB implementation.

This series fixes some data-races and adds a missing feature around the
commit 314001f0 ("af_unix: Add OOB support").

Changelog:
  - v3:
    - Add the first patch

  - v2: https://lore.kernel.org/netdev/20220315054801.72035-1-kuniyu@amazon.co.jp/
    - Add READ_ONCE() to avoid a race reported by KCSAN (Eric)
    - Add IS_ENABLED(CONFIG_AF_UNIX_OOB) (Shoaib)

  - v1: https://lore.kernel.org/netdev/20220314052110.53634-1-kuniyu@amazon.co.jp/
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4219196d d9a232d4
...@@ -2084,7 +2084,7 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other ...@@ -2084,7 +2084,7 @@ static int queue_oob(struct socket *sock, struct msghdr *msg, struct sock *other
if (ousk->oob_skb) if (ousk->oob_skb)
consume_skb(ousk->oob_skb); consume_skb(ousk->oob_skb);
ousk->oob_skb = skb; WRITE_ONCE(ousk->oob_skb, skb);
scm_stat_add(other, skb); scm_stat_add(other, skb);
skb_queue_tail(&other->sk_receive_queue, skb); skb_queue_tail(&other->sk_receive_queue, skb);
...@@ -2602,9 +2602,8 @@ static int unix_stream_recv_urg(struct unix_stream_read_state *state) ...@@ -2602,9 +2602,8 @@ static int unix_stream_recv_urg(struct unix_stream_read_state *state)
oob_skb = u->oob_skb; oob_skb = u->oob_skb;
if (!(state->flags & MSG_PEEK)) { if (!(state->flags & MSG_PEEK))
u->oob_skb = NULL; WRITE_ONCE(u->oob_skb, NULL);
}
unix_state_unlock(sk); unix_state_unlock(sk);
...@@ -2639,7 +2638,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk, ...@@ -2639,7 +2638,7 @@ static struct sk_buff *manage_oob(struct sk_buff *skb, struct sock *sk,
skb = NULL; skb = NULL;
} else if (sock_flag(sk, SOCK_URGINLINE)) { } else if (sock_flag(sk, SOCK_URGINLINE)) {
if (!(flags & MSG_PEEK)) { if (!(flags & MSG_PEEK)) {
u->oob_skb = NULL; WRITE_ONCE(u->oob_skb, NULL);
consume_skb(skb); consume_skb(skb);
} }
} else if (!(flags & MSG_PEEK)) { } else if (!(flags & MSG_PEEK)) {
...@@ -3094,11 +3093,10 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) ...@@ -3094,11 +3093,10 @@ static int unix_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
case SIOCATMARK: case SIOCATMARK:
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct unix_sock *u = unix_sk(sk);
int answ = 0; int answ = 0;
skb = skb_peek(&sk->sk_receive_queue); skb = skb_peek(&sk->sk_receive_queue);
if (skb && skb == u->oob_skb) if (skb && skb == READ_ONCE(unix_sk(sk)->oob_skb))
answ = 1; answ = 1;
err = put_user(answ, (int __user *)arg); err = put_user(answ, (int __user *)arg);
} }
...@@ -3139,6 +3137,10 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa ...@@ -3139,6 +3137,10 @@ static __poll_t unix_poll(struct file *file, struct socket *sock, poll_table *wa
mask |= EPOLLIN | EPOLLRDNORM; mask |= EPOLLIN | EPOLLRDNORM;
if (sk_is_readable(sk)) if (sk_is_readable(sk))
mask |= EPOLLIN | EPOLLRDNORM; mask |= EPOLLIN | EPOLLRDNORM;
#if IS_ENABLED(CONFIG_AF_UNIX_OOB)
if (READ_ONCE(unix_sk(sk)->oob_skb))
mask |= EPOLLPRI;
#endif
/* Connection-based need to check for termination and startup */ /* Connection-based need to check for termination and startup */
if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) && if ((sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET) &&
......
...@@ -218,10 +218,10 @@ main(int argc, char **argv) ...@@ -218,10 +218,10 @@ main(int argc, char **argv)
/* Test 1: /* Test 1:
* veriyf that SIGURG is * veriyf that SIGURG is
* delivered and 63 bytes are * delivered, 63 bytes are
* read and oob is '@' * read, oob is '@', and POLLPRI works.
*/ */
wait_for_data(pfd, POLLIN | POLLPRI); wait_for_data(pfd, POLLPRI);
read_oob(pfd, &oob); read_oob(pfd, &oob);
len = read_data(pfd, buf, 1024); len = read_data(pfd, buf, 1024);
if (!signal_recvd || len != 63 || oob != '@') { if (!signal_recvd || len != 63 || oob != '@') {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment