@@ -165,6 +165,7 @@ struct nvme_tcp_queue {
165
165
166
166
bool hdr_digest ;
167
167
bool data_digest ;
168
+ bool tls_enabled ;
168
169
struct ahash_request * rcv_hash ;
169
170
struct ahash_request * snd_hash ;
170
171
__le32 exp_ddgst ;
@@ -213,7 +214,21 @@ static inline int nvme_tcp_queue_id(struct nvme_tcp_queue *queue)
213
214
return queue - queue -> ctrl -> queues ;
214
215
}
215
216
216
- static inline bool nvme_tcp_tls (struct nvme_ctrl * ctrl )
217
+ /*
218
+ * Check if the queue is TLS encrypted
219
+ */
220
+ static inline bool nvme_tcp_queue_tls (struct nvme_tcp_queue * queue )
221
+ {
222
+ if (!IS_ENABLED (CONFIG_NVME_TCP_TLS ))
223
+ return 0 ;
224
+
225
+ return queue -> tls_enabled ;
226
+ }
227
+
228
+ /*
229
+ * Check if TLS is configured for the controller.
230
+ */
231
+ static inline bool nvme_tcp_tls_configured (struct nvme_ctrl * ctrl )
217
232
{
218
233
if (!IS_ENABLED (CONFIG_NVME_TCP_TLS ))
219
234
return 0 ;
@@ -368,7 +383,7 @@ static inline bool nvme_tcp_queue_has_pending(struct nvme_tcp_queue *queue)
368
383
369
384
static inline bool nvme_tcp_queue_more (struct nvme_tcp_queue * queue )
370
385
{
371
- return !nvme_tcp_tls ( & queue -> ctrl -> ctrl ) &&
386
+ return !nvme_tcp_queue_tls ( queue ) &&
372
387
nvme_tcp_queue_has_pending (queue );
373
388
}
374
389
@@ -1427,7 +1442,7 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
1427
1442
memset (& msg , 0 , sizeof (msg ));
1428
1443
iov .iov_base = icresp ;
1429
1444
iov .iov_len = sizeof (* icresp );
1430
- if (nvme_tcp_tls ( & queue -> ctrl -> ctrl )) {
1445
+ if (nvme_tcp_queue_tls ( queue )) {
1431
1446
msg .msg_control = cbuf ;
1432
1447
msg .msg_controllen = sizeof (cbuf );
1433
1448
}
@@ -1439,7 +1454,7 @@ static int nvme_tcp_init_connection(struct nvme_tcp_queue *queue)
1439
1454
goto free_icresp ;
1440
1455
}
1441
1456
ret = - ENOTCONN ;
1442
- if (nvme_tcp_tls ( & queue -> ctrl -> ctrl )) {
1457
+ if (nvme_tcp_queue_tls ( queue )) {
1443
1458
ctype = tls_get_record_type (queue -> sock -> sk ,
1444
1459
(struct cmsghdr * )cbuf );
1445
1460
if (ctype != TLS_RECORD_TYPE_DATA ) {
@@ -1587,7 +1602,10 @@ static void nvme_tcp_tls_done(void *data, int status, key_serial_t pskid)
1587
1602
qid , pskid );
1588
1603
queue -> tls_err = - ENOKEY ;
1589
1604
} else {
1590
- ctrl -> ctrl .tls_key = tls_key ;
1605
+ queue -> tls_enabled = true;
1606
+ if (qid == 0 )
1607
+ ctrl -> ctrl .tls_pskid = key_serial (tls_key );
1608
+ key_put (tls_key );
1591
1609
queue -> tls_err = 0 ;
1592
1610
}
1593
1611
@@ -1768,7 +1786,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid,
1768
1786
}
1769
1787
1770
1788
/* If PSKs are configured try to start TLS */
1771
- if (IS_ENABLED ( CONFIG_NVME_TCP_TLS ) && pskid ) {
1789
+ if (nvme_tcp_tls_configured ( nctrl ) && pskid ) {
1772
1790
ret = nvme_tcp_start_tls (nctrl , queue , pskid );
1773
1791
if (ret )
1774
1792
goto err_init_connect ;
@@ -1829,6 +1847,8 @@ static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid)
1829
1847
mutex_lock (& queue -> queue_lock );
1830
1848
if (test_and_clear_bit (NVME_TCP_Q_LIVE , & queue -> flags ))
1831
1849
__nvme_tcp_stop_queue (queue );
1850
+ /* Stopping the queue will disable TLS */
1851
+ queue -> tls_enabled = false;
1832
1852
mutex_unlock (& queue -> queue_lock );
1833
1853
}
1834
1854
@@ -1925,16 +1945,17 @@ static int nvme_tcp_alloc_admin_queue(struct nvme_ctrl *ctrl)
1925
1945
int ret ;
1926
1946
key_serial_t pskid = 0 ;
1927
1947
1928
- if (nvme_tcp_tls (ctrl )) {
1948
+ if (nvme_tcp_tls_configured (ctrl )) {
1929
1949
if (ctrl -> opts -> tls_key )
1930
1950
pskid = key_serial (ctrl -> opts -> tls_key );
1931
- else
1951
+ else {
1932
1952
pskid = nvme_tls_psk_default (ctrl -> opts -> keyring ,
1933
1953
ctrl -> opts -> host -> nqn ,
1934
1954
ctrl -> opts -> subsysnqn );
1935
- if (!pskid ) {
1936
- dev_err (ctrl -> device , "no valid PSK found\n" );
1937
- return - ENOKEY ;
1955
+ if (!pskid ) {
1956
+ dev_err (ctrl -> device , "no valid PSK found\n" );
1957
+ return - ENOKEY ;
1958
+ }
1938
1959
}
1939
1960
}
1940
1961
@@ -1957,13 +1978,14 @@ static int __nvme_tcp_alloc_io_queues(struct nvme_ctrl *ctrl)
1957
1978
{
1958
1979
int i , ret ;
1959
1980
1960
- if (nvme_tcp_tls (ctrl ) && !ctrl -> tls_key ) {
1981
+ if (nvme_tcp_tls_configured (ctrl ) && !ctrl -> tls_pskid ) {
1961
1982
dev_err (ctrl -> device , "no PSK negotiated\n" );
1962
1983
return - ENOKEY ;
1963
1984
}
1985
+
1964
1986
for (i = 1 ; i < ctrl -> queue_count ; i ++ ) {
1965
1987
ret = nvme_tcp_alloc_queue (ctrl , i ,
1966
- key_serial ( ctrl -> tls_key ) );
1988
+ ctrl -> tls_pskid );
1967
1989
if (ret )
1968
1990
goto out_free_queues ;
1969
1991
}
@@ -2144,6 +2166,11 @@ static void nvme_tcp_teardown_admin_queue(struct nvme_ctrl *ctrl,
2144
2166
if (remove )
2145
2167
nvme_unquiesce_admin_queue (ctrl );
2146
2168
nvme_tcp_destroy_admin_queue (ctrl , remove );
2169
+ if (ctrl -> tls_pskid ) {
2170
+ dev_dbg (ctrl -> device , "Wipe negotiated TLS_PSK %08x\n" ,
2171
+ ctrl -> tls_pskid );
2172
+ ctrl -> tls_pskid = 0 ;
2173
+ }
2147
2174
}
2148
2175
2149
2176
static void nvme_tcp_teardown_io_queues (struct nvme_ctrl * ctrl ,
0 commit comments