Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp636908rwb; Tue, 25 Jul 2023 23:44:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlH/WRd366n9kYsZAlW/uqZLgM849/ZWP6PHmilhIZ3PGZQGdo/YTLEOuRoErHKGR2i9id9r X-Received: by 2002:a05:6a21:a103:b0:12f:c61e:7cc3 with SMTP id aq3-20020a056a21a10300b0012fc61e7cc3mr1323881pzc.38.1690353876357; Tue, 25 Jul 2023 23:44:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690353876; cv=none; d=google.com; s=arc-20160816; b=IBzG0CrwfRMCTDxg7fWkJ19SKKfMk3z707yVGa4oWyeaMKaET4WlY2vAPv3jXBXXlD KIjtEeZsQcmF/nnyWOwFOYCVHhkbfQfMSE7qDIh0FqDTE/zzS8+KPzAx+oB4IKksGUMg jAEoJ1piu6DTQYPeTcEpHphFib5fBOEfBV4hvMPUHn95/QRvL3PIthV+WyZjregi59+P FxThbRPDVmlouftjtY7WlXbW3/8o/qDA/AsJ5NmuNB8i0iRLIvHcfsEnSdCAVRXu49WI 9DY7FLutGCHtgMwVazAHJ+3SAhrnboUa6FaPbnTCcWzdoPCVU5BRs5/NEmzFfontb6L8 rUUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=O3NQlaUK60NuvwjehIKaRwfMJtHsUWLsVxTpyD4aWk8=; fh=Ur4ILfbB7DQWli8m/wuvnSXdgoJaGdkbTX8HYvdhUQM=; b=p9T/onk2QIcdpaJcgfh2z8gQQnM5HRMSDRB2nOeX1MxxqzInuUoZPQ/bMwZhJnNFXq 1u6FsmfU6t7YK0M5wMDkLn8yJf9UoATPGDyJ9ffp6n9M9Z/6ipoPQJCQOHWsqIwzsUbm QhzS+FWaNgAK4aF4sxx1VB70C0qqTa1o26GJJBXPgDCwGHJVSMgQBtMuLt4gy+pd6j+w n8lZso7JUHusukgSeax0l6qqYBoFKam1ckIW36kfj0GxLP6p+dC4/GRow35q2qOWtEJJ BLJUF/TfIAkmLPyeb8yWAnDiB+oSd4bF/IN8ZpLFMO6bCLFyyQGgU6syN78IAU+/fIto m70g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fv9q5ZqV; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ik2-20020a170902ab0200b001ab1ba2572csi11656650plb.240.2023.07.25.23.44.23; Tue, 25 Jul 2023 23:44: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=@kernel.org header.s=k20201202 header.b=Fv9q5ZqV; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231665AbjGZG1H (ORCPT + 99 others); Wed, 26 Jul 2023 02:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229993AbjGZG1G (ORCPT ); Wed, 26 Jul 2023 02:27:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A69713E; Tue, 25 Jul 2023 23:27:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CC2D4615D5; Wed, 26 Jul 2023 06:27:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94C10C433C8; Wed, 26 Jul 2023 06:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690352824; bh=upPRTBdQI2wH9eTqLVZgmtXfPMny6sYV8ZuTbavkfn4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Fv9q5ZqVJ36qpYD6nJaBTYoyKJANH6Uyjo+MX8d/7K8LKhRtiqX0v3zl0vegmmJ5U gr8L7WicKs/RvyOdAnD/4dadB6QNKZHo9BE0A2RO+PUgUBFZXIckrNlR41HhMu96AA D2wGEhHUISY/MMi3YWVyRINWUCMh96+iWMcqS2nYEbeJho9fUa4u0rrUfxF05etIrT 6eJcqIxMKlJNfYT7jy3WwFUSJ19gp3qPvIvj1kAJxYETY8hCaFK/Nt5iuPenSU+w4d XGCyAKj3M9ZeA6LPV1cdybuZvrnpXhGuzCf6y513lVjH4QKO9pqu2WubOX9f4WyWN4 2RWMIk59eHf8w== Date: Tue, 25 Jul 2023 23:30:17 -0700 From: Bjorn Andersson To: Ekansh Gupta Cc: srinivas.kandagatla@linaro.org, linux-arm-msm@vger.kernel.org, ekangupt@qti.qualcomm.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, fastrpc.upstream@qti.qualcomm.com, stable Subject: Re: [PATCH v2] misc: fastrpc: Fix incorrect DMA mapping unmap request Message-ID: References: <1690182571-7348-1-git-send-email-quic_ekangupt@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1690182571-7348-1-git-send-email-quic_ekangupt@quicinc.com> X-Spam-Status: No, score=-7.1 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,T_SCC_BODY_TEXT_LINE 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 On Mon, Jul 24, 2023 at 12:39:31PM +0530, Ekansh Gupta wrote: > Scatterlist table is obtained during map create request and the same I'm guessing that this all happens in fastrpc_map_create() where: map->table = dma_buf_map_attachment_unlocked(map->attach, DMA_BIDIRECTIONAL); fails, we jump to map_err, and then call fastrpc_map_put(map), which then ends up in the code below? > table is used for DMA mapping unmap. In case there is any failure > while getting the sg_table, ERR_PTR is returned instead of sg_table. The problem isn't that ERR_PTR() is being returned, the problem is that this is being assigned to map->table and you keep running. > > When the map is getting freed, there is only a non-NULL check of > sg_table which will also be true in case failure was returned instead > of sg_table. This would result in improper unmap request. Add proper > check to avoid bad unmap request. > > Fixes: c68cfb718c8f ("misc: fastrpc: Add support for context Invoke method") > Cc: stable > Tested-by: Ekansh Gupta You always test your own patches, so no need to declare this. > Signed-off-by: Ekansh Gupta > --- > Changes in v2: > - Added fixes information to commit text > > drivers/misc/fastrpc.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c > index 9666d28..75da69a 100644 > --- a/drivers/misc/fastrpc.c > +++ b/drivers/misc/fastrpc.c > @@ -313,7 +313,7 @@ static void fastrpc_free_map(struct kref *ref) > > map = container_of(ref, struct fastrpc_map, refcount); > > - if (map->table) { > + if (map->table && !IS_ERR(map->table)) { Rather than carrying around an IS_ERR(map->table), I think you should address this at the originating place. E.g. assign the return value of the dma_buf_map_attachment_unlocked() to a local variable and only if it is valid you assign map->table. Or perhaps make it NULL in the error path. Regards, Bjorn > if (map->attr & FASTRPC_ATTR_SECUREMAP) { > struct qcom_scm_vmperm perm; > int vmid = map->fl->cctx->vmperms[0].vmid; > -- > 2.7.4 >