Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4568008rwb; Tue, 6 Sep 2022 09:14:39 -0700 (PDT) X-Google-Smtp-Source: AA6agR5BJqB4JAr2VMeFJ5onZHgrASJrCh4urRYugQ0yeuw7j0IhKBPAA3INtNYEc/6CaZ7JDNBH X-Received: by 2002:a17:907:30ca:b0:750:c6f7:45e1 with SMTP id vl10-20020a17090730ca00b00750c6f745e1mr14422802ejb.357.1662480879695; Tue, 06 Sep 2022 09:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662480879; cv=none; d=google.com; s=arc-20160816; b=U7II8eoY/tDtoVivs4WIAe4Bg6NBpm5TRW7ZMGs9ZS2VKMFm0DIUGKyKp9zRt6PwjW wDq89VgaeB0fdJjkk+qbpqdXrwOQOnneT1JM79MXxPAzxUNho08YG6ptGdhLCRVyj2Yy dNyORH4+PLM9tGldOsiBj3hYr8feLuNqE5VhXI5SZ9GeC2k/HgxmqZJU9IRn9R2OPx3U avdK7S608F7bgCBZVF5XPw/bQY29WaTtWDKBh1N81dvdQKsYIZ/bY/rrlVcr9fww8LGJ tb0TaB5agHhLkSpzq9C0tFOIJhqSbmwUmJdXetrHhAWOgr0e4v6rUTZaeYosg7cXfR11 z8dA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=an7dSERt/26EhqJItidiLtXBtzxGtN+5LT5ve0hOJK0=; b=bkT3aL8GgFxmBOF/OEon8zwBMp3/B2zufFHlRpdumVVqr0WcLukfmltGykYvRkTmBy S8zxDg06PlHRpTZSNKH9nhoTWzrzL6K51+mAFUxanmHQvtAsoLlOKl3XEn72mmW5rAp/ NWOR9mXSsmnmskMms22y0WU4ZBMygRIAsRX66PJeAR55MVEDVQ+kMk/Js9KvMDRFQeMG ABLx63t2OI/5e22/njV79jfBR9tGXhzKU6FTK5kTFPYa13EwSx0JCraNiGOaU6eDsM7r UvFCNrGoRU1TSFxE1hIDgsYPbmhoNSzbYvxBVeYvrDsoK3Ki2c4kqn54+OeVrokbh1of IekA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=s+haFtz3; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w5-20020a056402268500b0043e76d36437si10979745edd.27.2022.09.06.09.14.13; Tue, 06 Sep 2022 09:14:39 -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=@linuxfoundation.org header.s=korg header.b=s+haFtz3; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242172AbiIFOvH (ORCPT + 99 others); Tue, 6 Sep 2022 10:51:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239092AbiIFOum (ORCPT ); Tue, 6 Sep 2022 10:50:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11994A260C; Tue, 6 Sep 2022 07:07:51 -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 dfw.source.kernel.org (Postfix) with ESMTPS id D04B761557; Tue, 6 Sep 2022 13:46:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFD11C433C1; Tue, 6 Sep 2022 13:46:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471974; bh=qi279q5RAq2VFb7xHmWu8Mea+WWb0KcBgfWZrnBh1Dk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+haFtz3lcB6WK0KOcrhER71E8rBw21m52j1j11OaZQKV3mi39FFPviUfkJJOGNbr Bg5O/VVT3QX0oKJPYKfloLGFXt3AgqHstXD7WmBlmputKEclM2gTQhuE1/Zpdfbj3d 75kgz3pTMW6FDXor1jyPnpmXpaptyPSeRUlQzcoI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johan Hovold Subject: [PATCH 5.19 073/155] misc: fastrpc: fix memory corruption on open Date: Tue, 6 Sep 2022 15:30:21 +0200 Message-Id: <20220906132832.511628952@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132829.417117002@linuxfoundation.org> References: <20220906132829.417117002@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 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 model") 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 @@ -1948,7 +1948,7 @@ static int fastrpc_cb_probe(struct platf 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 platf 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) {