Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8198265rwi; Tue, 25 Oct 2022 03:52:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7feNNKf7tn35t68b16gsfGN03DwYe5qDLrQZAfz2o6KpjrrDaAnG3z0Gg+Df7xEB+j2mRh X-Received: by 2002:a17:903:18d:b0:186:9862:d15f with SMTP id z13-20020a170903018d00b001869862d15fmr13914771plg.6.1666695179263; Tue, 25 Oct 2022 03:52:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666695179; cv=none; d=google.com; s=arc-20160816; b=bOe9IpJobfIe2qSVtpvcnxE7x37N6NZvVljCR14QJMnsZOUn1XCJkfLm2czvPXVJfP veUSYheWtYNDhSHxW6NIcjtuSaj0Idguc5IhEuTi9hoHMqxUzj2wjdTzYO8cz7UPYAhh u9+lmBgk1ngfiC1XGJdd1yPEXhZ9jQ7sbeA4udjKfETTN67bW0ROZrzLrsvyuI/KJy/n CYaNZcE9RQUMpYzXfwRiW6phnfpsKNzlo0jRVT0/B8O09LmOzI1TNJLyTH+v8Ln7H9Mk klCwLkFZHEX8FhDu6P5NDjbWtFCLlVeq40pV/6g8p19VuWQOH7CUi679hTqNV1fQArNh TrEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=uzo+m+yxkYwzyyHwadLFPJlbIQv7qpQLm70p+UN05hA=; b=pGx1IWv74/n9CNV+M8EuiqJkIqMkuAYxlII/bH3nYUaAHpvLdjEJi4Ry5VGo2gnM8C F1OAqgDm5rooq4T/PtxRMjOIiw+ARFK9uYM+CzvPCDxrdYacdurazEWu9Lor9LCJBepT g5lg2a2iva8fWA8l31CUDm6GJkI0a4AUjRrfYSFdW53Tx++eKDAk+ww6CNzCTa89MTMP RgvIb6rkQXFUemIWA8qClITz9RRKW3y2x8m0D1dziOIt5BtoP9Ei1t6BzRVMUpMOnMHa U9BAoQ1Bxi/3gv+/y5wqhVtka0cfIfAzaU+UVxtBAlunge8LaeRF20f0VE8WjYY0AkRE O20A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d6ZDNCAc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k3-20020aa79d03000000b00557e3e7c420si3149791pfp.213.2022.10.25.03.52.47; Tue, 25 Oct 2022 03:52:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d6ZDNCAc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232434AbiJYKVd (ORCPT + 99 others); Tue, 25 Oct 2022 06:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbiJYKVA (ORCPT ); Tue, 25 Oct 2022 06:21:00 -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 4B9C0188A9D for ; Tue, 25 Oct 2022 03:17:48 -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 DF67661876 for ; Tue, 25 Oct 2022 10:17:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8AC4FC433C1; Tue, 25 Oct 2022 10:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666693067; bh=loBjWPuoKTGF/gO56VzkKo6krQdgRby7JIrG/EzZOSQ=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=d6ZDNCAcK4F26u54xQf8kDBp/8b3DW5BfO6g1lzeUvpUqST0Kw+Ohe0820AGWKYi+ /7Iqw8NZ0p6eQ/pqwMi1Gu67j2R14VHUyxddgBClTRfmn7+eiBCfjsq3GSF79nNNGz 0X7g+J7DfNAmhkRl2i3xi1iShD/jLXV9iOD0Aj/KAyEV5IbzhVMFLMbIuW+YD0HX3T B8i2fs2s6CKT9WlZ6lTFZXa/hnB4DlVRnIIZi1IMECfFVAoF+8Q0qD/kHO/VT7rrxh ahRkwDT3WUrOsLHpVfVQd0i2lzMAzWlJ4qQ4wL0BQod1CCuVzaQiHLp5VsXHdnMHQK 2bogCqmt8gCvw== Message-ID: Date: Tue, 25 Oct 2022 12:17:43 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v2 0/8] Fix several device private page reference counting issues Content-Language: en-US To: Alistair Popple , Andrew Morton , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Felix Kuehling , Lyude Paul References: From: "Vlastimil Babka (SUSE)" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/28/22 14:01, Alistair Popple wrote: > This series aims to fix a number of page reference counting issues in > drivers dealing with device private ZONE_DEVICE pages. These result in > use-after-free type bugs, either from accessing a struct page which no > longer exists because it has been removed or accessing fields within the > struct page which are no longer valid because the page has been freed. > > During normal usage it is unlikely these will cause any problems. However > without these fixes it is possible to crash the kernel from userspace. > These crashes can be triggered either by unloading the kernel module or > unbinding the device from the driver prior to a userspace task exiting. In > modules such as Nouveau it is also possible to trigger some of these issues > by explicitly closing the device file-descriptor prior to the task exiting > and then accessing device private memory. Hi, as this series was noticed to create a CVE [1], do you think a stable backport is warranted? I think the "It is possible to launch the attack remotely." in [1] is incorrect though, right? It looks to me that patch 1 would be needed since the CONFIG_DEVICE_PRIVATE introduction, while the following few only to kernels with 27674ef6c73f (probably not so critical as that includes no LTS)? Thanks, Vlastimil [1] https://nvd.nist.gov/vuln/detail/CVE-2022-3523 > This involves some minor changes to both PowerPC and AMD GPU code. > Unfortunately I lack hardware to test either of those so any help there > would be appreciated. The changes mimic what is done in for both Nouveau > and hmm-tests though so I doubt they will cause problems. > > To: Andrew Morton > To: linux-mm@kvack.org > Cc: linux-kernel@vger.kernel.org > Cc: amd-gfx@lists.freedesktop.org > Cc: nouveau@lists.freedesktop.org > Cc: dri-devel@lists.freedesktop.org > > Alistair Popple (8): > mm/memory.c: Fix race when faulting a device private page > mm: Free device private pages have zero refcount > mm/memremap.c: Take a pgmap reference on page allocation > mm/migrate_device.c: Refactor migrate_vma and migrate_deivce_coherent_page() > mm/migrate_device.c: Add migrate_device_range() > nouveau/dmem: Refactor nouveau_dmem_fault_copy_one() > nouveau/dmem: Evict device private memory during release > hmm-tests: Add test for migrate_device_range() > > arch/powerpc/kvm/book3s_hv_uvmem.c | 17 +- > drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 19 +- > drivers/gpu/drm/amd/amdkfd/kfd_migrate.h | 2 +- > drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 11 +- > drivers/gpu/drm/nouveau/nouveau_dmem.c | 108 +++++++---- > include/linux/memremap.h | 1 +- > include/linux/migrate.h | 15 ++- > lib/test_hmm.c | 129 ++++++++++--- > lib/test_hmm_uapi.h | 1 +- > mm/memory.c | 16 +- > mm/memremap.c | 30 ++- > mm/migrate.c | 34 +-- > mm/migrate_device.c | 239 +++++++++++++++++------- > mm/page_alloc.c | 8 +- > tools/testing/selftests/vm/hmm-tests.c | 49 +++++- > 15 files changed, 516 insertions(+), 163 deletions(-) > > base-commit: 088b8aa537c2c767765f1c19b555f21ffe555786