netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bluetooth: never linger on process exit
@ 2014-07-15  8:25 Vladimir Davydov
       [not found] ` <1405412728-4706-1-git-send-email-vdavydov-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
  2014-07-17 10:16 ` Marcel Holtmann
  0 siblings, 2 replies; 3+ messages in thread
From: Vladimir Davydov @ 2014-07-15  8:25 UTC (permalink / raw)
  To: davem
  Cc: netdev, linux-kernel, Marcel Holtmann, Gustavo Padovan, Johan Hedberg

If the current process is exiting, lingering on socket close will make
it unkillable, so we should avoid it.

Reproducer:

  #include <sys/types.h>
  #include <sys/socket.h>

  #define BTPROTO_L2CAP   0
  #define BTPROTO_SCO     2
  #define BTPROTO_RFCOMM  3

  int main()
  {
          int fd;
          struct linger ling;

          fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
          //or: fd = socket(PF_BLUETOOTH, SOCK_DGRAM, BTPROTO_L2CAP);
          //or: fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);

          ling.l_onoff = 1;
          ling.l_linger = 1000000000;
          setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));

          return 0;
  }

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
---
 net/bluetooth/l2cap_sock.c  |    3 ++-
 net/bluetooth/rfcomm/sock.c |    3 ++-
 net/bluetooth/sco.c         |    6 ++++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index e1378693cc90..d0fd8b04f2e6 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1111,7 +1111,8 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
 		l2cap_chan_close(chan, 0);
 		lock_sock(sk);
 
-		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
+		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
+		    !(current->flags & PF_EXITING))
 			err = bt_sock_wait_state(sk, BT_CLOSED,
 						 sk->sk_lingertime);
 	}
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index c603a5eb4720..8bbbb5ec468c 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -918,7 +918,8 @@ static int rfcomm_sock_shutdown(struct socket *sock, int how)
 		sk->sk_shutdown = SHUTDOWN_MASK;
 		__rfcomm_sock_close(sk);
 
-		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
+		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
+		    !(current->flags & PF_EXITING))
 			err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
 	}
 	release_sock(sk);
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c06dbd3938e8..dbbbc0292bd0 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -909,7 +909,8 @@ static int sco_sock_shutdown(struct socket *sock, int how)
 		sco_sock_clear_timer(sk);
 		__sco_sock_close(sk);
 
-		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
+		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
+		    !(current->flags & PF_EXITING))
 			err = bt_sock_wait_state(sk, BT_CLOSED,
 						 sk->sk_lingertime);
 	}
@@ -929,7 +930,8 @@ static int sco_sock_release(struct socket *sock)
 
 	sco_sock_close(sk);
 
