From patchwork Wed Oct 19 08:27:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 4678 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp212864wrs; Wed, 19 Oct 2022 02:08:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5OpxqUQjwhAbsjXSQHqfpVJ8TqWpzLxReSirBprNc9qBmhEaZoFHxOd2lyAwe7e7YnLxyO X-Received: by 2002:a17:907:2702:b0:78e:e94:2ac4 with SMTP id w2-20020a170907270200b0078e0e942ac4mr5816599ejk.679.1666170511803; Wed, 19 Oct 2022 02:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666170511; cv=none; d=google.com; s=arc-20160816; b=XxegMDIXX8lZu0tu7sg0GAZHVIWsZbwC6K82TnWO4eaDAi0pWvpqJgnLCid89LKI7X Gi1QE4hC7FMBXamKkspPnp87ASN4X/xwjEVAtAf6dmvShqunjhNSkWGxkRzIgnWHi2eJ cSo6d5WtF1eB805qOnBkHUqVDpXLB00VKQSQoQ8IXSmo6y6B22Qs44EIIpFlsHX9dkoL anbd9BFI+G4kgnTqoqSWKNRIh0u0pRpu985RQiutIF6XA+5mgiCkJnNJ6lUqHetnWmlf AiZQ1Ngfd03FuZGSwdBDRFsnbx/55Ri+ODTseFdL8gaQPAsMMFrvSe2YeEQussepjkn2 aCIw== 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=fL15fGdblnwNlIPCWmI+gsYyn/RSY8WYIj7lQ0ZygOU=; b=LoZsQAHVl7ZqXdC8cAVDXkkYlSFqPPXAWM3kCkdcivbOZaAkDdNd73gIiy9/F4ULRK Zq+3uNLIBwGQ97ldFbds88sCKfj4CcLqgrt9NMcJ3LnszkW1q3bhd81kBuF2dGn/osJf KQxLw9HEzJN3JfBTxK2HYXPjCLBXH/eBnlshCR7xUpUBiUAGACZyif1/tfg8sDxN4jJE xPZze1ZD8rDwWbK18ZPPTTt3IvZfSBXDCBFw9QpHBOL6S4fkUFn/SbpJxF+FcYLAXs9w /vro0OPkVpZjELSOjMKCmWjoDUyEANoLRA/LowqnsaKgtARCPuc7q9Fn6PcKXSN2cMW6 ybPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lVH1b+Sj; 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 mp34-20020a1709071b2200b0078034101c0esi14431149ejc.978.2022.10.19.02.07.59; Wed, 19 Oct 2022 02:08:31 -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=lVH1b+Sj; 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 S230108AbiJSJCm (ORCPT + 99 others); Wed, 19 Oct 2022 05:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232430AbiJSI7t (ORCPT ); Wed, 19 Oct 2022 04:59:49 -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 74990580A6; Wed, 19 Oct 2022 01:55:15 -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 6323D61820; Wed, 19 Oct 2022 08:53:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78432C433C1; Wed, 19 Oct 2022 08:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666169592; bh=eeSeoHdymaZAStSpJkEUImWkEipTe314hArLSoIZmUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lVH1b+SjaBFPNaegwA/qVHzefePQPaDZIG79UeTUr1H8oG/z4XANTlEwqUx2IVCPt uNU/1H5ZCWwTkZrMHt/UuN2KkHFKmoWzI/WrrFy00uEk6dgxgCSvzuzEQJ6JBNvXJc TmgiT4oxw4sz+4ASG6r8PGgp917UdZtPCCc+jej0= 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 6.0 333/862] spi: Ensure that sg_table wont be used after being freed Date: Wed, 19 Oct 2022 10:27:00 +0200 Message-Id: <20221019083304.757698722@linuxfoundation.org> X-Mailer: git-send-email 2.38.0 In-Reply-To: <20221019083249.951566199@linuxfoundation.org> References: <20221019083249.951566199@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.4 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?1747106410637576543?= X-GMAIL-MSGID: =?utf-8?q?1747106410637576543?= 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 32c01e684af3..4b42f2302a8a 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1097,6 +1097,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; } }