From: Jens Axboe Date: Fri, 29 Oct 2010 17:46:56 +0000 (-0600) Subject: block: limit vec count in bio_kmalloc() and bio_alloc_map_data() X-Git-Tag: v2.6.35.10~216 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=6033d45c07fc80b4c70899b081a3c11f5ee9f6ea;p=karo-tx-linux.git block: limit vec count in bio_kmalloc() and bio_alloc_map_data() commit f3f63c1c28bc861a931fac283b5bc3585efb8967 upstream. Reported-by: Dan Rosenberg Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman Signed-off-by: Andi Kleen --- diff --git a/fs/bio.c b/fs/bio.c index e7bf6ca64dcf..75ea4c3b1d10 100644 --- a/fs/bio.c +++ b/fs/bio.c @@ -370,6 +370,9 @@ struct bio *bio_kmalloc(gfp_t gfp_mask, int nr_iovecs) { struct bio *bio; + if (nr_iovecs > UIO_MAXIOV) + return NULL; + bio = kmalloc(sizeof(struct bio) + nr_iovecs * sizeof(struct bio_vec), gfp_mask); if (unlikely(!bio)) @@ -697,8 +700,12 @@ static void bio_free_map_data(struct bio_map_data *bmd) static struct bio_map_data *bio_alloc_map_data(int nr_segs, int iov_count, gfp_t gfp_mask) { - struct bio_map_data *bmd = kmalloc(sizeof(*bmd), gfp_mask); + struct bio_map_data *bmd; + + if (iov_count > UIO_MAXIOV) + return NULL; + bmd = kmalloc(sizeof(*bmd), gfp_mask); if (!bmd) return NULL;