Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3508253imu; Sun, 11 Nov 2018 16:43:44 -0800 (PST) X-Google-Smtp-Source: AJdET5e9QIZp8BaVpqDm7ugU8gIiR63DdXKHcgkHm61pmbcags1fTnnjI7VjCHeq3W+ul16l3zrH X-Received: by 2002:a17:902:b48b:: with SMTP id y11-v6mr9387581plr.135.1541983424113; Sun, 11 Nov 2018 16:43:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541983424; cv=none; d=google.com; s=arc-20160816; b=SikkgNx2iMRZUXA5z4rQjz0xFnxm9b9Ace7zVeOHejaZ+CxtZF+XpNdQ2EZ5ev0yj+ uMnc0C/UPn5cwUDN6S7sWkYY9rVJELaghcNUOur7wzdJ+MxnTyk1KX19GkK7B5l4XR11 8Wz664eFoAcLPU/HrNlt0mktekV6utREnY19c1Cgvwq/V0Qb/MacnnimR7DuQFiEbx03 mZXLhdNqrZTIrIP4rO0+Fm8dH7ii4x1oI7+ZKLqQ86XFBvKZCLaecPk7eKCMLGFuQhSL +JDv/GcxRVEbygKTsk6lYv6CtY+q49o6yzTGTseDyacWBfLsc5LUukuaR7kM9GE97rjf oMog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=x+V/mpkFJL350jC6rpFriOnnIh0JqQqhLM0py63U4ic=; b=IfJzWAeE3jxGG06078R5pQkgbKbnYpBqNUAf4vFqwpm2Lylr5fVI7Y4xzf1/rA3bMW N0y952BssJOizjwzryXgfko4n98dgL1BABnNcrIf4GxZGs//69bHP9USKugqSgcrx15O SkmzxkHPSz+zNcgifAG4lRUJ2vZIGs6DkdE73EPhJe4u5+WBZjrxR+qzuCZrdRC8CZLl PJ/BzxnjLapfydUApmeTuPCJWwmkefKo5NFaj8dnYXODDhGLWye0isOvY+0r/olxkjUs hhqKcWZrgbU9R+fwqn+jRA8H0vCOurGsPniXwyiXoFPsQWlgoiCSuwvtLyGdcIElqoPG srQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=u7yYS1FS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a10-v6si15512448pgf.445.2018.11.11.16.43.28; Sun, 11 Nov 2018 16:43:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=u7yYS1FS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729806AbeKLKcX (ORCPT + 99 others); Mon, 12 Nov 2018 05:32:23 -0500 Received: from merlin.infradead.org ([205.233.59.134]:35402 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726816AbeKLKcW (ORCPT ); Mon, 12 Nov 2018 05:32:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=x+V/mpkFJL350jC6rpFriOnnIh0JqQqhLM0py63U4ic=; b=u7yYS1FS0m5tLC26vNjK/hS2lC 9q48ZNVjylegLxaMQ1nOvj1YXhVLHFEl0U5qJReyGe0mCh0dJHhsgwpZoYn4uHcB6bT6SavyY6CMo q2jw28bIWDv6iRW5eh+IsLWPifcOMFU0AaTwbL19017qGryWM1KHYQo1wNs/+ekAw+Jn0nFbqipyJ kq1iSjN+d+7mQRD1CeobNKe8jY0p4Dp+RHNFIVf8vOHPDT0TfjAI5+KSJL5NOlpjoRvAFG6igiCX/ 0hjWfSdlV8iZbXj59XNoHKh71erudyVDgHWHIO6AsWVh4ZbDL7Q7bSLMSXTHZjNuxdRBTzVIWl9lS dlnRTxCw==; Received: from [64.114.255.97] (helo=worktop) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gM0IO-0004YT-To; Mon, 12 Nov 2018 00:41:41 +0000 Received: by worktop (Postfix, from userid 1000) id 326296E061A; Mon, 12 Nov 2018 01:41:40 +0100 (CET) Date: Mon, 12 Nov 2018 01:41:40 +0100 From: Peter Zijlstra To: Nadav Amit Cc: Ingo Molnar , LKML , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Andy Lutomirski , Kees Cook , Dave Hansen , Masami Hiramatsu Subject: Re: [PATCH v4 06/10] x86/alternative: use temporary mm for text poking Message-ID: <20181112004140.GF3056@worktop> References: <20181110231732.15060-1-namit@vmware.com> <20181110231732.15060-7-namit@vmware.com> <20181111145936.GA3021@worktop> <43C8C690-F079-4513-82CD-46A62DBA5A3B@vmware.com> <20181111235220.GB3056@worktop> <70EACCF7-D854-4051-9F71-4E966FD6C37B@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <70EACCF7-D854-4051-9F71-4E966FD6C37B@vmware.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 12, 2018 at 12:09:32AM +0000, Nadav Amit wrote: > > On Sun, Nov 11, 2018 at 08:53:07PM +0000, Nadav Amit wrote: > > > >>>> + /* > >>>> + * The lock is not really needed, but this allows to avoid open-coding. > >>>> + */ > >>>> + ptep = get_locked_pte(poking_mm, poking_addr, &ptl); > >>>> + > >>>> + /* > >>>> + * If we failed to allocate a PTE, fail. This should *never* happen, > >>>> + * since we preallocate the PTE. > >>>> + */ > >>>> + if (WARN_ON_ONCE(!ptep)) > >>>> + goto out; > >>> > >>> Since we hard rely on init getting that right; can't we simply get rid > >>> of this? > I understand. So the question is - what would you prefer: something like > PARANOID_WARN_ON_ONCE() or should I just remove the assertion? Something like: /* * @ptep cannot be NULL per construction in poking_init(). */ And then leave it at that. If it ever comes unstuck we'll get the NULL deref, which is just as good as a BUG_ON(). > >>>> +out: > >>>> + if (memcmp(addr, opcode, len)) > >>>> + r = -EFAULT; > >>> > >>> How could this ever fail? And how can we reliably recover from that? > >> > >> This code has been there before (with slightly uglier code). Before this > >> patch, a BUG_ON() was used here. However, I noticed that kgdb actually > >> checks that text_poke() succeeded after calling it and gracefully fail. > >> However, this was useless, since text_poke() would panic before kgdb gets > >> the chance to do anything (see patch 7). > > > > Yes, I know it was there before, and I did see kgdb do it too. But aside > > from that out-label case, which we also should never hit, how can we > > realistically ever fail that memcmp()? > > > > If we fail here, something is _seriously_ buggered. > > I agree. But as it may be useful at least to warn in such a case, as > debugging of SMC/CMC is hard. For example, if there is some sort of a race > between module (un)loading and static-keys - such a check might be > beneficial to indicate so. Having said that, changing it into VM_BUG_ON() or > something similar may make more sense. > > Personally, I don’t care much - I’m just worried that I made some intrusive > changes *and* you want me to remove the assertion that checks that I didn’t > screw up. Ah, so I'm perfectly fine with something like: VM_BUG_ON(memcmp()); I just don't see value in the whole return code here. If this comes unstuck, we're buggered beyond repair.