Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5990565pxb; Mon, 14 Feb 2022 12:32:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMuIEAWOcFh5Loshn9rWYNc/9WBV2h4fgUrcxIKszvoP9XGRHeTeJ2m3veRudj2izMNQMe X-Received: by 2002:a05:6a00:a8e:: with SMTP id b14mr449237pfl.32.1644870763311; Mon, 14 Feb 2022 12:32:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644870763; cv=none; d=google.com; s=arc-20160816; b=bfLP+MliOZvccrKzn6i+X2AklmcOlRF4TK0r7txy286fBIVDsfEa1jIlOiROuOrObe cRlBoZ2jYUwkwsw35pC5dtOPWEmq0995BEDC6Uxkh9IbGu6zvhYW34AlhMZNIzXI0vrd aLt6QLTaNqw0hZesri8CdMsQJEnsWYy1G+Aoe6mo+sbpDPAvz/+N5cdpKK7U/Iv314tx tSvUsOrqhc390/PgSxNUTvdqucKYguo+rs3WeoD2JNk1h4GvYbffshdwrtiLfiYwKOnn 2CWVG0x6iNo5fZjcXZcv+T9LekEc7MJhTYBXKc+H6ZPbLYsx9D3E/++1VZA4FCCea4sE upUQ== 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=b79uyTCVXRW8L64KaaIH1MnjASBshf5t86HslhSinvM=; b=RdRlpJVAqI+0UsluZN/meegOC/2xugf93zUg78zikt2VWZfMsDQZRSbEw57ds0DW70 5c27bsWRJEdJX4Ke0ydcZYHDUclg7BRagk7Cv9HqMYo0YiIhtQV01Btbgo+KiqF0b4zz wzslteHRvCkBXgWnaNaEqYMLXhYFVxU0esGI/VzQUu34wDw2pClJ4oHzgy+oGugotF6d ho5BoNFE5SkkElfPFlYR7zeYgKG4kVmFAdl0Hfti8hu+RhKWuf9NGKRNtRvwNfECgP/V 3LVkPkL0372FILzMQBafpFK1avt5k6/8RzC+DhRyX8VQCRDQbsiPzrRANUU9YTrA/Hx8 Gfjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cCFimEG3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g22si31365849pfv.115.2022.02.14.12.32.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 12:32:43 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cCFimEG3; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A882C10E551; Mon, 14 Feb 2022 12:02:40 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343759AbiBNJxc (ORCPT + 99 others); Mon, 14 Feb 2022 04:53:32 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:60854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245297AbiBNJuS (ORCPT ); Mon, 14 Feb 2022 04:50:18 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62856652CE; Mon, 14 Feb 2022 01:41:23 -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 955E8B80DC1; Mon, 14 Feb 2022 09:41:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CAD73C340E9; Mon, 14 Feb 2022 09:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831681; bh=GxuuGnP9KrUM6DZlJqqZTvE/JpWjy0vuXMwK9DCF/zI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cCFimEG3qYoD8uOoF3tcMCGYRjcXf5tEnGZYs8n8gCYEN/L3dLscBcn1WE/oKD6WD EX6B0IzHlXxG494lhKliVIsGjZC3VXTRHvLOYmVSbKgcIF9NDfgCLX1RCiPsU9dOgP KweLTHIu6yupfK/eQDB6wpc6Z1CMYo2JNft/p9z4= 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.10 061/116] misc: fastrpc: avoid double fput() on failed usercopy Date: Mon, 14 Feb 2022 10:26:00 +0100 Message-Id: <20220214092500.853984909@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092458.668376521@linuxfoundation.org> References: <20220214092458.668376521@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 ef49ac8d91019..d0471fec37fbb 100644 --- a/drivers/misc/fastrpc.c +++ b/drivers/misc/fastrpc.c @@ -1284,7 +1284,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