[PATCH] net/rds: Fix a use after free in rds_message_map_pages

From: Lv Yunlong
Date: Tue Mar 30 2021 - 06:17:26 EST


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@xxxxxxxxxxxxxxxx>
---
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