Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp783202lqt; Tue, 19 Mar 2024 03:56:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVgEvYeL6cs3gPUTSLJBpLZUNvRBDxkoWHzXwXQPoLCo9nKWznNaaoslqwLHPiSbbu1pjd/sbpQLjV3Ug3j+jfVlDZoxH3XAADLGJyyxQ== X-Google-Smtp-Source: AGHT+IHVkJX5/q1v6Voq7vRcNZ0xnEpIPF2iOYVoBp5CeNdxjiGQTsan7hGxKLekCQuVZJ27ult5 X-Received: by 2002:a54:4085:0:b0:3c3:7518:6e9e with SMTP id i5-20020a544085000000b003c375186e9emr11124935oii.59.1710845791355; Tue, 19 Mar 2024 03:56:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710845791; cv=pass; d=google.com; s=arc-20160816; b=yUaQ9MWT2pBzJML+7cnMx3iU5GVP0VDNYLCreNkZuZRxa9ZoBjd41ONx+sEJrFbEyO 83TM5ESDN4rKSFFHjf/Bqqqq7WP5JMaG4DR02QYvCJbu8Q9+ObdJc8zp1311I/7/1tqT aWBs7ejWexkk1VYjCVGpIYvJZfcIu/9mhO6ql1FJeWsOlKk7o14Vrrd1SmafeWqlLrQD zc18F5indb9OpICvxKo8NpzO4lwhdmU5vc8g9R8PUeIYu+RqImZpP1dQBeKz32hOkGel rMQ0Y970CcjzyVSiUynLo+y94T3K9PUVijxRwnXA2pZaBb7DAasNi/vpAJ95uYbMSp8Z BtkQ== 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=5uVXCANJ5w8rM/tkYp8vPaeEI4sY/7M2VBVceBxP1K4=; fh=xksad+Zzp83xTrVe2PmOl/WhHN932c88mU0+EksUUdg=; b=gjUuoze/PCFLpCrV7BqaytRzcIRuldGr6tBQnStjlXdv5lvLzbQ925TUgsIxgSxsMi 2P62lXnlf5gRAYYwvnlWqdslEc4M+bypwHExn2dklTTY4DQfNAda2SIvfCkItXXxL/BD roa4cllOIurkSHWOfuAbtEINarHr5yuTwHQ3NjMHCWOpzw4WlmYw3O4v2n3v5i+cNK8i YG4pjLD9W/pbioEE7KmAZNcrq7jp48250/yHyrck6ebaunBQ6LujA6s8RverGj+WQdb4 EhhswG+F5sO/nxNlV8SrYovxovabzWmFTic7eKdgBicI6rpWrkrAEvEklcu9iCR49+Of ndqg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=spEGFIwd; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-107424-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107424-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 n17-20020a63f811000000b005d42e7a9195si9893427pgh.713.2024.03.19.03.56.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 03:56:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107424-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=spEGFIwd; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-107424-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107424-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 E9E4C283E17 for ; Tue, 19 Mar 2024 10:55:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D1BA41C61; Tue, 19 Mar 2024 10:55:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="spEGFIwd" Received: from smtp-bc0b.mail.infomaniak.ch (smtp-bc0b.mail.infomaniak.ch [45.157.188.11]) (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 DC8FF7E116 for ; Tue, 19 Mar 2024 10:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710845737; cv=none; b=XkGsvlOk/WNwrVjv+zfsd7u03VFUK4DK6XwbF+oCCgyPr5QvGX33zt6BH9bWrO4O7JCs6LGl1UV5FQWKvyg6LVHxpgp+f/l+mkQbkPW1qGm+o4f96NjUAW5OCWA1S4gxy0xKC6CSIJSlnALyNFVgpoJpLsGo4KaNXTcJd6fCwlQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710845737; c=relaxed/simple; bh=cKJ21os4pRSqtvrUL/kk04kO+wQ5E5PRBKkuzOwE6dg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pm4jz93xFkYxF+aG7Eghw7HK1sy9GsOgRfv9pItHTavhxlRmhsHgfHCPpg+dQCEtsHkg0aC/86SKQF2h1DMOp5Qj/8Ebtl1pSkvP6GYFLCLP7TuQE+oyq4phl1rD9KLRQmsTFxt5OVi5FnVmVpja1Gam8pcZz9iNNCDSnMeyg5Q= 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=spEGFIwd; arc=none smtp.client-ip=45.157.188.11 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 (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4TzT4J40WGzM5V; Tue, 19 Mar 2024 11:49:20 +0100 (CET) Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4TzT4H6GDBz3g; Tue, 19 Mar 2024 11:49:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1710845360; bh=cKJ21os4pRSqtvrUL/kk04kO+wQ5E5PRBKkuzOwE6dg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=spEGFIwdpJZqa7BSkY0tEWGdJ6y+dr8xW4uOSjXPJfpYlV7oa60n5G2Tr9V+zXHUA wQ4ynSk2F6bNw0s0cuyAzP1aHiagfKAJQwOM4Pc689bnx1sTeClC4WU3tQ3dmsSptW LcWfKE2iVhbuBtnk8YilUaS6otG9+ivy/ZEJyrlE= 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 , "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 , 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 v3 2/7] kunit: Fix kthread reference Date: Tue, 19 Mar 2024 11:48:52 +0100 Message-ID: <20240319104857.70783-3-mic@digikod.net> In-Reply-To: <20240319104857.70783-1-mic@digikod.net> References: <20240319104857.70783-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/20240319104857.70783-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