Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH 0/2] Add __require_explicit_initialization and its first user
@ 2026-10-14 22:58 Kees Cook
  2026-10-14 22:58 ` [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations Kees Cook
  0 siblings, 1 reply; 11+ messages in thread
From: Kees Cook @ 2026-10-14 22:58 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Kees Cook, Greg Kroah-Hartman, Nathan Chancellor, Bill Wendling,
	Justin Stitt, Jonathan Corbet, Andy Whitcroft, Joe Perches,
	Mauro Carvalho Chehab, Christian König, Ian Rogers,
	Nick Desaulniers, Christian Brauner, Jan Kara, Al Viro, llvm,
	linux-doc, linux-fsdevel, linux-kernel, linux-hardening

Hi!

As discussed in Ian's kobj_type::release series[1], this takes its first
patch (to add __require_explicit_initialization), with Miguel's requested
comment tweak (the attribute needs Clang 20 or later), along with a first
user that needs no fix-ups first: seq_file's seq_operations callbacks,
which are called without a NULL check. This will make the attribute
available in v7.4-rc1, while the kobj_type fixes continue separately.

The annotation adds no warnings anywhere in the tree today that I could
find across allmodconfig builds:

  Clang 24.0.0git: x86_64, arm64, i386, arm, riscv, s390, loongarch, powerpc.
  GCC 16.2.0: x86_64, arm64, i386, arm, riscv, s390, m68k, mips, parisc,
	      sparc, loongarch, xtensa, arc, and openrisc.

Thanks!

-Kees

[1] https://lore.kernel.org/all/20261013223946.1836757-1-irogers@google.com/

Ian Rogers (1):
  Compiler Attributes: Add __require_explicit_initialization macro

Kees Cook (1):
  seq_file: Require explicit initialization of struct seq_operations

 scripts/checkpatch.pl                 |  1 +
 Documentation/conf.py                 |  1 +
 include/linux/compiler_attributes.h   | 12 ++++++++++++
 include/linux/seq_file.h              | 13 +++++++++----
 tools/lib/python/kdoc/xforms_lists.py |  1 +
 5 files changed, 24 insertions(+), 4 deletions(-)

-- 
2.55.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-14 22:58 [PATCH 0/2] Add __require_explicit_initialization and its first user Kees Cook
@ 2026-10-14 22:58 ` Kees Cook
  2026-10-15  5:21   ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Kees Cook @ 2026-10-14 22:58 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Kees Cook, Alexander Viro, Christian Brauner, Jan Kara,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-fsdevel, llvm, linux-kernel, linux-hardening

In the very unlikely chance that a seq_operations didn't get initialized,
we wouldn't want them calling some random location. As a first example
user of __require_explicit_initialization, annotate them so a missing
initializer is a compile-time warning.

Every seq_operations in the tree already sets all four, so no new warnings
are added.

Signed-off-by: Kees Cook <kees@kernel.org>
---
 include/linux/seq_file.h | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
index dc0e8c62d9e0..f0e7e52a0905 100644
--- a/include/linux/seq_file.h
+++ b/include/linux/seq_file.h
@@ -28,11 +28,16 @@ struct seq_file {
 	void *private;
 };
 
