Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4759193ybb; Tue, 14 Apr 2020 13:34:33 -0700 (PDT) X-Google-Smtp-Source: APiQypIMXeAUDMI9ywhZFAFu5JL130AiSnw3O0uT4xZMFTMCzdJww/8zK6cv4CJIl7vdcIn8noIj X-Received: by 2002:a17:906:3e52:: with SMTP id t18mr1865494eji.204.1586896473636; Tue, 14 Apr 2020 13:34:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586896473; cv=none; d=google.com; s=arc-20160816; b=nZcgLOgfAolrp5GO9OjciQOrb/kREe7mZKkxDqddR3rgRZ3tHoNb5A4T3cZnqoEOu4 qJ1UhG4W618Ybk+6iBPpW5P2Lr00+1b3C30tF6lYWFFvz9jp4JYfEBfrRlEChzkpNSTq 3Dxbe74/4HKKXOFgEfTaFxg11Ixl2di3XQAsQrmgtaL19LWX1+UzcyIVyA7CzGNjfbU6 nHqDqhftQSAiGysWN36Ff6SKqx79B9Vb+DsO0e/h40kJWtzlI82AkRW8ZCN5NBQipEaj M+oHW0iBIxObn/XEqS6HmnjGSlsN9aOqfTcM9R0nscrOK+8EfqxabDGfk9dtWp3Hichz jwiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:ironport-sdr:ironport-sdr; bh=jmEXcVkx9q8x9EmOfqVD1Hd1lLs5RhNt3orYMWTnI00=; b=mfTwP88irLEdhnKxMZKB0+uOIP7rk7o5E2oiQaTePTzQY9boomAw4YWO6fHK52rn3H ANYWCGqABL2Pmk0iPMp+Q78s1qmRyMvNf45VACXOxSa81Vptbl2mJQGPr+ZBwck2QGUS tfwYBu1uRMOZt1b9RFPXSViFzlhDkh/VjeZtNm2WMVeDrRkrlUBuTa7sODKLxZ3V6xew hw9IsUcsd4T6XGybIkoyKmqO3GOybykWBm+LEMHQ3pEWPzpbAggY1VacOzvvBS4akjC1 8WVRKjaJhvIxfNp8TkBHBhc+0LV9LEhP3ET1T31q30j90uxh203EUwrsPhnQ6QJWMBRL ePsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r28si4125545edi.545.2020.04.14.13.34.06; Tue, 14 Apr 2020 13:34:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731594AbgDMQan (ORCPT + 99 others); Mon, 13 Apr 2020 12:30:43 -0400 Received: from mga12.intel.com ([192.55.52.136]:5348 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731587AbgDMQam (ORCPT ); Mon, 13 Apr 2020 12:30:42 -0400 IronPort-SDR: 0UjSJ/RMfCiNIX0Hh3JAdOmfgE0+nvpvGr9R1lCZzMTkujWXkRbXhHGq7f+xKllFwPbD+NdFmR YrQ68/LQiEnQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2020 09:30:42 -0700 IronPort-SDR: YrPaTfiJBoTLNJE0b55d6fX275Obm/Ipg/2Y6SdKePOLQjN8gmg8/wMGZv8V3anyfg+1V056T+ 3SYUxrodWw1Q== X-IronPort-AV: E=Sophos;i="5.72,378,1580803200"; d="scan'208";a="256226157" Received: from rchatre-mobl.amr.corp.intel.com (HELO [10.254.108.87]) ([10.254.108.87]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Apr 2020 09:30:41 -0700 Subject: Re: linux-5.7-rc1/tools/testing/selftests/resctrl/cqm_test.c:89:15: error: Buffer is accessed out of bounds To: David Binderman , "fenghua.yu@intel.com" , "shuah@kernel.org" , Linux Kernel Mailing List , "linux-kselftest@vger.kernel.org" , Sai Praneeth Prakhya References: From: Reinette Chatre Message-ID: Date: Mon, 13 Apr 2020 09:30:38 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +Sai On 4/13/2020 2:43 AM, David Binderman wrote: > Hello there, > > Source code is > > while (fgets(temp, 1024, fp)) { > > but > > char *token_array[8], temp[512]; > > Use of compiler flag -D_FORTIFY_SOURCE=2 would have found the problem. > For example: > > # include > > extern void g( int); > > void > f( FILE * fp) > { > char buf[ 100]; > > while (fgets( buf, 200, fp) != 0) > { > g( 1); > } > } > > gives > > $ /home/dcb/gcc/results/bin/gcc -c -g -O2 -D_FORTIFY_SOURCE=2 apr13c.cc > In file included from /usr/include/stdio.h:867, > from apr13c.cc:2: > In function ?char* fgets(char*, int, FILE*)?, > inlined from ?void f(FILE*)? at apr13c.cc:11:14: > /usr/include/bits/stdio2.h:263:26: warning: call to ?__fgets_chk_warn? declared with attribute warning: fgets called with bigger size than length of destination buffer [-Wattribute-warning] > > I suggest switch on compiler flag -D_FORTIFY_SOURCE=2 in > all development builds. > Thank you very much for catching this David. Sai: could you include this fix in your upcoming series of fixes? Using the pattern of "fgets(buf, sizeof(buf), ...)" instead of hard coding the size should be helpful here. Reinette