Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1211528

[PATCH 12/14] RDS: make sure rds_send_drop_to properly takes the m_rs_lock

Path csiph.com!au2pb.net!feeder.erje.net!1.eu.feeder.erje.net!nntpspool01.opticnetworks.net!aioe.org!bofh.it!news.nic.it!robomod
From Santosh Shilimkar <santosh.shilimkar@oracle.com>
Newsgroups linux.kernel
Subject [PATCH 12/14] RDS: make sure rds_send_drop_to properly takes the m_rs_lock
Date Sun, 23 Aug 2015 00:50:03 +0200
Message-ID <q0pLR-7Ac-31@gated-at.bofh.it> (permalink)
References <q0pLP-7Ac-3@gated-at.bofh.it>
X-Original-To netdev@vger.kernel.org
X-Mailer git-send-email 1.9.1
X-Source-IP aserv0022.oracle.com [141.146.126.234]
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 55
Organization linux.* mail to news gateway
X-Original-Cc linux-kernel@vger.kernel.org, davem@davemloft.net, ssantosh@kernel.org, Santosh Shilimkar <santosh.shilimkar@oracle.com>
X-Original-Date Sat, 22 Aug 2015 15:45:33 -0700
X-Original-Message-ID <1440283535-4800-13-git-send-email-santosh.shilimkar@oracle.com>
X-Original-References <1440283535-4800-1-git-send-email-santosh.shilimkar@oracle.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1211528

Show key headers only | View raw


rds_send_drop_to() is used during socket tear down to find all the
messages on the socket and flush them .  It can race with the
acking code unless it takes the m_rs_lock on each and every message.

This plugs a hole where we didn't take m_rs_lock on any message that
didn't have the RDS_MSG_ON_CONN set.  Taking m_rs_lock avoids
double frees and other memory corruptions as the ack code trusts
the message m_rs pointer on a socket that had actually been freed.

We must take m_rs_lock to access m_rs.  Because of lock nesting and
rs access, we also need to acquire rs_lock.

Reviewed-by: Ajaykumar Hotchandani <ajaykumar.hotchandani@oracle.com>
Signed-off-by: Santosh Shilimkar <ssantosh@kernel.org>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
---
 net/rds/send.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/net/rds/send.c b/net/rds/send.c
index 96ae38d..b0fe412 100644
--- a/net/rds/send.c
+++ b/net/rds/send.c
@@ -778,8 +778,22 @@ void rds_send_drop_to(struct rds_sock *rs, struct sockaddr_in *dest)
 	while (!list_empty(&list)) {
 		rm = list_entry(list.next, struct rds_message, m_sock_item);
 		list_del_init(&rm->m_sock_item);
-
 		rds_message_wait(rm);
+
+		/* just in case the code above skipped this message
+		 * because RDS_MSG_ON_CONN wasn't set, run it again here
+		 * taking m_rs_lock is the only thing that keeps us
+		 * from racing with ack processing.
+		 */
+		spin_lock_irqsave(&rm->m_rs_lock, flags);
+
+		spin_lock(&rs->rs_lock);
+		__rds_send_complete(rs, rm, RDS_RDMA_CANCELED);
+		spin_unlock(&rs->rs_lock);
+
+		rm->m_rs = NULL;
+		spin_unlock_irqrestore(&rm->m_rs_lock, flags);
+
 		rds_message_put(rm);
 	}
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/14] RDS: Assorted bug fixes Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-08-23 00:50 +0200
  [PATCH 12/14] RDS: make sure rds_send_drop_to properly takes the m_rs_lock Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-08-23 00:50 +0200
  [PATCH 01/14] RDS: restore return value in rds_cmsg_rdma_args() Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-08-23 01:00 +0200
  [PATCH 06/14] RDS: check for congestion updates during rds_send_xmit Santosh Shilimkar <santosh.shilimkar@oracle.com> - 2015-08-23 01:00 +0200
  Re: [PATCH 00/14] RDS: Assorted bug fixes David Miller <davem@davemloft.net> - 2015-08-25 22:40 +0200

csiph-web