Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp648424imu; Fri, 11 Jan 2019 06:46:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN4uWr9B+NJRC7lw9gGxpUstpHp/m9+4X0yQEIBkAgjecpqBH8Bh/O08Jvf618BXlXnyVMlo X-Received: by 2002:a63:8d44:: with SMTP id z65mr3570703pgd.57.1547218012209; Fri, 11 Jan 2019 06:46:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547218012; cv=none; d=google.com; s=arc-20160816; b=iZWvLSt5jJPHTQe9pSFo4GQLx1CP4vfa7cSyumvev7uqGD9bdcoIU5pObDScSOVo4C TGcwGGreL/tZ1XjoiCIPLOHOv+DrDhM4y5NI3ZrZHlS8SvO3cHlXPw9KnQ/SyIGvWlt9 bMzFHUrWO86U18PJ8yVyKl9KVUQTyBfixn/RdGhWj9eALNrcEKBLv2rbaHGldImMjSr/ Rs0xJmB+sQx4bwydgAN49STXzjuuLxwxZEWhCwmqCgMj39VyEWSY0KhtIvx+fFVPAG9G s/w5ozGb9GjtiWUODz/xgkV8F0E6Rdq0LNom2HfKIiw8gZbyLxngO+AhVsq3bi4dWHge Ptkw== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EOmKhVV6iCo8DfA82ZZT0p2alm8V7IiSXWfcWGfvPDg=; b=q2dtFFSWJbtYfYo1LgLuuwAO3oZFVYEIritLdoKGzqSWxZLL46dx0TwkxVmpO0DyUx 1cIHC/RFTpzXYqTrMYID3g5rnlp4RpLe1FCWfY6ehuDTZVqkKi/Pv/vU6tfLXbXQEaI7 nHzh8gCAqcUgjfVCNzkN3EOZCm6HcEw9O+OQ/tcmDY6LW9DkYCiHletZhfMJYiYJSlRj 45qcgyzBsmL4jxRxgoIJJDQBUr+WL5CQEIqardl46S0J0jGs+qGDG/jYl0o3Q7eBr/qm Ez6AOLiePVn3oPMrE9d77i/fL8LrA1X5kS3VfVmz23VREBKymdvq4ugAlh3WkHlfj/Ni 74gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1dcoW7Rw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 39si17856349pla.352.2019.01.11.06.46.36; Fri, 11 Jan 2019 06:46:52 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1dcoW7Rw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404506AbfAKOn4 (ORCPT + 99 others); Fri, 11 Jan 2019 09:43:56 -0500 Received: from mail.kernel.org ([198.145.29.99]:36868 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404489AbfAKOnz (ORCPT ); Fri, 11 Jan 2019 09:43:55 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EACD020872; Fri, 11 Jan 2019 14:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547217834; bh=I5T0Zb/ZNJzGUgTjEGRCOozK+54Jmx3qq2UcA454X+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1dcoW7Rw77AeuXWWS4l9B/o0oSSQQ3IURbkjc/RQjoF0u/3Ftuxgay/lHPzxKj2Yf UOybuAaPbx7XJd77+ex72d/rD5ktNYqEKyj1h8YKN5Mah6OSXXc/8Mi86wP3P0MSF8 ZqSUKbmoYUhJhi1Mnu8t9smtYuL55ZmMPrZaD/rs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Shishkin Subject: [PATCH 4.20 58/65] intel_th: msu: Fix an off-by-one in attribute store Date: Fri, 11 Jan 2019 15:15:44 +0100 Message-Id: <20190111131103.899942834@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190111131055.331350141@linuxfoundation.org> References: <20190111131055.331350141@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alexander Shishkin commit ec5b5ad6e272d8d6b92d1007f79574919862a2d2 upstream. 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. Signed-off-by: Alexander Shishkin Fixes: ba82664c134ef ("intel_th: Add Memory Storage Unit driver") Cc: stable@vger.kernel.org # v4.4+ Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/intel_th/msu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/hwtracing/intel_th/msu.c +++ b/drivers/hwtracing/intel_th/msu.c @@ -1423,7 +1423,8 @@ nr_pages_store(struct device *dev, struc if (!end) break; - len -= end - p; + /* consume the number and the following comma, hence +1 */ + len -= end - p + 1; p = end + 1; } while (len);