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 X-Spam-Level: X-Spam-Status: No, score=-6.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FCBFC2D0A8 for ; Mon, 28 Sep 2020 12:00:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 867512073A for ; Mon, 28 Sep 2020 12:00:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="cpTT38ev" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 867512073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 79C1C6B005D; Mon, 28 Sep 2020 08:00:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 725FE8E0001; Mon, 28 Sep 2020 08:00:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C54C6B0068; Mon, 28 Sep 2020 08:00:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4110A6B005D for ; Mon, 28 Sep 2020 08:00:01 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E44911E19 for ; Mon, 28 Sep 2020 12:00:00 +0000 (UTC) X-FDA: 77312326560.10.loaf05_1811c2627181 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin10.hostedemail.com (Postfix) with ESMTP id C160416A0DE for ; Mon, 28 Sep 2020 12:00:00 +0000 (UTC) X-HE-Tag: loaf05_1811c2627181 X-Filterd-Recvd-Size: 6066 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf41.hostedemail.com (Postfix) with ESMTP for ; Mon, 28 Sep 2020 12:00:00 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id f142so613738qke.13 for ; Mon, 28 Sep 2020 04:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Nnyy03xtiFPqmZlbmE+teLd8X53Eyq870inKRyNgjhU=; b=cpTT38evNw+rKQlt8Mlfz+BF1L43eGL86jpoXMo+Dx5radXSYHjzMU4Ix0wbNMvD0H fvZcy2qIWnsxh6v42+ZhCo25LYDNx1+q6ijgiffs3Iu24+bsigZ/TM0X65cDYdtsVZ6C t6vNqOrmQ9xjh2s/D20MAfG0vXooZEloQRp9WHymBxHn/JfNF7dIKcp4kOBU2+7OPoIg Uyv9GlNtnrkczuMmQjyYtC7TWKuZT15bnCNwPI2cOG2R/GZAY0Sjmi6Oy/qfPFQfA1p+ KWxQxzawW7qf7uH2R0j1ReHvVA4h96xyCCAyEb60H0dWNZa71DG3pdblyQSdxENWNM9q v0CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Nnyy03xtiFPqmZlbmE+teLd8X53Eyq870inKRyNgjhU=; b=AIyaaJNrs8xQtcJQPfUKwJToKSaR+Gim7ciZwdx5Nhnv7inpByoAblYTxx1Ug4KTtG jLwphfVs1r+v2rCQHxfmV4qWdY+A4jh4qZx+cYeT3YwGvTlFHekt47UGZ0PS/siYhn7Z 0nJ6mpbw2KCRERmFIMRd0w7M0WgguhbSWys+yz95qf5falW2CoRCP6lyB4rr54AOl6SJ AabrQgqHmuoFrLQp00+32Yj9A1jfnZfeETZMWj+rQn23dWJ9x9tuZmqGAEKPCrK3MzZt fpFM2G+9cwXegMTdbnfN84zOhF/Vr2T31GVxIuxmOREBDkyre8HBdl/7cry2Rgt0m57U 7BWg== X-Gm-Message-State: AOAM530nn2lc3LJymKZod39T89ocf2Oa4WpHH3kkn8nqu1rkqCkwgLbx jrARqJT406BaBF1HXy5kPz/Erw== X-Google-Smtp-Source: ABdhPJy4ItawkHdUEb++0v6F8cioYGcvW7vFqwz9rqzCYPXyBaZkc0rsz2ludjLRsOxbhbldqcQIUA== X-Received: by 2002:a37:b8c2:: with SMTP id i185mr968855qkf.87.1601294399390; Mon, 28 Sep 2020 04:59:59 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id q72sm727727qka.22.2020.09.28.04.59.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Sep 2020 04:59:58 -0700 (PDT) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kMroz-001tq4-Rn; Mon, 28 Sep 2020 08:59:57 -0300 Date: Mon, 28 Sep 2020 08:59:57 -0300 From: Jason Gunthorpe To: "Jason A. Donenfeld" Cc: linux-mm@kvack.org, peterx@redhat.com, torvalds@linux-foundation.org, dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, chris@chris-wilson.co.uk, akpm@linux-foundation.org Subject: Re: [PATCH] mm: do not rely on mm == current->mm in __get_user_pages_locked Message-ID: <20200928115957.GM9916@ziepe.ca> References: <20200928103507.2164-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200928103507.2164-1-Jason@zx2c4.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.011358, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Sep 28, 2020 at 12:35:07PM +0200, Jason A. Donenfeld wrote: > It seems likely this block was pasted from internal_get_user_pages_fast, > which is not passed an mm struct and therefore uses current's. But > __get_user_pages_locked is passed an explicit mm, and current->mm is not > always valid. This was hit when being called from i915, which uses: > > pin_user_pages_remote-> > __get_user_pages_remote-> > __gup_longterm_locked-> > __get_user_pages_locked > > Before, this would lead to an OOPS: > > BUG: kernel NULL pointer dereference, address: 0000000000000064 > #PF: supervisor write access in kernel mode > #PF: error_code(0x0002) - not-present page > PGD 0 P4D 0 > Oops: 0002 [#1] SMP > CPU: 10 PID: 1431 Comm: kworker/u33:1 Tainted: P S U O 5.9.0-rc7+ #140 > Hardware name: LENOVO 20QTCTO1WW/20QTCTO1WW, BIOS N2OET47W (1.34 ) 08/06/2020 > Workqueue: i915-userptr-acquire __i915_gem_userptr_get_pages_worker [i915] > RIP: 0010:__get_user_pages_remote+0xd7/0x310 > Code: f5 01 00 00 83 7d 00 01 0f 85 ed 01 00 00 f7 c1 00 00 04 00 0f 84 58 01 00 00 65 48 8b 04 25 00 6d 01 00 48 8b 80 40 03 00 00 40 64 01 00 00 00 65 48 8b 04 25 00 6d 01 00 48 c7 44 24 18 00 > RSP: 0018:ffff888fdfe47de0 EFLAGS: 00010206 > RAX: 0000000000000000 RBX: 00007fe188531000 RCX: 0000000000040001 > RDX: 0000000000000001 RSI: 00007fe188531000 RDI: ffff888ff0748f00 > RBP: ffff888fdfe47e54 R08: ffff888fedc7d7c8 R09: 0000000000000000 > R10: 0000000000000018 R11: fefefefefefefeff R12: ffff888ff0748f00 > R13: ffff888fedc7d7c8 R14: ffff888f81fe3a40 R15: 0000000000042003 > FS: 0000000000000000(0000) GS:ffff888ffc480000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 0000000000000064 CR3: 0000000002009003 CR4: 00000000003706e0 > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > Call Trace: > __i915_gem_userptr_get_pages_worker+0xc8/0x260 [i915] > process_one_work+0x1ca/0x390 > worker_thread+0x48/0x3c0 > ? rescuer_thread+0x3d0/0x3d0 > kthread+0x114/0x130 > ? kthread_create_worker_on_cpu+0x40/0x40 > ret_from_fork+0x1f/0x30 > CR2: 0000000000000064 > > This commit fixes the problem by using the mm pointer passed to the > function rather than the bogus one in current. > > Fixes: 008cfe4418b3 ("mm: Introduce mm_struct.has_pinned") > Cc: Jason Gunthorpe > Cc: Peter Xu > Signed-off-by: Jason A. Donenfeld > --- > mm/gup.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Yes this looks like the right fix Reviewed-by: Jason Gunthorpe Thanks, Jason