diff mbox series

[V2,net-next,1/3] rds; Reset rs->rs_bound_addr in rds_add_bound() failure path

Message ID c1267c64f578141e16a544e6f1d792acbb1829d8.1513962765.git.sowmini.varadhan@oracle.com
State Accepted, archived
Delegated to: David Miller
Headers show
Series [V2,net-next,1/3] rds; Reset rs->rs_bound_addr in rds_add_bound() failure path | expand

Commit Message

Sowmini Varadhan Dec. 22, 2017, 5:38 p.m. UTC
If the rds_sock is not added to the bind_hash_table, we must
reset rs_bound_addr so that rds_remove_bound will not trip on
this rds_sock.

rds_add_bound() does a rds_sock_put() in this failure path, so
failing to reset rs_bound_addr will result in a socket refcount
bug, and will trigger a WARN_ON with the stack shown below when
the application subsequently tries to close the PF_RDS socket.

     WARNING: CPU: 20 PID: 19499 at net/rds/af_rds.c:496 \
		rds_sock_destruct+0x15/0x30 [rds]
       :
     __sk_destruct+0x21/0x190
     rds_remove_bound.part.13+0xb6/0x140 [rds]
     rds_release+0x71/0x120 [rds]
     sock_release+0x1a/0x70
     sock_close+0xe/0x20
     __fput+0xd5/0x210
     task_work_run+0x82/0xa0
     do_exit+0x2ce/0xb30
     ? syscall_trace_enter+0x1cc/0x2b0
     do_group_exit+0x39/0xa0
     SyS_exit_group+0x10/0x10
     do_syscall_64+0x61/0x1a0

Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
---
v2: target net-next, not net

 net/rds/bind.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

Comments

Santosh Shilimkar Dec. 22, 2017, 6:15 p.m. UTC | #1
On 12/22/2017 9:38 AM, Sowmini Varadhan wrote:
> If the rds_sock is not added to the bind_hash_table, we must
> reset rs_bound_addr so that rds_remove_bound will not trip on
> this rds_sock.
> 
> rds_add_bound() does a rds_sock_put() in this failure path, so
> failing to reset rs_bound_addr will result in a socket refcount
> bug, and will trigger a WARN_ON with the stack shown below when
> the application subsequently tries to close the PF_RDS socket.
> 
>       WARNING: CPU: 20 PID: 19499 at net/rds/af_rds.c:496 \
> 		rds_sock_destruct+0x15/0x30 [rds]
>         :
>       __sk_destruct+0x21/0x190
>       rds_remove_bound.part.13+0xb6/0x140 [rds]
>       rds_release+0x71/0x120 [rds]
>       sock_release+0x1a/0x70
>       sock_close+0xe/0x20
>       __fput+0xd5/0x210
>       task_work_run+0x82/0xa0
>       do_exit+0x2ce/0xb30
>       ? syscall_trace_enter+0x1cc/0x2b0
>       do_group_exit+0x39/0xa0
>       SyS_exit_group+0x10/0x10
>       do_syscall_64+0x61/0x1a0
> 
> Signed-off-by: Sowmini Varadhan <sowmini.varadhan@oracle.com>
> ---
> v2: target net-next, not net
> 
Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
diff mbox series

Patch

diff --git a/net/rds/bind.c b/net/rds/bind.c
index 75d43dc..5aa3a64 100644
--- a/net/rds/bind.c
+++ b/net/rds/bind.c
@@ -114,6 +114,7 @@  static int rds_add_bound(struct rds_sock *rs, __be32 addr, __be16 *port)
 			  rs, &addr, (int)ntohs(*port));
 			break;
 		} else {
+			rs->rs_bound_addr = 0;
 			rds_sock_put(rs);
 			ret = -ENOMEM;
 			break;