Skip to content

Commit

Permalink
tipc: fix shutdown() of connection oriented socket
Browse files Browse the repository at this point in the history
I confirmed that the problem fixed by commit 2a63866 ("tipc: fix
shutdown() of connectionless socket") also applies to stream socket.

----------
#include <sys/socket.h>
#include <unistd.h>
#include <sys/wait.h>

int main(int argc, char *argv[])
{
        int fds[2] = { -1, -1 };
        socketpair(PF_TIPC, SOCK_STREAM /* or SOCK_DGRAM */, 0, fds);
        if (fork() == 0)
                _exit(read(fds[0], NULL, 1));
        shutdown(fds[0], SHUT_RDWR); /* This must make read() return. */
        wait(NULL); /* To be woken up by _exit(). */
        return 0;
}
----------

Since shutdown(SHUT_RDWR) should affect all processes sharing that socket,
unconditionally setting sk->sk_shutdown to SHUTDOWN_MASK will be the right
behavior.

Signed-off-by: Tetsuo Handa <[email protected]>
Acked-by: Ying Xue <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Tetsuo Handa authored and davem330 committed Sep 10, 2020
1 parent 46cf789 commit a4b5cc9
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions net/tipc/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2771,10 +2771,7 @@ static int tipc_shutdown(struct socket *sock, int how)

trace_tipc_sk_shutdown(sk, NULL, TIPC_DUMP_ALL, " ");
__tipc_shutdown(sock, TIPC_CONN_SHUTDOWN);
if (tipc_sk_type_connectionless(sk))
sk->sk_shutdown = SHUTDOWN_MASK;
else
sk->sk_shutdown = SEND_SHUTDOWN;
sk->sk_shutdown = SHUTDOWN_MASK;

if (sk->sk_state == TIPC_DISCONNECTING) {
/* Discard any unreceived messages */
Expand Down

0 comments on commit a4b5cc9

Please sign in to comment.