提交 24e093b9 编写于 作者: J Jia-Ju Bai 提交者: Greg Kroah-Hartman

fs: afs: Fix a possible null-pointer dereference in afs_put_read()

[ Upstream commit a6eed4ab5dd4bfb696c1a3f49742b8d1846a66a0 ]

In afs_read_dir(), there is an if statement on line 255 to check whether
req->pages is NULL:
	if (!req->pages)
		goto error;

If req->pages is NULL, afs_put_read() on line 337 is executed.
In afs_put_read(), req->pages[i] is used on line 195.
Thus, a possible null-pointer dereference may occur in this case.

To fix this possible bug, an if statement is added in afs_put_read() to
check req->pages.

This bug is found by a static analysis tool STCheck written by us.

Fixes: f3ddee8d ("afs: Fix directory handling")
Signed-off-by: NJia-Ju Bai <baijiaju1990@gmail.com>
Signed-off-by: NDavid Howells <dhowells@redhat.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
上级 8e5179f9
...@@ -193,11 +193,13 @@ void afs_put_read(struct afs_read *req) ...@@ -193,11 +193,13 @@ void afs_put_read(struct afs_read *req)
int i; int i;
if (refcount_dec_and_test(&req->usage)) { if (refcount_dec_and_test(&req->usage)) {
if (req->pages) {
for (i = 0; i < req->nr_pages; i++) for (i = 0; i < req->nr_pages; i++)
if (req->pages[i]) if (req->pages[i])
put_page(req->pages[i]); put_page(req->pages[i]);
if (req->pages != req->array) if (req->pages != req->array)
kfree(req->pages); kfree(req->pages);
}
kfree(req); kfree(req);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册