~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/rxrpc/conn_service.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/rxrpc/conn_service.c (Version linux-6.11-rc3) and /net/rxrpc/conn_service.c (Version linux-5.8.18)


  1 // SPDX-License-Identifier: GPL-2.0-or-later        1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /* Service connection management                    2 /* Service connection management
  3  *                                                  3  *
  4  * Copyright (C) 2016 Red Hat, Inc. All Rights      4  * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved.
  5  * Written by David Howells (dhowells@redhat.c      5  * Written by David Howells (dhowells@redhat.com)
  6  */                                                 6  */
  7                                                     7 
  8 #include <linux/slab.h>                             8 #include <linux/slab.h>
  9 #include "ar-internal.h"                            9 #include "ar-internal.h"
 10                                                    10 
 11 /*                                                 11 /*
 12  * Find a service connection under RCU conditi     12  * Find a service connection under RCU conditions.
 13  *                                                 13  *
 14  * We could use a hash table, but that is subj     14  * We could use a hash table, but that is subject to bucket stuffing by an
 15  * attacker as the client gets to pick the epo     15  * attacker as the client gets to pick the epoch and cid values and would know
 16  * the hash function.  So, instead, we use a h     16  * the hash function.  So, instead, we use a hash table for the peer and from
 17  * that an rbtree to find the service connecti     17  * that an rbtree to find the service connection.  Under ordinary circumstances
 18  * it might be slower than a large hash table,     18  * it might be slower than a large hash table, but it is at least limited in
 19  * depth.                                          19  * depth.
 20  */                                                20  */
 21 struct rxrpc_connection *rxrpc_find_service_co     21 struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *peer,
 22                                                    22                                                      struct sk_buff *skb)
 23 {                                                  23 {
 24         struct rxrpc_connection *conn = NULL;      24         struct rxrpc_connection *conn = NULL;
 25         struct rxrpc_conn_proto k;                 25         struct rxrpc_conn_proto k;
 26         struct rxrpc_skb_priv *sp = rxrpc_skb(     26         struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
 27         struct rb_node *p;                         27         struct rb_node *p;
 28         unsigned int seq = 1;                  !!  28         unsigned int seq = 0;
 29                                                    29 
 30         k.epoch = sp->hdr.epoch;                   30         k.epoch = sp->hdr.epoch;
 31         k.cid   = sp->hdr.cid & RXRPC_CIDMASK;     31         k.cid   = sp->hdr.cid & RXRPC_CIDMASK;
 32                                                    32 
 33         do {                                       33         do {
 34                 /* Unfortunately, rbtree walki     34                 /* Unfortunately, rbtree walking doesn't give reliable results
 35                  * under just the RCU read loc     35                  * under just the RCU read lock, so we have to check for
 36                  * changes.                        36                  * changes.
 37                  */                                37                  */
 38                 seq++; /* 2 on the 1st/lockles << 
 39                 read_seqbegin_or_lock(&peer->s     38                 read_seqbegin_or_lock(&peer->service_conn_lock, &seq);
 40                                                    39 
 41                 p = rcu_dereference_raw(peer->     40                 p = rcu_dereference_raw(peer->service_conns.rb_node);
 42                 while (p) {                        41                 while (p) {
 43                         conn = rb_entry(p, str     42                         conn = rb_entry(p, struct rxrpc_connection, service_node);
 44                                                    43 
 45                         if (conn->proto.index_     44                         if (conn->proto.index_key < k.index_key)
 46                                 p = rcu_derefe     45                                 p = rcu_dereference_raw(p->rb_left);
 47                         else if (conn->proto.i     46                         else if (conn->proto.index_key > k.index_key)
 48                                 p = rcu_derefe     47                                 p = rcu_dereference_raw(p->rb_right);
 49                         else                       48                         else
 50                                 break;             49                                 break;
 51                         conn = NULL;               50                         conn = NULL;
 52                 }                                  51                 }
 53         } while (need_seqretry(&peer->service_     52         } while (need_seqretry(&peer->service_conn_lock, seq));
 54                                                    53 
 55         done_seqretry(&peer->service_conn_lock     54         done_seqretry(&peer->service_conn_lock, seq);
 56         _leave(" = %d", conn ? conn->debug_id      55         _leave(" = %d", conn ? conn->debug_id : -1);
 57         return conn;                               56         return conn;
 58 }                                                  57 }
 59                                                    58 
 60 /*                                                 59 /*
 61  * Insert a service connection into a peer's t     60  * Insert a service connection into a peer's tree, thereby making it a target
 62  * for incoming packets.                           61  * for incoming packets.
 63  */                                                62  */
 64 static void rxrpc_publish_service_conn(struct      63 static void rxrpc_publish_service_conn(struct rxrpc_peer *peer,
 65                                        struct      64                                        struct rxrpc_connection *conn)
 66 {                                                  65 {
 67         struct rxrpc_connection *cursor = NULL     66         struct rxrpc_connection *cursor = NULL;
 68         struct rxrpc_conn_proto k = conn->prot     67         struct rxrpc_conn_proto k = conn->proto;
 69         struct rb_node **pp, *parent;              68         struct rb_node **pp, *parent;
 70                                                    69 
 71         write_seqlock(&peer->service_conn_lock !!  70         write_seqlock_bh(&peer->service_conn_lock);
 72                                                    71 
 73         pp = &peer->service_conns.rb_node;         72         pp = &peer->service_conns.rb_node;
 74         parent = NULL;                             73         parent = NULL;
 75         while (*pp) {                              74         while (*pp) {
 76                 parent = *pp;                      75                 parent = *pp;
 77                 cursor = rb_entry(parent,          76                 cursor = rb_entry(parent,
 78                                   struct rxrpc     77                                   struct rxrpc_connection, service_node);
 79                                                    78 
 80                 if (cursor->proto.index_key <      79                 if (cursor->proto.index_key < k.index_key)
 81                         pp = &(*pp)->rb_left;      80                         pp = &(*pp)->rb_left;
 82                 else if (cursor->proto.index_k     81                 else if (cursor->proto.index_key > k.index_key)
 83                         pp = &(*pp)->rb_right;     82                         pp = &(*pp)->rb_right;
 84                 else                               83                 else
 85                         goto found_extant_conn     84                         goto found_extant_conn;
 86         }                                          85         }
 87                                                    86 
 88         rb_link_node_rcu(&conn->service_node,      87         rb_link_node_rcu(&conn->service_node, parent, pp);
 89         rb_insert_color(&conn->service_node, &     88         rb_insert_color(&conn->service_node, &peer->service_conns);
 90 conn_published:                                    89 conn_published:
 91         set_bit(RXRPC_CONN_IN_SERVICE_CONNS, &     90         set_bit(RXRPC_CONN_IN_SERVICE_CONNS, &conn->flags);
 92         write_sequnlock(&peer->service_conn_lo !!  91         write_sequnlock_bh(&peer->service_conn_lock);
 93         _leave(" = %d [new]", conn->debug_id);     92         _leave(" = %d [new]", conn->debug_id);
 94         return;                                    93         return;
 95                                                    94 
 96 found_extant_conn:                                 95 found_extant_conn:
 97         if (refcount_read(&cursor->ref) == 0)  !!  96         if (atomic_read(&cursor->usage) == 0)
 98                 goto replace_old_connection;       97                 goto replace_old_connection;
 99         write_sequnlock(&peer->service_conn_lo !!  98         write_sequnlock_bh(&peer->service_conn_lock);
100         /* We should not be able to get here.      99         /* We should not be able to get here.  rxrpc_incoming_connection() is
101          * called in a non-reentrant context,     100          * called in a non-reentrant context, so there can't be a race to
102          * insert a new connection.               101          * insert a new connection.
103          */                                       102          */
104         BUG();                                    103         BUG();
105                                                   104 
106 replace_old_connection:                           105 replace_old_connection:
107         /* The old connection is from an outda    106         /* The old connection is from an outdated epoch. */
108         _debug("replace conn");                   107         _debug("replace conn");
109         rb_replace_node_rcu(&cursor->service_n    108         rb_replace_node_rcu(&cursor->service_node,
110                             &conn->service_nod    109                             &conn->service_node,
111                             &peer->service_con    110                             &peer->service_conns);
112         clear_bit(RXRPC_CONN_IN_SERVICE_CONNS,    111         clear_bit(RXRPC_CONN_IN_SERVICE_CONNS, &cursor->flags);
113         goto conn_published;                      112         goto conn_published;
114 }                                                 113 }
115                                                   114 
116 /*                                                115 /*
117  * Preallocate a service connection.  The conn    116  * Preallocate a service connection.  The connection is placed on the proc and
118  * reap lists so that we don't have to get the    117  * reap lists so that we don't have to get the lock from BH context.
119  */                                               118  */
120 struct rxrpc_connection *rxrpc_prealloc_servic    119 struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *rxnet,
121                                                   120                                                            gfp_t gfp)
122 {                                                 121 {
123         struct rxrpc_connection *conn = rxrpc_ !! 122         struct rxrpc_connection *conn = rxrpc_alloc_connection(gfp);
124                                                   123 
125         if (conn) {                               124         if (conn) {
126                 /* We maintain an extra ref on    125                 /* We maintain an extra ref on the connection whilst it is on
127                  * the rxrpc_connections list.    126                  * the rxrpc_connections list.
128                  */                               127                  */
129                 conn->state = RXRPC_CONN_SERVI    128                 conn->state = RXRPC_CONN_SERVICE_PREALLOC;
130                 refcount_set(&conn->ref, 2);   !! 129                 atomic_set(&conn->usage, 2);
131                                                   130 
132                 atomic_inc(&rxnet->nr_conns);     131                 atomic_inc(&rxnet->nr_conns);
133                 write_lock(&rxnet->conn_lock);    132                 write_lock(&rxnet->conn_lock);
134                 list_add_tail(&conn->link, &rx    133                 list_add_tail(&conn->link, &rxnet->service_conns);
135                 list_add_tail(&conn->proc_link    134                 list_add_tail(&conn->proc_link, &rxnet->conn_proc_list);
136                 write_unlock(&rxnet->conn_lock    135                 write_unlock(&rxnet->conn_lock);
137                                                   136 
138                 rxrpc_see_connection(conn, rxr !! 137                 trace_rxrpc_conn(conn->debug_id, rxrpc_conn_new_service,
                                                   >> 138                                  atomic_read(&conn->usage),
                                                   >> 139                                  __builtin_return_address(0));
139         }                                         140         }
140                                                   141 
141         return conn;                              142         return conn;
142 }                                                 143 }
143                                                   144 
144 /*                                                145 /*
145  * Set up an incoming connection.  This is cal    146  * Set up an incoming connection.  This is called in BH context with the RCU
146  * read lock held.                                147  * read lock held.
147  */                                               148  */
148 void rxrpc_new_incoming_connection(struct rxrp    149 void rxrpc_new_incoming_connection(struct rxrpc_sock *rx,
149                                    struct rxrp    150                                    struct rxrpc_connection *conn,
150                                    const struc    151                                    const struct rxrpc_security *sec,
                                                   >> 152                                    struct key *key,
151                                    struct sk_b    153                                    struct sk_buff *skb)
152 {                                                 154 {
153         struct rxrpc_skb_priv *sp = rxrpc_skb(    155         struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
154                                                   156 
155         _enter("");                               157         _enter("");
156                                                   158 
157         conn->proto.epoch       = sp->hdr.epoc    159         conn->proto.epoch       = sp->hdr.epoch;
158         conn->proto.cid         = sp->hdr.cid     160         conn->proto.cid         = sp->hdr.cid & RXRPC_CIDMASK;
159         conn->orig_service_id   = sp->hdr.serv !! 161         conn->params.service_id = sp->hdr.serviceId;
160         conn->service_id        = sp->hdr.serv    162         conn->service_id        = sp->hdr.serviceId;
161         conn->security_ix       = sp->hdr.secu    163         conn->security_ix       = sp->hdr.securityIndex;
162         conn->out_clientflag    = 0;              164         conn->out_clientflag    = 0;
163         conn->security          = sec;            165         conn->security          = sec;
                                                   >> 166         conn->server_key        = key_get(key);
164         if (conn->security_ix)                    167         if (conn->security_ix)
165                 conn->state     = RXRPC_CONN_S    168                 conn->state     = RXRPC_CONN_SERVICE_UNSECURED;
166         else                                      169         else
167                 conn->state     = RXRPC_CONN_S    170                 conn->state     = RXRPC_CONN_SERVICE;
168                                                   171 
169         /* See if we should upgrade the servic    172         /* See if we should upgrade the service.  This can only happen on the
170          * first packet on a new connection.      173          * first packet on a new connection.  Once done, it applies to all
171          * subsequent calls on that connection    174          * subsequent calls on that connection.
172          */                                       175          */
173         if (sp->hdr.userStatus == RXRPC_USERST    176         if (sp->hdr.userStatus == RXRPC_USERSTATUS_SERVICE_UPGRADE &&
174             conn->service_id == rx->service_up    177             conn->service_id == rx->service_upgrade.from)
175                 conn->service_id = rx->service    178                 conn->service_id = rx->service_upgrade.to;
176                                                   179 
177         atomic_set(&conn->active, 1);          << 
178                                                << 
179         /* Make the connection a target for in    180         /* Make the connection a target for incoming packets. */
180         rxrpc_publish_service_conn(conn->peer, !! 181         rxrpc_publish_service_conn(conn->params.peer, conn);
                                                   >> 182 
                                                   >> 183         _net("CONNECTION new %d {%x}", conn->debug_id, conn->proto.cid);
181 }                                                 184 }
182                                                   185 
183 /*                                                186 /*
184  * Remove the service connection from the peer    187  * Remove the service connection from the peer's tree, thereby removing it as a
185  * target for incoming packets.                   188  * target for incoming packets.
186  */                                               189  */
187 void rxrpc_unpublish_service_conn(struct rxrpc    190 void rxrpc_unpublish_service_conn(struct rxrpc_connection *conn)
188 {                                                 191 {
189         struct rxrpc_peer *peer = conn->peer;  !! 192         struct rxrpc_peer *peer = conn->params.peer;
190                                                   193 
191         write_seqlock(&peer->service_conn_lock !! 194         write_seqlock_bh(&peer->service_conn_lock);
192         if (test_and_clear_bit(RXRPC_CONN_IN_S    195         if (test_and_clear_bit(RXRPC_CONN_IN_SERVICE_CONNS, &conn->flags))
193                 rb_erase(&conn->service_node,     196                 rb_erase(&conn->service_node, &peer->service_conns);
194         write_sequnlock(&peer->service_conn_lo !! 197         write_sequnlock_bh(&peer->service_conn_lock);
195 }                                                 198 }
196                                                   199 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php