[Devel] [PATCH VZ9 v3] fs/fuse kio: skip looking into response to request from userspace

Liu Kui kui.liu at virtuozzo.com
Tue Jul 30 07:16:27 MSK 2024


Response to userspace requests should not be analyzed and translated
to msg->errors. Instead the entire response message should be just
passed to userspace and let userspace handle it.

Fix the issue that userspace krpcio getting aborted by PCS_RPC_ERROR_RESP
response.

Signed-off-by: Liu Kui <kui.liu at virtuozzo.com>
---
 fs/fuse/kio/pcs/pcs_krpc.c | 11 ++++++-----
 fs/fuse/kio/pcs/pcs_krpc.h |  3 ++-
 fs/fuse/kio/pcs/pcs_rpc.c  |  7 +++++++
 3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/kio/pcs/pcs_krpc.c b/fs/fuse/kio/pcs/pcs_krpc.c
index 567d8a0c884f..f61e8e2c813f 100644
--- a/fs/fuse/kio/pcs/pcs_krpc.c
+++ b/fs/fuse/kio/pcs/pcs_krpc.c
@@ -105,7 +105,8 @@ static void krpc_msg_get_response_iter(struct pcs_msg *msg, int offset,
 	struct pcs_msg *req = msg->private;
 	struct krpc_req *kreq = req->private2;
 
-	if (!(kreq->flags & KRPC_REQ_F_RESP_BUFF)) {
+	if (!(kreq->flags & KRPC_REQ_F_RESP_BUFF) ||
+		(kreq->flags & KRPC_REQ_F_ERR_RESP)) {
 		/* No data payload */
 		BUG_ON(msg->size > PAGE_SIZE);
 
@@ -148,16 +149,16 @@ struct pcs_msg *krpc_get_hdr(struct pcs_rpc *ep, struct pcs_rpc_hdr *h)
 	if (msg == NULL)
 		return NULL;
 
-	req_h = (struct pcs_rpc_hdr *)msg_inline_head(msg);
-	if (req_h->type != (h->type & ~PCS_RPC_DIRECTION))
-		return NULL;
-
 	kreq = msg->private2;
 
 	resp = pcs_rpc_alloc_input_msg(ep, sizeof(struct pcs_rpc_hdr));
 	if (!resp)
 		return NULL;
 
+	req_h = (struct pcs_rpc_hdr *)msg_inline_head(msg);
+	if (req_h->type != (h->type & ~PCS_RPC_DIRECTION))
+		kreq->flags |= KRPC_REQ_F_ERR_RESP;
+
 	memcpy(resp->_inline_buffer, h, sizeof(struct pcs_rpc_hdr));
 	memcpy(kreq->hdr_buf, h, sizeof(struct pcs_rpc_hdr));
 	resp->size = h->len;
diff --git a/fs/fuse/kio/pcs/pcs_krpc.h b/fs/fuse/kio/pcs/pcs_krpc.h
index 6c0ef20ebc99..8100dfb2629d 100644
--- a/fs/fuse/kio/pcs/pcs_krpc.h
+++ b/fs/fuse/kio/pcs/pcs_krpc.h
@@ -93,7 +93,8 @@ struct krpc_req {
 
 #define KRPC_REQ_F_ALIGNMENT	PCS_KRPC_MSG_F_ALIGNMENT
 #define KRPC_REQ_F_RESP_BUFF	PCS_KRPC_MSG_F_RESP_BUFF	/* data buff is for read response */
-#define KRPC_REQ_F_ABORTED		0x10000
+#define KRPC_REQ_F_ABORTED	0x10000
+#define KRPC_REQ_F_ERR_RESP	0x20000
 	int flags;
 
 	struct pcs_msg		msg;
diff --git a/fs/fuse/kio/pcs/pcs_rpc.c b/fs/fuse/kio/pcs/pcs_rpc.c
index deebc1dddf1b..f990f0f30609 100644
--- a/fs/fuse/kio/pcs/pcs_rpc.c
+++ b/fs/fuse/kio/pcs/pcs_rpc.c
@@ -484,6 +484,12 @@ static void handle_response(struct pcs_rpc * ep, struct pcs_msg * msg)
 	pcs_msg_del_calendar(req);
 	list_del(&req->list);
 
+	/* don't try to interpret response to request from userspace */
+	if (!(h->xid.origin.val & PCS_NODE_ALT_MASK)) {
+		req->response = msg;
+		goto skip;
+	}
+
 	if (h->type == PCS_RPC_ERROR_RESP) {
 		struct pcs_rpc_error_resp * eh = (struct pcs_rpc_error_resp *)msg->_inline_buffer;
 
@@ -502,6 +508,7 @@ static void handle_response(struct pcs_rpc * ep, struct pcs_msg * msg)
 			req->response = msg;
 	}
 
+skip:
 	if (ep->ops->hook_response)
 		ep->ops->hook_response(ep, req);
 
-- 
2.39.3 (Apple Git-146)



More information about the Devel mailing list