Skip to content

Commit 0697620

Browse files
committed
Merge: nvme: update the drivers to the latest version
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/3889 # Merge Request Required Information Update the nvme drivers to the latest upstream version This MR changes the name of the "nvme-common" kernel module to "nvme-auth" and also adds a new kernel module called "nvme-keyring". This should be safe because those modules are about a feature called "NVMe In-Band Authentication" that at the moment is marked as Tech Preview, customers should not use it in production systems. JIRA: https://issues.redhat.com/browse/RHEL-25547 JIRA: https://issues.redhat.com/browse/RHEL-28783 Signed-off-by: Maurizio Lombardi <mlombard@redhat.com> ## Summary of Changes ## Approved Development Ticket All submissions to CentOS Stream must reference an approved ticket in [Red Hat Jira](https://issues.redhat.com/). Please follow the CentOS Stream [contribution documentation](https://docs.centos.org/en-US/stream-contrib/quickstart/) for how to file this ticket and have it approved. Approved-by: Chris Leech <cleech@redhat.com> Approved-by: John Meneghini <jmeneghi@redhat.com> Merged-by: Lucas Zampieri <lzampier@redhat.com>
2 parents 1189201 + 8755e80 commit 0697620

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2602
-979
lines changed

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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
config NVME_COMMON
3+
config NVME_KEYRING
44
tristate
5+
select KEYS
6+
7+
config NVME_AUTH
8+
tristate
9+
select CRYPTO
10+
select CRYPTO_HMAC
11+
select CRYPTO_SHA256
12+
select CRYPTO_SHA512
13+
select CRYPTO_DH
14+
select CRYPTO_DH_RFC7919_GROUPS

drivers/nvme/common/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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-y += auth.o
8+
nvme-auth-y += auth.o
9+
nvme-keyring-y += keyring.o

drivers/nvme/common/auth.c

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ size_t nvme_auth_hmac_hash_len(u8 hmac_id)
150150
}
151151
EXPORT_SYMBOL_GPL(nvme_auth_hmac_hash_len);
152152

