Skip to contentSkip to conversation

xen: xenbus: Fix a possible data race in xs_request_enter

PATCH In review Jia-Ju Bai 2 participants 5 messages May 8, 2018 Xen hypervisor interface

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

PATCH 1/1 xen: xenbus: Fix a possible data race in xs_request_enter

The read operation to "req->type" is protected by the lock on line 128, but the write operation to this data on line 118 is not protected by the lock. Thus, there may exist a data race for "req->type".

To fix this data race, the write operation to "req->type" should be also protected by the lock.

---
 drivers/xen/xenbus/xenbus_xs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/xenbus/xenbus_xs.c +2 -2
index 49a3874ae6bb..274cdfee08b1 100644
@@ -115,10 +115,10 @@ static uint32_t xs_request_enter(struct xb_req_data *req)
 {
 	uint32_t rq_id;
 
-	req->type = req->msg.type;
-
 	spin_lock(&xs_state_lock);
 
+	req->type = req->msg.type;
+
 	while (!xs_state_users && xs_suspend_active) {
 		spin_unlock(&xs_state_lock);
 		wait_event(xs_state_enter_wq, xs_suspend_active == 0);
Signature · 1 line
2.17.0
maintainer
#1 lore raw
Quoted 7 lines · Jia-Ju Bai

The read operation to "req->type" is protected by the lock on line 128, but the write operation to this data on line 118 is not protected by the lock. Thus, there may exist a data race for "req->type".

To fix this data race, the write operation to "req->type" should be also protected by the lock.

No, xs_request_enter() is never called for a request already visible to another thread or processor. So no race exists.

Juergen

Quoted 14 lines
---
 drivers/xen/xenbus/xenbus_xs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/xenbus/xenbus_xs.c +0 -0
index 49a3874ae6bb..274cdfee08b1 100644
@@ -115,10 +115,10 @@ static uint32_t xs_request_enter(struct xb_req_data *req)
 {
 	uint32_t rq_id;

drivers/xen/xenbus/xenbus_xs.c static uint32_t xs_request_enter(struct xb_req_data *req) · line 124

Quoted 10 lines
drivers/xen/xenbus/xenbus_xs.c +2 -2
 
-	req->type = req->msg.type;
-
 	spin_lock(&xs_state_lock);
 
+	req->type = req->msg.type;
+
 	while (!xs_state_users && xs_suspend_active) {
 		spin_unlock(&xs_state_lock);
 		wait_event(xs_state_enter_wq, xs_suspend_active == 0);

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

maintainer
#2 lore raw
In reply to Jia-Ju Bai
Quoted 7 lines · Jia-Ju Bai

The read operation to "req->type" is protected by the lock on line 128, but the write operation to this data on line 118 is not protected by the lock. Thus, there may exist a data race for "req->type".

To fix this data race, the write operation to "req->type" should be also protected by the lock.

No, xs_request_enter() is never called for a request already visible to another thread or processor. So no race exists.

Juergen

Quoted 24 lines
---
 drivers/xen/xenbus/xenbus_xs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/xen/xenbus/xenbus_xs.c +2 -2
index 49a3874ae6bb..274cdfee08b1 100644
@@ -115,10 +115,10 @@ static uint32_t xs_request_enter(struct xb_req_data *req)
 {
 	uint32_t rq_id;
 
-	req->type = req->msg.type;
-
 	spin_lock(&xs_state_lock);
 
+	req->type = req->msg.type;
+
 	while (!xs_state_users && xs_suspend_active) {
 		spin_unlock(&xs_state_lock);
 		wait_event(xs_state_enter_wq, xs_suspend_active == 0);
author
#3 lore raw
Quoted 10 lines · Juergen Gross
Quoted 7 lines · Jia-Ju Bai

The read operation to "req->type" is protected by the lock on line 128, but the write operation to this data on line 118 is not protected by the lock. Thus, there may exist a data race for "req->type".

To fix this data race, the write operation to "req->type" should be also protected by the lock.

No, xs_request_enter() is never called for a request already visible to another thread or processor. So no race exists.

Okay, thanks for your reply.

Best wishes,
Jia-Ju Bai

author
#4 lore raw
In reply to Juergen Gross
Quoted 10 lines · Juergen Gross
Quoted 7 lines · Jia-Ju Bai

The read operation to "req->type" is protected by the lock on line 128, but the write operation to this data on line 118 is not protected by the lock. Thus, there may exist a data race for "req->type".

To fix this data race, the write operation to "req->type" should be also protected by the lock.

No, xs_request_enter() is never called for a request already visible to another thread or processor. So no race exists.

Okay, thanks for your reply.

Best wishes,
Jia-Ju Bai

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel