Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp72062pxb; Mon, 13 Sep 2021 13:15:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyzr4cydErxPpZkHrX1gWcpBLXhFHgwwNUmLS0D/sWo5hNPA4LN11Iz+Q89WZ1IKDBQBXWO X-Received: by 2002:a17:906:2c0b:: with SMTP id e11mr14866186ejh.284.1631564117901; Mon, 13 Sep 2021 13:15:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631564117; cv=none; d=google.com; s=arc-20160816; b=MbYKloBzcH6EG07yfeueq9mSBuIYTdkZuGZ3yT9+iLG6p0z1lTUkNxkyDK+R6S1taf f7+zsBE88kdhCOQyGXJED1WemI5HqtgJCNCljRhIku2AZ62dXYFXgpGrMjbz+3+8Y6yj AF251g1AqsnIPGKtIaLgCukDyajZY2gV/XlPggnoNyAXG8QXgASdTe9swJSEXisSyFUH 8a0YIIHRZ1MYmuPWSAXzuS7mRR36eS0d/AX0bzvQ0LEaNFAHTNY/QzNmVGG7JZFoJSo6 OT9ceHdgJnGUJU9aHR/3TmjyuAovyZVMJN0HTt/zrkcbPSShmVuUAyAPhYzU0yRsycxc mtgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ij3jV3R3+svzvtqVsyaBlQ5n1qyNl87+SiI8VAx8Mjw=; b=iZdsA9IdAyrLOYoqNbILZ1oLJTf7sZquucxc3kdPqMaGj8szkNY259FLR+nl3ktj7k Jk4fjL9MUifeTVyoiyR11E297KEM3xLlqFQ4TX8gROBMPfrrfeBEt7pftYKEAEtAl4WD fKGOW7tVpuHMudYucEoJo5Cefi3vgDl+n2y82H8iry85Id5cI7clbgcJ+n6G9MmbRMqi u+Gfy2kaD4W0y72/7GXw03q7z902+CfWkpN4TUXo/B9Lz2Xb/1VFZxZ8RI3UUHnpWJci At0I6BgzHnaoH2s7CpsjiEv+umgZKUbuelQDkavUYWv1FeErkjnUje6jXcN78/NW8AvB aYmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QLufXUFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f21si7751171edf.336.2021.09.13.13.14.46; Mon, 13 Sep 2021 13:15:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QLufXUFt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244890AbhIMNu4 (ORCPT + 99 others); Mon, 13 Sep 2021 09:50:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:51840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243923AbhIMNqw (ORCPT ); Mon, 13 Sep 2021 09:46:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1DA2161390; Mon, 13 Sep 2021 13:32:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631539933; bh=E2gaqacbnSvjmZv8/VuoSdvRIMm9/gn2oFPg9AuhrBM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QLufXUFtFFjBMezgPSV3IAtSY3gpSAa7W0W3tudBw/izQstvGpHGzt3HNxdkKBJsq SgYv9fF/yWNbBkQYUKnCde7cG11jSFyn6bu70RCyz9AYziBLZkpgu3U/uqmzf/aIwh IS96kHrW+WPcpXxuSig7snTxn5KhvcPPUnRUrfzk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.10 220/236] bio: fix page leak bio_add_hw_page failure Date: Mon, 13 Sep 2021 15:15:25 +0200 Message-Id: <20210913131107.845268278@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210913131100.316353015@linuxfoundation.org> References: <20210913131100.316353015@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Begunkov commit d9cf3bd531844ffbfe94b16e417037a16efc988d upstream. __bio_iov_append_get_pages() doesn't put not appended pages on bio_add_hw_page() failure, so potentially leaking them, fix it. Also, do the same for __bio_iov_iter_get_pages(), even though it looks like it can't be triggered by userspace in this case. Fixes: 0512a75b98f8 ("block: Introduce REQ_OP_ZONE_APPEND") Cc: stable@vger.kernel.org # 5.8+ Signed-off-by: Pavel Begunkov Link: https://lore.kernel.org/r/1edfa6a2ffd66d55e6345a477df5387d2c1415d0.1626653825.git.asml.silence@gmail.com Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/bio.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/block/bio.c +++ b/block/bio.c @@ -978,6 +978,14 @@ static int __bio_iov_bvec_add_pages(stru return 0; } +static void bio_put_pages(struct page **pages, size_t size, size_t off) +{ + size_t i, nr = DIV_ROUND_UP(size + (off & ~PAGE_MASK), PAGE_SIZE); + + for (i = 0; i < nr; i++) + put_page(pages[i]); +} + #define PAGE_PTRS_PER_BVEC (sizeof(struct bio_vec) / sizeof(struct page *)) /** @@ -1022,8 +1030,10 @@ static int __bio_iov_iter_get_pages(stru if (same_page) put_page(page); } else { - if (WARN_ON_ONCE(bio_full(bio, len))) - return -EINVAL; + if (WARN_ON_ONCE(bio_full(bio, len))) { + bio_put_pages(pages + i, left, offset); + return -EINVAL; + } __bio_add_page(bio, page, len, offset); } offset = 0; @@ -1068,6 +1078,7 @@ static int __bio_iov_append_get_pages(st len = min_t(size_t, PAGE_SIZE - offset, left); if (bio_add_hw_page(q, bio, page, len, offset, max_append_sectors, &same_page) != len) { + bio_put_pages(pages + i, left, offset); ret = -EINVAL; break; }