Re: [050/107] block: check for proper length of iov entries earlierin blk_rq_map_user_iov()

From: Ben Hutchings
Date: Fri Nov 04 2011 - 11:24:48 EST


On Wed, 2011-11-02 at 15:14 -0700, Greg KH wrote:
> 2.6.32-longterm review patch. If anyone has any objections, please let us know.
>
> ------------------
>
> From: Xiaotian Feng <dfeng@xxxxxxxxxx>
>
> commit 5478755616ae2ef1ce144dded589b62b2a50d575 upstream.
>
> commit 9284bcf checks for proper length of iov entries in
> blk_rq_map_user_iov(). But if the map is unaligned, kernel
> will break out the loop without checking for the proper length.
> So we need to check the proper length before the unalign check.

This will catch an unaligned zero-length entry. But there's still no
check for zero-length iov entries *after* the unaligned entry.

[...]
> --- a/block/blk-map.c
> +++ b/block/blk-map.c
> @@ -201,12 +201,13 @@ int blk_rq_map_user_iov(struct request_q
> for (i = 0; i < iov_count; i++) {
> unsigned long uaddr = (unsigned long)iov[i].iov_base;
>
> + if (!iov[i].iov_len)
> + return -EINVAL;
> +
> if (uaddr & queue_dma_alignment(q)) {
> unaligned = 1;
> break;

I think the correct fix is just to remove the 'break'.

Ben.

> }
> - if (!iov[i].iov_len)
> - return -EINVAL;
> }
>
> if (unaligned || (q->dma_pad_mask & len) || map_data)
>

--
Ben Hutchings
Sturgeon's Law: Ninety percent of everything is crap.

Attachment: signature.asc
Description: This is a digitally signed message part