| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* Service connection management |
|---|
| 2 | 3 | * |
|---|
| 3 | 4 | * Copyright (C) 2016 Red Hat, Inc. All Rights Reserved. |
|---|
| 4 | 5 | * Written by David Howells (dhowells@redhat.com) |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of the GNU General Public Licence |
|---|
| 8 | | - * as published by the Free Software Foundation; either version |
|---|
| 9 | | - * 2 of the Licence, or (at your option) any later version. |
|---|
| 10 | 6 | */ |
|---|
| 11 | 7 | |
|---|
| 12 | 8 | #include <linux/slab.h> |
|---|
| 13 | 9 | #include "ar-internal.h" |
|---|
| 10 | + |
|---|
| 11 | +static struct rxrpc_bundle rxrpc_service_dummy_bundle = { |
|---|
| 12 | + .ref = REFCOUNT_INIT(1), |
|---|
| 13 | + .debug_id = UINT_MAX, |
|---|
| 14 | + .channel_lock = __SPIN_LOCK_UNLOCKED(&rxrpc_service_dummy_bundle.channel_lock), |
|---|
| 15 | +}; |
|---|
| 14 | 16 | |
|---|
| 15 | 17 | /* |
|---|
| 16 | 18 | * Find a service connection under RCU conditions. |
|---|
| .. | .. |
|---|
| 97 | 99 | return; |
|---|
| 98 | 100 | |
|---|
| 99 | 101 | found_extant_conn: |
|---|
| 100 | | - if (atomic_read(&cursor->usage) == 0) |
|---|
| 102 | + if (refcount_read(&cursor->ref) == 0) |
|---|
| 101 | 103 | goto replace_old_connection; |
|---|
| 102 | 104 | write_sequnlock_bh(&peer->service_conn_lock); |
|---|
| 103 | 105 | /* We should not be able to get here. rxrpc_incoming_connection() is |
|---|
| .. | .. |
|---|
| 130 | 132 | * the rxrpc_connections list. |
|---|
| 131 | 133 | */ |
|---|
| 132 | 134 | conn->state = RXRPC_CONN_SERVICE_PREALLOC; |
|---|
| 133 | | - atomic_set(&conn->usage, 2); |
|---|
| 135 | + refcount_set(&conn->ref, 2); |
|---|
| 136 | + conn->bundle = rxrpc_get_bundle(&rxrpc_service_dummy_bundle); |
|---|
| 134 | 137 | |
|---|
| 135 | 138 | atomic_inc(&rxnet->nr_conns); |
|---|
| 136 | 139 | write_lock(&rxnet->conn_lock); |
|---|
| .. | .. |
|---|
| 139 | 142 | write_unlock(&rxnet->conn_lock); |
|---|
| 140 | 143 | |
|---|
| 141 | 144 | trace_rxrpc_conn(conn->debug_id, rxrpc_conn_new_service, |
|---|
| 142 | | - atomic_read(&conn->usage), |
|---|
| 145 | + refcount_read(&conn->ref), |
|---|
| 143 | 146 | __builtin_return_address(0)); |
|---|
| 144 | 147 | } |
|---|
| 145 | 148 | |
|---|
| .. | .. |
|---|
| 152 | 155 | */ |
|---|
| 153 | 156 | void rxrpc_new_incoming_connection(struct rxrpc_sock *rx, |
|---|
| 154 | 157 | struct rxrpc_connection *conn, |
|---|
| 158 | + const struct rxrpc_security *sec, |
|---|
| 159 | + struct key *key, |
|---|
| 155 | 160 | struct sk_buff *skb) |
|---|
| 156 | 161 | { |
|---|
| 157 | 162 | struct rxrpc_skb_priv *sp = rxrpc_skb(skb); |
|---|
| .. | .. |
|---|
| 164 | 169 | conn->service_id = sp->hdr.serviceId; |
|---|
| 165 | 170 | conn->security_ix = sp->hdr.securityIndex; |
|---|
| 166 | 171 | conn->out_clientflag = 0; |
|---|
| 172 | + conn->security = sec; |
|---|
| 173 | + conn->server_key = key_get(key); |
|---|
| 167 | 174 | if (conn->security_ix) |
|---|
| 168 | 175 | conn->state = RXRPC_CONN_SERVICE_UNSECURED; |
|---|
| 169 | 176 | else |
|---|