Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp26751imu; Sun, 4 Nov 2018 18:06:09 -0800 (PST) X-Google-Smtp-Source: AJdET5eFupbfGyUoo9ayXjb6K+to59KLvBOBBym8f3JPVIkC9Dd4WkE11/416ggrCu7gZdhpmCRj X-Received: by 2002:a63:4d1d:: with SMTP id a29-v6mr15854410pgb.408.1541383569016; Sun, 04 Nov 2018 18:06:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541383568; cv=none; d=google.com; s=arc-20160816; b=jJMyRWzWRksJe8cz7Tu3/MpnffFkqPWNjRyrASM0lgWN6AVcSr6Nb8Vi+P3JxYfrVk VwyfJ3OoBDKyICW0XsI0tCkOFajl5dQJK/g31gfatyWMj0j6Br+q+FOmSHjPnlSTpiY7 i6FFUaffkmBxDAxiYDCZxE2FiODVMhi0B+xcD7wc+Rs2iN8k3ofl6F/6GSKdY8vMp9EA Pk4lE8IXsoKBgr3zg0TC0LRYT7bGDib8c63p98V9f1qIusZN5Y2ar2vVSPDIY5tLaRpS 16PkMGW10SFILKJk8w/MBGxWXv9C+WtGmuyx5SxJzQg4dp7R00UZ4WeOA1vKfVbc76J4 PQew== 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 :references:in-reply-to:date:cc:to:from:subject:message-id; bh=3MncgDcAou1UaLqZaAMt7H8NSEjvjxHnqN1C/NaXHmA=; b=Q/RM+GBryJikAyhi/nXNmDrVYFlnvst5irGarY9n0ms1omd5UfSKK+sVAkKbn8RoXU 6ZUPho3+OBbtVONgKtYVIBPwXr+XVIxxnrNQIPYa8swVxSBkSw9SZvuE8SB60sks9apF fvYuJhs4DMEySo5SnaTtX3wYcXUkJJYg7i15koCY61RrQOvouY14dIBKjicPWQDwZeSf XqM1GXYljKChBOP3hHWHSM20yh/Wxlu6/alVByizFwG4pqjVCtqc1xhj6E2MfGY1Rg41 5RSh0vXFf5HCXCd/SLOM6TfTALPnIzRpSoPr2xlZ8zJVHIY0K7uKxXNiwoDkqITOIb7D sMBw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k21-v6si40909758pgl.169.2018.11.04.18.05.40; Sun, 04 Nov 2018 18:06:08 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbeKELWY (ORCPT + 99 others); Mon, 5 Nov 2018 06:22:24 -0500 Received: from mga09.intel.com ([134.134.136.24]:31647 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725966AbeKELWX (ORCPT ); Mon, 5 Nov 2018 06:22:23 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Nov 2018 18:05:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,466,1534834800"; d="scan'208";a="271357213" Received: from unknown (HELO localhost.localdomain) ([10.10.37.145]) by orsmga005.jf.intel.com with ESMTP; 04 Nov 2018 18:05:09 -0800 Message-ID: <1541384613.28670.5.camel@intel.com> Subject: Re: [PATCH] misc: mic: fix a DMA pool free failure From: Sudeep Dutt To: Wenwen Wang Cc: Sudeep Dutt , Kangjie Lu , Ashutosh Dixit , Arnd Bergmann , Greg Kroah-Hartman , open list Date: Sun, 04 Nov 2018 18:23:33 -0800 In-Reply-To: <1539891966-8017-1-git-send-email-wang6495@umn.edu> References: <1539891966-8017-1-git-send-email-wang6495@umn.edu> Content-Type: text/plain; charset="us-ascii" X-Mailer: Evolution 3.12.11 (3.12.11-15.el7) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 2018-10-18 at 14:46 -0500, Wenwen Wang wrote: > In _scif_prog_signal(), a DMA pool is allocated if the MIC Coprocessor is > not X100, i.e., the boolean variable 'x100' is false. This DMA pool will be > freed eventually through the callback function scif_prog_signal_cb() with > the parameter of 'status', which actually points to the start of DMA pool. > Specifically, in scif_prog_signal_cb(), the 'ep' field and the > 'src_dma_addr' field of 'status' are used to free the DMA pool by invoking > dma_pool_free(). Given that 'status' points to the start address of the DMA > pool, both 'status->ep' and 'status->src_dma_addr' are in the DMA pool. And > so, the device has the permission to access them. Even worse, a malicious > device can modify them. As a result, dma_pool_free() will not succeed. > > To avoid the above issue, this patch introduces a new data structure, i.e., > scif_cb_arg, to store the arguments required by the call back function. A > variable 'cb_arg' is allocated in _scif_prog_signal() to pass the > arguments. 'cb_arg' will be freed after dma_pool_free() in > scif_prog_signal_cb(). > > Signed-off-by: Wenwen Wang > --- > drivers/misc/mic/scif/scif_fence.c | 17 +++++++++++++---- > drivers/misc/mic/scif/scif_rma.h | 14 ++++++++++++++ > 2 files changed, 27 insertions(+), 4 deletions(-) > > diff --git a/drivers/misc/mic/scif/scif_fence.c b/drivers/misc/mic/scif/scif_fence.c > index cac3bcc..30f7d9b 100644 > --- a/drivers/misc/mic/scif/scif_fence.c > +++ b/drivers/misc/mic/scif/scif_fence.c > @@ -195,10 +195,11 @@ static inline void *scif_get_local_va(off_t off, struct scif_window *window) > > static void scif_prog_signal_cb(void *arg) > { > - struct scif_status *status = arg; > + struct scif_cb_arg *cb_arg = arg; > > - dma_pool_free(status->ep->remote_dev->signal_pool, status, > - status->src_dma_addr); > + dma_pool_free(cb_arg->ep->remote_dev->signal_pool, cb_arg->status, > + cb_arg->src_dma_addr); > + kfree(cb_arg); > } > > static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val) > @@ -209,6 +210,7 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val) > bool x100 = !is_dma_copy_aligned(chan->device, 1, 1, 1); > struct dma_async_tx_descriptor *tx; > struct scif_status *status = NULL; > + struct scif_cb_arg *cb_arg = NULL; > dma_addr_t src; > dma_cookie_t cookie; > int err; > @@ -257,8 +259,15 @@ static int _scif_prog_signal(scif_epd_t epd, dma_addr_t dst, u64 val) > goto dma_fail; > } > if (!x100) { > + err = -ENOMEM; Should err be set to -ENOMEM only if the cb_arg allocation fails? > + cb_arg = kmalloc(sizeof(*cb_arg), GFP_KERNEL); > + if (!cb_arg) > + goto dma_fail; > + cb_arg->src_dma_addr = src; > + cb_arg->status = status; > + cb_arg->ep = ep; > tx->callback = scif_prog_signal_cb; > - tx->callback_param = status; > + tx->callback_param = cb_arg; > } cb_arg should be freed if there is a dma_submit_error(..) below in the dma_fail path. Wenwen, can you please fix these up and resend the patch? Thanks, Sudeep Dutt