From patchwork Mon Oct 24 11:29:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9735 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp548510wru; Mon, 24 Oct 2022 09:41:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MkD15Qck1asfQt0a/GpeoFz4WyPtGz+3gwAtCMYd/jnEvhPMkAAF5vGUvfOzlKnRc1ePg X-Received: by 2002:a05:6402:3988:b0:44e:6f08:ddfb with SMTP id fk8-20020a056402398800b0044e6f08ddfbmr31168906edb.89.1666629705490; Mon, 24 Oct 2022 09:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666629705; cv=none; d=google.com; s=arc-20160816; b=gUL43Eo4vhPU1s0s6rUkRMWNYYg3dkMBIa/z2Jnvfv/JTDbODRDO09UgmowVu4ThKW Jb4igAzfqDeRHEz6u65KV5nMcqbMwOidAxfmXuDt/OfwSLC8BgzmjLX9X0tjmEjP35R/ L4RU1OQctGMkzqWmypflx9KqPi7pU/cgZ1AEY79ZFw6KZwh29IC2pbJ6RykFyRPVfBMX y03T97YxVLfIlLEijqE/yzR7b5TCyvo6Ax0oNZMqdWbYKN6V4M6gAk7DrYWMo9Y5RAcZ LaxUHee+rhvSQISNb0L6fHLmzfIyeA0UGybGCVwVNfgChLovTRUWPp59Ilc+oo3mDq/1 dDYw== 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=/ZG8MZKQq+u828gaQQCmnnRLGGAIblghSHwglGRJS/Q=; b=NUN7NxdRr46PbLeZc2B2DGev+mCIaIfQ3pOHPohRKqKGRSbIjkQl2NF6ngtThRguvy vzZ6FiNSp5EEbLwrMnCr6qf6nj2kgK51gHIcfdxV6Ht6iXwk++/zkf1lXJnwNZI1nfeo UZaS+/qgC4aY3J4MNMe3lcWMZNo809BoO/qZTg/y/px9mrnRHsFxGNeGtGQsIufHDzUs kqK+7E6puJV4gN85uHH/k/5ZRr8deWGBTLjf51DUjxmsKJgz8uhCVNLvaGyEBDwraYVy s4rvlCXgUaufqzaGRM5QKtb0Tge2dGbWgM4B9hIhEmvCrlNbUCtvyqPX7QgkABSedFX2 7ybA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="aDrST+/m"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s19-20020a056402015300b00459060fce1bsi168592edu.574.2022.10.24.09.41.21; Mon, 24 Oct 2022 09:41:45 -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="aDrST+/m"; 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 S234450AbiJXQkX (ORCPT + 99 others); Mon, 24 Oct 2022 12:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234244AbiJXQjr (ORCPT ); Mon, 24 Oct 2022 12:39:47 -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 A656156BB5; Mon, 24 Oct 2022 08:26:52 -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 AD092B81996; Mon, 24 Oct 2022 12:43:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13C91C433D7; Mon, 24 Oct 2022 12:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666615387; bh=cNB5yuiLH6ZtpQ2wUOYKIZtk5Q/9DzwbtN7X7TPvm3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDrST+/mCfNt0B3LL877g6ZEfU7ryWhc8eO2DwdX6jFC4CXJGumCOCZvh8FNT3Iiy 7FHbdcVdt6R/oJBiKyzh08mQrJlbQez1icbAWh1SnmX5tPORA5hPbzLnY6JhE39/v2 bG1l6UWGDsOzKQa90JToCekKTmNznMK5v96BigvQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marek Szyprowski , Mark Brown , Sasha Levin Subject: [PATCH 5.15 200/530] spi: Ensure that sg_table wont be used after being freed Date: Mon, 24 Oct 2022 13:29:04 +0200 Message-Id: <20221024113054.107478506@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747587910067722656?= X-GMAIL-MSGID: =?utf-8?q?1747587910067722656?= From: Marek Szyprowski [ Upstream commit 8e9204cddcc3fea9affcfa411715ba4f66e97587 ] SPI code checks for non-zero sgt->orig_nents to determine if the buffer has been DMA-mapped. Ensure that sg_table is really zeroed after free to avoid potential NULL pointer dereference if the given SPI xfer object is reused again without being DMA-mapped. Fixes: 0c17ba73c08f ("spi: Fix cache corruption due to DMA/PIO overlap") Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20220930113408.19720-1-m.szyprowski@samsung.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 556d65af5e23..06dd1be54925 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1007,6 +1007,8 @@ void spi_unmap_buf(struct spi_controller *ctlr, struct device *dev, if (sgt->orig_nents) { dma_unmap_sg(dev, sgt->sgl, sgt->orig_nents, dir); sg_free_table(sgt); + sgt->orig_nents = 0; + sgt->nents = 0; } }