From 14bc610d32a8fd8ebb1f87c147df9614ca4e57da Mon Sep 17 00:00:00 2001 From: Andrey Markovytch Date: Wed, 2 Dec 2015 15:47:14 +0200 Subject: pfk: fixed crash that occurred because of bio's without data bio's without data are not relevant, bio_had_data checks this, replaced redundant checks to call to this function. Also, additional clean ups performed Change-Id: I315bcf43cf3d32e78d53b818571da1f5175f8ac3 Signed-off-by: Andrey Markovytch --- security/pfe/pfk.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/security/pfe/pfk.c b/security/pfe/pfk.c index 0ed4106d8f4b..ccaed3b23fec 100644 --- a/security/pfe/pfk.c +++ b/security/pfe/pfk.c @@ -166,9 +166,9 @@ static int pfk_get_page_index(const struct bio *bio, pgoff_t *page_index) if (!bio || !page_index) return -EINVAL; - /* check bio bi_size > 0 before using the bio->bi_io_vec[] array */ - if (!(bio->bi_iter).bi_size) + if (!bio_has_data((struct bio *)bio)) return -EINVAL; + if (!bio->bi_io_vec) return -EINVAL; if (!bio->bi_io_vec->bv_page) @@ -196,9 +196,10 @@ static struct inode *pfk_bio_get_inode(const struct bio *bio) { if (!bio) return NULL; - /* check bio bi_size > 0 before using the bio->bi_io_vec[] array */ - if (!(bio->bi_iter).bi_size) + + if (!bio_has_data((struct bio *)bio)) return NULL; + if (!bio->bi_io_vec) return NULL; if (!bio->bi_io_vec->bv_page) @@ -609,17 +610,13 @@ bool pfk_allow_merge_bio(struct bio *bio1, struct bio *bio2) void *ecryptfs_data2 = NULL; pgoff_t offset1, offset2; bool res = false; - struct inode *inode1 = NULL; - struct inode *inode2 = NULL; + /* if there is no pfk, don't disallow merging blocks */ if (!pfk_is_ready()) - return -ENODEV; + return true; if (!bio1 || !bio2) - return -EPERM; - - inode1 = pfk_bio_get_inode(bio1); - inode2 = pfk_bio_get_inode(bio2); + return false; ecryptfs_data1 = pfk_get_ecryptfs_data(pfk_bio_get_inode(bio1)); ecryptfs_data2 = pfk_get_ecryptfs_data(pfk_bio_get_inode(bio2)); -- cgit v1.2.3