Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5733981pxb; Mon, 14 Feb 2022 06:27:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYrGcKA9qmCbQpzM2lFcNZTf6IgpW59Cr2SnnwdXr+3AsqDUZHg8QVJqhzRvOetiw6ckqd X-Received: by 2002:a17:907:d0f:: with SMTP id gn15mr12029347ejc.195.1644848842479; Mon, 14 Feb 2022 06:27:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644848842; cv=none; d=google.com; s=arc-20160816; b=PJ0txLeE+ckeARdjjMDWmV5aLD+UMPDrowKKfoPPJrqr6gh3oa1G5YKVzouhDdl5Ix 1yO4AvjKWkLeFgdnD2LWCaTvfSw3rYTGTiaeUy/1g2B0jq+oQ5wE58oRCoo8Z8OgvM1R akAMTWEHzoeLNmCT75k5lf968TnxomjO2dpfNRFbb78PYA9FmUydhBYm1xCpYSVWhrtp 0ofS3CZ81G6Z5abZ1DHlPsj5h+TULerEXi0/qWExLg8YDeEQ35qDhyiCHnJfAiTh4DfZ c+HMr8R7UD88wjci6fUN65s3PLlyNA6Y2PWovQDZQ9CvuLG89/cQ1P2vNdh7kUAUa/Z+ RHSg== 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=hfj1I3jykbPNyYJxsujiwI7bt9ip20ZuFyC+jPYa3GA=; b=G/vnaqP4XElNuMxCUw6s8EtRzVbimWSw6Z9OuYXweN77Sl/w3fJWCbAbuJb/hI9LPy RGqs+BKV4GETMZmAu4hO5k5jKrVYcHd37ZsqH0tloKKP5QxjYEb6PF6pW7cJ737qbITa FcWv0Nz9DQjBibxwoj+Nb7Tj+ZJxxK2al6grPGBUXCMcu8NeGPJDtPcn9K+RJHLZcUXI L4BeiusOrnFnK8mGbHnL2EpubLm6iM1m/x+dl1EvVgbBVvGWJJEl4gLmXnKt2LcpQab/ dDKttXSBGQtU44TpjFduAnKQr21UxrgtzFMKY6MWh36FZN4GfnndeflftoeomRv+xBDP i0eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aj1yweXn; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds9si22669560ejc.302.2022.02.14.06.26.58; Mon, 14 Feb 2022 06:27:22 -0800 (PST) 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=aj1yweXn; 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 S245092AbiBNJox (ORCPT + 99 others); Mon, 14 Feb 2022 04:44:53 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245522AbiBNJlg (ORCPT ); Mon, 14 Feb 2022 04:41:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2906F65813; Mon, 14 Feb 2022 01:37:34 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id C636CB80DCD; Mon, 14 Feb 2022 09:37:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E214EC340E9; Mon, 14 Feb 2022 09:37:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831451; bh=wNgkAF06IGvZrAxpv0aSJAIX++t4ouMnr681T3JhozU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aj1yweXn1yYCxTmQc/wxkXnci+uun91Xi5BwTzmX9uzjsuuDwmK+/JXO/7cjj9c1I vihgEeRTEyirdDTv/UKgY8pqGWQLhkJqWr+9HzR/1Bp4iLHN46MdqYpMlQvVAzJxXg o72+fxkrXo2PMVw29YkpYAeiYmLZ7JWK/fYBYYAM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Christian=20K=C3=B6nig?= , Mathias Krause , Sasha Levin Subject: [PATCH 5.4 39/71] misc: fastrpc: avoid double fput() on failed usercopy Date: Mon, 14 Feb 2022 10:26:07 +0100 Message-Id: <20220214092453.349087538@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092452.020713240@linuxfoundation.org> References: <20220214092452.020713240@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 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 From: Mathias Krause [ Upstream commit 46963e2e0629cb31c96b1d47ddd89dc3d8990b34 ] If the copy back to userland fails for the FASTRPC_IOCTL_ALLOC_DMA_BUFF ioctl(), we shouldn't assume that 'buf->dmabuf' is still valid. In fact, dma_buf_fd() called fd_install() before, i.e. "consumed" one reference, leaving us with none. Calling dma_buf_put() will therefore put a reference we no longer own, leading to a valid file descritor table entry for an already released 'file' object which is a straight use-after-free. Simply avoid calling dma_buf_put() and rely on the process exit code to do the necessary cleanup, if needed, i.e. if the file descriptor is still valid. Fixes: 6cffd79504ce ("misc: fastrpc: Add support for dmabuf exporter") Acked-by: Christian König Signed-off-by: Mathias Krause Link: https://lore.kernel.org/r/20220127130218.809261-1-minipli@grsecurity.net Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/fastrpc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c index f76c64084f4b2..fb5ddf3864fdd 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1245,7 +1245,14 @@ static int fastrpc_dmabuf_alloc(struct fastrpc_user *fl, char __user *argp) } if (copy_to_user(argp, &bp, sizeof(bp))) { - dma_buf_put(buf->dmabuf); + /* + * The usercopy failed, but we can't do much about it, as + * dma_buf_fd() already called fd_install() and made the + * file descriptor accessible for the current process. It + * might already be closed and dmabuf no longer valid when + * we reach this point. Therefore "leak" the fd and rely on + * the process exit path to do any required cleanup. + */ return -EFAULT; } -- 2.34.1