[PATCH -next 2/2] smb3: fix potential wild-ptr-deref in 'smb3_free_compound_rqst'
From: Ye Bin
Date: Thu Oct 13 2022 - 02:48:44 EST
As 'smb3_init_transform_rq' first set 'new_rq[i].rq_npages', then
allocate page, if allocate page failed will call 'smb3_free_compound_rqst'
to free page. However, there may only allocate part of 'rq_npages' pages
which will lead to wild-ptr-deref when free pages.
To solve above issue just increase 'new_rq[i].rq_npages' after allocate
page success.
Signed-off-by: Ye Bin <yebin10@xxxxxxxxxx>
---
fs/cifs/smb2ops.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
index 180f0260cbc4..a1b47ce4ea15 100644
--- a/fs/cifs/smb2ops.c
+++ b/fs/cifs/smb2ops.c
@@ -4467,7 +4467,6 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
goto err_free;
nrq->rq_pages = pages;
- nrq->rq_npages = npages;
nrq->rq_offset = orq->rq_offset;
nrq->rq_pagesz = orq->rq_pagesz;
nrq->rq_tailsz = orq->rq_tailsz;
@@ -4480,6 +4479,7 @@ smb3_init_transform_rq(struct TCP_Server_Info *server, int num_rqst,
pages[j] = alloc_page(GFP_KERNEL|__GFP_HIGHMEM);
if (!pages[j])
goto err_free;
+ nrq->rq_npages++;
}
/* copy pages form the old */
--
2.31.1