Skip to content

Commit 249e0a4

Browse files
MaxKellermannidryomov
authored andcommitted
ceph: fix crash after fscrypt_encrypt_pagecache_blocks() error
The function move_dirty_folio_in_page_array() was created by commit ce80b76 ("ceph: introduce ceph_process_folio_batch() method") by moving code from ceph_writepages_start() to this function. This new function is supposed to return an error code which is checked by the caller (now ceph_process_folio_batch()), and on error, the caller invokes redirty_page_for_writepage() and then breaks from the loop. However, the refactoring commit has gone wrong, and it by accident, it always returns 0 (= success) because it first NULLs the pointer and then returns PTR_ERR(NULL) which is always 0. This means errors are silently ignored, leaving NULL entries in the page array, which may later crash the kernel. The simple solution is to call PTR_ERR() before clearing the pointer. Cc: [email protected] Fixes: ce80b76 ("ceph: introduce ceph_process_folio_batch() method") Link: https://lore.kernel.org/ceph-devel/[email protected]/ Signed-off-by: Max Kellermann <[email protected]> Reviewed-by: Ilya Dryomov <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent cce7c15 commit 249e0a4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

fs/ceph/addr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,9 @@ static inline int move_dirty_folio_in_page_array(struct address_space *mapping,
12641264
0,
12651265
gfp_flags);
12661266
if (IS_ERR(pages[index])) {
1267-
if (PTR_ERR(pages[index]) == -EINVAL) {
1267+
int err = PTR_ERR(pages[index]);
1268+
1269+
if (err == -EINVAL) {
12681270
pr_err_client(cl, "inode->i_blkbits=%hhu\n",
12691271
inode->i_blkbits);
12701272
}
@@ -1273,7 +1275,7 @@ static inline int move_dirty_folio_in_page_array(struct address_space *mapping,
12731275
BUG_ON(ceph_wbc->locked_pages == 0);
12741276

12751277
pages[index] = NULL;
1276-
return PTR_ERR(pages[index]);
1278+
return err;
12771279
}
12781280
} else {
12791281
pages[index] = &folio->page;

0 commit comments

Comments
 (0)