From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932713AbbLVP2r (ORCPT ); Tue, 22 Dec 2015 10:28:47 -0500 Received: from mga02.intel.com ([134.134.136.20]:36316 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755180AbbLVP2D (ORCPT ); Tue, 22 Dec 2015 10:28:03 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,464,1444719600"; d="scan'208";a="876834109" From: Alexander Shishkin To: Greg KH Cc: linux-kernel@vger.kernel.org, Alexander Shishkin Subject: [PATCH v3 7/9] stm class: Prevent user-controllable allocations Date: Tue, 22 Dec 2015 17:25:21 +0200 Message-Id: <1450797923-23072-8-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 List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the character device write method allocates a temporary buffer for user's data, but the user's data size is not sanitized and can cause arbitrarily large allocations via kzalloc() or an integer overflow that will then result in overwriting kernel memory. This patch trims the input buffer size to avoid these issues. Reported-by: Sasha Levin Signed-off-by: Alexander Shishkin --- drivers/hwtracing/stm/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c index 40a8b79ab7..aef8ddb244 100644 --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -406,6 +406,9 @@ static ssize_t stm_char_write(struct file *file, const char __user *buf, char *kbuf; int err; + if (count + 1 > PAGE_SIZE) + count = PAGE_SIZE - 1; + /* * if no m/c have been assigned to this writer up to this * point, use "default" policy entry -- 2.6.4