From patchwork Sat Oct 22 07:22:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1095396wrr; Sat, 22 Oct 2022 01:02:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6r4Q/QUv8PQszHKs1OZDvqHCLrs0OaleUg8JT/jIjjLjd9/czeh91zJh1+kO124mvCdwAK X-Received: by 2002:a05:6a00:1da1:b0:563:2e07:db1b with SMTP id z33-20020a056a001da100b005632e07db1bmr22964990pfw.22.1666425756087; Sat, 22 Oct 2022 01:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666425756; cv=none; d=google.com; s=arc-20160816; b=NzBVeXWVcAuEvACGC6PTqOAZhubMBvZn4eD4Z4nrrAdPXKxgbv5g4lhdDRxH2hOUma 61XQ41FQk/P2Lou5K5cQ8r1Td56xQej7Yj+idLZNvp6HRv8hbYrrLX2n7oQxEZQD31wK UoVc2eu2WC6E6wys1MI5oWTSSWzHKguBRxQ/N7cJ/ibHyg51D+5ySrJqDI7rmxA6BaCY PzZRNt4nOo3aWNvDavABnZzpX+6AHdiMFYVjBRBiiYTtymTuqJKoFwv/71Z6oGB096L7 GRdolBaE0CNhi7BtGTZPbxjsnpBINl6Qq97yFhKSygZYor04Pmyi9loGzLmxpoBWctbY Q63g== 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=INTi5KWJdpM4tZdt+qWRvfUpk5Hv/Po257sPG9nLI7c=; b=gcibMpghBV7Bm5owMsyJHWZhbcP2vEmxv2FQafgB+Uu4apwBv9U9+X2NfX35FAJGwt MOuzbgfo4s4OF81V8VbHzsArS+HyZpOzEAvBZ5EeQhpjSUb2pF5oU+/oFhrv+jZRdYPk T30WntL6aPEF1bxl4+DQM6cxSjPQfIaeX2sQKx61h6y+HKV2uPTMzuvEVhZJZCm4ym9h OL1eBJqsxLMACzDAgbLbRT3z1KAYIOhZvutwcz97FhRKDqOkOScV4wUGtQmjC5tLsTs7 yGFDESthmLJAv1K40u0IYTxonBhM4EaDGgE59poo3WYgwtepVkRd3Kq7AAV37Glb+Htg PsXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=D58ohirG; 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 z14-20020a170902d54e00b00183f6ff535dsi27364410plf.490.2022.10.22.01.02.22; Sat, 22 Oct 2022 01:02:36 -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=D58ohirG; 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 S232410AbiJVIB5 (ORCPT + 99 others); Sat, 22 Oct 2022 04:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232230AbiJVHy1 (ORCPT ); Sat, 22 Oct 2022 03:54:27 -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 7752829F66F; Sat, 22 Oct 2022 00:47:16 -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 3AA8360B1A; Sat, 22 Oct 2022 07:46:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51428C433D7; Sat, 22 Oct 2022 07:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666424803; bh=e9rDTZzYaQS3sxO5Dhrp00pJNaqgumzz+ILinbeYFx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D58ohirG3xCE3YJnevGLIqRqMu7saGDKd7JD/a/vvML7mzrT7yvt2y4Zcx4c1ahFq /2UYfB52fcvrZan+/j84+vlq4atguenM8LZC5SpTEmngyM3H/0zY7SgcHTRMHKsuB8 tppqaM7CbofXIIomdvfTZcKzX7QoHikXxb90YDmA= 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.19 282/717] spi: Ensure that sg_table wont be used after being freed Date: Sat, 22 Oct 2022 09:22:41 +0200 Message-Id: <20221022072503.655201205@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 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?1747374053198298532?= X-GMAIL-MSGID: =?utf-8?q?1747374053198298532?= 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 2c616024f7c0..f595e516058c 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1047,6 +1047,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; } }