mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	sctp: check duplicate node before inserting a new transport
sctp has changed to use rhlist for transport rhashtable since commit7fda702f93("sctp: use new rhlist interface on sctp transport rhashtable"). But rhltable_insert_key doesn't check the duplicate node when inserting a node, unlike rhashtable_lookup_insert_key. It may cause duplicate assoc/transport in rhashtable. like: client (addr A, B) server (addr X, Y) connect to X INIT (1) ------------> connect to Y INIT (2) ------------> INIT_ACK (1) <------------ INIT_ACK (2) <------------ After sending INIT (2), one transport will be created and hashed into rhashtable. But when receiving INIT_ACK (1) and processing the address params, another transport will be created and hashed into rhashtable with the same addr Y and EP as the last transport. This will confuse the assoc/transport's lookup. This patch is to fix it by returning err if any duplicate node exists before inserting it. Fixes:7fda702f93("sctp: use new rhlist interface on sctp transport rhashtable") Reported-by: Fabio M. Di Nitto <fdinitto@redhat.com> Signed-off-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
							parent
							
								
									7e1392fb94
								
							
						
					
					
						commit
						cd2b708750
					
				
					 1 changed files with 13 additions and 0 deletions
				
			
		| 
						 | 
					@ -872,6 +872,8 @@ void sctp_transport_hashtable_destroy(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int sctp_hash_transport(struct sctp_transport *t)
 | 
					int sctp_hash_transport(struct sctp_transport *t)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct sctp_transport *transport;
 | 
				
			||||||
 | 
						struct rhlist_head *tmp, *list;
 | 
				
			||||||
	struct sctp_hash_cmp_arg arg;
 | 
						struct sctp_hash_cmp_arg arg;
 | 
				
			||||||
	int err;
 | 
						int err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -882,8 +884,19 @@ int sctp_hash_transport(struct sctp_transport *t)
 | 
				
			||||||
	arg.paddr = &t->ipaddr;
 | 
						arg.paddr = &t->ipaddr;
 | 
				
			||||||
	arg.lport = htons(t->asoc->base.bind_addr.port);
 | 
						arg.lport = htons(t->asoc->base.bind_addr.port);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						list = rhltable_lookup(&sctp_transport_hashtable, &arg,
 | 
				
			||||||
 | 
								       sctp_hash_params);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						rhl_for_each_entry_rcu(transport, tmp, list, node)
 | 
				
			||||||
 | 
							if (transport->asoc->ep == t->asoc->ep) {
 | 
				
			||||||
 | 
								err = -EEXIST;
 | 
				
			||||||
 | 
								goto out;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = rhltable_insert_key(&sctp_transport_hashtable, &arg,
 | 
						err = rhltable_insert_key(&sctp_transport_hashtable, &arg,
 | 
				
			||||||
				  &t->node, sctp_hash_params);
 | 
									  &t->node, sctp_hash_params);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					out:
 | 
				
			||||||
	if (err)
 | 
						if (err)
 | 
				
			||||||
		pr_err_once("insert transport fail, errno %d\n", err);
 | 
							pr_err_once("insert transport fail, errno %d\n", err);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue