Received: by 2002:a25:86ce:0:0:0:0:0 with SMTP id y14csp2183264ybm; Thu, 23 May 2019 12:44:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwy//ybtlTXV+hU+pEkIpinMPxFxTEVmx4HxLEuTT4S79ETcST65Zky+vElgOS2paR5X1cx X-Received: by 2002:a17:90a:dd45:: with SMTP id u5mr3647961pjv.109.1558640644642; Thu, 23 May 2019 12:44:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558640644; cv=none; d=google.com; s=arc-20160816; b=Ex3GXDvHQhtyBpuU+FcnUWZAa5IT8JsNnggp0GpJQP/gz/7wF5z672adnMXbBZFcvR WZGRWSserBtJw6N8rbgSoLCr5Rc5D249p56OiL0xXiYOKYLa6Zgt0nK1uO8XGvuZ/0TK euJ4FIrCEHcf0T6jsxlmweCYvS1u/7j6Iw/EFX1xFsVprdQ2qwFGO7DYcxzFWBw6sVJ7 WAQqW/GSoS2uyh9qdjjV+gGH15vbCkwnXABf2S+dXNGvPe2qxG+/cbTmXgYP/i1kIrEu dZUjcFzOBMzsBPlVbD05Vg9Jj3jqbP1Qd40+9TSDGrI0yj70b5CKwQ44eZ8aRNxtHOJC +ihg== 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=nv0Oq0kyTzVu+7zMESUKw+J7u9dPh4g+CesOrj2RRSP+/vZIqWdyZI6ZAEqjKL8l68 lKLdt1J5f6737WdvfWEIWx3vWm18Qu2RPF70jnZGZ6DGNRWvCNJdv89kpYz6L95ns5DL A2vgUfS0dua1QAOwsIHX+s2SOKeoLIuAf8OwXUOZeG4zrUq/LHlLeo4BrJT6z2vlXAV7 Jw4v45vmNL23YTmxIZVfWlVIHebL0Jy8PDM07ratPYOeFPdSjo1wHyY1He/rcdpfGBtP vjTyUXiqrQbojY4VCaue98JqlvbO5L6yoUr3zJzzyLu4JWea/14PE9CHg4jmwyQ/58z3 6CAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SR6wh2AD; 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 x21si535535pll.85.2019.05.23.12.43.49; Thu, 23 May 2019 12:44:04 -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=SR6wh2AD; 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 S2390729AbfEWTlA (ORCPT + 99 others); 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;