+/* All four are called without checking for NULL. */
 struct seq_operations {
-	void * (*start) (struct seq_file *m, loff_t *pos);
-	void (*stop) (struct seq_file *m, void *v);
-	void * (*next) (struct seq_file *m, void *v, loff_t *pos);
-	int (*show) (struct seq_file *m, void *v);
+	void *(*start)(struct seq_file *m, loff_t *pos)
+		__require_explicit_initialization;
+	void (*stop)(struct seq_file *m, void *v)
+		__require_explicit_initialization;
+	void *(*next)(struct seq_file *m, void *v, loff_t *pos)
+		__require_explicit_initialization;
+	int (*show)(struct seq_file *m, void *v)
+		__require_explicit_initialization;
 };
 
 #define SEQ_SKIP 1
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-14 22:58 ` [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations Kees Cook
@ 2026-10-15  5:21   ` Greg KH
  2026-10-15  5:46     ` Miguel Ojeda
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2026-10-15  5:21 UTC (permalink / raw)
  To: Kees Cook
  Cc: Miguel Ojeda, Alexander Viro, Christian Brauner, Jan Kara,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-fsdevel, llvm, linux-kernel, linux-hardening

On Wed, Oct 14, 2026 at 03:58:16PM -0700, Kees Cook wrote:
> In the very unlikely chance that a seq_operations didn't get initialized,
> we wouldn't want them calling some random location. As a first example
> user of __require_explicit_initialization, annotate them so a missing
> initializer is a compile-time warning.
> 
> Every seq_operations in the tree already sets all four, so no new warnings
> are added.
> 
> Signed-off-by: Kees Cook <kees@kernel.org>
> ---
>  include/linux/seq_file.h | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
> index dc0e8c62d9e0..f0e7e52a0905 100644
> --- a/include/linux/seq_file.h
> +++ b/include/linux/seq_file.h
> @@ -28,11 +28,16 @@ struct seq_file {
>  	void *private;
>  };
>  
> +/* All four are called without checking for NULL. */
>  struct seq_operations {
> -	void * (*start) (struct seq_file *m, loff_t *pos);
> -	void (*stop) (struct seq_file *m, void *v);
> -	void * (*next) (struct seq_file *m, void *v, loff_t *pos);
> -	int (*show) (struct seq_file *m, void *v);
> +	void *(*start)(struct seq_file *m, loff_t *pos)
> +		__require_explicit_initialization;
> +	void (*stop)(struct seq_file *m, void *v)
> +		__require_explicit_initialization;
> +	void *(*next)(struct seq_file *m, void *v, loff_t *pos)
> +		__require_explicit_initialization;
> +	int (*show)(struct seq_file *m, void *v)
> +		__require_explicit_initialization;
>  };

Hm, I acked the first patch, but seeing this "in the wild" is
interesting.  Feels kind of ackward, but I don't really know what to
suggest instead?  What about just making the lines longer:

	void *(*start)(struct seq_file *m, loff_t *pos)		__require_explicit_initialization;
	void (*stop)(struct seq_file *m, void *v)		__require_explicit_initialization;
	void *(*next)(struct seq_file *m, void *v, loff_t *pos) __require_explicit_initialization;
	int (*show)(struct seq_file *m, void *v)		__require_explicit_initialization;

?

Anyway, I don't know.  I like this feature, and maybe it's going to be
used so infrequently it's not a big deal, but feels clunky.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  5:21   ` Greg KH
@ 2026-10-15  5:46     ` Miguel Ojeda
  2026-10-15  5:57       ` Kees Cook
  0 siblings, 1 reply; 11+ messages in thread
From: Miguel Ojeda @ 2026-10-15  5:46 UTC (permalink / raw)
  To: Greg KH
  Cc: Kees Cook, Miguel Ojeda, Alexander Viro, Christian Brauner,
	Jan Kara, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-fsdevel, llvm, linux-kernel, linux-hardening

On Thu, Oct 15, 2026 at 7:21 AM Greg KH <greg@kroah.com> wrote:
>
> Anyway, I don't know.  I like this feature, and maybe it's going to be
> used so infrequently it's not a big deal, but feels clunky.

Perhaps we could call it something shorter, like `__explicit_init` or
similar -- I don't see that substring (even without the double
underscores) used anywhere.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  5:46     ` Miguel Ojeda
@ 2026-10-15  5:57       ` Kees Cook
  2026-10-15  7:11         ` Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Kees Cook @ 2026-10-15  5:57 UTC (permalink / raw)
  To: Miguel Ojeda, Greg KH
  Cc: Miguel Ojeda, Alexander Viro, Christian Brauner, Jan Kara,
	Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
	linux-fsdevel, llvm, linux-kernel, linux-hardening



On October 14, 2026 10:46:02 PM PDT, Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
>On Thu, Oct 15, 2026 at 7:21 AM Greg KH <greg@kroah.com> wrote:
>>
>> Anyway, I don't know.  I like this feature, and maybe it's going to be
>> used so infrequently it's not a big deal, but feels clunky.
>
>Perhaps we could call it something shorter, like `__explicit_init` or
>similar -- I don't see that substring (even without the double
>underscores) used anywhere.

That's nice, yeah. And it's not the first time we've changed the "spelling" of an attribute.

Does anyone object to that? I can replace it with that in my tree...

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  5:57       ` Kees Cook
@ 2026-10-15  7:11         ` Greg KH
  2026-10-15  7:47           ` Miguel Ojeda
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2026-10-15  7:11 UTC (permalink / raw)
  To: Kees Cook
  Cc: Miguel Ojeda, Miguel Ojeda, Alexander Viro, Christian Brauner,
	Jan Kara, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-fsdevel, llvm, linux-kernel, linux-hardening

On Wed, Oct 14, 2026 at 10:57:57PM -0700, Kees Cook wrote:
> 
> 
> On October 14, 2026 10:46:02 PM PDT, Miguel Ojeda <miguel.ojeda.sandonis@gmail.com> wrote:
> >On Thu, Oct 15, 2026 at 7:21 AM Greg KH <greg@kroah.com> wrote:
> >>
> >> Anyway, I don't know.  I like this feature, and maybe it's going to be
> >> used so infrequently it's not a big deal, but feels clunky.
> >
> >Perhaps we could call it something shorter, like `__explicit_init` or
> >similar -- I don't see that substring (even without the double
> >underscores) used anywhere.

