Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp252723lqr; Wed, 5 Jun 2024 05:16:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyWs2mo1pn7m/svxuTrY8sePOhoSM2rD2pDlkTylBlvoZxuZEoscLaK3CLj93b8qXArRKC1hIhwx73fEIbvzgt3++jOtlJc1Hmb/ktWA== X-Google-Smtp-Source: AGHT+IFYdRRuqzuQyLaGjmd2R6KE7s5AXnFlIhB9fBM0KWHEHSTIsvCSwXz5DNQTd8AAQKX6q7dn X-Received: by 2002:a05:6359:4ca7:b0:199:2ecd:ec4c with SMTP id e5c5f4694b2df-19c6c688471mr275070555d.11.1717589817237; Wed, 05 Jun 2024 05:16:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717589817; cv=pass; d=google.com; s=arc-20160816; b=Ebcplgb/Llgd+3I9SmcFp0TiLHlInXDHRQWEMOvhasTT8tZ8hSXQlHKlOZZ7kk5wO1 JzmJJ1+jp4wDit++13OjR1xSXWr4Q9RMcWuqLlpjPqkO+nXIdy4XWRLcAgE1dxPG+BeE 013PHYC6Z28aOV694+EbiRnSB1bv9RueS0cauT3vddSlkD93EgZo8+zlR4UZmG86mQHu 7ZuNwo/SHX290nEx3aJGg8ZzOGomec/5nX5wUo0PJXZDPmGEwxD6+NNyB9/0VxCZ3YVZ HGr2hVDDmDOpA0Oq5xO+t0M7Ei6eR8jEjmwOBXmCwzjvgQR1CqLLRytH3cU175skc0JZ LP8Q== 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=6XrSVN9LCjeMRRdhLYtzw3E6urhyxjyEVdwsHCZ8LJc=; fh=G2DR1Vpkshs1WPnb1O+2LDjvwFo1fyBKK/uOP2bnUnE=; b=Iub0Agaa6ZpWljt0u6dcbbCNPFr4vr7nR0f7M7BFDw0UwmAqkh8MoGWTHJSgCXsylr eVm/BOpkNpIuzFcPFxjUqidqWAdXSxDdkoeeqBIrWtG7iZ2g0/IvlTn3KxcMZfQXTkbR ArB9kG7q68JVwp+7xjtvovH83MoD5525fW0cc94mNOx7tNPT/pIXgsvyYvAUZ/8NFvl/ xun4MI36Hy30PQSVM7D8YznM2ddYpwT+/qct9OrMEmDwN7prx4UTFn8BsJ66GKhIli2U EYN2SqrQPd7po14TVb4shhrfuzxCqNWm2cIP/JRatJ0BHi3iphz6yq4qXaSA8maM9E/t bbXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hFMJuUL1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202407-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43ff2466b7esi121973071cf.231.2024.06.05.05.16.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hFMJuUL1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202407-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202407-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id EB4B91C231FE for ; Wed, 5 Jun 2024 12:16:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9911D198E60; Wed, 5 Jun 2024 11:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hFMJuUL1" 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 C045F19412B; Wed, 5 Jun 2024 11:54:57 +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=1717588497; cv=none; b=gjfe1mk7w3Qz/bCoh+CEpulZAypgahRRyS03PlbIpzC+nnXerxBRTtefNMEVxIOkOGNFrM6+lWAqtnDMp/bMYyuNCoO0sJhi6KikHGPlUgC+O2g7cksv5aXAjvGbYKK0JFaG8Id6kEnZ4xJkxezAOjdGEnkgSoPQTknR2AGio18= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588497; c=relaxed/simple; bh=kiI/Lw2TK9Xytq4SD7omgBRD9aRnbSVuuUnrkQXDmf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pddTx/ABjHK2M8WID85Wla235+wki5mP0oatDMNeRJFkQi+EjznynERnMLPDxgTqOEwB4O5zWuV+zklTEJVpTSffWHQ8ptudW228qjb+T7p1FkXZCb23MJbGAVIlziDnKEUOIjkMfrgWJg51oehtjJ20Nj4nktOOCMfKZR91Jgg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hFMJuUL1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id D233EC3277B; Wed, 5 Jun 2024 11:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588497; bh=kiI/Lw2TK9Xytq4SD7omgBRD9aRnbSVuuUnrkQXDmf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hFMJuUL1JA2elYKgKSmpgR4eSJL/1r5sE0B7oVz2+wUeToirXEQfugfi4bcnltIlQ 2mhgryxBrnVK95L6lJa14ptDl42h4mzGPQ0Ktc+GSEKjK6+ZYA3nmUnmcBcTg98XNi tmEDz+wkCGU3D1VTD7z/Iw2LP6Ymrvq9dX3SYpuxNJ8S+XlKAn7myVmgkIdHRVTIpF lRijNoLG6xZ4IdLMqdVUcq6IHm6YOrxTIO0HGinuwHroF6gXq/ryI+oFR0J1G5NkT9 9pbNbVYHz6ZXYrc0pN+W2SXZiQV9di8/bIx5s5RxH6AJ0sh15A8TUPqKanSBuTrdMp bkLVwW6PLOCWA== 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 5.10 7/7] greybus: Fix use-after-free bug in gb_interface_release due to race condition. Date: Wed, 5 Jun 2024 07:54:36 -0400 Message-ID: <20240605115442.2964376-7-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605115442.2964376-1-sashal@kernel.org> References: <20240605115442.2964376-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 5.10.218 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 9ec949a438ef6..52ef6be9d4499 100644 --- a/drivers/greybus/interface.c +++ b/drivers/greybus/interface.c @@ -694,6 +694,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