Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4662950ybb; Tue, 7 Apr 2020 11:51:49 -0700 (PDT) X-Google-Smtp-Source: APiQypLwbFTqFCmYcLasHx0sRP4rnheCgHvdJqLkGmslgKdTe1OFfzqXOJaei9RHLaGyE8UuBZWP X-Received: by 2002:a4a:c28e:: with SMTP id b14mr3045069ooq.39.1586285509621; Tue, 07 Apr 2020 11:51:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586285509; cv=none; d=google.com; s=arc-20160816; b=Clic62QZzrX2zYSkLHIX/TaUwg798g7E8SkoDdGT4I6XNSomEdISFdzx5XL7vreJq1 mXvys55MpLia8Aja+eYp4jDA/7Sq8yO8Z8BCHyfd1Ruhf7DipBvTYk8msDDU9uh878Y4 yI4jVN4aL75ams689kc+D2Uw5h8FtdvkeVrmYA1gng7d17B/S4RefSK+wCJJoajwcXXW ciAxP5t3c4YMrIKzUF4BaT5quyYVrl3T6n/5CBjtEF1/Exy5gminnXKj7zoTmOk6MJcf KPu/5Nl1rsRYJIbgrF7/SrktIxDids6iH7j2JzAIDfjojaE5T0Q44BYc7hdLKoN3ES6o AlGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Suvq4awERSu9bs80SCBq2DlNufQxhmBcC3EIi1++Fao=; b=ql6H6weyXvAqFQFHjkN6dwicpSxGuweYKh/wMFqc2W1Fz+a5BsgVZaXfjSk8riENxc 7qENxqGpPJ/vmG4M0vORMNnqWwg1wiYDFpit6cJOBpdzX4Yhm4WLydLhP42HfPkCQl11 bV9BRNnFt/mJbC/7Wb4Zwz6m4F07pwB+EYlN2EikI+kZY3S2S0Mq/61i4X2ovq6v+guM nknq9LOyBuqk44pOpJAaX8t9DHVo4xZD3n1HnngCwAOXGep+6t9+QfdXwRbLtCkrywu8 GezOza3XX1Tod+kSAcnaJ9n/gAiKOh95A94Xr1u7NeDm/KBJMv7Hfj3xt4VjSj85VXZj DVFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=EIG+NjOV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si1404289otq.313.2020.04.07.11.51.33; Tue, 07 Apr 2020 11:51:49 -0700 (PDT) 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=pass header.i=@chromium.org header.s=google header.b=EIG+NjOV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbgDGStf (ORCPT + 99 others); Tue, 7 Apr 2020 14:49:35 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37484 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726332AbgDGStf (ORCPT ); Tue, 7 Apr 2020 14:49:35 -0400 Received: by mail-pl1-f194.google.com with SMTP id x1so1578957plm.4 for ; Tue, 07 Apr 2020 11:49:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Suvq4awERSu9bs80SCBq2DlNufQxhmBcC3EIi1++Fao=; b=EIG+NjOVoVewtNoSIS22Haj7eCmbPISciyN5tPQN++I7aI2MMgHG4fM9SiURoPOZYM AUK3c58YTfua5utr1e+1lOdquYZx7xIQ8EtEyTOGA9VS7DyPBdwR0YSu03BtOSYONXvp BylB+tzgBcTby8Y2Fc2Zb9AuYrcicdNU5K5k4= 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=Suvq4awERSu9bs80SCBq2DlNufQxhmBcC3EIi1++Fao=; b=WP3cb6ETr6lORtzUjB8NUkkC5Ml35/be4/4OcVWWOLLv/R0LSD/+FIJ2GVLkkvuG+E rZqmxKXtsDiyXdlbSSAETktkriNrnzAvPBvI+RuCJtIxn9lbHGRkFectx1yKnbT/VtuJ V+QnuL/+iBWxqMTJLpVYgA9mOVMOfU4AndsNGBiAO61wGp9g5mfuHMG5Z+KruFbRT3oZ JNvQ8m+fJVIymAnpqz0goYXA/WxCAY9UbZPm4PDLVpnNcfRbLtvtesLJ73IcKECWHxZ2 5ZgMxv6TQIAJ5KOSTJJI4MvMIXtxBvBKiE5YzvYUpz8n21TSr9nZFNRVKh0+l+Q4qlH9 Simw== X-Gm-Message-State: AGi0PuYmiVJ5Z2ueCQLIk0oh/s5n1URPlyr3uRxdqxh51txD85s4gDES wTW9bq3svSKiQQdBLbEdAc7PWA== X-Received: by 2002:a17:90a:1b42:: with SMTP id q60mr833912pjq.84.1586285374402; Tue, 07 Apr 2020 11:49:34 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w29sm13725421pge.25.2020.04.07.11.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2020 11:49:33 -0700 (PDT) Date: Tue, 7 Apr 2020 11:49:32 -0700 From: Kees Cook To: Peter Zijlstra Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, hch@infradead.org, sean.j.christopherson@intel.com, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, kenny@panix.com, jeyu@kernel.org, rasmus.villemoes@prevas.dk, pbonzini@redhat.com, fenghua.yu@intel.com, xiaoyao.li@intel.com, nadav.amit@gmail.com, thellstrom@vmware.com, tony.luck@intel.com, rostedt@goodmis.org, gregkh@linuxfoundation.org, jannh@google.com, David.Laight@aculab.com, dcovelli@vmware.com, mhiramat@kernel.org Subject: Re: [PATCH 4/4] x86,module: Detect CRn and DRn manipulation Message-ID: <202004071148.DCC2365B@keescook> References: <20200407110236.930134290@infradead.org> <20200407111007.429362016@infradead.org> <202004070958.CB8A3DA71D@keescook> <20200407181325.GJ20730@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200407181325.GJ20730@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 07, 2020 at 08:13:25PM +0200, Peter Zijlstra wrote: > On Tue, Apr 07, 2020 at 10:01:04AM -0700, Kees Cook wrote: > > On Tue, Apr 07, 2020 at 01:02:40PM +0200, Peter Zijlstra wrote: > > > Since we now have infrastructure to analyze module text, disallow > > > modules that write to CRn and DRn registers. > > > > > > Signed-off-by: Peter Zijlstra (Intel) > > > --- > > > arch/x86/kernel/module.c | 21 +++++++++++++++++++++ > > > 1 file changed, 21 insertions(+) > > > > > > --- a/arch/x86/kernel/module.c > > > +++ b/arch/x86/kernel/module.c > > > @@ -266,6 +266,22 @@ static bool insn_is_vmx(struct insn *ins > > > return false; > > > } > > > > > > +static bool insn_is_mov_CRn(struct insn *insn) > > > +{ > > > + if (insn->opcode.bytes[0] == 0x0f && insn->opcode.bytes[1] == 0x22) > > > + return true; > > > > I always cringe at numeric literals. Would it be overkill to add defines > > for these (and the others that have comments next to them in 3/4)? It > > makes stuff easier to grep, etc. (e.g. we have register names in > > arch/x86/include/asm/asm.h, do we need instruction names somewhere else? > > I assume objtool has a bunch of this too...) > > objtool does not, have a peek at tools/objtool/arch/x86/decode.c Eek. > I'm not sure what the best way is here, the x86 opcode map is a > disaster. Even the mnemonic doesn't help us here, as that's just MOV :/ Yeah, I'm not sure either. I guess leave this as-is. -- Kees Cook