Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2869780rwe; Mon, 29 Aug 2022 01:30:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR6zosuQyR/pc+s8AHC74LFRcu25oifCEETY4C1LS3rQdmXDMubq25t3oe/W+XbnMGsvEFHc X-Received: by 2002:a05:6a00:e1b:b0:537:7c74:c405 with SMTP id bq27-20020a056a000e1b00b005377c74c405mr15440342pfb.43.1661761802372; Mon, 29 Aug 2022 01:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661761802; cv=none; d=google.com; s=arc-20160816; b=j8jXS1ikd5gJVLjtih3Wwe6SmQPy7MBpR1YOvXQ6jkRk2adB7qtJpVeksG9NolN0N2 tIz49ey8M5KYVwxmTYbxQWq69tfx56ZwQWY239XYXyg0Hy2xRaooFkWTvZYDaFrxa0XB 21oHZ1hyTnW+2ip3DuN5nd1C64iBqq0NnBHiqa4NmhKa7KReiDiSQuzzfOLdpSFjJPwo PVYFTG3geFGPD3Ra9BciuIzRrJOqa+zEcZeVne5Kjdlf9SDU81WE5LvYMrNXAQqt9jXg 76ETeY8oNTFxJkMA7WCwN2c8yEmbCQxBEDHYrc3XOB22bWQJ3AFJhv/3mYYKj9waFJS3 j/Cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A+xoGaw3KbiT0HCG1NLuJNiHVicFh7Q8Xp6YfseCUI8=; b=owbyPZe4KnmyXMAu5UkfcPVLy2iGBZCO56QItGuevWzQS8X7ymneLxLsRqmToftz7k 99ejcWJ6tG/ivyadX4go1yVj/+Q/1rg8c/zI1z7JMhpOoT6QCrEnTwfze8Kx52tSAdgS g//D3nb1Lv8ppA3nk8p2XZaWiBXGkuYPK+Kh3ms1Ss9Y7iGIsHUH9ztrUy4JUsYQQxUd LzG4kwlmn1LaWkE1cWq5mLdYGCesEu7htceRTMgSCVPsnO9aerS5IT7iJR54mqK0MKva L6WxJ0qz1HhVskWAQxw+sYFNPf7YRoTlJN1+A9LutJqAzmo+DRFE2WlTVqjW4mWFwEIo wkBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XUoHJHaD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c14-20020a17090a8d0e00b001fde53d5d79si754873pjo.5.2022.08.29.01.29.50; Mon, 29 Aug 2022 01:30:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XUoHJHaD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229827AbiH2IGv (ORCPT + 99 others); Mon, 29 Aug 2022 04:06:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229775AbiH2IGs (ORCPT ); Mon, 29 Aug 2022 04:06:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 488191FCD9; Mon, 29 Aug 2022 01:06:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AE45AB80D56; Mon, 29 Aug 2022 08:06:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A595C433D7; Mon, 29 Aug 2022 08:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661760404; bh=KNKGIE3bHAIRg1FhRy5svzN00TPQDw3yiZKUrgewicQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XUoHJHaDPKJowsLt/nWFKf9SxrhygruA3UBkM7z5BJy4erb6YRzwUkLkQnTFsD2ki Ctxbhn+fGLuH2Lri3qI64izeRE6/cZ5zqi0YuigMolu13Ez6iKsnVXDj9NO7PaviBm b8seh2f44G0++OAyrExhnCyu+9hXAc98XA7qDrSVhZ3wrsskKyX4h7bgqRGeWNMW5C LcaBxLO88NzGhodtRdnCih0W5WcAng5RSsBtypFZbu/JAaN0u8+fcRbUouL43mXJYk Z/EVwt2mBADRPPWhDjBwc8KEvKciLh70vMqzhUWbB1V+hGtlOSykX1ubIm31LQud+J hGh7+VFgKqLaA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1oSZnI-0007jW-3g; Mon, 29 Aug 2022 10:06:52 +0200 From: Johan Hovold To: Srinivas Kandagatla , Amol Maheshwari Cc: Greg Kroah-Hartman , Arnd Bergmann , Bjorn Andersson , Manivannan Sadhasivam , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org Subject: [PATCH 2/3] misc: fastrpc: fix memory corruption on open Date: Mon, 29 Aug 2022 10:05:30 +0200 Message-Id: <20220829080531.29681-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220829080531.29681-1-johan+linaro@kernel.org> References: <20220829080531.29681-1-johan+linaro@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The probe session-duplication overflow check incremented the session count also when there were no more available sessions so that memory beyond the fixed-size slab-allocated session array could be corrupted in fastrpc_session_alloc() on open(). Fixes: f6f9279f2bf0 ("misc: fastrpc: Add Qualcomm fastrpc basic driver model") Cc: stable@vger.kernel.org # 5.1 Signed-off-by: Johan Hovold --- drivers/misc/fastrpc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index 88091778c1b8..6e312ac85668 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1948,7 +1948,7 @@ static int fastrpc_cb_probe(struct platform_device *pdev) spin_unlock_irqrestore(&cctx->lock, flags); return -ENOSPC; } - sess = &cctx->session[cctx->sesscount]; + sess = &cctx->session[cctx->sesscount++]; sess->used = false; sess->valid = true; sess->dev = dev; @@ -1961,13 +1961,12 @@ static int fastrpc_cb_probe(struct platform_device *pdev) struct fastrpc_session_ctx *dup_sess; for (i = 1; i < sessions; i++) { - if (cctx->sesscount++ >= FASTRPC_MAX_SESSIONS) + if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) break; - dup_sess = &cctx->session[cctx->sesscount]; + dup_sess = &cctx->session[cctx->sesscount++]; memcpy(dup_sess, sess, sizeof(*dup_sess)); } } - cctx->sesscount++; spin_unlock_irqrestore(&cctx->lock, flags); rc = dma_set_mask(dev, DMA_BIT_MASK(32)); if (rc) { -- 2.35.1