-	if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime) {
+	if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
+	    !(current->flags & PF_EXITING)) {
 		lock_sock(sk);
 		err = bt_sock_wait_state(sk, BT_CLOSED, sk->sk_lingertime);
 		release_sock(sk);
-- 
1.7.10.4

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

* Re: [PATCH] bluetooth: never linger on process exit
       [not found] ` <1405412728-4706-1-git-send-email-vdavydov-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
@ 2014-07-17 10:05   ` Marcel Holtmann
  0 siblings, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2014-07-17 10:05 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: David S. Miller, Network Development, LKML, Gustavo F. Padovan,
	Johan Hedberg, Linux Bluetooth mailing list

Hi Vladimir,

please always include linux-bluetooth-u79uwXL29TY76Z2rM5mHXA@public.gmane.org since otherwise it might be missed in the massive amount of emails that is LKML.

> If the current process is exiting, lingering on socket close will make
> it unkillable, so we should avoid it.
> 
> Reproducer:
> 
>  #include <sys/types.h>
>  #include <sys/socket.h>
> 
>  #define BTPROTO_L2CAP   0
>  #define BTPROTO_SCO     2
>  #define BTPROTO_RFCOMM  3
> 
>  int main()
>  {
>          int fd;
>          struct linger ling;
> 
>          fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
>          //or: fd = socket(PF_BLUETOOTH, SOCK_DGRAM, BTPROTO_L2CAP);
>          //or: fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
> 
>          ling.l_onoff = 1;
>          ling.l_linger = 1000000000;
>          setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
> 
>          return 0;
>  }
> 
> Signed-off-by: Vladimir Davydov <vdavydov-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
> Cc: Marcel Holtmann <marcel-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
> Cc: Gustavo Padovan <gustavo-THi1TnShQwVAfugRpC6u6w@public.gmane.org>
> Cc: Johan Hedberg <johan.hedberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
> net/bluetooth/l2cap_sock.c  |    3 ++-
> net/bluetooth/rfcomm/sock.c |    3 ++-
> net/bluetooth/sco.c         |    6 ++++--
> 3 files changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
> index e1378693cc90..d0fd8b04f2e6 100644
> --- a/net/bluetooth/l2cap_sock.c
> +++ b/net/bluetooth/l2cap_sock.c
> @@ -1111,7 +1111,8 @@ static int l2cap_sock_shutdown(struct socket *sock, int how)
> 		l2cap_chan_close(chan, 0);
> 		lock_sock(sk);
> 
> -		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime)
> +		if (sock_flag(sk, SOCK_LINGER) && sk->sk_lingertime &&
> +		    !(current->flags & PF_EXITING))
> 			err = bt_sock_wait_state(sk, BT_CLOSED,
> 						 sk->sk_lingertime);
> 	}

The only other example of using PF_EXITING I found is net/ipv4/af_inet.c and if this is the preferred way of handling this, the patch looks fine to me.

Regards

Marcel

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

* Re: [PATCH] bluetooth: never linger on process exit
  2014-07-15  8:25 [PATCH] bluetooth: never linger on process exit Vladimir Davydov
       [not found] ` <1405412728-4706-1-git-send-email-vdavydov-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
@ 2014-07-17 10:16 ` Marcel Holtmann
  1 sibling, 0 replies; 3+ messages in thread
From: Marcel Holtmann @ 2014-07-17 10:16 UTC (permalink / raw)
  To: Vladimir Davydov
  Cc: David S. Miller, Network Development, LKML, Gustavo F. Padovan,
	Johan Hedberg, Linux Bluetooth mailing list

Hi Vladimir,

> If the current process is exiting, lingering on socket close will make
> it unkillable, so we should avoid it.
> 
> Reproducer:
> 
>  #include <sys/types.h>
>  #include <sys/socket.h>
> 
>  #define BTPROTO_L2CAP   0
>  #define BTPROTO_SCO     2
>  #define BTPROTO_RFCOMM  3
> 
>  int main()
>  {
>          int fd;
>          struct linger ling;
> 
>          fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
>          //or: fd = socket(PF_BLUETOOTH, SOCK_DGRAM, BTPROTO_L2CAP);
>          //or: fd = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO);
> 
>          ling.l_onoff = 1;
>          ling.l_linger = 1000000000;
>          setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof(ling));
> 
>          return 0;
>  }
> 
> Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
> Cc: Marcel Holtmann <marcel@holtmann.org>
> Cc: Gustavo Padovan <gustavo@padovan.org>
> Cc: Johan Hedberg <johan.hedberg@gmail.com>
> ---
> net/bluetooth/l2cap_sock.c  |    3 ++-
> net/bluetooth/rfcomm/sock.c |    3 ++-
> net/bluetooth/sco.c         |    6 ++++--
> 3 files changed, 8 insertions(+), 4 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

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

end of thread, other threads:[~2014-07-17 10:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-15  8:25 [PATCH] bluetooth: never linger on process exit Vladimir Davydov
     [not found] ` <1405412728-4706-1-git-send-email-vdavydov-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2014-07-17 10:05   ` Marcel Holtmann
2014-07-17 10:16 ` Marcel Holtmann

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).