Skip to content

Commit

Permalink
AFS: Stop readlink() on AFS crashing due to NULL 'file' ptr
Browse files Browse the repository at this point in the history
kAFS crashes when asked to read a symbolic link because page_getlink()
passes a NULL file pointer to read_mapping_page(), but afs_readpage()
expects a file pointer from which to extract a key.

Modify afs_readpage() to request the appropriate key from the calling
process's keyrings if a file struct is not supplied with one attached.

Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Anton Blanchard <anton@samba.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
dhowells authored and torvalds committed Aug 27, 2009
1 parent 1e23502 commit 9886e83
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions fs/afs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,16 @@ static int afs_readpage(struct file *file, struct page *page)

inode = page->mapping->host;

ASSERT(file != NULL);
key = file->private_data;
ASSERT(key != NULL);
if (file) {
key = file->private_data;
ASSERT(key != NULL);
} else {
key = afs_request_key(AFS_FS_S(inode->i_sb)->volume->cell);
if (IS_ERR(key)) {
ret = PTR_ERR(key);
goto error_nokey;
}
}

_enter("{%x},{%lu},{%lu}", key_serial(key), inode->i_ino, page->index);

Expand Down Expand Up @@ -207,12 +214,17 @@ static int afs_readpage(struct file *file, struct page *page)
unlock_page(page);
}

if (!file)
key_put(key);
_leave(" = 0");
return 0;

error:
SetPageError(page);
unlock_page(page);
if (!file)
key_put(key);
error_nokey:
_leave(" = %d", ret);
return ret;
}
Expand Down

0 comments on commit 9886e83

Please sign in to comment.