Skip to contentSkip to conversation

RDMA/rxe: Zero out index member of struct rxe_queue

PATCH Applied Xiao Yang 4 participants 13 messages Aug 20, 2021 – Sep 1, 2021

Subsystems (2)
lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH 1/1 RDMA/rxe: Zero out index member of struct rxe_queue

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
 	if (*num_elem < 0)
 		goto err1;
 
-	q = kmalloc(sizeof(*q), GFP_KERNEL);
+	q = kzalloc(sizeof(*q), GFP_KERNEL);
 	if (!q)
 		goto err1;
 
Signature · 1 line
2.25.1
#1 lore raw

Hi Olga Kornievskaia,

Could you check if this patch can fix your issues?

https://www.spinics.net/lists/linux-rdma/msg104358.html
https://www.spinics.net/lists/linux-rdma/msg104359.html
https://www.spinics.net/lists/linux-rdma/msg104360.html

By the way, this patch can fix my panic.

Best Regards,
Xiao Yang

Quoted 29 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
 	if (*num_elem < 0)
 		goto err1;
 
-	q = kmalloc(sizeof(*q), GFP_KERNEL);
+	q = kzalloc(sizeof(*q), GFP_KERNEL);
 	if (!q)
 		goto err1;
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Xiao Yang
Quoted 22 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 69

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
 	if (*num_elem < 0)
 		goto err1;
 
-	q = kmalloc(sizeof(*q), GFP_KERNEL);
+	q = kzalloc(sizeof(*q), GFP_KERNEL);
 	if (!q)
 		goto err1;
 

Thanks for this!! I am happy to take the blame but this has been there from the original 2016 rxe commit. Its a good catch.

#3 lore raw
Quoted 25 lines · Bob Pearson
Quoted 24 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
  drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
  	if (*num_elem<  0)
  		goto err1;
 
Quoted 7 lines

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 69

Quoted 6 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
-	q = kmalloc(sizeof(*q), GFP_KERNEL);
+	q = kzalloc(sizeof(*q), GFP_KERNEL);
  	if (!q)
  		goto err1;
 

Thanks for this!! I am happy to take the blame but this has been there from the original 2016 rxe commit. Its a good catch.

Hi Bob,

The original 2016 rxe commit actually introduced kmalloc() but it initialized all members of struct rxe_queue at subsequent steps. When the new index member of struct rxe_queue was added, it didn't initialized at subsequent steps. So I think the issue was caused by your patch.
I use kzalloc() to fix the issue because I want to avoid the same issue when another new member will be added in future.

Best Regards,
Xiao Yang

Quoted 1 line
#4 lore raw
Quoted 33 lines · On 8/21/21 8:00 AM, [email protected] wrote:
Quoted 25 lines · Bob Pearson
Quoted 24 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
  drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
  	if (*num_elem<  0)
  		goto err1;
 
Quoted 7 lines

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 69

Quoted 6 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
-	q = kmalloc(sizeof(*q), GFP_KERNEL);
+	q = kzalloc(sizeof(*q), GFP_KERNEL);
  	if (!q)
  		goto err1;
 

Thanks for this!! I am happy to take the blame but this has been there from the original 2016 rxe commit. Its a good catch.

Quoted 7 lines

Hi Bob,

The original 2016 rxe commit actually introduced kmalloc() but it initialized all members of struct rxe_queue at subsequent steps. When the new index member of struct rxe_queue was added, it didn't initialized at subsequent steps. So I think the issue was caused by your patch.

Yup. My comment was really that if it was an old one I was guilty either way most likely. But this is a good catch.

Quoted 6 lines

I use kzalloc() to fix the issue because I want to avoid the same issue when another new member will be added in future.

Best Regards,
Xiao Yang

Quoted 1 line
maintainer Applied
#5 lore raw
In reply to Xiao Yang
Quoted 8 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Quoted 7 lines

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-rc, thanks

Jason

maintainer
#6 lore raw
In reply to Xiao Yang
Quoted 22 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 66

Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
        if (*num_elem < 0)
                goto err1;
 
-       q = kmalloc(sizeof(*q), GFP_KERNEL);
+       q = kzalloc(sizeof(*q), GFP_KERNEL);

Perhaps this is why I can not reproduce this problem in the local host.

Zhu Yanjun

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_queue.c +0 -1
        if (!q)
                goto err1;
 
--

2.25.1

#7 lore raw
Quoted 25 lines · Zhu Yanjun
Quoted 24 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
  drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
         if (*num_elem<  0)
                 goto err1;
 
Quoted 3 lines

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 66

Quoted 2 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
-       q = kmalloc(sizeof(*q), GFP_KERNEL);
+       q = kzalloc(sizeof(*q), GFP_KERNEL);

Perhaps this is why I can not reproduce this problem in the local host.

Hi Yanjun,

I forgot to say that I reproduced the issue on my local vm.

Best Regards,
Xiao Yang

Quoted 10 lines

Zhu Yanjun

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_queue.c +0 -1
         if (!q)
                 goto err1;
 
--

2.25.1

