From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6534CC282DC for ; Wed, 17 Apr 2019 03:34:11 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3121821773 for ; Wed, 17 Apr 2019 03:34:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="azj7Dyic"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="MqulNFXR"; dkim=fail reason="key not found in DNS" (0-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="MwvkwFPe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3121821773 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=eAIdair6pDaW4U+XNG4YHKjqJpUX/4SSoazRz4XynRc=; b=azj7Dyic4OwmzrY9zz7oJabww jrns9ZZ73JWaFwcXDwyGNuwhIPChC3WHyEWCgvfSfNkDurhFu+B/Z4KxNEu+/EfwZ56SJawe4N6Jm cNuic2/C1Y/+mYlpghSmLdcu/R/UbG5uq/CeqcrXeY/4/fd7cSPGvu0e4Kt6VSBqBjX16BVDo4e1s 6lkzBbGDHdsekuFWxGaqLkwtrYtKVAwln1vS1UsR9BHNf0bEBkZfsu1k4L4A1QnjRHJ8Rqu11b4Z4 TOY32mdD2on7kZwEJXXCSxY6CIaDNcTHw9NK1RcpJUXJKeiXUTbt3z/0tALqENGQC1TWK9BIatFj2 xa2eID9DA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGbKp-0006uT-Dc; Wed, 17 Apr 2019 03:34:07 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGbKm-0006uA-Lv for linux-arm-kernel@lists.infradead.org; Wed, 17 Apr 2019 03:34:06 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5AAD461154; Wed, 17 Apr 2019 03:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1555472043; bh=PzgmwJfnMi4Kpa1Xk54pqu2dCmWAYIrQ7kjuXbx9PGg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=MqulNFXRrPriMCrU0qyBy3lo67fT3BtQ+v1sZR6u1P9fCAMxqncsUH1PTu1Lnamwz R1z340Pyh2cY60ulbDGjq9xzojixkB+OOitVGUcQvxz04Vl7STelUbWekoudDZsBCu 0YC1oC8uxUPRjSJvQs4jEW0RJZVDq1sru1ekguU8= Received: from [10.79.128.26] (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: saiprakash.ranjan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 03E3660CF0; Wed, 17 Apr 2019 03:33:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1555472042; bh=PzgmwJfnMi4Kpa1Xk54pqu2dCmWAYIrQ7kjuXbx9PGg=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=MwvkwFPeOlhLD9sOV64latcnXfRh2YTGBeH26aTcra73sgUTCforqYFlBHTTeiz5z JPcT5ceb0wOkt+xy6DQNl2GZUZ6J3BSNZlWoR55XX51ktgFkvCnDtpbM8ciG3MSCG9 8s9P5dqSvzXJId/2LXGJiPHAR1B/FBWbEGDAJV5w= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 03E3660CF0 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=saiprakash.ranjan@codeaurora.org Subject: Re: [PATCH] stm class: Fix out of bound access from bitmap allocation To: Alexander Shishkin , Greg Kroah-Hartman , Mulu He , David Laight , Tingwei Zhang , Maxime Coquelin , Alexandre Torgue , linux-stm32@st-md-mailman.stormreply.com, Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan References: <20190405122256.27840-1-saiprakash.ranjan@codeaurora.org> <87mukqc7v8.fsf@ashishki-desk.ger.corp.intel.com> From: Sai Prakash Ranjan Message-ID: Date: Wed, 17 Apr 2019 09:03:54 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <87mukqc7v8.fsf@ashishki-desk.ger.corp.intel.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_203404_751929_07B9294E X-CRM114-Status: GOOD ( 21.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rajendra Nayak , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Sibi Sankar , Vivek Gautam , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 4/16/2019 8:30 PM, Alexander Shishkin wrote: > Sai Prakash Ranjan writes: > >> From: Mulu He >> >> Bitmap allocation works on array of unsigned longs and >> for stm master allocation when the number of software >> channels is 32, 4 bytes are allocated and there is a out of >> bound access at the first 8 bytes access of bitmap region. > > Does the below fix the problem for you? > > From fb22b9ab109b332e58d72df13563e270befbd0e3 Mon Sep 17 00:00:00 2001 > From: Alexander Shishkin > Date: Tue, 16 Apr 2019 17:47:02 +0300 > Subject: [PATCH] stm class: Fix channel bitmap on 32-bit systems > > Commit 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace > Module devices") naively calculates the channel bitmap size in 64-bit > chunks regardless of the size of underlying unsigned long, making the > bitmap half as big on a 32-bit system. This leads to an out of bounds > access with the upper half of the bitmap. > > Fix this by using BITS_TO_LONGS. While at it, convert to using > struct_size() for the total size calculation of the master struct. > > Signed-off-by: Alexander Shishkin > Fixes: 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices") > Reported-by: Mulu He > Cc: stable@vger.kernel.org # v4.4+ > --- > drivers/hwtracing/stm/core.c | 6 ++---- > 1 file changed, 2 insertions(+), 4 deletions(-) > > diff --git a/drivers/hwtracing/stm/core.c b/drivers/hwtracing/stm/core.c > index 5b5807cbcf7c..8c45e79e47db 100644 > --- a/drivers/hwtracing/stm/core.c > +++ b/drivers/hwtracing/stm/core.c > @@ -166,11 +166,9 @@ stm_master(struct stm_device *stm, unsigned int idx) > static int stp_master_alloc(struct stm_device *stm, unsigned int idx) > { > struct stp_master *master; > - size_t size; > > - size = ALIGN(stm->data->sw_nchannels, 8) / 8; > - size += sizeof(struct stp_master); > - master = kzalloc(size, GFP_ATOMIC); > + master = kzalloc(struct_size(master, chan_map, BITS_TO_LONGS(stm->data->sw_nchannels)), > + GFP_ATOMIC); > if (!master) > return -ENOMEM; > > ++ David Yes it does fix the issue. Actually initial fix internally was using BITS_TO_LONGS, don't no why they deferred from it. Anyways thanks for the patch. - Sai -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel