Received: by 2002:ab2:3b09:0:b0:1ed:14ea:9113 with SMTP id b9csp15728lqc; Thu, 29 Feb 2024 09:05:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWwn3NixyP0kUyUEs8pUO9lcTldrLzcQT7zeEVzGNM+kli57N0Ngvk23ZxNsRa7eO/EI6JGFAWqGDAWYCN4IJY9GOL/PDQDVeP/WdlreA== X-Google-Smtp-Source: AGHT+IGT9HTRAefWKVJKeUfi5fwJ8XNstQuKsGuUMfBoVVUP+Rxoqt94wCGGTQ4q0nzAfuxK8HFz X-Received: by 2002:a6b:630b:0:b0:7c7:cd56:f17 with SMTP id p11-20020a6b630b000000b007c7cd560f17mr2674334iog.19.1709226329923; Thu, 29 Feb 2024 09:05:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709226329; cv=pass; d=google.com; s=arc-20160816; b=zoRs9lAxwYYsE6s6fEBLnwXyM4ARewMrM8dQnKH+qMbbRfej6GATvmiQ6nrbudYNTl 55kBFkXcX4bYqmfKdqr5F4F1MyjjK/E4MNHf6sKCgIb3DlWyVVhn0HUAkjV8IFecirFm bJ7bXGZNopFD6/6TaKCK/IQ/xKLSbxw37xNJXTccj6CP4cShL6JonnUPRCVPhpWJAAOX NDhzYMwbHSKVg4agrw1ymM6IVXNcFGM3ZM/Tl6yvCwYfT/ZTaZB3Lzx5AchuD2wxA+bd 6L7655sggQtG+DsesvjgqSgbqDAV8JYSp/GczLs3L1G2F4pqjdBiNipXt/5E8GDhiix8 Ydjg== 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=MNglwpmLEePBb8360PGrEXCzcK/Vl81TDbkPNteMmZg=; fh=MR/wbEn34JHmT+rtzWNq5RVU/RKi8DhjSvb3ywiuLkE=; b=Dre7uklJATQiLw/dK7FjcJDHskprhm9+oLeQHot7IVVz1v2GG5ZgqFfsnY7s9nJu7A yz25ZE4NvmG1XbmfFkaU8iTwPXQWzQBkbnzsJqvw+nXRQctrqFzBozYD9JrHUgdHIohP Drf2/YWajtGXuncBBIdHdV1DyI6fyPuqeVIaPP2ypztuXydthND9K5UikJO6BmT1uSmU x1KXPCoVhVBUJMxx1FKVEn5X4fb14OynDqjbxcx8hCrTjGEQjhHr5fRTXB2P535lhryP afNaZ9Uu72ZnaxvxtzBKRnUFqgIvwmXZmxOtTuGltb1MAoq0IGf+Vn2ZZyR11b9pHnit fBXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=gcmoNxGK; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-87136-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87136-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h1-20020a0566380f0100b00473f2e06ccbsi654181jas.12.2024.02.29.09.05.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 09:05:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87136-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=gcmoNxGK; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-87136-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87136-linux.lists.archive=gmail.com@vger.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 98894289789 for ; Thu, 29 Feb 2024 17:05:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05F1670AFA; Thu, 29 Feb 2024 17:04:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="gcmoNxGK" Received: from smtp-42ac.mail.infomaniak.ch (smtp-42ac.mail.infomaniak.ch [84.16.66.172]) (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 BCC844AEDA for ; Thu, 29 Feb 2024 17:04:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709226277; cv=none; b=q1Sko7fl7Hk+C5q0SEF5oIDKjCKXK71mlTftfSp/CSO9/6FWFN5Et1kDSoh7y5e9YRemBuQa9Dkzx50kvzt/T/vmo37xzA3yME+XKNk7ccf+K5GE7za/MyxvUrItBEBJfF2cAkh9rNRxrkXP3uGFTE9kGwgJzw1htkjqHu59qwY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709226277; c=relaxed/simple; bh=f3wQ1gxeTPJnB2/Gx7Deo/AawwvRjdcM6xP+hwNtgJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KEmfoe8pcIRkOrR96prnb21IxZTZ5N4luf/5JRID1l6Uvn8pvTethbPHfvTba3IPzN+BsyGBCg//bb8WfRB6zyssdenFP8spzyHPVqNfQvm4KAb8yzSdICHxvCbSrBJswtquNItjklDW8KRLr5GEBSbsHo+zlkkdLaocPHiIMc8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=gcmoNxGK; arc=none smtp.client-ip=84.16.66.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0000.mail.infomaniak.ch (unknown [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4TlyHt43J2zMrktk; Thu, 29 Feb 2024 18:04:26 +0100 (CET) Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4TlyHt04GMz3g; Thu, 29 Feb 2024 18:04:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1709226266; bh=f3wQ1gxeTPJnB2/Gx7Deo/AawwvRjdcM6xP+hwNtgJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gcmoNxGKgHYnKVXBDTBQhQzczqpk0AxQqq9JNXYdDODHvh/MAoOXfB/kwfdeEagYp NERBG2Kr74hChpupRTAofgZCk4ummr2hEYGU9T9zi+Tiqlcq/wnfCSFRB+ktAVcOJM XfkR6BWeRDyyrWQGtYg1MRUyDHGWxF7r/xVDhEOA= From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Brendan Higgins , David Gow , Kees Cook , Rae Moar , Shuah Khan Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Alan Maguire , Borislav Petkov , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , James Morris , Luis Chamberlain , "Madhavan T . Venkataraman" , Marco Pagani , Paolo Bonzini , Sean Christopherson , Stephen Boyd , Thara Gopinath , Thomas Gleixner , Vitaly Kuznetsov , Wanpeng Li , Zahra Tarkhani , kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org Subject: [PATCH v1 3/8] kunit: Fix kthread reference Date: Thu, 29 Feb 2024 18:04:04 +0100 Message-ID: <20240229170409.365386-4-mic@digikod.net> In-Reply-To: <20240229170409.365386-1-mic@digikod.net> References: <20240229170409.365386-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha There is a race condition when a kthread finishes after the deadline and before the call to kthread_stop(), which may lead to use after free. Cc: Brendan Higgins Cc: David Gow Cc: Rae Moar Cc: Shuah Khan Signed-off-by: Mickaël Salaün --- lib/kunit/try-catch.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/kunit/try-catch.c b/lib/kunit/try-catch.c index a5cb2ef70a25..73f5007f20ea 100644 --- a/lib/kunit/try-catch.c +++ b/lib/kunit/try-catch.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "try-catch-impl.h" @@ -65,14 +66,15 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context) try_catch->context = context; try_catch->try_completion = &try_completion; try_catch->try_result = 0; - task_struct = kthread_run(kunit_generic_run_threadfn_adapter, - try_catch, - "kunit_try_catch_thread"); + task_struct = kthread_create(kunit_generic_run_threadfn_adapter, + try_catch, "kunit_try_catch_thread"); if (IS_ERR(task_struct)) { try_catch->try_result = PTR_ERR(task_struct); try_catch->catch(try_catch->context); return; } + get_task_struct(task_struct); + wake_up_process(task_struct); time_remaining = wait_for_completion_timeout(&try_completion, kunit_test_timeout()); @@ -82,6 +84,7 @@ void kunit_try_catch_run(struct kunit_try_catch *try_catch, void *context) kthread_stop(task_struct); } + put_task_struct(task_struct); exit_code = try_catch->try_result; if (!exit_code) -- 2.44.0