Skip to content

Commit

Permalink
net/rds: Fix a use after free in rds_message_map_pages
Browse files Browse the repository at this point in the history
[ Upstream commit bdc2ab5 ]

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 assigns ERR_CAST(rm->data.op_sg) to err before the rm is
freed to avoid the uaf.

Fixes: 7dba920 ("net/rds: Use ERR_PTR for rds_message_alloc_sgs()")
Signed-off-by: Lv Yunlong <lyl2019@mail.ustc.edu.cn>
Reviewed-by: Håkon Bugge <haakon.bugge@oracle.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Yunlongs authored and gregkh committed Apr 14, 2021
1 parent 05bbe9d commit 4cfae7b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion net/rds/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
void *err = ERR_CAST(rm->data.op_sg);
rds_message_put(rm);
return ERR_CAST(rm->data.op_sg);
return err;
}

for (i = 0; i < rm->data.op_nents; ++i) {
Expand Down

0 comments on commit 4cfae7b

Please sign in to comment.