Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2174282ybm; Thu, 23 May 2019 12:34:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjPGE06zxt6JOFO7Y4ZXc5KFKScEu4epobiO7fsyj78gMHn12T61kZpxNdT8iAv3r9I8eF X-Received: by 2002:a17:90a:ae10:: with SMTP id t16mr3700130pjq.51.1558640080309; Thu, 23 May 2019 12:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640080; cv=none; d=google.com; s=arc-20160816; b=Uk+QSgsztU3HZWl/x1F92gYiPazJfn8aKgPaOriEk1YBEq7XnDa3HkB/ds6mjWIv74 p053JARUXb6JuIdVe5x8oGMz7dy6+0gkE+uh6x7xGI/tebkRtbbW7HWdUv+Hh7rewGMJ O5GF5gD+NYwiDqRY2tOtiHphmTy40pfJq8SfO3ItY/newkTQ4/L9wkkYuZYrBYPoW5LK ysiwzMUd71bWPOvFRG5HHVqOd676tuOeC4pEI+G9Nrn0Hs/A7VlRNL2UDup5qyOxsGHi StY8cIAWPGcQ9QtjDneQ7qNuhCvkgdVd4NYccNYxA8hyh32FYSE5tHwYlT/3uWw5iqEx krzg== 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=M+vypwm/+whpVDUmdTVSkcU7YaIGjGUVbRBmvgdWrj8=; b=g+NvtGBXcQYoQuiQKQe8WEta4hnxA5sf3c8Z4U3ipkYjS/vES8gy1CyU41CoFNGtf/ FNYA2llQ1FDhr8gK52AYUqOEAHz7qc/zUHdkFZ5nmsbG3byN/wnlyyn9ZGp5fF5u5s4M huV+cM5WGy0Boz3uRrr85XdRbUx4UZ5J1TWFQVfgYltxXTSy0vm5Ihf3NNZYyVEUSHZE 3hRvYrUKJgictVbuos9oaaviSgwBGQw6ObKSJduZ1weRscQbbFWUChgjfRi1zokZiJMS xicLnOx5u/RlLhrKk46B5PNu2w3CMrllZyRtCFYI7fFSSU5JJ1bI+zuU0Q01Fb8eRh4H 5FFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="n8zDyE/b"; 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 h4si307309pjs.103.2019.05.23.12.34.24; Thu, 23 May 2019 12:34:40 -0700 (PDT) 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="n8zDyE/b"; 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 S2392016AbfEWTcC (ORCPT + 99 others); Thu, 23 May 2019 15:32:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:45788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403886AbfEWTb7 (ORCPT ); Thu, 23 May 2019 15:31:59 -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 79D0D2054F; Thu, 23 May 2019 19:31:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558639919; bh=q0NoChondQNBMPI/IILqxPHisepa81MuFB32CinsJs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n8zDyE/bLYpEiBg2FLAsl80sR1Kx/SsQTK8AsRNhWYmQV/8MQFLFLUxnVN+mZn1nr u9FW8LiPY/4hsCP+T5Nfe6DfDsZd2OFWFvMwawCNrAgB6xYrAv1KQr38coTlgfoZII TCTgHs/LGP+NpYgjpqIecO0J1IArCwkckqdUg86M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexander Shishkin , Mulu He Subject: [PATCH 4.19 022/114] stm class: Fix channel bitmap on 32-bit systems Date: Thu, 23 May 2019 21:05:21 +0200 Message-Id: <20190523181733.894465792@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190523181731.372074275@linuxfoundation.org> References: <20190523181731.372074275@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;