153+
u32 nvme_auth_key_struct_size(u32 key_len)
154+
{
155+
struct nvme_dhchap_key key;
156+
157+
return struct_size(&key, key, key_len);
158+
}
159+
EXPORT_SYMBOL_GPL(nvme_auth_key_struct_size);
160+
153161
struct nvme_dhchap_key *nvme_auth_extract_key(unsigned char *secret,
154162
u8 key_hash)
155163
{
@@ -163,14 +171,9 @@ struct nvme_dhchap_key *nvme_auth_extract_key(unsigned char *secret,
163171
p = strrchr(secret, ':');
164172
if (p)
165173
allocated_len = p - secret;
166-
key = kzalloc(sizeof(*key), GFP_KERNEL);
174+
key = nvme_auth_alloc_key(allocated_len, 0);
167175
if (!key)
168176
return ERR_PTR(-ENOMEM);
169-
key->key = kzalloc(allocated_len, GFP_KERNEL);
170-
if (!key->key) {
171-
ret = -ENOMEM;
172-
goto out_free_key;
173-
}
174177

175178
key_len = base64_decode(secret, allocated_len, key->key);
176179
if (key_len < 0) {
@@ -187,14 +190,6 @@ struct nvme_dhchap_key *nvme_auth_extract_key(unsigned char *secret,
187190
goto out_free_secret;
188191
}
189192

190-
if (key_hash > 0 &&
191-
(key_len - 4) != nvme_auth_hmac_hash_len(key_hash)) {
192-
pr_err("Mismatched key len %d for %s\n", key_len,
193-
nvme_auth_hmac_name(key_hash));
194-
ret = -EINVAL;
195-
goto out_free_secret;
196-
}
197-
198193
/* The last four bytes is the CRC in little-endian format */
199194
key_len -= 4;
200195
/*
@@ -213,37 +208,51 @@ struct nvme_dhchap_key *nvme_auth_extract_key(unsigned char *secret,
213208
key->hash = key_hash;
214209
return key;
215210
out_free_secret:
216-
kfree_sensitive(key->key);
217-
out_free_key:
218-
kfree(key);
211+
nvme_auth_free_key(key);
219212
return ERR_PTR(ret);
220213
}
221214
EXPORT_SYMBOL_GPL(nvme_auth_extract_key);
222215

216+
struct nvme_dhchap_key *nvme_auth_alloc_key(u32 len, u8 hash)
217+
{
218+
u32 num_bytes = nvme_auth_key_struct_size(len);
219+
struct nvme_dhchap_key *key = kzalloc(num_bytes, GFP_KERNEL);
220+
221+
if (key) {
222+
key->len = len;
223+
key->hash = hash;
224+
}
225+
return key;
226+
}
227+
EXPORT_SYMBOL_GPL(nvme_auth_alloc_key);
228+
223229
void nvme_auth_free_key(struct nvme_dhchap_key *key)
224230
{
225231
if (!key)
226232
return;
227-
kfree_sensitive(key->key);
228-
kfree(key);
233+
kfree_sensitive(key);
229234
}
230235
EXPORT_SYMBOL_GPL(nvme_auth_free_key);
231236

232-
u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn)
237+
struct nvme_dhchap_key *nvme_auth_transform_key(
238+
struct nvme_dhchap_key *key, char *nqn)
233239
{
234240
const char *hmac_name;
235241
struct crypto_shash *key_tfm;
236242
struct shash_desc *shash;
237-
u8 *transformed_key;
238-
int ret;
243+
struct nvme_dhchap_key *transformed_key;
244+
int ret, key_len;
239245

240-
if (!key || !key->key) {
246+
if (!key) {
241247
pr_warn("No key specified\n");
242248
return ERR_PTR(-ENOKEY);
243249
}
244250
if (key->hash == 0) {
245-
transformed_key = kmemdup(key->key, key->len, GFP_KERNEL);
246-
return transformed_key ? transformed_key : ERR_PTR(-ENOMEM);
251+
key_len = nvme_auth_key_struct_size(key->len);
252+
transformed_key = kmemdup(key, key_len, GFP_KERNEL);
253+
if (!transformed_key)
254+
return ERR_PTR(-ENOMEM);
255+
return transformed_key;
247256
}
248257
hmac_name = nvme_auth_hmac_name(key->hash);
249258
if (!hmac_name) {
@@ -253,7 +262,7 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn)
253262

254263
key_tfm = crypto_alloc_shash(hmac_name, 0, 0);
255264
if (IS_ERR(key_tfm))
256-
return (u8 *)key_tfm;
265+
return ERR_CAST(key_tfm);
257266

258267
shash = kmalloc(sizeof(struct shash_desc) +
259268
crypto_shash_descsize(key_tfm),
@@ -263,7 +272,8 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn)
263272
goto out_free_key;
264273
}
265274

266-
transformed_key = kzalloc(crypto_shash_digestsize(key_tfm), GFP_KERNEL);
275+
key_len = crypto_shash_digestsize(key_tfm);
276+
transformed_key = nvme_auth_alloc_key(key_len, key->hash);
267277
if (!transformed_key) {
268278
ret = -ENOMEM;
269279
goto out_free_shash;
@@ -282,7 +292,7 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn)
282292
ret = crypto_shash_update(shash, "NVMe-over-Fabrics", 17);
283293
if (ret < 0)
284294
goto out_free_transformed_key;
285-
ret = crypto_shash_final(shash, transformed_key);
295+
ret = crypto_shash_final(shash, transformed_key->key);
286296
if (ret < 0)
287297
goto out_free_transformed_key;
288298

@@ -292,7 +302,7 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn)
292302
return transformed_key;
293303

294304
out_free_transformed_key:
295-
kfree_sensitive(transformed_key);
305+
nvme_auth_free_key(transformed_key);
296306
out_free_shash:
297307
kfree(shash);
298308
out_free_key:
@@ -331,7 +341,6 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
331341
u8 *challenge, u8 *aug, size_t hlen)
332342
{
333343
struct crypto_shash *tfm;
334-
struct shash_desc *desc;
335344
u8 *hashed_key;
336345
const char *hmac_name;
337346
int ret;
@@ -359,29 +368,11 @@ int nvme_auth_augmented_challenge(u8 hmac_id, u8 *skey, size_t skey_len,
359368
goto out_free_key;
360369
}
361370

362-
desc = kmalloc(sizeof(struct shash_desc) + crypto_shash_descsize(tfm),
363-
GFP_KERNEL);
364-
if (!desc) {
365-
ret = -ENOMEM;
366-
goto out_free_hash;
367-
}
368-
desc->tfm = tfm;
369-
370371
ret = crypto_shash_setkey(tfm, hashed_key, hlen);
371372
if (ret)
372-
goto out_free_desc;
373-
374-
ret = crypto_shash_init(desc);
375-
if (ret)
376-
goto out_free_desc;
377-
378-
ret = crypto_shash_update(desc, challenge, hlen);
379-
if (ret)
380-
goto out_free_desc;
373+
goto out_free_hash;
381374

382-
ret = crypto_shash_final(desc, aug);
383-
out_free_desc:
384-
kfree_sensitive(desc);
375+
ret = crypto_shash_tfm_digest(tfm, challenge, hlen, aug);
385376
out_free_hash:
386377
crypto_free_shash(tfm);
387378
out_free_key:
@@ -480,4 +471,5 @@ int nvme_auth_generate_key(u8 *secret, struct nvme_dhchap_key **ret_key)
480471
}
481472
EXPORT_SYMBOL_GPL(nvme_auth_generate_key);
482473

474+
MODULE_DESCRIPTION("NVMe Authentication framework");
483475
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)