diff mbox

block: fix possible NULL dereference

Message ID 1457609953-24101-1-git-send-email-sudipm.mukherjee@gmail.com (mailing list archive)
State Rejected, archived
Delegated to: Jens Axboe
Headers show

Commit Message

Sudip Mukherjee March 10, 2016, 11:39 a.m. UTC
We were checking for iter to be NULL after dereferencing it. Lets first
check it and then use it.

Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>
---
 block/blk-map.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Johannes Thumshirn March 10, 2016, 12:03 p.m. UTC | #1
On Thu, Mar 10, 2016 at 05:09:13PM +0530, Sudip Mukherjee wrote:
> We were checking for iter to be NULL after dereferencing it. Lets first
> check it and then use it.
> 
> Signed-off-by: Sudip Mukherjee <sudip.mukherjee@codethink.co.uk>

Good catch
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Jens Axboe March 10, 2016, 3:44 p.m. UTC | #2
On 03/10/2016 04:39 AM, Sudip Mukherjee wrote:
> We were checking for iter to be NULL after dereferencing it. Lets first
> check it and then use it.

Nobody calls it with iter == NULL, I think we should just kill the !iter 
check
diff mbox

Patch

diff --git a/block/blk-map.c b/block/blk-map.c
index a54f054..089ed59 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -126,7 +126,7 @@  int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
 			const struct iov_iter *iter, gfp_t gfp_mask)
 {
 	struct iovec iov, prv = {.iov_base = NULL, .iov_len = 0};
-	bool copy = (q->dma_pad_mask & iter->count) || map_data;
+	bool copy;
 	struct bio *bio = NULL;
 	struct iov_iter i;
 	int ret;
@@ -134,6 +134,7 @@  int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
 	if (!iter || !iter->count)
 		return -EINVAL;
 
+	copy = (q->dma_pad_mask & iter->count) || map_data;
 	iov_for_each(iov, i, *iter) {
 		unsigned long uaddr = (unsigned long) iov.iov_base;