Skip to contentSkip to conversation

nvmet: use appropriate types for authentication payload lengths

PATCH Superseded Sreeraj S Kurup 5 participants 7 messages Oct 31 – Nov 4

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet: use appropriate types for authentication payload lengths

The authentication payload length is obtained as a u32 value from the NVMe command, but nvmet_auth_challenge() and nvmet_auth_success1() accept it as a signed int.

Use u32 for the payload length parameters in both functions to keep their types consistent with the value returned by nvmet_auth_receive_data_len() and avoid an unnecessary conversion from unsigned to signed.

Also, use size_t for data_size in nvmet_auth_challenge(), since the calculation includes sizeof(), which returns size_t. This avoids implicitly narrowing the calculated payload size to int.

These changes make the payload length handling consistent with the underlying types and avoid potential signedness and narrowing issues.

---
 drivers/nvme/target/fabrics-cmd-auth.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/target/fabrics-cmd-auth.c +3 -3
index 70136f6c22e8..99caad6fb87f 100644
@@ -448,13 +448,13 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
 	nvmet_req_complete(req, status);
 }
 
-static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_challenge(struct nvmet_req *req, void *d, u32 al)
 {
 	struct nvmf_auth_dhchap_challenge_data *data = d;
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
 	int ret = 0;
 	int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id);
-	int data_size = sizeof(*data) + hash_len;
+	size_t data_size = sizeof(*data) + hash_len;
 
 	if (ctrl->dh_tfm)
 		data_size += ctrl->dh_keysize;
@@ -488,7 +488,7 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
 	return ret;
 }
 
-static int nvmet_auth_success1(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_success1(struct nvmet_req *req, void *d, u32 al)
 {
 	struct nvmf_auth_dhchap_success1_data *data = d;
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
Signature · 1 line
2.55.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] nvmet: format specifier mismatch in nvmet_auth_challenge() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] nvmet: format specifier mismatch in nvmet_auth_challenge()
--

commit 53d4c9b2a209bbb82f1d82e67292975434b27d23
Author: Sreeraj S Kurup <[email protected]>

nvmet: use appropriate types for authentication payload lengths

This commit changes the payload length parameter al in nvmet_auth_challenge() and nvmet_auth_success1() from int to u32, and changes data_size in nvmet_auth_challenge() from int to size_t.

Quoted 10 lines
drivers/nvme/target/fabrics-cmd-auth.c +1 -1
index 70136f6c22e8c..99caad6fb87fb 100644
@@ -448,13 +448,13 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
 	nvmet_req_complete(req, status);
 }
 
-static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_challenge(struct nvmet_req *req, void *d, u32 al)

drivers/nvme/target/fabrics-cmd-auth.c void nvmet_execute_auth_send(struct nvmet_req *req) · line 460

Quoted 10 lines
drivers/nvme/target/fabrics-cmd-auth.c +1 -1
 {
 	struct nvmf_auth_dhchap_challenge_data *data = d;
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
 	int ret = 0;
 	int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id);
-	int data_size = sizeof(*data) + hash_len;
+	size_t data_size = sizeof(*data) + hash_len;
 
 	if (ctrl->dh_tfm)
 		data_size += ctrl->dh_keysize;

[Severity: Low]
Now that al is u32 and data_size is size_t in nvmet_auth_challenge(), does the pr_debug() immediately below also need its format specifiers updated from %d to %u and %zu to avoid a -Wformat warning on 64-bit builds?

	if (al < data_size) {
		pr_debug("%s: buffer too small (al %d need %d)\n", __func__,
			 al, data_size);
		return -EINVAL;
	}
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw

PATCH v2 1/1 nvmet: use appropriate types for authentication payload lengths

In reply to Sreeraj S Kurup

The authentication payload length is obtained as a u32 value from the NVMe command, but nvmet_auth_challenge() and nvmet_auth_success1() accept it as a signed int.

Use u32 for the payload length parameters in both functions to keep their types consistent with the value returned by nvmet_auth_receive_data_len() and avoid an unnecessary conversion from unsigned to signed.

Also, use size_t for data_size in nvmet_auth_challenge(), since the calculation includes sizeof(), which returns size_t. This avoids implicitly narrowing the calculated payload size to int.

These changes make the payload length handling consistent with the underlying types and avoid potential signedness and narrowing issues.

