From patchwork Tue Dec 22 15:25:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Shishkin X-Patchwork-Id: 58935 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp3303230lbb; Tue, 22 Dec 2015 07:26:51 -0800 (PST) X-Received: by 10.98.75.10 with SMTP id y10mr36565254pfa.86.1450798011756; Tue, 22 Dec 2015 07:26:51 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13si3893277pas.128.2015.12.22.07.26.49; Tue, 22 Dec 2015 07:26:51 -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; 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 S1755037AbbLVP0a (ORCPT + 29 others); Tue, 22 Dec 2015 10:26:30 -0500 Received: from mga14.intel.com ([192.55.52.115]:62933 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754898AbbLVPZx (ORCPT ); Tue, 22 Dec 2015 10:25:53 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 22 Dec 2015 07:25:53 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,464,1444719600"; d="scan'208";a="876833080" Received: from um.fi.intel.com (HELO localhost) ([10.237.72.212]) by orsmga002.jf.intel.com with ESMTP; 22 Dec 2015 07:25:51 -0800 From: Alexander Shishkin To: Greg KH Cc: linux-kernel@vger.kernel.org, Chunyan Zhang , Alexander Shishkin Subject: [PATCH v3 6/9] stm class: Fix an off-by-one in master array allocation Date: Tue, 22 Dec 2015 17:25:20 +0200 Message-Id: <1450797923-23072-7-git-send-email-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1450797923-23072-1-git-send-email-alexander.shishkin@linux.intel.com> References: <1450797923-23072-1-git-send-email-alexander.shishkin@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chunyan Zhang Since both sw_start and sw_end are master indices, the size of array that holds them is sw_end - sw_start + 1, which the current code gets wrong, allocating one item less than required. This patch corrects the allocation size, avoiding potential slab corruption. Signed-off-by: Chunyan Zhang [alexander.shishkin@linux.intel.com: re-wrote the commit message] Signed-off-by: Alexander Shishkin --- drivers/hwtracing/stm/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- 2.6.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index ddcb606ace..40a8b79ab7 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -618,7 +618,7 @@ int stm_register_device(struct device *parent, struct stm_data *stm_data, if (!stm_data->packet || !stm_data->sw_nchannels) return -EINVAL; - nmasters = stm_data->sw_end - stm_data->sw_start; + nmasters = stm_data->sw_end - stm_data->sw_start + 1; stm = kzalloc(sizeof(*stm) + nmasters * sizeof(void *), GFP_KERNEL); if (!stm) return -ENOMEM;