nvmet-tcp: fix data digest pointer calculation
Subsystems (2)
PATCH 1/1 nvmet-tcp: fix data digest pointer calculation
exp_ddgst is of type __le32, &cmd->exp_ddgst + cmd->offset increases &cmd->exp_ddgst by 4 * cmd->offset, fix this by type casting &cmd->exp_ddgst to u8 *.
--- drivers/nvme/target/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/target/tcp.c +1 -1
@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset, .iov_len =NVME_TCP_DIGEST_LENGTH - cmd->offset };int ret;
Signature · 1 line
2.0.2
Christoph Hellwig
maintainerQuoted 15 lines · Varun Prakash
exp_ddgstis of type__le32,&cmd->exp_ddgst+cmd->offsetincreases&cmd->exp_ddgstby 4 *cmd->offset, fix this by type casting&cmd->exp_ddgstto u8 *.Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")Signed-off-by Varun Prakash <[email protected]>--- drivers/nvme/target/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/nvme/target/tcp.c +0
-0
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 5 lines
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,
Wouldn't be the better fix to divide cmd->offset by 4 instead of the casts? I can fix this up inline if that is ok.
Sagi Grimberg
maintainerQuoted 11 lines
Quoted 11 lines
exp_ddgstis of type__le32,&cmd->exp_ddgst+cmd->offsetincreases&cmd->exp_ddgstby 4 *cmd->offset, fix this by type casting&cmd->exp_ddgstto u8 *.Fixes 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver")Signed-off-by Varun Prakash <[email protected]>--- drivers/nvme/target/tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 10 lines
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,Wouldn't be the better fix to divide
cmd->offsetby 4 instead of the casts? I can fix this up inline if that is ok.
Don't really mind, what makes it a better fix?
Christoph Hellwig
maintainerQuoted 14 lines · Sagi Grimberg
Quoted 5 lines
Quoted 5 lines
drivers/nvme/target/tcp.c +0
-0@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)Quoted 8 lines
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 5 lines
drivers/nvme/target/tcp.c +1
-1struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,Wouldn't be the better fix to divide
cmd->offsetby 4 instead of the casts? I can fix this up inline if that is ok.
Quoted 1 line
Don't really mind, what makes it a better fix?
I generally prefer to avoid casts as they paper over bugs.
Sagi Grimberg
maintainerQuoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 11 lines
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,Wouldn't be the better fix to divide
cmd->offsetby 4 instead of the casts? I can fix this up inline if that is ok.
Quoted 3 lines
Quoted 1 line
Don't really mind, what makes it a better fix?
I generally prefer to avoid casts as they paper over bugs.
I'm fine either way.
Quoted 15 lines · Sagi Grimberg
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 11 lines
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,Wouldn't be the better fix to divide
cmd->offsetby 4 instead of the casts? I can fix this up inline if that is ok.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Don't really mind, what makes it a better fix?
I generally prefer to avoid casts as they paper over bugs.
I'm fine either way.
cmd->offset can have value 0,1,2,3. cmd->offset / 4 will always be 0. If 2 bytes of digest are transmitted in the first call to kernel_sendmsg() then in the second call remaining 2 bytes has to be transmitted so data digest buffer pointer should increase by 2 bytes.
There is one more bug in nvmet_try_send_ddgst() it currently does not check whether digest is send successfully. For successful digest send cmd->offset + ret should be equal to NVME_TCP_DIGEST_LENGTH.
Sagi Grimberg
maintainerQuoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 16 lines
Quoted 14 lines
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 11 lines
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,Wouldn't be the better fix to divide
cmd->offsetby 4 instead of the casts? I can fix this up inline if that is ok.Don't really mind, what makes it a better fix?
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
I generally prefer to avoid casts as they paper over bugs.
I'm fine either way.
cmd->offsetcan have value 0,1,2,3.cmd->offset/ 4 will always be 0. If 2 bytes of digest are transmitted in the first call tokernel_sendmsg()then in the second call remaining 2 bytes has to be transmitted so data digest buffer pointer should increase by 2 bytes.
Right, so let's just change the cast to (void *). Varun, can you respin the patches?
Quoted 21 lines · Sagi Grimberg
Quoted 21 lines
Quoted 20 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
drivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 11 lines
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,Wouldn't be the better fix to divide
cmd->offsetby 4 instead of the casts? I can fix this up inline if that is ok.Quoted 3 lines
Quoted 1 line
Don't really mind, what makes it a better fix?
I generally prefer to avoid casts as they paper over bugs.
I'm fine either way.
Quoted 7 lines
Quoted 4 lines
cmd->offsetcan have value 0,1,2,3.cmd->offset/ 4 will always be 0. If 2 bytes of digest are transmitted in the first call tokernel_sendmsg()then in the second call remaining 2 bytes has to be transmitted so data digest buffer pointer should increase by 2 bytes.Right, so let's just change the cast to (void *). Varun, can you respin the patches?
Both the patches are already applied to nvme-5.15, should I send v2 or create a new patch for u8 * -> void * change?
Christoph Hellwig
maintainerQuoted 2 lines · Varun Prakash
Both the patches are already applied to nvme-5.15, should I send v2 or create a new patch for u8 * -> void * change?
I'm about to send the pull request with them to Jens. It is too late in the cycle now to respin again.
Sagi Grimberg
maintainerQuoted 6 lines
Quoted 3 lines
Both the patches are already applied to nvme-5.15, should I send v2 or create a new patch for u8 * -> void * change?
I'm about to send the pull request with them to Jens. It is too late in the cycle now to respin again.
We can take care of that later...
Keith Busch
maintainerdrivers/nvme/target/tcp.c static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch) · line 705
Quoted 6 lines · Varun Prakash
drivers/nvme/target/tcp.c +1
-1@@ -702,7 +702,7 @@ static int nvmet_try_send_ddgst(struct nvmet_tcp_cmd *cmd, bool last_in_batch)struct nvmet_tcp_queue *queue = cmd->queue;struct msghdr msg = { .msg_flags =MSG_DONTWAIT };struct kvec iov = { - .iov_base = &cmd->exp_ddgst + cmd->offset, + .iov_base = (u8 *)&cmd->exp_ddgst + cmd->offset,
This certainly works too (and it's already applied anyway), though everywhere else in this driver casts these to 'void *'.