diff options
author | Rémi Denis-Courmont <remi.denis-courmont@nokia.com> | 2010-09-15 12:19:53 +0000 |
---|---|---|
committer | Jonas ABERG <jonas.aberg@stericsson.com> | 2011-01-24 10:46:12 +0100 |
commit | 147d984477e1c10e1c55f8a0dc1072aa1e9bfcfb (patch) | |
tree | 4c1790e3a685b4c997ed5e2a7b4105875dcc2f2e /net | |
parent | 07763a28461757e443aa4b7635a72c9758beb47a (diff) |
Phonet: remove dangling pipe if an endpoint is closed early
Closing a pipe endpoint is not normally allowed by the Phonet pipe,
other than as a side after-effect of removing the pipe between two
endpoints. But there is no way to prevent Linux userspace processes
from being killed or suffering from bugs, so this can still happen.
We might as well forcefully close Phonet pipe endpoints then.
The cellular modem supports only a few existing pipes at a time. So we
really should not leak them. This change instructs the modem to destroy
the pipe if either of the pipe's endpoint (Linux socket) is closed too
early.
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Change-Id: I4c4e400de8fc228bf2c2e64cfe59fd11842d812a
Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/13151
Reviewed-by: QATOOLS
Reviewed-by: B Sampath KUMAR <sampath.kumar@stericsson.com>
Tested-by: B Sampath KUMAR <sampath.kumar@stericsson.com>
Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/phonet/pep.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/net/phonet/pep.c b/net/phonet/pep.c index a040220a74c..54ed1aa9436 100644 --- a/net/phonet/pep.c +++ b/net/phonet/pep.c @@ -620,6 +620,28 @@ drop: return err; } +static int pipe_do_remove(struct sock *sk) +{ + struct pep_sock *pn = pep_sk(sk); + struct pnpipehdr *ph; + struct sk_buff *skb; + + skb = alloc_skb(MAX_PNPIPE_HEADER, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + skb_reserve(skb, MAX_PNPIPE_HEADER); + __skb_push(skb, sizeof(*ph)); + skb_reset_transport_header(skb); + ph = pnp_hdr(skb); + ph->utid = 0; + ph->message_id = PNS_PIPE_REMOVE_REQ; + ph->pipe_handle = pn->pipe_handle; + ph->data[0] = PAD; + + return pn_skb_send(sk, skb, &pipe_srv); +} + /* associated socket ceases to exist */ static void pep_sock_close(struct sock *sk, long timeout) { @@ -638,7 +660,10 @@ static void pep_sock_close(struct sock *sk, long timeout) sk_for_each_safe(sknode, p, n, &pn->ackq) sk_del_node_init(sknode); sk->sk_state = TCP_CLOSE; - } + } else if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED)) + /* Forcefully remove dangling Phonet pipe */ + pipe_do_remove(sk); + ifindex = pn->ifindex; pn->ifindex = 0; release_sock(sk); |