From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757226AbdKOC5D (ORCPT ); Tue, 14 Nov 2017 21:57:03 -0500 Received: from mga02.intel.com ([134.134.136.20]:38026 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756545AbdKOC4w (ORCPT ); Tue, 14 Nov 2017 21:56:52 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,398,1505804400"; d="scan'208";a="7766801" Date: Tue, 14 Nov 2017 18:56:03 -0800 From: Ricardo Neri To: Ingo Molnar Cc: Thomas Gleixner , "H. Peter Anvin" , Borislav Petkov , Andy Lutomirski , Tony Luck , Paolo Bonzini , "Ravi V. Shankar" , x86@kernel.org, ricardo.neri@intel.com, linux-kernel@vger.kernel.org Subject: Re: [RESEND PATCH v2 4/4] x86/umip: Warn if UMIP-protected instructions are used Message-ID: <20171115025603.GB10377@voyager> References: <1510640985-18412-1-git-send-email-ricardo.neri-calderon@linux.intel.com> <1510640985-18412-5-git-send-email-ricardo.neri-calderon@linux.intel.com> <20171114073408.tir3raeas7ouvyzp@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171114073408.tir3raeas7ouvyzp@gmail.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 14, 2017 at 08:34:08AM +0100, Ingo Molnar wrote: > > * Ricardo Neri wrote: > > > +const char * const umip_insns[5] = { > > + [UMIP_INST_SGDT] = "sgdt", > > + [UMIP_INST_SIDT] = "sidt", > > + [UMIP_INST_SMSW] = "smsw", > > + [UMIP_INST_SLDT] = "sldt", > > + [UMIP_INST_STR] = "str", > > +}; > > Sigh ... It made sense to me to capitalize code and changelogs but keep the printed warnings in lower case. Thus, the format would look like: umip: smsw instruction cannot be used by applications. I do see that this could be confusing with STR. I will capitalize these as well. > > > +/* > > + * If you change these strings, ensure that buffers using them are sufficiently > > + * large. > > + */ > > +static const char umip_warn_use[] = "cannot be used by applications."; > > +static const char umip_warn_emu[] = "For now, expensive software emulation returns result."; > > Please use the string literals directly, don't add an extra obfuscation layer. > > Plus: > > > + unsigned char buf[MAX_INSN_SIZE], warn[128]; > > > + snprintf(warn, sizeof(warn), "%s %s", umip_insns[umip_inst], > > + umip_warn_use); > > This is incredibly fragile against future buffer overflows, and warning about it > in comments does not make it less fragile! I need to concatenate the instruction mnemonic with the a string. Does something like this is more acceptable? unsigned char warn[50]; ... strcpy(warn, umip_insns[umip_inst]); strcat(warn, " instruction cannot be used by applications."); umip_pr_warn(regs, warn, 0); In this manner I use the string literal directly but I still have a buffer that might overflow. Code looks more clear to me. I could #defines for the string lengths or set a maximum length. Thanks and BR, Ricardo