---
v2:
- Update the debug format specifiers in "nvmet_auth_challenge()" to match the updated parameter types. Use "%u" for the "u32" payload length and "%zu" for the "size_t" data size to avoid format type mismatches and ensure correct debug output.

 drivers/nvme/target/fabrics-cmd-auth.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/nvme/target/fabrics-cmd-auth.c +4 -4
index 70136f6c22e8..c90917d26c98 100644
@@ -448,18 +448,18 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
 	nvmet_req_complete(req, status);
 }
 
-static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_challenge(struct nvmet_req *req, void *d, u32 al)
 {
 	struct nvmf_auth_dhchap_challenge_data *data = d;
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
 	int ret = 0;
 	int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id);
-	int data_size = sizeof(*data) + hash_len;
+	size_t data_size = sizeof(*data) + hash_len;
 
 	if (ctrl->dh_tfm)
 		data_size += ctrl->dh_keysize;
 	if (al < data_size) {
-		pr_debug("%s: buffer too small (al %d need %d)\n", __func__,
+		pr_debug("%s: buffer too small (al %u need %zu)\n", __func__,
 			 al, data_size);
 		return -EINVAL;
 	}
@@ -488,7 +488,7 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
 	return ret;
 }
 
-static int nvmet_auth_success1(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_success1(struct nvmet_req *req, void *d, u32 al)
 {
 	struct nvmf_auth_dhchap_success1_data *data = d;
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
Signature · 1 line
2.55.0
maintainer Applied
#4 lore raw
In reply to Sreeraj S Kurup
Quoted 9 lines · Sreeraj S Kurup

The authentication payload length is obtained as a u32 value from the NVMe command, but nvmet_auth_challenge() and nvmet_auth_success1() accept it as a signed int.

Use u32 for the payload length parameters in both functions to keep their types consistent with the value returned by nvmet_auth_receive_data_len() and avoid an unnecessary conversion from unsigned to signed.

Quoted 6 lines

Also, use size_t for data_size in nvmet_auth_challenge(), since the calculation includes sizeof(), which returns size_t. This avoids implicitly narrowing the calculated payload size to int.

These changes make the payload length handling consistent with the underlying types and avoid potential signedness and narrowing issues.

Thanks, applied to nvme-7.4.

maintainer Reviewed-by on v1 1/1
#6 lore raw
In reply to Sreeraj S Kurup
Quoted 42 lines · Sreeraj S Kurup

The authentication payload length is obtained as a u32 value from the NVMe command, but nvmet_auth_challenge() and nvmet_auth_success1() accept it as a signed int.

Use u32 for the payload length parameters in both functions to keep their types consistent with the value returned by nvmet_auth_receive_data_len() and avoid an unnecessary conversion from unsigned to signed.

Also, use size_t for data_size in nvmet_auth_challenge(), since the calculation includes sizeof(), which returns size_t. This avoids implicitly narrowing the calculated payload size to int.

These changes make the payload length handling consistent with the underlying types and avoid potential signedness and narrowing issues.

---
  drivers/nvme/target/fabrics-cmd-auth.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/target/fabrics-cmd-auth.c +2 -2
index 70136f6c22e8..99caad6fb87f 100644
@@ -448,13 +448,13 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
  	nvmet_req_complete(req, status);
  }
 
-static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_challenge(struct nvmet_req *req, void *d, u32 al)
  {
  	struct nvmf_auth_dhchap_challenge_data *data = d;
  	struct nvmet_ctrl *ctrl = req->sq->ctrl;
  	int ret = 0;
  	int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id);
-	int data_size = sizeof(*data) + hash_len;
+	size_t data_size = sizeof(*data) + hash_len;
 
  	if (ctrl->dh_tfm)
  		data_size += ctrl->dh_keysize;

drivers/nvme/target/fabrics-cmd-auth.c static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al) · line 494

Quoted 8 lines
drivers/nvme/target/fabrics-cmd-auth.c +1 -1
@@ -488,7 +488,7 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
  	return ret;
  }
 
-static int nvmet_auth_success1(struct nvmet_req *req, void *d, int al)
+static int nvmet_auth_success1(struct nvmet_req *req, void *d, u32 al)
  {
  	struct nvmf_auth_dhchap_success1_data *data = d;
  	struct nvmet_ctrl *ctrl = req->sq->ctrl;

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich