Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp5977313ybc; Wed, 27 Nov 2019 12:45:41 -0800 (PST) X-Google-Smtp-Source: APXvYqz7PdmMH7IW+KpsOSKqA72LA26l7E4Ln2Ytex4wGMmumeQSCmIW4/gVzBdcm0PJAiX9/fu/ X-Received: by 2002:a05:6402:1ac4:: with SMTP id ba4mr8655210edb.201.1574887541274; Wed, 27 Nov 2019 12:45:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574887541; cv=none; d=google.com; s=arc-20160816; b=iFVHTTspsgF6vbBvg1W5RinJM7GcVQWPx63XrQNY289Dt/WWvunpINDw78STS81Qn+ BBDE4nJRo5PXcnl20r2pRj3P+0/8FdqgiLkiIaPuHuo9b9miUmpge1CKJqdkg7AHmHqb THPnXHhUCpu1H+4ZA9lZdZp8NlfaW7U15ist56GWrDMij+rkrPw45y0qhOiTLaGnFd1K OHPZAmMyf7g8sQSMrSxOoM8V7C3ylE6y6DdZ+U6NxQKtRpvgpaWTDLLX/wEr7MFKSUlu xGBYYXXh42ulAx+B4ZYLabbbxzaWCsIoKg/zMr7h11GUj0+gYIYx8BXZZkt0CCGKzZ90 ISTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=v5x5Rn2wPX0XskJ2XDelJAMMMMYiA5bawjlr6XUlyJw=; b=ThDK20GdKhyiwzCkp1X/IiPnKtNkqSg2HOMLRPu3dHpwGuA1aAyJFKxzYOd+UlUW/9 FBAYolBBTQOlnn/UFm+P2nfIAHG4jYNqW7w0vn0lpRD49IAtLy8i8/Gg0xzxybzEOwAk s/oLdzsBCubl49z5mW7JxU3fvFkSU6Z533IDmD8NAO4AHvL8A8bZn7lZAldLAmp8Vlcx U5Q6Hylc5T6rnOPDBDfR0MnZjMbTySK2wdiKK2BNEb/yjmB/hLxxi0IDXFwE/yYx8Soc UgdjgZ2mj1ekwCHG3MBelT+tVDFHIQrjwk4kGGCte2bb2i6sRxa5WfzOKCIUEJqueByd HBzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LdkV5iJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a19si1346848eje.396.2019.11.27.12.45.17; Wed, 27 Nov 2019 12:45:41 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LdkV5iJB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729297AbfK0UmI (ORCPT + 99 others); Wed, 27 Nov 2019 15:42:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:48014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729288AbfK0UmG (ORCPT ); Wed, 27 Nov 2019 15:42:06 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9DE5621787; Wed, 27 Nov 2019 20:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574887326; bh=XP4W78k7tWdh+OxHKfg/hOgoXSYlnsAKcT0blXHT8RY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LdkV5iJB4BgisIrrjnXjJ2nKUyZoxtaQxuz2+qkfUkBJRVeQ0bYPpkbFS32N3fBSg GMdMbWzaREvvyH9JD/CjeskVvsh8MYhjinPo5CK0uGSPUcDxYoMGdngbE2f/bEhal+ 37kCax0fTrAbwWh+FVPPbPLG+Ei5Me5wRuVo+Zxs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wenwen Wang , Sasha Levin Subject: [PATCH 4.9 025/151] misc: mic: fix a DMA pool free failure Date: Wed, 27 Nov 2019 21:30:08 +0100 Message-Id: <20191127203016.158952166@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191127203000.773542911@linuxfoundation.org> References: <20191127203000.773542911@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang [ Upstream commit 6b995f4eec34745f6cb20d66d5277611f0b3c3fa ] In _scif_prog_signal(), the boolean variable 'x100' is used to indicate whether the MIC Coprocessor is X100. If 'x100' is true, the status descriptor will be used to write the value to the destination. Otherwise, a DMA pool will be allocated for this purpose. Specifically, if the DMA pool is allocated successfully, two memory addresses will be returned. One is for the CPU and the other is for the device to access the DMA pool. The former is stored to the variable 'status' and the latter is stored to the variable 'src'. After the allocation, the address in 'src' is saved to 'status->src_dma_addr', which is actually in the DMA pool, and 'src' is then modified. Later on, if an error occurs, the execution flow will transfer to the label 'dma_fail', which will check 'x100' and free up the allocated DMA pool if 'x100' is false. The point here is that 'status->src_dma_addr' is used for freeing up the DMA pool. As mentioned before, 'status->src_dma_addr' is in the DMA pool. And thus, the device is able to modify this data. This can potentially cause failures when freeing up the DMA pool because of the modified device address. This patch avoids the above issue by using the variable 'src' (with necessary calculation) to free up the DMA pool. Signed-off-by: Wenwen Wang Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/mic/scif/scif_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/mic/scif/scif_fence.c b/drivers/misc/mic/scif/scif_fence.c index cac3bcc308a7e..7bb929f05d852 100644 --- a/drivers/misc/mic/scif/scif_fence.c +++ b/drivers/misc/mic/scif/scif_fence.c @@ -272,7 +272,7 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val) dma_fail: if (!x100) dma_pool_free(ep->remote_dev->signal_pool, status, - status->src_dma_addr); + src - offsetof(struct scif_status, val)); alloc_fail: return err; } -- 2.20.1