maintainer
#8 lore raw
Quoted 27 lines · On Mon, Aug 23, 2021 at 12:37 PM [email protected] <[email protected]>…
Quoted 25 lines · Zhu Yanjun
Quoted 24 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
  drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
         if (*num_elem<  0)
                 goto err1;
 
Quoted 6 lines
Quoted 3 lines

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 66

Quoted 2 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
-       q = kmalloc(sizeof(*q), GFP_KERNEL);
+       q = kzalloc(sizeof(*q), GFP_KERNEL);

Perhaps this is why I can not reproduce this problem in the local host.

Hi Yanjun,

I forgot to say that I reproduced the issue on my local vm.

Which OS are you using to reproduce this problem?

Zhu Yanjun

Quoted 13 lines

Best Regards,
Xiao Yang

Quoted 10 lines

Zhu Yanjun

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_queue.c +0 -1
         if (!q)
                 goto err1;
 
--

2.25.1

#9 lore raw
Quoted 28 lines · Zhu Yanjun
Quoted 26 lines · On Mon, Aug 23, 2021 at 12:37 PM [email protected] <[email protected]>…
Quoted 25 lines · Zhu Yanjun
Quoted 24 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
   drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
          if (*num_elem<   0)
                  goto err1;
 
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 66

Quoted 2 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
-       q = kmalloc(sizeof(*q), GFP_KERNEL);
+       q = kzalloc(sizeof(*q), GFP_KERNEL);

Perhaps this is why I can not reproduce this problem in the local host.

Hi Yanjun,

I forgot to say that I reproduced the issue on my local vm.

Which OS are you using to reproduce this problem?

OS is fedora31.

Quoted 14 lines

Zhu Yanjun

Quoted 12 lines

Best Regards,
Xiao Yang

Quoted 10 lines

Zhu Yanjun

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_queue.c +0 -1
          if (!q)
                  goto err1;
 
--

2.25.1

maintainer
#10 lore raw
Quoted 33 lines · On Mon, Aug 23, 2021 at 2:18 PM [email protected] <[email protected]>…
Quoted 31 lines · Zhu Yanjun
Quoted 29 lines · On Mon, Aug 23, 2021 at 12:37 PM [email protected] <[email protected]>…
Quoted 28 lines · Zhu Yanjun
Quoted 21 lines · Xiao Yang

1) New index member of struct rxe_queue is introduced but not zeroed so the initial value of index may be random.
2) Current index is not masked off to index_mask.
In such case, producer_addr() and consumer_addr() will get an invalid address by the random index and then accessing the invalid address triggers the following panic:
"BUG: unable to handle page fault for address: ffff9ae2c07a1414"

Fix the issue by using kzalloc() to zero out index member.

Fixes 5bcf5a59c41e ("RDMA/rxe: Protext kernel index from user space")
---
   drivers/infiniband/sw/rxe/rxe_queue.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/sw/rxe/rxe_queue.c +0 -0
index 85b812586ed4..72d95398e604 100644

drivers/infiniband/sw/rxe/rxe_queue.c struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem, · line 66

Quoted 5 lines
drivers/infiniband/sw/rxe/rxe_queue.c +1 -1
@@ -63,7 +63,7 @@ struct rxe_queue *rxe_queue_init(struct rxe_dev *rxe, int *num_elem,
          if (*num_elem<   0)
                  goto err1;
 
-       q = kmalloc(sizeof(*q), GFP_KERNEL);
+       q = kzalloc(sizeof(*q), GFP_KERNEL);

Perhaps this is why I can not reproduce this problem in the local host.

Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Hi Yanjun,

I forgot to say that I reproduced the issue on my local vm.

Which OS are you using to reproduce this problem?

OS is fedora31.

Can you reproduce this problem on Ubuntu 20.04?

Thanks,
Zhu Yanjun

Quoted 15 lines
Quoted 15 lines

Zhu Yanjun

Quoted 12 lines

Best Regards,
Xiao Yang

Quoted 10 lines

Zhu Yanjun

Quoted 8 lines
drivers/infiniband/sw/rxe/rxe_queue.c +0 -1
          if (!q)
                  goto err1;
 
--

2.25.1

#11 lore raw
Quoted 1 line · Zhu Yanjun

Can you reproduce this problem on Ubuntu 20.04?

Hi Yanjun,

I cannot reproduce this issue on Ubuntu 20.04 vm for now.
I think I didn't hit the condition where q->index gets the random value after kmalloc().
Perhaps only when allocating the memory which has been used and freed before.

Best Regards,
Xiao Yang

Quoted 2 lines

Thanks,
Zhu Yanjun

maintainer
#12 lore raw
Quoted 8 lines · On Wed, Sep 1, 2021 at 1:42 PM [email protected] <[email protected]>…
Quoted 1 line · Zhu Yanjun

Can you reproduce this problem on Ubuntu 20.04?

Hi Yanjun,

I cannot reproduce this issue on Ubuntu 20.04 vm for now.
I think I didn't hit the condition where q->index gets the random value after kmalloc().

Sure. Thanks a lot.
I can not reproduce this problem on Ubuntu 20.04.

Zhu Yanjun

Quoted 7 lines

Perhaps only when allocating the memory which has been used and freed before.

Best Regards,
Xiao Yang

Quoted 2 lines

Thanks,
Zhu Yanjun