Skip to content

Commit 4b80378

Browse files
committed
Merge tag 'block-6.7-2023-11-10' of git://git.kernel.dk/linux
Pull block fixes from Jens Axboe: - NVMe pull request via Keith: - nvme keyring config compile fixes (Hannes and Arnd) - fabrics keep alive fixes (Hannes) - tcp authentication fixes (Mark) - io_uring_cmd error handling fix (Anuj) - stale firmware attribute fix (Daniel) - tcp memory leak (Christophe) - crypto library usage simplification (Eric) - nbd use-after-free fix. May need a followup, but at least it's better than what it was before (Li) - Rate limit write on read-only device warnings (Yu) * tag 'block-6.7-2023-11-10' of git://git.kernel.dk/linux: nvme: keyring: fix conditional compilation nvme: common: make keyring and auth separate modules blk-core: use pr_warn_ratelimited() in bio_check_ro() nbd: fix uaf in nbd_open nvme: start keep-alive after admin queue setup nvme-loop: always quiesce and cancel commands before destroying admin q nvme-tcp: avoid open-coding nvme_tcp_teardown_admin_queue() nvme-auth: always set valid seq_num in dhchap reply nvme-auth: add flag for bi-directional auth nvme-auth: auth success1 msg always includes resp nvme: fix error-handling for io_uring nvme-passthrough nvme: update firmware version after commit nvme-tcp: Fix a memory leak nvme-auth: use crypto_shash_tfm_digest()
2 parents d035e4e + 37d9486 commit 4b80378

File tree

18 files changed

+72
-80
lines changed

18 files changed

+72
-80
lines changed

block/blk-core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ static inline void bio_check_ro(struct bio *bio)
501501
if (op_is_write(bio_op(bio)) && bdev_read_only(bio->bi_bdev)) {
502502
if (op_is_flush(bio->bi_opf) && !bio_sectors(bio))
503503
return;
504-
pr_warn("Trying to write to read-only block-device %pg\n",
505-
bio->bi_bdev);
504+
pr_warn_ratelimited("Trying to write to read-only block-device %pg\n",
505+
bio->bi_bdev);
506506
/* Older lvm-tools actually trigger this */
507507
}
508508
}

drivers/block/nbd.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ static void nbd_dev_remove(struct nbd_device *nbd)
250250
struct gendisk *disk = nbd->disk;
251251

252252
del_gendisk(disk);
253-
put_disk(disk);
254253
blk_mq_free_tag_set(&nbd->tag_set);
255254

256255
/*
@@ -261,7 +260,7 @@ static void nbd_dev_remove(struct nbd_device *nbd)
261260
idr_remove(&nbd_index_idr, nbd->index);
262261
mutex_unlock(&nbd_index_mutex);
263262
destroy_workqueue(nbd->recv_workq);
264-
kfree(nbd);
263+
put_disk(disk);
265264
}
266265

267266
static void nbd_dev_remove_work(struct work_struct *work)
@@ -1608,13 +1607,21 @@ static void nbd_release(struct gendisk *disk)
16081607
nbd_put(nbd);
16091608
}
16101609

1610+
static void nbd_free_disk(struct gendisk *disk)
1611+
{
1612+
struct nbd_device *nbd = disk->private_data;
1613+
1614+
kfree(nbd);
1615+
}
1616+
16111617
static const struct block_device_operations nbd_fops =
16121618
{
16131619
.owner = THIS_MODULE,
16141620
.open = nbd_open,
16151621
.release = nbd_release,
16161622
.ioctl = nbd_ioctl,
16171623
.compat_ioctl = nbd_ioctl,
1624+
.free_disk = nbd_free_disk,
16181625
};
16191626

16201627
#if IS_ENABLED(CONFIG_DEBUG_FS)

drivers/nvme/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
obj-$(CONFIG_NVME_COMMON) += common/
3+
obj-y += common/
44
obj-y += host/
55
obj-y += target/

drivers/nvme/common/Kconfig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
config NVME_COMMON
4-
tristate
5-
63
config NVME_KEYRING
7-
bool
4+
tristate
85
select KEYS
96

107
config NVME_AUTH
11-
bool
8+
tristate
129
select CRYPTO
1310
select CRYPTO_HMAC
1411
select CRYPTO_SHA256

drivers/nvme/common/Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
ccflags-y += -I$(src)
44

5-
obj-$(CONFIG_NVME_COMMON) += nvme-common.o
5+
obj-$(CONFIG_NVME_AUTH) += nvme-auth.o
6+
obj-$(CONFIG_NVME_KEYRING) += nvme-keyring.o
67

7-
nvme-common-$(CONFIG_NVME_AUTH) += auth.o
8-
nvme-common-$(CONFIG_NVME_KEYRING) += keyring.o
8+
nvme-auth-y += auth.o
9+
nvme-keyring-y += keyring.o

drivers/nvme/common/auth.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
341341
u8 *challenge, u8 *aug, size_t hlen)
342342
{
343343
struct crypto_shash *tfm;
344-
struct shash_desc *desc;
345344
u8 *hashed_key;
346345
const char *hmac_name;
347346
int ret;
@@ -369,29 +368,11 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
369368
goto out_free_key;
370369
}
371370

372-
desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm),
373-
GFP_KERNEL);
374-
if (!desc) {
375-
ret = -ENOMEM;
376-
goto out_free_hash;
377-
}
378-
desc->tfm = tfm;
379-
380371
ret = crypto_shash_setkey(tfm, hashed_key, hlen);
381372
if (ret)
382-
goto out_free_desc;
383-
384-
ret = crypto_shash_init(desc);
385-
if (ret)
386-
goto out_free_desc;
387-
388-
ret = crypto_shash_update(desc, challenge, hlen);
389-
if (ret)
390-
goto out_free_desc;
373+
goto out_free_hash;
391374

392-
ret = crypto_shash_final(desc, aug);
393-
out_free_desc:
394-
kfree_sensitive(desc);
375+
ret = crypto_shash_tfm_digest(tfm, challenge, hlen, aug);
395376
out_free_hash:
396377
crypto_free_shash(tfm);
397378
out_free_key:

drivers/nvme/common/keyring.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ key_serial_t nvme_tls_psk_default(struct key *keyring,
151151
}
152152
EXPORT_SYMBOL_GPL(nvme_tls_psk_default);
153153

154-
int nvme_keyring_init(void)
154+
static int __init nvme_keyring_init(void)
155155
{
156156
int err;
157157

@@ -171,12 +171,15 @@ int nvme_keyring_init(void)
171171
}
172172
return 0;
173173
}
174-
EXPORT_SYMBOL_GPL(nvme_keyring_init);
175174

176-
void nvme_keyring_exit(void)
175+
static void __exit nvme_keyring_exit(void)
177176
{
178177
unregister_key_type(&nvme_tls_psk_key_type);
179178
key_revoke(nvme_keyring);
180179
key_put(nvme_keyring);
181180
}
182-
EXPORT_SYMBOL_GPL(nvme_keyring_exit);
181+
182+
MODULE_LICENSE("GPL v2");
183+
MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>");
184+
module_init(nvme_keyring_init);
185+
module_exit(nvme_keyring_exit);

drivers/nvme/host/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ config NVME_TCP
9595
config NVME_TCP_TLS
9696
bool "NVMe over Fabrics TCP TLS encryption support"
9797
depends on NVME_TCP
98-
select NVME_COMMON
9998
select NVME_KEYRING
10099
select NET_HANDSHAKE
101100
select KEYS
@@ -110,7 +109,6 @@ config NVME_TCP_TLS
110109
config NVME_HOST_AUTH
111110
bool "NVM Express over Fabrics In-Band Authentication"
112111
depends on NVME_CORE
113-
select NVME_COMMON
114112
select NVME_AUTH
115113
help
116114
This provides support for NVMe over Fabrics In-Band Authentication.

drivers/nvme/host/auth.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct nvme_dhchap_queue_context {
2929
int error;
3030
u32 s1;
3131
u32 s2;
32+
bool bi_directional;
3233
u16 transaction;
3334
u8 status;
3435
u8 dhgroup_id;
@@ -312,17 +313,17 @@ static int nvme_auth_set_dhchap_reply_data(struct nvme_ctrl *ctrl,
312313
data->dhvlen = cpu_to_le16(chap->host_key_len);
313314
memcpy(data->rval, chap->response, chap->hash_len);
314315
if (ctrl->ctrl_key) {
316+
chap->bi_directional = true;
315317
get_random_bytes(chap->c2, chap->hash_len);
316318
data->cvalid = 1;
317-
chap->s2 = nvme_auth_get_seqnum();
318319
memcpy(data->rval + chap->hash_len, chap->c2,
319320
chap->hash_len);
320321
dev_dbg(ctrl->device, "%s: qid %d ctrl challenge %*ph\n",
321322
__func__, chap->qid, (int)chap->hash_len, chap->c2);
322323
} else {
323324
memset(chap->c2, 0, chap->hash_len);
324-
chap->s2 = 0;
325325
}
326+
chap->s2 = nvme_auth_get_seqnum();
326327
data->seqnum = cpu_to_le32(chap->s2);
327328
if (chap->host_key_len) {
328329
dev_dbg(ctrl->device, "%s: qid %d host public key %*ph\n",
@@ -339,10 +340,7 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,
339340
struct nvme_dhchap_queue_context *chap)
340341
{
341342
struct nvmf_auth_dhchap_success1_data *data = chap->buf;
342-
size_t size = sizeof(*data);
343-
344-
if (chap->s2)
345-
size += chap->hash_len;
343+
size_t size = sizeof(*data) + chap->hash_len;
346344

347345
if (size > CHAP_BUF_SIZE) {
348346
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
@@ -663,6 +661,7 @@ static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap)
663661
chap->error = 0;
664662
chap->s1 = 0;
665663
chap->s2 = 0;
664+
chap->bi_directional = false;
666665
chap->transaction = 0;
667666
memset(chap->c1, 0, sizeof(chap->c1));
668667
memset(chap->c2, 0, sizeof(chap->c2));
@@ -825,7 +824,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
825824
goto fail2;
826825
}
827826

828-
if (chap->s2) {
827+
if (chap->bi_directional) {
829828
/* DH-HMAC-CHAP Step 5: send success2 */
830829
dev_dbg(ctrl->device, "%s: qid %d send success2\n",
831830
__func__, chap->qid);

