Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1184885lqe; Mon, 8 Apr 2024 00:49:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVaRpwfWpDk8KWeRVxqMNwVmQjOx3kp6O79415xM6ydSuvEcQppEdbXgabSssxqXrd0BYQwQmzHT/RS3vC4XUznknv8mt1F7E/H2xzOtQ== X-Google-Smtp-Source: AGHT+IH77xCL04x/fN1x56kLwnAtbd7210ONHOiNDGIp8IQ47ciwUgtKnYfw+lJRqg2jLeXnI5O+ X-Received: by 2002:a50:cd19:0:b0:56e:2df8:8c80 with SMTP id z25-20020a50cd19000000b0056e2df88c80mr5128676edi.35.1712562557576; Mon, 08 Apr 2024 00:49:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712562557; cv=pass; d=google.com; s=arc-20160816; b=t4nqdxHjttku97JgaasI+ZfFoXXzhVxJFCBZ4jLMlTuWCxF6RetbzFSWbKhznIP5uq jxVc3q9UQkzL+GxCyDgsKyxtzyEvRjyi9J34xNw81pakr9v8ibqxD0BsHLCvs0XMoMoB aVnF89bNY9PYEU7X+G56ItAgpLxzBaUXIh+LHBJlPr3qQ0qacEwMv5cHtW9S7g6X3R8Y 26zyXRZgMe28cJQ/o4Uf0BZSG8xsFroRfGYrXc5W+lQzyT/jDVvcn2b77rrIuPMeo014 6t/+hr4Xh6OmcKlNTp/tYXhidyuZubhZnuTvAhRVrG358tj6iUFg8BbUurf6KSnxgZQi fZ0w== 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=Mu6qCkeJNr1PPLz9J1vatxpwn4njuqEkQ3wAe2TXeuo=; fh=ebRmPuOzT/NtOLoMMfuhuYI4lG8a7a9TwT5pL03u+Ns=; b=l7DTbQYQrTCj5gISwAe+VQt225O26gbp6P7H4ztGUNvG2ARJFCJvHvodsatvqGdAy3 HrhMJrZvpMDRXVzIPgqgrsfjdupxiB/Gl5PMDyWrryxp9QtzBKQMvy4Mrkvo817VXP2W XdCiZA2moKtYuAaQkMAv+06BaWDGNJspUdWryUmhbyeUKG+PvPUKElWwGoxFetJUdE7F L1vkByGTtEw0fjisKWK79ynLxxQUqnFInMJFufnBmuIrRkxvZTlQggRxda5xmX+g0Qg4 Q5KMjMVXhojAMwlwoc/qtxjzJDt4HzBwxyWh7B113vbzcY82hT/bJF2oxrccQmfVS4FN lUsg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=WKQv+p9G; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-134938-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134938-linux.lists.archive=gmail.com@vger.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 c24-20020a50d658000000b0056bfa25550asi3333905edj.302.2024.04.08.00.49.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 00:49:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-134938-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=@digikod.net header.s=20191114 header.b=WKQv+p9G; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-134938-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-134938-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4EE021F21C00 for ; Mon, 8 Apr 2024 07:49:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6763C3BB47; Mon, 8 Apr 2024 07:47:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="WKQv+p9G" Received: from smtp-bc09.mail.infomaniak.ch (smtp-bc09.mail.infomaniak.ch [45.157.188.9]) (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 C68DD2C69A for ; Mon, 8 Apr 2024 07:47:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712562424; cv=none; b=bORNxGcQo4yUssOnv6pTZXVMU5ZwE9c/qH/w2/594t02kosYCqfjz1NLoUbTIBaS4vIYKfKwVCsseBnKchLWuEXxTjhYdBELyUV9fJt+T+f4JX6I7YQxfS+2PVOk5NyaFAjdYH+dKIo0OkgTJ56bdMUxWsJUzSXXFN1IHgWZlug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712562424; c=relaxed/simple; bh=6Iw+PQ6mBt8QbMOSfNH3ppo/54xw6BUauZjHO04urRI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uv0raDYiVZA4Bkr7NVCBIvXV9EtMLZzWiYuEPYdPCqYsk98gO5Dx2yidVIAyi55go2LgHa5AmnQZPovDwGpQw0oe5nK1JJOg/Pc6IK9ZN5xZJKwhAUqH5IKxIB3bDyVgHsJh2iR7CnOsyFLPP6DjEl77oZzHaVAGU2i0zU6PAi0= 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=WKQv+p9G; arc=none smtp.client-ip=45.157.188.9 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-4-0000.mail.infomaniak.ch (smtp-4-0000.mail.infomaniak.ch [10.7.10.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VCh4Y74BQzMSk; Mon, 8 Apr 2024 09:46:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1712562413; bh=6Iw+PQ6mBt8QbMOSfNH3ppo/54xw6BUauZjHO04urRI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKQv+p9Gk0jxfFem0q2/Gur7IS1MQ/zci0LgHJAv+K5Jne10lQtxjdfBNDJSYI0W1 KMtoG6WxjA9B84AXvaOuYxgrN4okbGPiqDMUz34Zylk+Okiu+N1tNn5qgKN2J9zYXy tlZdAqyj7rZY+x2Y5qRp5DxKi9SsCd99f66pypew= Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4VCh4Y1Dz0zgsN; Mon, 8 Apr 2024 09:46:53 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Brendan Higgins , David Gow , Rae Moar , Shuah Khan Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Alan Maguire , Borislav Petkov , Dave Hansen , "Eric W . Biederman" , "H . Peter Anvin" , Ingo Molnar , James Morris , Kees Cook , Luis Chamberlain , "Madhavan T . Venkataraman" , Marco Pagani , Paolo Bonzini , Sean Christopherson , Stephen Boyd , Thara Gopinath , Thomas Gleixner , Vitaly Kuznetsov , Zahra Tarkhani , kunit-dev@googlegroups.com, kvm@vger.kernel.org, linux-hardening@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-security-module@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org Subject: [PATCH v4 RESEND 2/7] kunit: Fix kthread reference Date: Mon, 8 Apr 2024 09:46:20 +0200 Message-ID: <20240408074625.65017-3-mic@digikod.net> In-Reply-To: <20240408074625.65017-1-mic@digikod.net> References: <20240408074625.65017-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: Shuah Khan Reviewed-by: Kees Cook Fixes: adf505457032 ("kunit: fix UAF when run kfence test case test_gfpzero") Reviewed-by: David Gow Reviewed-by: Rae Moar Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240408074625.65017-3-mic@digikod.net --- Changes since v2: * Add Fixes tag as suggested by David. * Add David's and Rae's Reviewed-by. Changes since v1: * Add Kees's Reviewed-by. --- 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