From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754663AbbE0TRA (ORCPT ); Wed, 27 May 2015 15:17:00 -0400 Received: from smtprelay0024.hostedemail.com ([216.40.44.24]:39024 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754637AbbE0TQx (ORCPT ); Wed, 27 May 2015 15:16:53 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:960:968:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2110:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3167:3353:3622:3865:3867:3868:3870:3872:3874:4250:4321:5007:6142:6143:6261:6742:7903:10004:10400:10848:11026:11232:11473:11657:11658:11914:12043:12296:12438:12517:12519:12555:12740:13069:13138:13231:13311:13357:21080:21088,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0 X-HE-Tag: trip30_1e5c2cd6c8e41 X-Filterd-Recvd-Size: 2982 Message-ID: <1432754207.2846.162.camel@perches.com> Subject: Re: [tip:x86/cpu] x86/cpu: Strip any /proc/ cpuinfo model name field whitespace From: Joe Perches To: Borislav Petkov Cc: luto@amacapital.net, peterz@infradead.org, dvlasenk@redhat.com, torvalds@linux-foundation.org, imammedo@redhat.com, brgerst@gmail.com, mingo@kernel.org, prarit@redhat.com, dave.hansen@linux.intel.com, fenghua.yu@intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@suse.de, linux-tip-commits@vger.kernel.org Date: Wed, 27 May 2015 12:16:47 -0700 In-Reply-To: <20150527190626.GC19407@pd.tnic> References: <1432050210-32036-1-git-send-email-prarit@redhat.com> <1432628901-18044-15-git-send-email-bp@alien8.de> <1432746454.2846.154.camel@perches.com> <20150527190626.GC19407@pd.tnic> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.12.11-0ubuntu3 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2015-05-27 at 21:06 +0200, Borislav Petkov wrote: > On Wed, May 27, 2015 at 10:07:34AM -0700, Joe Perches wrote: > > This code can memmove from beyond the x86_model_id field. > > ... in the theoretical case where some model ID has more than 64 - 48 > preceding white spaces. > > I guess we want to be prepared here for insane CPU model IDs coming from > virtualization. > > > Maybe: > > char *model = strim(c->x86_model_id); > > memmove(c->x86_model_id, model, strlen(model) + 1); > > Yes, and additionally limit that string length: > > --- > diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c [] > @@ -383,6 +383,9 @@ static const struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; > static void get_model_name(struct cpuinfo_x86 *c) > { > unsigned int *v; > + const char *model; > + > +#define MODEL_ID_MAXLEN 48 > > if (c->extended_cpuid_level < 0x80000004) > return; > @@ -391,13 +394,15 @@ static void get_model_name(struct cpuinfo_x86 *c) > cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]); > cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]); > cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]); > - c->x86_model_id[48] = 0; > + c->x86_model_id[MODEL_ID_MAXLEN] = 0; > > /* > * Remove leading whitespace on Intel processors and trailing > * whitespace on AMD processors. > */ > - memmove(c->x86_model_id, strim(c->x86_model_id), 48); > + model = strim(c->x86_model_id); > + > + memmove(c->x86_model_id, model, strnlen(model, MODEL_ID_MAXLEN) + 1); I don't see any value in the #define or strnlen over strlen as it's guaranteed terminated by the = 0 above, but thanks. cheers, Joe