linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/rds: Fix a use after free in rds_message_map_pages
@ 2021-03-30 10:16 Lv Yunlong
  2021-03-31  0:02 ` David Miller
  0 siblings, 1 reply; 5+ messages in thread
From: Lv Yunlong @ 2021-03-30 10:16 UTC (permalink / raw)
  To: santosh.shilimkar, davem, kuba
  Cc: netdev, linux-rdma, rds-devel, linux-kernel, Lv Yunlong

In rds_message_map_pages, the rm is freed by rds_message_put(rm).
But rm is still used by rm->data.op_sg in return value.

My patch replaces ERR_CAST(rm->data.op_sg) to ERR_PTR(-ENOMEM) to avoid
the uaf.

Fixes: 7dba92037baf3 ("net/rds: Use ERR_PTR for rds_message_alloc_sgs()")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 net/rds/message.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/rds/message.c b/net/rds/message.c
index 071a261fdaab..cecd968c9b25 100644
--- a/net/rds/message.c
+++ b/net/rds/message.c
@@ -348,7 +348,7 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
 	rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs);
 	if (IS_ERR(rm->data.op_sg)) {
 		rds_message_put(rm);
-		return ERR_CAST(rm->data.op_sg);
+		return ERR_PTR(-ENOMEM);
 	}
 
 	for (i = 0; i < rm->data.op_nents; ++i) {
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread
* [PATCH] net/rds: Fix a use after free in rds_message_map_pages
@ 2021-03-11  8:46 Lv Yunlong
  2021-03-19  2:25 ` lyl2019
  0 siblings, 1 reply; 5+ messages in thread
From: Lv Yunlong @ 2021-03-11  8:46 UTC (permalink / raw)
  To: santosh.shilimkar, davem, kuba
  Cc: netdev, linux-rdma, rds-devel, linux-kernel, Lv Yunlong

In rds_message_map_pages, rds_message_put() will free rm.
Maybe store the value of rm->data.op_sg ahead of rds_message_put()
is better. Otherwise other threads could allocate the freed chunk
and may change the value of rm->data.op_sg.

Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
---
 net/rds/message.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/rds/message.c b/net/rds/message.c
index 071a261fdaab..392e3a2f41a0 100644
--- a/net/rds/message.c
+++ b/net/rds/message.c
@@ -347,8 +347,9 @@ struct rds_message *rds_message_map_pages(unsigned long *page_addrs, unsigned in
 	rm->data.op_nents = DIV_ROUND_UP(total_len, PAGE_SIZE);
 	rm->data.op_sg = rds_message_alloc_sgs(rm, num_sgs);
 	if (IS_ERR(rm->data.op_sg)) {
+		struct scatterlist *tmp = rm->data.op_sg;
 		rds_message_put(rm);
-		return ERR_CAST(rm->data.op_sg);
+		return ERR_CAST(tmp);
 	}
 
 	for (i = 0; i < rm->data.op_nents; ++i) {
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-31  2:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30 10:16 [PATCH] net/rds: Fix a use after free in rds_message_map_pages Lv Yunlong
2021-03-31  0:02 ` David Miller
2021-03-31  2:02   ` lyl2019
  -- strict thread matches above, loose matches on Subject: below --
2021-03-11  8:46 Lv Yunlong
2021-03-19  2:25 ` lyl2019

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).