From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756364AbdJPQuL (ORCPT ); Mon, 16 Oct 2017 12:50:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33322 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754625AbdJPQM0 (ORCPT ); Mon, 16 Oct 2017 12:12:26 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vitaly Mayatskikh , Al Viro Subject: [PATCH 3.18 14/19] fix unbalanced page refcounting in bio_map_user_iov Date: Mon, 16 Oct 2017 18:12:05 +0200 Message-Id: <20171016160922.756909129@linuxfoundation.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171016160922.020176454@linuxfoundation.org> References: <20171016160922.020176454@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Vitaly Mayatskikh commit 95d78c28b5a85bacbc29b8dba7c04babb9b0d467 upstream. bio_map_user_iov and bio_unmap_user do unbalanced pages refcounting if IO vector has small consecutive buffers belonging to the same page. bio_add_pc_page merges them into one, but the page reference is never dropped. Signed-off-by: Vitaly Mayatskikh Signed-off-by: Al Viro Signed-off-by: Greg Kroah-Hartman --- block/bio.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/block/bio.c +++ b/block/bio.c @@ -1338,6 +1338,7 @@ static struct bio *__bio_map_user_iov(st offset = uaddr & ~PAGE_MASK; for (j = cur_page; j < page_limit; j++) { unsigned int bytes = PAGE_SIZE - offset; + unsigned short prev_bi_vcnt = bio->bi_vcnt; if (len <= 0) break; @@ -1352,6 +1353,13 @@ static struct bio *__bio_map_user_iov(st bytes) break; + /* + * check if vector was merged with previous + * drop page reference if needed + */ + if (bio->bi_vcnt == prev_bi_vcnt) + put_page(pages[j]); + len -= bytes; offset = 0; }