From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA1CB1F0991 for ; Wed, 11 Mar 2026 10:47:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773226062; cv=none; b=WAf7PnDC9K66BI2vnlXXNql2dfGIBqZ2VFUevVxZPhD5MpoyCBAwLiIDCjgiB3YNPyvTg5/0uP/IE00JqlPYg08zQI1zyovXy9LopFJKk57PJHhAa6JbL3iMxkFWxp5GjuOYSlb8OSYUqqQ70OugTGrUG8CVXMqsMlGB2wRTtCE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773226062; c=relaxed/simple; bh=zRCIOZXGAulewyBbqGE0TlQlTPqeFeIDTbPGyy24MV0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M/Kvey38hxllltljXfUMcc0Q0tWF+/5PyKrN9phktKQxGWnHkG3ATtbdm6KS0CpsAme7GrSDTLiT9fBCVdIL57ALELxUEsO1pj0IgxmWrCUGRlRMNdO7Et2C3DSFDYEl0Y2ARDIs2wdfyOtsmkSOaIdm1vxK5oWecDvWPZ648R4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=l+NfnaGG; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="l+NfnaGG" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-482f454be5bso9529125e9.0 for ; Wed, 11 Mar 2026 03:47:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773226059; x=1773830859; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=us9WYwCiTBLLsk5cVeG22xmuXfkRkjPu0Kbcd1njBZs=; b=l+NfnaGGhGE/Qag8NAZKtowOcVY2wLQCbEgf8MnpvieTQKfxTgLXG7gVpu41GQE3Cp lhcuSJ3ojhuoA+XvMW4ZK8DqWwguSBIQJdzHM+m0gGn1i58Im+PG8aw4GSSmMwNkHayu W9J2Et5BO3MOuAYEpSQbP4o8f9J9gsDj/OANzpqDRda1qkC6GXeo6tLR1/FbLVhhy7Cf MUxhHc5jx0lvSaHnxQ6WahuluHX1XzGqARVN8PyVe1PrQbU+agAKtUfEmOiyxhtTA+gY BR6kn5ugraDiB91Rov4L/mant481Z758KVbs1s66hkgz+KSI4U1uv3Da1yI4gGWMgZ4d Uvjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773226059; x=1773830859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=us9WYwCiTBLLsk5cVeG22xmuXfkRkjPu0Kbcd1njBZs=; b=WrELlxACBI7OYkLHhgf1hr6gR+SUM3YWjoZ7aEZf0pOqa2ji2Ir67WekcCpua98SYZ SVNydr9QsuToEEQ/uYC6QFx6xUmh3D2zUtlp9dFY2979fQ8e2Pm1M9Ux1nt6bHw/4LJr lQr5DED0CbdhQkix7L+J8riMvzmTvJ3i9+j+BOAWOsY8L0RXluGD0Is5Y5I5zRlIse+g wHi+JWHPrEgNuW1U82dx9PWKOhzvvlQ2NOigBJ0Zn5QsPBwvkDaDpcf6OwWID0+dYbYk eYrWFAZx0DF3O8F4vOfmPEyonzBM7vSTytk7iksk8GYR/l6Q1NUf8v29PcnyzglXtknX xrXQ== X-Forwarded-Encrypted: i=1; AJvYcCWxYtC6TDSCxAXjQIffsZZyCS9n7GWOTWaNWw0BmpjX5kF+GUcP2zC6iArxaAd1ZflV9XQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yxw+HiaSaMblTG3EKHA3Vbs+yimMIw2EsmYoIR0dbjdOh5Ev4G/ hM3UnDmD9H6JvXSvVukcB57Mc81Q16p8A9wc4MMpEbMgOrQCkFEzI13s X-Gm-Gg: ATEYQzyEk77+K23QpasA97wlWiY2sEr0+K78X/DPn4C5EW4F/0M3HqO4YefF8yJwVkT B8YOlWvlWm+Qa0pv4lJEGghNOkQCFl67CijIJ4a1J8MscJooMWOomZhxhLycgBBpGiTs3R50FG8 0r5dGF+A9e/8N4KboUWnfkWEzaDde8ZVpHa6fmxOHjuZwMQ9B+WcM5egIgDzUeB4TvGo1W5a53I auHlCLbJtSnh/h+yh4oh3Eyt3JiXiERR7/iPq0iln0Q+pmdlYvZCyPHnS3GXydzMzmOC564XyIt +bpdcLFzUgY8Dv5tIlOi+cVedmq8h7XhhKzZsu1sAPzw89GUJmSaDOumJ1u2QhNHS+CMDGnmg18 CQfpiNrfU/k9hnL0+dpHO5ATJYnUJJmSckqDepGYbF7znmWg2PhO76lBbxBooz4BgSNFDw+alZt y1pTZB/o9HkbuQpYk8PPuTjlFkns/nR2NdwmqBAlWCJvGu//rzk/0PLerI35z8VUfuMebCIx63t NE= X-Received: by 2002:a05:600c:5298:b0:479:13e9:3d64 with SMTP id 5b1f17b1804b1-4854b291dc2mr30148705e9.15.1773226058755; Wed, 11 Mar 2026 03:47:38 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-439f820a2f1sm5725154f8f.30.2026.03.11.03.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Mar 2026 03:47:38 -0700 (PDT) Date: Wed, 11 Mar 2026 10:47:36 +0000 From: David Laight To: Christian Brauner Cc: Linus Torvalds , linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, linux-nfs@vger.kernel.org, bpf@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfs@lists.linux.dev, io-uring@vger.kernel.org, audit@vger.kernel.org, rcu@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev, netdev@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, Christian Loehle , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 1/2] kthread: remove kthread_exit() Message-ID: <20260311104736.51b53405@pumpkin> In-Reply-To: <20260310-work-kernel-exit-v2-1-30711759d87b@kernel.org> References: <20260310-work-kernel-exit-v2-0-30711759d87b@kernel.org> <20260310-work-kernel-exit-v2-1-30711759d87b@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 10 Mar 2026 15:56:09 +0100 Christian Brauner wrote: > In 28aaa9c39945 ("kthread: consolidate kthread exit paths to prevent use-after-free") > we folded kthread_exit() into do_exit() when we fixed a nasty UAF bug. > We left kthread_exit() around as an alias to do_exit(). Remove it > completely. ... > -#define module_put_and_kthread_exit(code) kthread_exit(code) > +#define module_put_and_kthread_exit(code) do_exit(code) I'm intrigued... How does that actually know to do the module_put()? (I know it does one - otherwise my driver wouldn't unload.) The corresponding try_module_get(THIS_MODULE) is done before the kthread_run() (and has to be 'put' if that fails). So there is an explicit 'get' but an implicit 'put'. While a loadable module that creates a kthread usually needs to give the kthread a reference to its module and then have that reference released as the kthread exits, I can imagine cases where that isn't true. (Or broken code that just hopes the module won't be unloaded just as the kthread exits.) It actually makes me think that module_put_and_exit() ought to have a 'module' parameter. Or, perhaps, kthread_create() should have the module parameter and hold a reference to that module until it exits. David