From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756300AbdKOIlM (ORCPT ); Wed, 15 Nov 2017 03:41:12 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:44318 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754189AbdKOIlE (ORCPT ); Wed, 15 Nov 2017 03:41:04 -0500 X-Google-Smtp-Source: AGs4zMYEVsx8rKXGS76g6jTB3SFmF+DRWktXBlnbLZFnkaf4IJEIm5m8Eu2dbE82pNRbv9yFkmZPrA== Date: Wed, 15 Nov 2017 09:41:00 +0100 From: Ingo Molnar To: Ricardo Neri 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: <20171115084100.lkzww5e56asjtkyy@gmail.com> 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> <20171115025603.GB10377@voyager> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171115025603.GB10377@voyager> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Ricardo Neri wrote: > > > + 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. This is still very fragile. The right solution would be to make umip_pr_warn() a varargs helper function, so that you can just use it to print things the usual way. I'd also use a __attribute__((format(printf))) specification to get good build-time warnings. Thanks, Ingo