__must_init might be smaller?

Naming is hard :)

> That's nice, yeah. And it's not the first time we've changed the "spelling" of an attribute.
> 
> Does anyone object to that? I can replace it with that in my tree...

No objection from me to make it shorter, and yes, we can always change
it going forward if someone comes up with a better term.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  7:11         ` Greg KH
@ 2026-10-15  7:47           ` Miguel Ojeda
  2026-10-15  8:47             ` Greg KH
  2026-10-15 20:07             ` Kees Cook
  0 siblings, 2 replies; 11+ messages in thread
From: Miguel Ojeda @ 2026-10-15  7:47 UTC (permalink / raw)
  To: Greg KH
  Cc: Kees Cook, Miguel Ojeda, Alexander Viro, Christian Brauner,
	Jan Kara, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-fsdevel, llvm, linux-kernel, linux-hardening

On Thu, Oct 15, 2026 at 9:11 AM Greg KH <greg@kroah.com> wrote:
>
> __must_init might be smaller?

That sounds fine too. I like that it says that something *has* to be
done (like the original name did). Hmm... On the other hand, I guess
"must" could sound like one has to initialize the field "somehow",
i.e. writing:

  struct S s = {};

definitely initializes it, yet the compiler would warn. Would
"explicit" hint a bit more at the fact that one has to actually
"write" the field, even if it may have been initialized anyway?

(Of course, if one knows that the attribute only applies to fields,
then it doesn't make much of a difference)

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  7:47           ` Miguel Ojeda
@ 2026-10-15  8:47             ` Greg KH
  2026-10-15 22:29               ` Ian Rogers
  2026-10-15 20:07             ` Kees Cook
  1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2026-10-15  8:47 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Kees Cook, Miguel Ojeda, Alexander Viro, Christian Brauner,
	Jan Kara, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-fsdevel, llvm, linux-kernel, linux-hardening

On Thu, Oct 15, 2026 at 09:47:34AM +0200, Miguel Ojeda wrote:
> On Thu, Oct 15, 2026 at 9:11 AM Greg KH <greg@kroah.com> wrote:
> >
> > __must_init might be smaller?
> 
> That sounds fine too. I like that it says that something *has* to be
> done (like the original name did). Hmm... On the other hand, I guess
> "must" could sound like one has to initialize the field "somehow",
> i.e. writing:
> 
>   struct S s = {};
> 
> definitely initializes it, yet the compiler would warn. Would
> "explicit" hint a bit more at the fact that one has to actually
> "write" the field, even if it may have been initialized anyway?

"explicit" is a description, "must" is an action that tells the reader
what they have to do, so maybe "must" is better?

Anyway, I don't care, naming is hard, either is fine with me, I'll let
the authors of the patch here pick what they want :)

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  7:47           ` Miguel Ojeda
  2026-10-15  8:47             ` Greg KH
@ 2026-10-15 20:07             ` Kees Cook
  2026-10-15 20:47               ` Nick Desaulniers
  1 sibling, 1 reply; 11+ messages in thread
From: Kees Cook @ 2026-10-15 20:07 UTC (permalink / raw)
  To: Miguel Ojeda, Ian Rogers
  Cc: Greg KH, Miguel Ojeda, Alexander Viro, Christian Brauner,
	Jan Kara, Nathan Chancellor, Nick Desaulniers, Bill Wendling,
	Justin Stitt, linux-fsdevel, llvm, linux-kernel, linux-hardening

