Skip to content

Commit b0ef1b1

Browse files
hreineckeChristoph Hellwig
authored andcommitted
nvme-auth: don't use NVMe status codes
NVMe status codes are part of the wire protocol, and shouldn't be fabricated in the stack. So with this patch the authentication code is switched over to use error codes; as a side effect authentication failures due to internal error won't be retried anymore. But that shouldn't have happened anyway. Signed-off-by: Hannes Reinecke <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 0686fb3 commit b0ef1b1

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

drivers/nvme/host/auth.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
158158

159159
if (size > CHAP_BUF_SIZE) {
160160
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
161-
return NVME_SC_INVALID_FIELD;
161+
return -EINVAL;
162162
}
163163

164164
hmac_name = nvme_auth_hmac_name(data->hashid);
@@ -167,7 +167,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
167167
"qid %d: invalid HASH ID %d\n",
168168
chap->qid, data->hashid);
169169
chap->status = NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
170-
return NVME_SC_INVALID_FIELD;
170+
return -EPROTO;
171171
}
172172

173173
if (chap->hash_id == data->hashid && chap->shash_tfm &&
@@ -193,7 +193,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
193193
chap->qid, hmac_name, PTR_ERR(chap->shash_tfm));
194194
chap->shash_tfm = NULL;
195195
chap->status = NVME_AUTH_DHCHAP_FAILURE_FAILED;
196-
return NVME_SC_AUTH_REQUIRED;
196+
return -ENOMEM;
197197
}
198198

199199
if (crypto_shash_digestsize(chap->shash_tfm) != data->hl) {
@@ -203,7 +203,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
203203
crypto_free_shash(chap->shash_tfm);
204204
chap->shash_tfm = NULL;
205205
chap->status = NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
206-
return NVME_SC_AUTH_REQUIRED;
206+
return -EPROTO;
207207
}
208208

209209
chap->hash_id = data->hashid;
@@ -219,7 +219,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
219219
chap->qid, data->dhgid);
220220
chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
221221
/* Leave previous dh_tfm intact */
222-
return NVME_SC_AUTH_REQUIRED;
222+
return -EPROTO;
223223
}
224224

225225
if (chap->dhgroup_id == data->dhgid &&
@@ -242,7 +242,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
242242
"qid %d: empty DH value\n",
243243
chap->qid);
244244
chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
245-
return NVME_SC_INVALID_FIELD;
245+
return -EPROTO;
246246
}
247247

248248
chap->dh_tfm = crypto_alloc_kpp(kpp_name, 0, 0);
@@ -254,7 +254,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
254254
chap->qid, ret, gid_name);
255255
chap->status = NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
256256
chap->dh_tfm = NULL;
257-
return NVME_SC_AUTH_REQUIRED;
257+
return -ret;
258258
}
259259
dev_dbg(ctrl->device, "qid %d: selected DH group %s\n",
260260
chap->qid, gid_name);
@@ -263,7 +263,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
263263
"qid %d: invalid DH value for NULL DH\n",
264264
chap->qid);
265265
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
266-
return NVME_SC_INVALID_FIELD;
266+
return -EPROTO;
267267
}
268268
chap->dhgroup_id = data->dhgid;
269269

@@ -274,7 +274,7 @@ static int nvme_auth_process_dhchap_challenge(struct nvme_ctrl *ctrl,
274274
chap->ctrl_key = kmalloc(dhvlen, GFP_KERNEL);
275275
if (!chap->ctrl_key) {
276276
chap->status = NVME_AUTH_DHCHAP_FAILURE_FAILED;
277-
return NVME_SC_AUTH_REQUIRED;
277+
return -ENOMEM;
278278
}
279279
chap->ctrl_key_len = dhvlen;
280280
memcpy(chap->ctrl_key, data->cval + chap->hash_len,
@@ -344,15 +344,15 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,
344344

345345
if (size > CHAP_BUF_SIZE) {
346346
chap->status = NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
347-
return NVME_SC_INVALID_FIELD;
347+
return -EINVAL;
348348
}
349349

350350
if (data->hl != chap->hash_len) {
351351
dev_warn(ctrl->device,
352352
"qid %d: invalid hash length %u\n",
353353
chap->qid, data->hl);
354354
chap->status = NVME_AUTH_DHCHAP_FAILURE_HASH_UNUSABLE;
355-
return NVME_SC_INVALID_FIELD;
355+
return -EPROTO;
356356
}
357357

358358
/* Just print out information for the admin queue */
@@ -376,7 +376,7 @@ static int nvme_auth_process_dhchap_success1(struct nvme_ctrl *ctrl,
376376
"qid %d: controller authentication failed\n",
377377
chap->qid);
378378
chap->status = NVME_AUTH_DHCHAP_FAILURE_FAILED;
379-
return NVME_SC_AUTH_REQUIRED;
379+
return -ECONNREFUSED;
380380
}
381381

382382
/* Just print out information for the admin queue */
@@ -730,7 +730,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
730730
NVME_AUTH_DHCHAP_MESSAGE_CHALLENGE);
731731
if (ret) {
732732
chap->status = ret;
733-
chap->error = NVME_SC_AUTH_REQUIRED;
733+
chap->error = -ECONNREFUSED;
734734
return;
735735
}
736736

@@ -798,7 +798,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
798798
NVME_AUTH_DHCHAP_MESSAGE_SUCCESS1);
799799
if (ret) {
800800
chap->status = ret;
801-
chap->error = NVME_SC_AUTH_REQUIRED;
801+
chap->error = -ECONNREFUSED;
802802
return;
803803
}
804804

@@ -819,7 +819,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
819819
ret = nvme_auth_process_dhchap_success1(ctrl, chap);
820820
if (ret) {
821821
/* Controller authentication failed */
822-
chap->error = NVME_SC_AUTH_REQUIRED;
822+
chap->error = -ECONNREFUSED;
823823
goto fail2;
824824
}
825825

0 commit comments

Comments
 (0)