From patchwork Mon Oct 24 11:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9093 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp446087wru; Mon, 24 Oct 2022 06:13:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6QHsTLtBxHsSbOl/ew+EZXqrTaqAFADFOwCiT3nBOQZuwr8aMJt3MfY/A8zpFxU8EQgS8l X-Received: by 2002:a17:90b:4a92:b0:213:2421:5f38 with SMTP id lp18-20020a17090b4a9200b0021324215f38mr2541662pjb.10.1666617222017; Mon, 24 Oct 2022 06:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666617222; cv=none; d=google.com; s=arc-20160816; b=w+UBatv/2uS+AyJHbRlNSZJg0/5t5lh2V53J1Tz6b9pZF+asir9UC9reSwHbZmK+JJ qpX6so8DeqzAutY2YO0v7cdWVHeiQD/KtlILiw1vUbMM4uysOZ8F/fy+127TBdJMQ7tp l1wBVfBixuPPornP9RfYO7LrjOQ5z8N8vIVI4LXmP91uq3DZV2A39PNigKTBRnl+dHhS TeEADjnn3+DuYk7SUESimlpL9b4s5RyrMQ7hZ0QU8TFsw1O3lSpzY1TWc9+7TpTiMyzE mo/Scv4GzOyP3fLxQ9hRuHOLk5r8IfWsOtCnY1PH+rNgqo2ukQcv2lB/3LzHWE0ovx9r bYPQ== 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=FybOF60lRV1R6y6nkroF8kgdzc+dQB8RZVbrLWhWj9M=; b=LLHZ0hNh6JqiE8ZMkUdpPzxMCFjrCLAARBVtXLdMHNbA89RDm6qfwcNh81nLWtPt0u 5tatJ82Lrd+BNdCq0HnLkEOLJ0qBWOJl32W8TpcMvT3DjH16t+0s/KaoOgavts4Ifekq Ev69JhnbVxttIbwY4xRF+th3yCfOVcwYzWuJXjxgSd17XyqnMKvSIMeflTLlQsbmyET7 spiOZ+tzWOX8KfgWQ+u7ROQuRPqNsFnQXToQ3VnukSquyGP2AbM/UiOmxAsrEB7WJ0nr zlcIvCGtGU4dVqXa80s1PSuShzWhNIPXr18dXowIHifCMrE/XbLrbeZcq8fwvMJ3xD6I a6vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wYZhaXHK; 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 z13-20020a63190d000000b0043c3f90f7c8si9459413pgl.655.2022.10.24.06.13.28; Mon, 24 Oct 2022 06:13:42 -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=wYZhaXHK; 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 S235790AbiJXNNJ (ORCPT + 99 others); Mon, 24 Oct 2022 09:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236026AbiJXNK3 (ORCPT ); Mon, 24 Oct 2022 09:10:29 -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 A60C55F7C; Mon, 24 Oct 2022 05:24:08 -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 324FF61291; Mon, 24 Oct 2022 12:21:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41F61C433D6; Mon, 24 Oct 2022 12:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614108; bh=6O4z8Vt1okk5kqyVrnSRDcWXI5nJOhSa6Y7hw/EFT0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wYZhaXHKcdC5dc7sPAw/4bYuQuiJzcFHxz0AcR1VVUSd24o/vtsSsWKwxMS9S7ZQc /ga8wFUC8vi3dyEILUbX1lny6WV2PVHnaAhnFVulJexOvJdjBX1B8akf6Oe/1SbeOD EEjmwsAeAw6mhrvXAt1Yo5f68JMM7J1lvu4kqrxM= 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.10 135/390] spi: Ensure that sg_table wont be used after being freed Date: Mon, 24 Oct 2022 13:28:52 +0200 Message-Id: <20221024113028.425937864@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@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?1747574819977873043?= X-GMAIL-MSGID: =?utf-8?q?1747574819977873043?= 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 6ea7b286c80c..857a1399850c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -946,6 +946,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; } }