Skip to content

Commit

Permalink
fs: afs: Fix a possible null-pointer dereference in afs_put_read()
Browse files Browse the repository at this point in the history
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: f3ddee8 ("afs: Fix directory handling")
Signed-off-by: Jia-Ju Bai <[email protected]>
Signed-off-by: David Howells <[email protected]>
  • Loading branch information
XidianGeneral authored and dhowells committed Jul 30, 2019
1 parent 4a46fdb commit a6eed4a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fs/afs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ void afs_put_read(struct afs_read *req)
int i;

if (refcount_dec_and_test(&req->usage)) {
for (i = 0; i < req->nr_pages; i++)
if (req->pages[i])
put_page(req->pages[i]);
if (req->pages != req->array)
kfree(req->pages);
if (req->pages) {
for (i = 0; i < req->nr_pages; i++)
if (req->pages[i])
put_page(req->pages[i]);
if (req->pages != req->array)
kfree(req->pages);
}
kfree(req);
}
}
Expand Down

0 comments on commit a6eed4a

Please sign in to comment.