Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2383867lqp; Sun, 24 Mar 2024 17:02:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUn9u7/u5cygPee8XaEYMqHuXMpPoY/rzlajlur8f/m4XZJEh4lck1zm9CLKU5Aji5I06tv3kUyeZE2hS64UT2UiLalkpuc3eAEeK2k5Q== X-Google-Smtp-Source: AGHT+IGvLQp2E9y/NesyNV22EvdZJ8FKNwCh577TOfgo+Uv1iCUO546Onud+p0RS3CR7B/AP5pIy X-Received: by 2002:a17:906:1788:b0:a46:4e73:9c67 with SMTP id t8-20020a170906178800b00a464e739c67mr2916842eje.68.1711324947653; Sun, 24 Mar 2024 17:02:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324947; cv=pass; d=google.com; s=arc-20160816; b=FZmCKfFmtem+w20ovXoOBJm/nQoj7q1Sjrfb76PKU7XUl2KVY1i+gM/MeDQYZu6Z9n HfvEnBoso/Bt8lcVyLphzsh2bGUN1n2VuC1uh8KCB5ZvdJHdrte0bM7wnR2rUoeGTwZ2 ddeK8nv2FbJz1Ql11FhlXFGdkj78BLj477pVBqn/pKunFE24Z2a1W8Nn1R2zS3k5vcv5 yXNiqtCqyHzx0sbfSy0zncN4HsnJ1CsmQo92WfGevlrH4J8WfCLeAh/7NGk9oLcQ8keQ wqRhBdM0qY9nbd81mgqkJJ/7yLFZzm+Y2subQ2GEL381hp0PQp8BF18ooDA3q94KcS2P g/sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=4Yg2UpskBzzAvJ/2NOqxSpwFPwWxLhuGbWKrqoEA5Eg=; fh=Wb8Eq+FBtt0lOKVhBaIsG3azgemKSb09LcGJTHQciL4=; b=Iqc28JgaBZwSONZFrRzBOU2BnjCFKniHNte7jhZmzPOBM/BtRKPJqTEWpov1zyhIA4 1DTpYAPYQVQNyfb0FUcRGEaFsZl/iZLK9bVEKt4LRefuXaa7xQLUK6JklK9EVoMwvHPz vEZ7gd0q6+20OPR0EpXlFB3B3DHZsRwIM5wgMSpIbRqp6u9Etzwop7wHy36Jl1PmluFJ EZLtNqU1U++Rghwigsjd9Yx9OrtChk9XL8YtJeMJCEUUC45cyvynfudjL1lkflGrrih9 v8qhP+U+RMuw2F6r+VLUHDllw41GL9cME2vAKvTBAT/Mwqvnpbz6xgITOfxNWTeGQCmQ k2yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SeB1BpL8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113290-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u21-20020a170906409500b00a47b173a6d7si739715ejj.526.2024.03.24.17.02.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:02:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SeB1BpL8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113290-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113290-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A7D201F220B9 for ; Mon, 25 Mar 2024 00:02:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0EF818E807; Sun, 24 Mar 2024 22:41:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SeB1BpL8" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B765A18E7E6; Sun, 24 Mar 2024 22:41:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320090; cv=none; b=EXRSw+ItUjCpgBz04vWfNBdbo5Vow7FUo8Xe036v1XWB1V+DpVJQhA8Y0jJHqV+nwJwKJH5I2oy/qs/ev8zDi6cSjdjcL5+DfTpLeeqh5UrlYb5LtrkVY/3VrQZ3VL1WGTGVF3sIwDG7CspVu45SWNa5kkZ1YHiK/GICj8jgves= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320090; c=relaxed/simple; bh=ScxSW6UgPUsVoztvMsj+KZEAdBvd7VPwubsif2s549w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D0NpzIdPQGXX3mOuhvkaz6HSVETMnQmXipjSyGs1SHy8te6lmMp14Vd9YlaeiXVBCcak7wGizlzVPZ5gcImn/Xi/re7jHLjnuzysGfA8zetI0nFPwhAmOKoiO3HXTnMazMIInC+H5BWMe/gAfVLdayTY7PTIoEJYx7ggD3ZMdMM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SeB1BpL8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F06BCC43390; Sun, 24 Mar 2024 22:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320090; bh=ScxSW6UgPUsVoztvMsj+KZEAdBvd7VPwubsif2s549w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SeB1BpL8dcybdlQmxf7AjaHmK+m0NuvumjH6yAyUbzMoqC0Og4qZdNVnWRDBJJ9nh 7SDMFBV9lxiHQjyzgNMPsaWPenT7GTZv2OVBY1IsDLcb9T6KBOb4Y+FdHVwZzaQpyQ 7lT/LxMndSBqeDRcL7fxWz7JeqKkmWn8HDzZLmzPLWFhmMIdw5NNDMafjlXpvuhmRN jVa9NW9TDZjVFtHKSZ97/Yfyvtmk3t2yzIuiUVLFquPpmU4TH/eejozDT6TOeOfCjQ tgT9vmsRfqBwFV60JzkHd0XNFDImmvnHVKqU+ZftphLi7/4BTk19FSBMmnySgnk0HD AJ2RHmFZTolKw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zhipeng Lu , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 6.8 399/715] media: edia: dvbdev: fix a use-after-free Date: Sun, 24 Mar 2024 18:29:38 -0400 Message-ID: <20240324223455.1342824-400-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Zhipeng Lu [ Upstream commit 8c64f4cdf4e6cc5682c52523713af8c39c94e6d5 ] In dvb_register_device, *pdvbdev is set equal to dvbdev, which is freed in several error-handling paths. However, *pdvbdev is not set to NULL after dvbdev's deallocation, causing use-after-frees in many places, for example, in the following call chain: budget_register |-> dvb_dmxdev_init |-> dvb_register_device |-> dvb_dmxdev_release |-> dvb_unregister_device |-> dvb_remove_device |-> dvb_device_put |-> kref_put When calling dvb_unregister_device, dmxdev->dvbdev (i.e. *pdvbdev in dvb_register_device) could point to memory that had been freed in dvb_register_device. Thereafter, this pointer is transferred to kref_put and triggering a use-after-free. Link: https://lore.kernel.org/linux-media/20240203134046.3120099-1-alexious@zju.edu.cn Fixes: b61901024776 ("V4L/DVB (5244): Dvbdev: fix illegal re-usage of fileoperations struct") Signed-off-by: Zhipeng Lu Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/dvb-core/dvbdev.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c index 49f0eb7d0b9d3..733d0bc4b4cc3 100644 --- a/drivers/media/dvb-core/dvbdev.c +++ b/drivers/media/dvb-core/dvbdev.c @@ -490,6 +490,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, dvbdevfops = kmemdup(template->fops, sizeof(*dvbdevfops), GFP_KERNEL); if (!dvbdevfops) { kfree(dvbdev); + *pdvbdev = NULL; mutex_unlock(&dvbdev_register_lock); return -ENOMEM; } @@ -498,6 +499,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, if (!new_node) { kfree(dvbdevfops); kfree(dvbdev); + *pdvbdev = NULL; mutex_unlock(&dvbdev_register_lock); return -ENOMEM; } @@ -531,6 +533,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, } list_del(&dvbdev->list_head); kfree(dvbdev); + *pdvbdev = NULL; up_write(&minor_rwsem); mutex_unlock(&dvbdev_register_lock); return -EINVAL; @@ -553,6 +556,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, dvb_media_device_free(dvbdev); list_del(&dvbdev->list_head); kfree(dvbdev); + *pdvbdev = NULL; mutex_unlock(&dvbdev_register_lock); return ret; } @@ -571,6 +575,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev, dvb_media_device_free(dvbdev); list_del(&dvbdev->list_head); kfree(dvbdev); + *pdvbdev = NULL; mutex_unlock(&dvbdev_register_lock); return PTR_ERR(clsdev); } -- 2.43.0