On Thu, Oct 15, 2026 at 09:47:34AM +0200, Miguel Ojeda wrote:
> On Thu, Oct 15, 2026 at 9:11 AM Greg KH <greg@kroah.com> wrote:
> >
> > __must_init might be smaller?
> 
> That sounds fine too. I like that it says that something *has* to be
> done (like the original name did). Hmm... On the other hand, I guess
> "must" could sound like one has to initialize the field "somehow",
> i.e. writing:
> 
>   struct S s = {};
> 
> definitely initializes it, yet the compiler would warn. Would
> "explicit" hint a bit more at the fact that one has to actually
> "write" the field, even if it may have been initialized anyway?
> 
> (Of course, if one knows that the attribute only applies to fields,
> then it doesn't make much of a difference)

Hmm, I just noticed Clang isn't diagnosing for file-scoped definitions.
I've opened: https://github.com/llvm/llvm-project/issues/232483

Do we want to wait on this attribute until Clang has full coverage for
all initializer cases, or land the attribute so we can continue to add
coverage for function-level coverage? I'm worried about a compiler bump
(once the bug is fixed) suddenly exposing a bunch of missed
initializers, but then again we also have no users yet...

-Kees

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15 20:07             ` Kees Cook
@ 2026-10-15 20:47               ` Nick Desaulniers
  0 siblings, 0 replies; 11+ messages in thread
From: Nick Desaulniers @ 2026-10-15 20:47 UTC (permalink / raw)
  To: Kees Cook
  Cc: Miguel Ojeda, Ian Rogers, Greg KH, Miguel Ojeda, Alexander Viro,
	Christian Brauner, Jan Kara, Nathan Chancellor, Bill Wendling,
	Justin Stitt, linux-fsdevel, llvm, linux-kernel, linux-hardening

On Thu, Oct 15, 2026 at 1:07 PM Kees Cook <kees@kernel.org> wrote:
>
> On Thu, Oct 15, 2026 at 09:47:34AM +0200, Miguel Ojeda wrote:
> > On Thu, Oct 15, 2026 at 9:11 AM Greg KH <greg@kroah.com> wrote:
> > >
> > > __must_init might be smaller?
> >
> > That sounds fine too. I like that it says that something *has* to be
> > done (like the original name did). Hmm... On the other hand, I guess
> > "must" could sound like one has to initialize the field "somehow",
> > i.e. writing:
> >
> >   struct S s = {};
> >
> > definitely initializes it, yet the compiler would warn. Would
> > "explicit" hint a bit more at the fact that one has to actually
> > "write" the field, even if it may have been initialized anyway?
> >
> > (Of course, if one knows that the attribute only applies to fields,
> > then it doesn't make much of a difference)
>
> Hmm, I just noticed Clang isn't diagnosing for file-scoped definitions.
> I've opened: https://github.com/llvm/llvm-project/issues/232483
>
> Do we want to wait on this attribute until Clang has full coverage for
> all initializer cases, or land the attribute so we can continue to add
> coverage for function-level coverage? I'm worried about a compiler bump
> (once the bug is fixed) suddenly exposing a bunch of missed
> initializers, but then again we also have no users yet...

This is a false negative, right? When it gets fixed in clang, the
existing uses in globals start getting checked.  Nothing that would
require compiler version checks, IMO.

>
> -Kees
>
> --
> Kees Cook



-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations
  2026-10-15  8:47             ` Greg KH
@ 2026-10-15 22:29               ` Ian Rogers
  0 siblings, 0 replies; 11+ messages in thread
From: Ian Rogers @ 2026-10-15 22:29 UTC (permalink / raw)
  To: Greg KH
  Cc: Miguel Ojeda, Kees Cook, Miguel Ojeda, Alexander Viro,
	Christian Brauner, Jan Kara, Nathan Chancellor, Nick Desaulniers,
	Bill Wendling, Justin Stitt, linux-fsdevel, llvm, linux-kernel,
	linux-hardening

On Thu, Oct 15, 2026 at 1:50 AM Greg KH <greg@kroah.com> wrote:
>
> On Thu, Oct 15, 2026 at 09:47:34AM +0200, Miguel Ojeda wrote:
> > On Thu, Oct 15, 2026 at 9:11 AM Greg KH <greg@kroah.com> wrote:
> > >
> > > __must_init might be smaller?
> >
> > That sounds fine too. I like that it says that something *has* to be
> > done (like the original name did). Hmm... On the other hand, I guess
> > "must" could sound like one has to initialize the field "somehow",
> > i.e. writing:
> >
> >   struct S s = {};
> >
> > definitely initializes it, yet the compiler would warn. Would
> > "explicit" hint a bit more at the fact that one has to actually
> > "write" the field, even if it may have been initialized anyway?
>
> "explicit" is a description, "must" is an action that tells the reader
> what they have to do, so maybe "must" is better?
>
> Anyway, I don't care, naming is hard, either is fine with me, I'll let
> the authors of the patch here pick what they want :)

Fwiw, I like __must_init for being both short and intention revealing.
I'll hold off sending my v2 for kobject::release to avoid renaming the
attribute.

Thanks,
Ian

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-10-15 22:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-14 22:58 [PATCH 0/2] Add __require_explicit_initialization and its first user Kees Cook
2026-10-14 22:58 ` [PATCH 2/2] seq_file: Require explicit initialization of struct seq_operations Kees Cook
2026-10-15  5:21   ` Greg KH
2026-10-15  5:46     ` Miguel Ojeda
2026-10-15  5:57       ` Kees Cook
2026-10-15  7:11         ` Greg KH
2026-10-15  7:47           ` Miguel Ojeda
2026-10-15  8:47             ` Greg KH
2026-10-15 22:29               ` Ian Rogers
2026-10-15 20:07             ` Kees Cook
2026-10-15 20:47               ` Nick Desaulniers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox