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=-6.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,USER_AGENT_GIT 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 EF99BC282DD for ; Thu, 23 May 2019 19:41:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BC6F72075E for ; Thu, 23 May 2019 19:41:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558640461; bh=q0NoChondQNBMPI/IILqxPHisepa81MuFB32CinsJs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=dcKBUjaxBna55piG1Yxq0xOLvmGw/c9CjZWYA8EXlk90fgrGQS2SVAqrWh98csgwU Us1MZ+EHJOlbsBgY6rhvLNRYrfE1p3McbnrTYtdGZPV8pALTbRNlh3sJ6enDOYrWKE SJgD1qMTY8zxQUVEV6DBq4JDunPoK1ldi644Lau4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390080AbfEWTlA (ORCPT ); Thu, 23 May 2019 15:41:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:57472 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389021AbfEWTUh (ORCPT ); Thu, 23 May 2019 15:20:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 7DED820863; Thu, 23 May 2019 19:20:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639237; bh=q0NoChondQNBMPI/IILqxPHisepa81MuFB32CinsJs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SR6wh2AD8Bc2iEUX9wk7wN4hP29Tngh4msMou+qVDKJeYWfpR3WWDWj4MAePzeoL6 hhhkFV7YBQYtiZsE+fO9TeUNf1Cv0zQgYdpm1Tv7cTV2Hs/eIE+kGzD4syu5CRxs4w POKolaxa062DhpPgTSCk9A0Rv7m2CNm7b6uc8/xw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Shishkin , Mulu He Subject: [PATCH 5.0 030/139] stm class: Fix channel bitmap on 32-bit systems Date: Thu, 23 May 2019 21:05:18 +0200 Message-Id: <20190523181724.637400086@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181720.120897565@linuxfoundation.org> References: <20190523181720.120897565@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Alexander Shishkin commit 51e0f227812ed81a368de54157ebe14396b4be03 upstream. 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+ Signed-off-by: Greg Kroah-Hartman --- drivers/hwtracing/stm/core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/hwtracing/stm/core.c +++ b/drivers/hwtracing/stm/core.c @@ -166,11 +166,10 @@ stm_master(struct stm_device *stm, unsig 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;