From nobody Mon Sep 8 08:44:18 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBABBC6FA89 for ; Tue, 13 Sep 2022 15:05:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235189AbiIMPFb (ORCPT ); Tue, 13 Sep 2022 11:05:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235218AbiIMPDh (ORCPT ); Tue, 13 Sep 2022 11:03:37 -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 5D1EA2725; Tue, 13 Sep 2022 07:29:32 -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 3F921B80F97; Tue, 13 Sep 2022 14:27:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D4BCC433D6; Tue, 13 Sep 2022 14:27:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079234; bh=WuC1rQF3W9/vxLyB8Fdq9aPmEjSav70ng3fgW4s7m0Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rD/e3fDyHl8YJOdFAbgo0DFxOkIMX07GFb3KPfTvUf+P34VCkSgGrGDRsCD4hEG+Z sxgmgXaUFBMBoezHgwtqK1K4DmyqAIBVZBJmOgx0T28dQLrXFYdet79GwV+26qna0Q 3E4Rxd9ILDhpf9z5uj24LRzqEN0TCK9IPkzrPqCY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 5.4 029/108] misc: fastrpc: fix memory corruption on open Date: Tue, 13 Sep 2022 16:06:00 +0200 Message-Id: <20220913140354.895626796@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Johan Hovold commit d245f43aab2b61195d8ebb64cef7b5a08c590ab4 upstream. 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 mode= l") Cc: stable@vger.kernel.org # 5.1 Signed-off-by: Johan Hovold Link: https://lore.kernel.org/r/20220829080531.29681-3-johan+linaro@kernel.= org Signed-off-by: Greg Kroah-Hartman --- drivers/misc/fastrpc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1362,7 +1362,7 @@ static int fastrpc_cb_probe(struct platf spin_unlock_irqrestore(&cctx->lock, flags); return -ENOSPC; } - sess =3D &cctx->session[cctx->sesscount]; + sess =3D &cctx->session[cctx->sesscount++]; sess->used =3D false; sess->valid =3D true; sess->dev =3D dev; @@ -1375,13 +1375,12 @@ static int fastrpc_cb_probe(struct platf struct fastrpc_session_ctx *dup_sess; =20 for (i =3D 1; i < sessions; i++) { - if (cctx->sesscount++ >=3D FASTRPC_MAX_SESSIONS) + if (cctx->sesscount >=3D FASTRPC_MAX_SESSIONS) break; - dup_sess =3D &cctx->session[cctx->sesscount]; + dup_sess =3D &cctx->session[cctx->sesscount++]; memcpy(dup_sess, sess, sizeof(*dup_sess)); } } - cctx->sesscount++; spin_unlock_irqrestore(&cctx->lock, flags); rc =3D dma_set_mask(dev, DMA_BIT_MASK(32)); if (rc) {