Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp258879lqr; Wed, 5 Jun 2024 05:28:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVUtW/jZOqLOiFE3ozh7ECG5lVcBeElmMV/UHZGvgf0Y39EZmNcCpAEJ0jwOEsv5O/L2Te84oUDIUF6v4pHV5qlwbOx921VRIh1v+lQzg== X-Google-Smtp-Source: AGHT+IG6kb1MQ0qBhAMbWZIQIa5Yj6jUcS+ilS8Pd0xbz4aZ8E9L1oyfi4Oj7UGK/130+olY6HHx X-Received: by 2002:a05:6a20:4327:b0:1af:5a6f:1c62 with SMTP id adf61e73a8af0-1b2b6e8f23cmr3298774637.4.1717590512976; Wed, 05 Jun 2024 05:28:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717590512; cv=pass; d=google.com; s=arc-20160816; b=uNppKcZPDM2IH9n9ZTGFo+q9Seva0ZrbgEhKjj3qPWAHaSYXTqGLIWl2P4faqXmNaU eJzuJ+KcBEy0WG8Ddi7X305rMJILtIh6kVNdnEWxiGTu/Z4JNZt2m56MgukEvJNy/ccv TTCSheIi6G9q2xs/YNl9TyvAugc+WyNE1XIuRInAFqfxQMzZTlPmTVWtc8SetCvFZibv LWsM8dHmnQSujXM6wePfNq+yj2V0ZkNJSu6amCNgwgJ/DCp8jUuKTjKAjfO3vR7nookZ HEfCWG8u3EjtW4M+R/wkAbAMbJPxtFVWFJPZWyXFbWEPsRrrJEXcjpzVnhcoEWfJW+i/ Q99w== 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=YLzoa6hjunA5fFbK1sO/TM5nEwAoWd0OvGRlpHc17seVT9M9IlbXWN7BmwrYkFTA/w 0WqCpoJH/d4el6tRCklfhw7LWgJMv2raWeW/W2zIfx/OMUeEcQ2zG7cePZOwkPXHVNWi 48QnhzpelHpMln67Q4nLMrlFQncIPPzcPBNZWMjJK+yBygsaDSxlYHuJwzk5DDKlvpHS h7VS/kTQk0/KoErbYE5Y6D+zIglJxroOxFMOFJdanqwI8BqdkaGjtHEg3mzXemLdxP85 GowxC1HKVe/g2CJ4N63eJ4A1Xf9tOuxeZr8eRTSXrmTwlSgjCvFgr8aLaSjs631XBdcd ZyrQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rJyO1eFw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202390-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202390-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 d2e1a72fcca58-7026f797585si5209746b3a.195.2024.06.05.05.28.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:28:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202390-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=rJyO1eFw; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202390-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202390-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 8763B2872A6 for ; Wed, 5 Jun 2024 12:13:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 991BC197528; Wed, 5 Jun 2024 11:54:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rJyO1eFw" 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 BD088196C9A; Wed, 5 Jun 2024 11:54:06 +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=1717588446; cv=none; b=FfdgXBWvYj564nw16zccpfJIx9WvOYiWTWKdVh8Vqp7TCKwhvp2JkTjAAYNwwxyuOX/d5VEW2ZXE7bCWgWdxPnTNuePTgYVhJCr61rhBZk4RL2RVFbDOaj6lknU3r8vrKvxtnFK/xxa4JG83zjLvGNxW07NRbIpQqmMzlD/4fnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588446; c=relaxed/simple; bh=kiI/Lw2TK9Xytq4SD7omgBRD9aRnbSVuuUnrkQXDmf0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K5W/DffwO3Zt3DCpgqhUOt2/Dzy3kWd3cgINv2EB5p3qooDfUCbn2PDmGL7cr68vW3uCoye/9xyrmV1XTg8m+s4pc8YbkOal1EjOwr6KMSyj7fxfLd6uNaT3XerF//QLxa2MXt603q/9r+5Nqe72GQymzCEQoiX0MLT4/OedV80= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rJyO1eFw; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70E47C32786; Wed, 5 Jun 2024 11:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588446; bh=kiI/Lw2TK9Xytq4SD7omgBRD9aRnbSVuuUnrkQXDmf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rJyO1eFwRmdFWdWSuTAeHp3tP1NPl6lcIciiTOT4dUbrmD5+QNRcsdHoCow6dENHj OdV7irkqRA+RzFkcxPzYyx1MUFpjbpyUs1ZnRrkUKXC1Ux0QaPhs+RwRfdgvLUHQRY /dSksl+xCjaGzkpU9IDHClr/K6oHGXm5eQpyq0lPApJQtJvzbDR+27HOXrPM869gy9 M0ptnwRX/pkIiFXT7HkeW//gYqhiJ77tl6TJfERy1lgKUz73+Agv58nOOeVFBcq/NN jqy07aMuGbCbXlUH0pbpwWxxBWhRJ6XM3o9XS43yBsx4cLuXckaXfFu5tj8LfAtTKi o1fN1FLWwM+Cg== 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.1 12/12] greybus: Fix use-after-free bug in gb_interface_release due to race condition. Date: Wed, 5 Jun 2024 07:53:17 -0400 Message-ID: <20240605115334.2963803-12-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605115334.2963803-1-sashal@kernel.org> References: <20240605115334.2963803-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.1.92 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