Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp239015lqr; Wed, 5 Jun 2024 04:55:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUwhTUtkw6oBhJY4Sgb4m9wuwZs4R811ejD56MV9TLobW3UKSL/yybuSEJ7HvuLWFTXG5eBgUzl98lktqVicCjPnqGpt83UcXcExQ2FA== X-Google-Smtp-Source: AGHT+IGfpyRzHbx4zZvotjr62DXHU2bYmNmXcJQGa3d/j/aNzH2orXZGLFnhZlOPoOYYDrL/eBAa X-Received: by 2002:a17:903:1c2:b0:1f4:b2ce:8dbe with SMTP id d9443c01a7336-1f6a590400dmr26706075ad.9.1717588514344; Wed, 05 Jun 2024 04:55:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717588514; cv=pass; d=google.com; s=arc-20160816; b=Zm16sRXgoe6Q2nDIiPK+5MJpa2vDXnvCGudRkFlQaTdL/v+WDsCpz7NTEFAJMsycco VbWXMtF8hLGF6zqfINkO8ycS47MbLwwecLfxNNGX/IHNr5/TgGBgf6hs724pkQFh3iDe 2LqTrUk8CGr2HvofXhGQPVZwNujSxSKpFJiG2IOuTwY0CtsYgxVJccpGOrfSP+SSngY/ CYOxMmdIWZMIw6mBn5GFW9XVWrEYJMHMMX6ogMDbFVHcHIWdEI5Gre2U4RA9XONkrBOb E/7yM56IZQLBUvCktKSvYjD5GCP6DB91hUZsMCQ16Miw35vlPgd8f7U6iWr6jow6nbDh WbPg== 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=fGJf9q7cFaH+S0tKEkglUI99ujyQdffP702z/sGMJ4Y=; fh=G2DR1Vpkshs1WPnb1O+2LDjvwFo1fyBKK/uOP2bnUnE=; b=VJ7wjr9UUum1FZOak3W+oiCE6Mj2m7P3znYMIbYpBNcI92/lEZKAiUBs1A2qXtN4xN yxBdH6NHi0hUZ/dDBK5KqfOsLltu3gDR0jX58FIKLaizFxJ597CWccqLDWSCJFU2T+p/ 9XaPp23hVGbKAcRTiI7VKEg5oDGybzYuMEoT23G1otMGfjoqdlmi+XmR3ETC3Xd5SRa7 tDBNIq+Ms4baFrLgc+uQ8Xx0Q4m1Vxdsl8wPiugj/Dv9k4RUPMdyopaTycmG2Q32jGtq EVGDdFOJxcDBGU10PsvUcC02d0SwHYD74ElQZ3LCX6tgrhL82zxc/mMeADFiXc6vP58r ip1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jz3sn4f6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202320-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202320-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1f665ea4e96si24909255ad.504.2024.06.05.04.55.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 04:55:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202320-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jz3sn4f6; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202320-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202320-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EF44128F813 for ; Wed, 5 Jun 2024 11:55:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6081A1990AE; Wed, 5 Jun 2024 11:50:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jz3sn4f6" 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 8063419885B; Wed, 5 Jun 2024 11:50:15 +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=1717588215; cv=none; b=tJotDGLEoeeTqFrV5pvGZz6gBlLqyplKrTWt43ArGZPpA4FwVIUtKeNL/Yh4jc9CK6tm+WaNY6jqwcpgAi/wm0nw5+FV/LO6Hf6HuphlXoCo33Ht+d8QPuvKz8KsiYLusy7h8VEx0i/YqH2Q2VlNRfn1tw4ECuVtth0Jc/+oKOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588215; c=relaxed/simple; bh=F7cpV+a+C7Mbpd4Oog7sdLoU5k2L8t8xst9Mf7jNOQc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CkymNMycWoAqaNyJhVzFiHuFDzUB35RedBqzxDDlAywkOUgLP4gnCcRPusTIyWkebVu8pJK4b87QJi1uqDOe6NKTcXgxmMKVvzcNJdMRUP2C6Bea1+gHvVoeMSk+Pe9N30UQzZy00FiFpd+fnZRF4dkwCkdZUkLX2rMHuZd7lwo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jz3sn4f6; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 909BCC4AF07; Wed, 5 Jun 2024 11:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588215; bh=F7cpV+a+C7Mbpd4Oog7sdLoU5k2L8t8xst9Mf7jNOQc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jz3sn4f6NJBNWErnpXXRXslCw3AzEvQ+DPaKcqtAx1CvCFuCaK6we4qHZX+Nf838u HlbmOUHzXl+HjAKOEMzCnRkXwNUW7+nFnTqRhHawsdIwhiTSsgS58NIPOIL1NtiG8h 7cgoUutJt9/8CEX8oJ3jiW7UqhpmDMOgDs8WPOrGbdRYUiiQ02p9y64d1uHQ28bRAM 0DXhFuZGW6bN/aMplomyNqse9JidLQW7SsMScWkm/IFHXxhtRbtCTgFyKdzYuKbZHR 3RT7VgXcnvo70Zr4OTZfeWBlWqPV3LXqlBVS9tij5EUN+EHHRcZjLO0VAiLMWSNXc7 VEtQbiJPd0BJQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sicong Huang , Greg Kroah-Hartman , Sasha Levin , johan@kernel.org, greybus-dev@lists.linaro.org Subject: [PATCH AUTOSEL 6.9 20/28] greybus: Fix use-after-free bug in gb_interface_release due to race condition. Date: Wed, 5 Jun 2024 07:48:49 -0400 Message-ID: <20240605114927.2961639-20-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605114927.2961639-1-sashal@kernel.org> References: <20240605114927.2961639-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 X-stable-base: Linux 6.9.3 Content-Transfer-Encoding: 8bit From: Sicong Huang [ Upstream commit 5c9c5d7f26acc2c669c1dcf57d1bb43ee99220ce ] In gb_interface_create, &intf->mode_switch_completion is bound with gb_interface_mode_switch_work. Then it will be started by gb_interface_request_mode_switch. Here is the relevant code. if (!queue_work(system_long_wq, &intf->mode_switch_work)) { ... } If we call gb_interface_release to make cleanup, there may be an unfinished work. This function will call kfree to free the object "intf". However, if gb_interface_mode_switch_work is scheduled to run after kfree, it may cause use-after-free error as gb_interface_mode_switch_work will use the object "intf". The possible execution flow that may lead to the issue is as follows: CPU0 CPU1 | gb_interface_create | gb_interface_request_mode_switch gb_interface_release | kfree(intf) (free) | | gb_interface_mode_switch_work | mutex_lock(&intf->mutex) (use) Fix it by canceling the work before kfree. Signed-off-by: Sicong Huang Link: https://lore.kernel.org/r/20240416080313.92306-1-congei42@163.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/greybus/interface.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/greybus/interface.c b/drivers/greybus/interface.c index fd58a86b0888d..d022bfb5e95d7 100644 --- a/drivers/greybus/interface.c +++ b/drivers/greybus/interface.c @@ -693,6 +693,7 @@ static void gb_interface_release(struct device *dev) trace_gb_interface_release(intf); + cancel_work_sync(&intf->mode_switch_work); kfree(intf); } -- 2.43.0