Return-Path: Received: from mail.kernel.org ([198.145.29.99]:47862 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727502AbeLSTVy (ORCPT ); Wed, 19 Dec 2018 14:21:54 -0500 Date: Wed, 19 Dec 2018 20:21:51 +0100 From: Greg Kroah-Hartman To: Alexander Shishkin Cc: Mathieu Poirier , linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2 3/3] intel_th: msu: Fix an off-by-one in attribute store Message-ID: <20181219192151.GA4413@kroah.com> References: <20181219151922.44839-1-alexander.shishkin@linux.intel.com> <20181219151922.44839-4-alexander.shishkin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181219151922.44839-4-alexander.shishkin@linux.intel.com> Sender: stable-owner@vger.kernel.org List-ID: On Wed, Dec 19, 2018 at 05:19:22PM +0200, Alexander Shishkin wrote: > The 'nr_pages' attribute of the 'msc' subdevices parses a comma-separated > list of window sizes, passed from userspace. However, there is a bug in > the string parsing logic wherein it doesn't exclude the comma character > from the range of characters as it consumes them. This leads to an > out-of-bounds access given a sufficiently long list. For example: > > > # echo 8,8,8,8 > /sys/bus/intel_th/devices/0-msc0/nr_pages > > ================================================================== > > BUG: KASAN: slab-out-of-bounds in memchr+0x1e/0x40 > > Read of size 1 at addr ffff8803ffcebcd1 by task sh/825 > > > > CPU: 3 PID: 825 Comm: npktest.sh Tainted: G W 4.20.0-rc1+ > > Call Trace: > > dump_stack+0x7c/0xc0 > > print_address_description+0x6c/0x23c > > ? memchr+0x1e/0x40 > > kasan_report.cold.5+0x241/0x308 > > memchr+0x1e/0x40 > > nr_pages_store+0x203/0xd00 [intel_th_msu] > > Fix this by accounting for the comma character. Ugh, this is one major reason sysfs files are "one value per file". You should never have to "parse" a sysfs file for something like this. It's a bit too late now, but please, never create such a sysfs file again :( greg k-h