nvmet-tcp: Fix a possible UAF in queue intialization setup
Subsystems (3)
Sagi Grimberg
maintainerPATCH 1/1 nvmet-tcp: Fix a possible UAF in queue intialization setup
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."
Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Also, be extra careful not to continue processing the socket, so set queue rcv_state to NVMET_TCP_RECV_ERR upon a socket error.
--- drivers/nvme/target/tcp.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/nvme/target/tcp.c +2 -5
@@ -372,6 +372,7 @@ static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue)static void nvmet_tcp_socket_error (struct nvmet_tcp_queue *queue,int status) { + queue->rcv_state =NVMET_TCP_RECV_ERR ;if (status == -EPIPE || status == -ECONNRESET )kernel_sock_shutdown (queue->sock,SHUT_RDWR );else
@@ -910,15 +911,11 @@ static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) iov.iov_len =sizeof (*icresp); ret =kernel_sendmsg (queue->sock, &msg, &iov,1 , iov.iov_len);if (ret <0 ) - goto free_crypto; +return ret;/* queue removal will cleanup */ queue->state =NVMET_TCP_Q_LIVE ;nvmet_prepare_receive_pdu (queue);return 0 ; -free_crypto: -if (queue->hdr_digest || queue->data_digest) -nvmet_tcp_free_crypto (queue); -return ret; } static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue,
Signature · 1 line
2.41.0
Quoted 10 lines · Sagi Grimberg
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Quoted 7 lines
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>---
Prior to this patch nvmet_tcp_free_crypto has only two callers [1], does it makes sense to in-line nvmet_tcp_free_crypto() in only remaining caller nvmet_tcp_release_queue_work() ?
Irrespective of that looks good to me.
-ck
[1]
1 tcp.c nvmet_tcp_handle_icreq 920 nvmet_tcp_free_crypto(queue);
2 tcp.c nvmet_tcp_release_queue_work 1499 nvmet_tcp_free_crypto(queue);
Sagi Grimberg
maintainerQuoted 14 lines
Quoted 14 lines
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.
Quoted 8 lines
Quoted 4 lines
Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>---
Prior to this patch
nvmet_tcp_free_cryptohas only two callers [1], does it makes sense to in-linenvmet_tcp_free_crypto()in only remaining callernvmet_tcp_release_queue_work()?
Its also the opposite of nvmet_tcp_alloc_crypto. Possible to fold both but I think its also fine to keep.
Quoted 4 lines
Irrespective of that looks good to me.
Reviewed-by Chaitanya Kulkarni <[email protected]>
Thanks
Hello,
Quoted 10 lines · On Mon, 2 Oct 2023 13:54:28 +0300 Sagi Grimberg <[email protected]> wrote:
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Quoted 6 lines
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>
Would it be better to add Fixes: and Cc: stable lines?
Thanks,
SJ
Quoted 37 lines
--- drivers/nvme/target/tcp.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/nvme/target/tcp.c +2
-5@@ -372,6 +372,7 @@ static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue)static void nvmet_tcp_socket_error (struct nvmet_tcp_queue *queue,int status) { + queue->rcv_state =NVMET_TCP_RECV_ERR ;if (status == -EPIPE || status == -ECONNRESET )kernel_sock_shutdown (queue->sock,SHUT_RDWR );else @@ -910,15 +911,11 @@ static int nvmet_tcp_handle_icreq(struct nvmet_tcp_queue *queue) iov.iov_len =sizeof (*icresp); ret =kernel_sendmsg (queue->sock, &msg, &iov,1 , iov.iov_len);if (ret <0 ) - goto free_crypto; +return ret;/* queue removal will cleanup */ queue->state =NVMET_TCP_Q_LIVE ;nvmet_prepare_receive_pdu (queue);return 0 ; -free_crypto: -if (queue->hdr_digest || queue->data_digest) -nvmet_tcp_free_crypto (queue); -return ret; } static void nvmet_tcp_handle_req_failure(struct nvmet_tcp_queue *queue,Signature · 1 line
2.41.0
Sagi Grimberg
maintainerQuoted 15 lines
Hello,
Quoted 10 lines · On Mon, 2 Oct 2023 13:54:28 +0300 Sagi Grimberg <[email protected]> wrote:
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Quoted 8 lines
Quoted 6 lines
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>Would it be better to add Fixes: and Cc: stable lines?
This issue existed since the introduction of the driver, I am not sure it applies cleanly that far back...
I figured that the description and Reported-by tag will trigger stable kernel pick up...
Greg KH
maintainerQuoted 22 lines · Sagi Grimberg
Quoted 22 lines
Hello,
Quoted 16 lines · On Mon, 2 Oct 2023 13:54:28 +0300 Sagi Grimberg <[email protected]> wrote:
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>
Quoted 7 lines
Quoted 1 line
Would it be better to add Fixes: and Cc: stable lines?
This issue existed since the introduction of the driver, I am not sure it applies cleanly that far back...
I figured that the description and Reported-by tag will trigger stable kernel pick up...
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
Sagi Grimberg
maintainerQuoted 30 lines
Quoted 22 lines
Quoted 22 lines
Hello,
Quoted 16 lines · On Mon, 2 Oct 2023 13:54:28 +0300 Sagi Grimberg <[email protected]> wrote:
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>Quoted 7 lines
Quoted 1 line
Would it be better to add Fixes: and Cc: stable lines?
This issue existed since the introduction of the driver, I am not sure it applies cleanly that far back...
I figured that the description and Reported-by tag will trigger stable kernel pick up...
Quoted 8 lines
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.</formletter>
I could have sworn to have seen patches that did not have stable CCd nor a Fixes tag and was picked up for stable kernels :)
But I guess those were either hallucinations or someone sending patches to stable...
I can resend with CC to stable.
Thanks.
Quoted 18 lines · On Wed, 4 Oct 2023 16:25:13 +0300 Sagi Grimberg <[email protected]> wrote:
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Hello,
Quoted 13 lines · On Mon, 2 Oct 2023 13:54:28 +0300 Sagi Grimberg <[email protected]> wrote:
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>Would it be better to add Fixes: and Cc: stable lines?
This issue existed since the introduction of the driver, I am not sure it applies cleanly that far back...
Based on the rule[1], I think people who need this fix on the old kernel would do that. I'd just say adding Fixes: would help it, so better than nothing.
[1] https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
I figured that the description and Reported-by tag will trigger stable kernel pick up...
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
Quoted 4 lines
Quoted 1 line
</formletter>
I could have sworn to have seen patches that did not have stable CCd nor a Fixes tag and was picked up for stable kernels :)
I could also swear. Stable kernel maintainers are great at finding fixes on their own. But I think adding those could help them avoiding any mistake, and therefore better than nothing, again.
Quoted 4 lines
But I guess those were either hallucinations or someone sending patches to stable...
I can resend with CC to stable.
Thank you :)
Thanks,
SJ
Quoted 4 lines
Thanks.
Sasha Levin
maintainerQuoted 37 lines · Sagi Grimberg
Quoted 37 lines
Quoted 22 lines
Quoted 22 lines
Hello,
Quoted 16 lines · On Mon, 2 Oct 2023 13:54:28 +0300 Sagi Grimberg <[email protected]> wrote:
From Alon:
"Due to a logical bug in the NVMe-oF/TCP subsystem in the Linux kernel, a malicious user can cause a UAF and a double free, which may lead to RCE (may also lead to an LPE in case the attacker already has local privileges)."Hence, when a queue initialization fails after the ahash requests are allocated, it is guaranteed that the queue removal async work will be called, hence leave the deallocation to the queue removal.
Also, be extra careful not to continue processing the socket, so set queue
rcv_statetoNVMET_TCP_RECV_ERRupon a socket error.Reported-by Alon Zahavi <[email protected]>Tested-by Alon Zahavi <[email protected]>Signed-off-by Sagi Grimberg <[email protected]>Quoted 7 lines
Quoted 1 line
Would it be better to add Fixes: and Cc: stable lines?
This issue existed since the introduction of the driver, I am not sure it applies cleanly that far back...
I figured that the description and Reported-by tag will trigger stable kernel pick up...
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
Quoted 6 lines
Quoted 1 line
</formletter>
I could have sworn to have seen patches that did not have stable CCd nor a Fixes tag and was picked up for stable kernels :)
But I guess those were either hallucinations or someone sending patches to stable...
That happens, but there are no guarantees around it.
If you really want for a patch to land in stable, and want to know if for some reason it didn't, the only way to do it is with an explicit stable tag. Otherwise it's just "best effort".
Signature · 2 lines
Thanks, Sasha
Looks good:
Keith Busch
maintainerApplied for nvme-6.6.