Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1659405rwb; Tue, 29 Nov 2022 17:18:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf7k9VDKBP9kOnIlLBCcYMM6yWQhJYJ/PI/zDRhyh+u5QMjFE/6SmTHu3dS3GCnuMzSwZqnq X-Received: by 2002:a17:902:f68a:b0:188:dd56:1eea with SMTP id l10-20020a170902f68a00b00188dd561eeamr39906995plg.80.1669771091230; Tue, 29 Nov 2022 17:18:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669771091; cv=none; d=google.com; s=arc-20160816; b=Q51t+M0glwIVb8TH+G8s7Zcbu2ibaT2yEzGVOq+XyjmMHxjmGDc+WOHQqQvHI0h4Zg wHXHGgbHpKOux26A6oCuUgC+orcUGkDvnmV3wgj07kAv7Dx8HUYiHQl7P0NlqxhcpUPM 4Pbe1lhWCIcFlNrwSGJcaDsOp5rFnNCjtAXGzDTNMXdldSGbEvtF8rpMkneDE7gE61xh +j4/QD1IccTQyH4fSHAQuVHaDy9qHHPqPHCinhRDyXhucistBTt1TU9IbmxH0qDiIadE NjtkBFZmyOZZ+Ke50u3e0WELOZLqPd0spjRUjuLk42aa4mw/TmNYZ3vRQjbN2aglrVzC Z7Jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:dkim-signature:from; bh=5SiIziV2QvgfgWy4Sra39N19zHYZdg3yjH/6YkkoY70=; b=uFlOqIYn5tMZdnUGtaNQNfWsw7XPX7keN6g9lLYfZWF+AZqaf7xB4GtNHepACIlrGE cZWgm/RUnH5wHulJow//Pq9g0PAG1P1UA9N4ytGqc/WedR38ZdoZCGLu6aJyZVK7oc8X njiOjGKE95uDs1x7/q02BMXx7pUvDMYe8NbGL4S/Dq1yD/n5bvicYBrgLXDsjZcCCnF4 1Iy79K75iBYprIiqeMPCbxPhnDRdPeUraoJOWtuTx/T3VgEJ0kh5L7FH5XwbxRGrh/Fq 86KJQqQh4EHteoWwjh2lb9vaj3igafFkOPDu+lWbvHl/nW6JH+XHL9s/nlLWvwbG4Qjy lb3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dR14Xtp6; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g64-20020a636b43000000b0047731d8c0ddsi15055852pgc.511.2022.11.29.17.17.59; Tue, 29 Nov 2022 17:18:11 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=dR14Xtp6; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbiK3AHr (ORCPT + 84 others); Tue, 29 Nov 2022 19:07:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230024AbiK3AHo (ORCPT ); Tue, 29 Nov 2022 19:07:44 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E06210CC for ; Tue, 29 Nov 2022 16:07:40 -0800 (PST) From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1669766858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5SiIziV2QvgfgWy4Sra39N19zHYZdg3yjH/6YkkoY70=; b=dR14Xtp6esMbAQrAii7xeIiVEfSQm0RDd3HVtwIR9PCOFih5+eCi/J2GnGG0lKPGyIv8lD u1Dw6ZoweVqLEVR5cIDaKtXJFjCx9aSEeCFjh0+FlF6w0N4RFZBqfIgU/V+l/5/Q2rHp3d AV8emDpu1AS4x2tBEMvsOZvRtxplISqLl3pmisswtnYzwjYrU69IORthfb0wBpLAUTBbvb hSjQTzhpuK2q3SQU5udlonxNETZW4SrgReUgcZQnxpUe8GOH+8umBolLPAWWuRLq3GWCm5 KE50KgE61neLmUcwcS0NYHjsnaYR2sqiQBV1hlTqW0l+bdlj3b9oVxGsWYA6ow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1669766858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5SiIziV2QvgfgWy4Sra39N19zHYZdg3yjH/6YkkoY70=; b=ZGTtwUuaLjW/reabBaeefnObjYXel7/uzUNHvxXzyRakUVdAeLKNX1mhnM9h3IWuvm3tPg PEe+iAVvZJqrbtCA== To: Jann Horn Cc: Andrei Vagin , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] time/namespace: Forbid timens page faults under kthread_use_mm() In-Reply-To: References: <20221129191839.2471308-1-jannh@google.com> <20221129191839.2471308-2-jannh@google.com> <87fse1v4rf.ffs@tglx> Date: Wed, 30 Nov 2022 01:07:37 +0100 Message-ID: <87y1rttid2.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 Tue, Nov 29 2022 at 23:28, Jann Horn wrote: > On Tue, Nov 29, 2022 at 10:18 PM Thomas Gleixner wrote: >> But the way more interesting question is: >> >> > struct page *find_timens_vvar_page(struct vm_area_struct *vma) >> > { >> > + /* >> > + * We can't handle faults where current's timens does not match the >> > + * timens associated with the mm_struct. This can happen if a page fault >> > + * occurs in a kthread that is using kthread_use_mm(). >> > + */ >> >> How does a kthread, which obvioulsy did kthread_use_mm(), end up trying to >> fault in the time namespace vvar page? > > By doing copy_from_user()? That's what kthread_use_mm() is for, right? > If you look through the users of kthread_use_mm(), most of them use it > to be able to use the normal usercopy functions. See the users in usb > gadget code, and the VFIO code, and the AMD GPU code. And if you're > doing usercopy on userspace addresses, then you can basically always > hit a vvar page - even if you had somehow checked beforehand what the > address points to, userspace could have moved a vvar region in that > spot in the meantime. > > That said, I haven't actually tried it. But I don't think there's > anything in the page fault handling path that distinguishes between > copy_from_user() faults in kthread context and other userspace faults > in a relevant way? True. >> It neither answers the obvious question why this is a problem of the >> time namespace vvar page and not a general issue versus a kthread, which >> borrowed a user mm, ending up in vdso_fault() in the first place? > > Is it a problem if a kthread ends up in the other parts of > vdso_fault() or vvar_fault()? From what I can tell, nothing in there > except for the timens stuff is going to care whether it's hit from a > userspace fault or from a kthread. > > Though, looking at it again now, I guess the `sym_offset == > image->sym_vvar_page` path is also going to misbehave, so I guess we > could try to instead make the vdso/vvar fault handlers bail out in > kthread context for all the architectures, since we're only going to > hit that if userspace is deliberately doing something bad... Deliberately or stupdily, does not matter. But squashing the problem right at the entry point is definitely the better than making it a special case of timens. >> None of those VDSO (user space) addresses are subject to be faulted in >> by anything else than the associated user space task(s). > > Are you saying that it's not possible or that it doesn't happen when > userspace is well-behaved? My subconcious self told me that a kthread won't do that unless it's buggered which makes the vdso fault path the least of our problems, but thinking more about it: You are right, that there are ways that the kthread ends up with a vdso page address.... Bah! Still my point stands that this is not a timens VDSO issue, but an issue of: kthread tries to fault in a VDSO page of whatever nature. Thanks, tglx