From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04E1DECAAA1 for ; Fri, 9 Sep 2022 18:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbiIISc3 (ORCPT ); Fri, 9 Sep 2022 14:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbiIISc2 (ORCPT ); Fri, 9 Sep 2022 14:32:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EA35128969 for ; Fri, 9 Sep 2022 11:32:26 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0E0EB620B3 for ; Fri, 9 Sep 2022 18:32:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C2B1C433C1; Fri, 9 Sep 2022 18:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662748345; bh=11VHjxNF/yRY0Gd/HjVKomzvCN7mHSCTneZ64og4qco=; h=Subject:To:Cc:From:Date:From; b=0RTfCWxg/Ug/+0N66pyIunH9LLIKapfXy88nLlUOy0XjenFXKyJbG/JX4bZBLA+Yr zSij2vvxSd5x16J+rqAEFw8iaRHLGKjCrp+LfO3YIFTg3a8HRZRSNcZJBo3j/DovqG JqUltE/9/QViO1fC3bx5ZrE/6D0y1kx13E+i82hE= Subject: FAILED: patch "[PATCH] vfio/type1: Unpin zero pages" failed to apply to 5.10-stable tree To: alex.williamson@redhat.com, david@redhat.com, lpivarc@redhat.com Cc: From: Date: Fri, 09 Sep 2022 20:32:22 +0200 Message-ID: <1662748342197146@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org The patch below does not apply to the 5.10-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . Possible dependencies: 873aefb376bb ("vfio/type1: Unpin zero pages") 4b6c33b32296 ("vfio/type1: Prepare for batched pinning with struct vfio_batch") be16c1fd99f4 ("vfio/type1: Change success value of vaddr_get_pfn()") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 873aefb376bbc0ed1dd2381ea1d6ec88106fdbd4 Mon Sep 17 00:00:00 2001 From: Alex Williamson Date: Mon, 29 Aug 2022 21:05:40 -0600 Subject: [PATCH] vfio/type1: Unpin zero pages There's currently a reference count leak on the zero page. We increment the reference via pin_user_pages_remote(), but the page is later handled as an invalid/reserved page, therefore it's not accounted against the user and not unpinned by our put_pfn(). Introducing special zero page handling in put_pfn() would resolve the leak, but without accounting of the zero page, a single user could still create enough mappings to generate a reference count overflow. The zero page is always resident, so for our purposes there's no reason to keep it pinned. Therefore, add a loop to walk pages returned from pin_user_pages_remote() and unpin any zero pages. Cc: stable@vger.kernel.org Reported-by: Luboslav Pivarc Reviewed-by: David Hildenbrand Link: https://lore.kernel.org/r/166182871735.3518559.8884121293045337358.stgit@omen Signed-off-by: Alex Williamson diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index db516c90a977..8706482665d1 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -558,6 +558,18 @@ static int vaddr_get_pfns(struct mm_struct *mm, unsigned long vaddr, ret = pin_user_pages_remote(mm, vaddr, npages, flags | FOLL_LONGTERM, pages, NULL, NULL); if (ret > 0) { + int i; + + /* + * The zero page is always resident, we don't need to pin it + * and it falls into our invalid/reserved test so we don't + * unpin in put_pfn(). Unpin all zero pages in the batch here. + */ + for (i = 0 ; i < ret; i++) { + if (unlikely(is_zero_pfn(page_to_pfn(pages[i])))) + unpin_user_page(pages[i]); + } + *pfn = page_to_pfn(pages[0]); goto done; }