drivers/nvme/host/core.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "nvme.h"
2626
#include "fabrics.h"
2727
#include <linux/nvme-auth.h>
28-
#include <linux/nvme-keyring.h>
2928

3029
#define CREATE_TRACE_POINTS
3130
#include "trace.h"
@@ -483,6 +482,7 @@ EXPORT_SYMBOL_GPL(nvme_cancel_tagset);
483482

484483
void nvme_cancel_admin_tagset(struct nvme_ctrl *ctrl)
485484
{
485+
nvme_stop_keep_alive(ctrl);
486486
if (ctrl->admin_tagset) {
487487
blk_mq_tagset_busy_iter(ctrl->admin_tagset,
488488
nvme_cancel_request, ctrl);
@@ -3200,6 +3200,8 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended)
32003200
clear_bit(NVME_CTRL_DIRTY_CAPABILITY, &ctrl->flags);
32013201
ctrl->identified = true;
32023202

3203+
nvme_start_keep_alive(ctrl);
3204+
32033205
return 0;
32043206
}
32053207
EXPORT_SYMBOL_GPL(nvme_init_ctrl_finish);
@@ -4074,8 +4076,21 @@ static void nvme_get_fw_slot_info(struct nvme_ctrl *ctrl)
40744076
return;
40754077

40764078
if (nvme_get_log(ctrl, NVME_NSID_ALL, NVME_LOG_FW_SLOT, 0, NVME_CSI_NVM,
4077-
log, sizeof(*log), 0))
4079+
log, sizeof(*log), 0)) {
40784080
dev_warn(ctrl->device, "Get FW SLOT INFO log error\n");
4081+
goto out_free_log;
4082+
}
4083+
4084+
if (log->afi & 0x70 || !(log->afi & 0x7)) {
4085+
dev_info(ctrl->device,
4086+
"Firmware is activated after next Controller Level Reset\n");
4087+
goto out_free_log;
4088+
}
4089+
4090+
memcpy(ctrl->subsys->firmware_rev, &log->frs[(log->afi & 0x7) - 1],
4091+
sizeof(ctrl->subsys->firmware_rev));
4092+
4093+
out_free_log:
40794094
kfree(log);
40804095
}
40814096

@@ -4333,7 +4348,6 @@ void nvme_stop_ctrl(struct nvme_ctrl *ctrl)
43334348
{
43344349
nvme_mpath_stop(ctrl);
43354350
nvme_auth_stop(ctrl);
4336-
nvme_stop_keep_alive(ctrl);
43374351
nvme_stop_failfast_work(ctrl);
43384352
flush_work(&ctrl->async_event_work);
43394353
cancel_work_sync(&ctrl->fw_act_work);
@@ -4344,8 +4358,6 @@ EXPORT_SYMBOL_GPL(nvme_stop_ctrl);
43444358

43454359
void nvme_start_ctrl(struct nvme_ctrl *ctrl)
43464360
{
4347-
nvme_start_keep_alive(ctrl);
4348-
43494361
nvme_enable_aen(ctrl);
43504362

43514363
/*
@@ -4724,16 +4736,11 @@ static int __init nvme_core_init(void)
47244736
result = PTR_ERR(nvme_ns_chr_class);
47254737
goto unregister_generic_ns;
47264738
}
4727-
result = nvme_keyring_init();
4728-
if (result)
4729-
goto destroy_ns_chr;
47304739
result = nvme_init_auth();
47314740
if (result)
4732-
goto keyring_exit;
4741+
goto destroy_ns_chr;
47334742
return 0;
47344743

4735-
keyring_exit:
4736-
nvme_keyring_exit();
47374744
destroy_ns_chr:
47384745
class_destroy(nvme_ns_chr_class);
47394746
unregister_generic_ns:
@@ -4757,7 +4764,6 @@ static int __init nvme_core_init(void)
47574764
static void __exit nvme_core_exit(void)
47584765
{
47594766
nvme_exit_auth();
4760-
nvme_keyring_exit();
47614767
class_destroy(nvme_ns_chr_class);
47624768
class_destroy(nvme_subsys_class);
47634769
class_destroy(nvme_class);

0 commit comments

Comments
 (0)