* [RFC] docs: Define c_paren_attributes for attributes with arguments
@ 2022-09-02 22:35 Kees Cook
2022-09-09 5:08 ` Akira Yokosawa
2022-09-21 21:00 ` Jonathan Corbet
0 siblings, 2 replies; 4+ messages in thread
From: Kees Cook @ 2022-09-02 22:35 UTC (permalink / raw)
To: Jonathan Corbet
Cc: Kees Cook, Mauro Carvalho Chehab, linux-doc, linux-kernel,
linux-hardening
While Sphinx's "c_id_attributes" is needed for basic attributes, any
attributes with arguments need to be defined in "c_paren_attributes"
to avoid errors like:
include/linux/fortify-string.h:116: warning: Function parameter or member '__builtin_strncpy' not described in '__diagnose_as'
include/linux/fortify-string.h:116: warning: Function parameter or member '1' not described in '__diagnose_as'
include/linux/fortify-string.h:116: warning: Function parameter or member '2' not described in '__diagnose_as'
include/linux/fortify-string.h:116: warning: Function parameter or member '3' not described in '__diagnose_as'
Move such attributes to "c_paren_attributes" and add __alloc_size
and __diagnose_as to the list.
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-doc@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
This patch is a lie (the above warning is actually not fixed), but I
was hoping someone could help with this. The Sphinx documentation says:
c_paren_attributes
A list of strings that the parser additionally should accept as
attributes with one argument. That is, if my_align_as is in the list,
then my_align_as(X) is parsed as an attribute for all strings X that
have balanced braces ((), [], and {}). This can for example be used
when attributes have been #define d for portability.
However, this appears to only work for attributes with literally a single
argument not "all strings X", so things like __printf and __diagnose_as
don't work.
Does this need fixing in Sphinx? Or am I missing something?
---
Documentation/conf.py | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/Documentation/conf.py b/Documentation/conf.py
index 934727e23e0e..17f996e3709f 100644
--- a/Documentation/conf.py
+++ b/Documentation/conf.py
@@ -59,18 +59,14 @@ if major >= 3:
# include/linux/compiler_attributes.h:
"__alias",
- "__aligned",
"__aligned_largest",
"__always_inline",
- "__assume_aligned",
"__cold",
"__attribute_const__",
"__copy",
"__pure",
"__designated_init",
"__visible",
- "__printf",
- "__scanf",
"__gnu_inline",
"__malloc",
"__mode",
@@ -80,7 +76,6 @@ if major >= 3:
"__noreturn",
"__packed",
"__pure",
- "__section",
"__always_unused",
"__maybe_unused",
"__used",
@@ -97,6 +92,21 @@ if major >= 3:
# include/linux/linkage.h:
"asmlinkage",
+
+ # include/linux/fortify-string.h:
+ "__FORTIFY_INLINE",
+ ]
+
+ # Same as c_id_attributes above, but for those with arguments.
+ c_paren_attributes = [
+ # include/linux/compiler_attributes.h:
+ "__aligned",
+ "__alloc_size",
+ "__assume_aligned",
+ "__diagnose_as",
+ "__printf",
+ "__scanf",
+ "__section",
]
else:
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC] docs: Define c_paren_attributes for attributes with arguments
2022-09-02 22:35 [RFC] docs: Define c_paren_attributes for attributes with arguments Kees Cook
@ 2022-09-09 5:08 ` Akira Yokosawa
2022-09-22 5:30 ` Kees Cook
2022-09-21 21:00 ` Jonathan Corbet
1 sibling, 1 reply; 4+ messages in thread
From: Akira Yokosawa @ 2022-09-09 5:08 UTC (permalink / raw)
To: Kees Cook
Cc: corbet, linux-doc, linux-hardening, linux-kernel, mchehab,
Akira Yokosawa
Hi Kees,
I expected some responses from Jon, but looks like he's been busy
elsewhere. Let me chime in.
On Fri, 2 Sep 2022 15:35:07 -0700, Kees Cook wrote:
> While Sphinx's "c_id_attributes" is needed for basic attributes, any
> attributes with arguments need to be defined in "c_paren_attributes"
> to avoid errors like:
>
> include/linux/fortify-string.h:116: warning: Function parameter or member '__builtin_strncpy' not described in '__diagnose_as'
> include/linux/fortify-string.h:116: warning: Function parameter or member '1' not described in '__diagnose_as'
> include/linux/fortify-string.h:116: warning: Function parameter or member '2' not described in '__diagnose_as'
> include/linux/fortify-string.h:116: warning: Function parameter or member '3' not described in '__diagnose_as'
These warnings are from ./scripts/kernel-doc.
So I think you need to teach the script about "__diagnose_as" so that
the kernel-doc comment of strncpy() can be converted to reST doc
which Sphinx can understand.
Past changes in ./scripts/kernel-doc might give you some hints.
That said, I think Jon should be able to provide a pin-point suggestion.
HTH,
Thanks, akira
>
> Move such attributes to "c_paren_attributes" and add __alloc_size
> and __diagnose_as to the list.>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
> Cc: linux-doc@vger.kernel.org
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> This patch is a lie (the above warning is actually not fixed), but I
> was hoping someone could help with this. The Sphinx documentation says:>
> c_paren_attributes
> A list of strings that the parser additionally should accept as
> attributes with one argument. That is, if my_align_as is in the list,
> then my_align_as(X) is parsed as an attribute for all strings X that
> have balanced braces ((), [], and {}). This can for example be used
> when attributes have been #define d for portability.
>
> However, this appears to only work for attributes with literally a single
> argument not "all strings X", so things like __printf and __diagnose_as
> don't work.
>
> Does this need fixing in Sphinx? Or am I missing something?
> ---
> Documentation/conf.py | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/conf.py b/Documentation/conf.py
> index 934727e23e0e..17f996e3709f 100644
> --- a/Documentation/conf.py
> +++ b/Documentation/conf.py
> @@ -59,18 +59,14 @@ if major >= 3:
>
> # include/linux/compiler_attributes.h:
> "__alias",
> - "__aligned",
> "__aligned_largest",
> "__always_inline",
> - "__assume_aligned",
> "__cold",
> "__attribute_const__",
> "__copy",
> "__pure",
> "__designated_init",
> "__visible",
> - "__printf",
> - "__scanf",
> "__gnu_inline",
> "__malloc",
> "__mode",
> @@ -80,7 +76,6 @@ if major >= 3:
> "__noreturn",
> "__packed",
> "__pure",
> - "__section",
> "__always_unused",
> "__maybe_unused",
> "__used",
> @@ -97,6 +92,21 @@ if major >= 3:
>
> # include/linux/linkage.h:
> "asmlinkage",
> +
> + # include/linux/fortify-string.h:
> + "__FORTIFY_INLINE",
> + ]
> +
> + # Same as c_id_attributes above, but for those with arguments.
> + c_paren_attributes = [
> + # include/linux/compiler_attributes.h:
> + "__aligned",
> + "__alloc_size",
> + "__assume_aligned",
> + "__diagnose_as",
> + "__printf",
> + "__scanf",
> + "__section",
> ]
>
> else:
> --
> 2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] docs: Define c_paren_attributes for attributes with arguments
2022-09-02 22:35 [RFC] docs: Define c_paren_attributes for attributes with arguments Kees Cook
2022-09-09 5:08 ` Akira Yokosawa
@ 2022-09-21 21:00 ` Jonathan Corbet
1 sibling, 0 replies; 4+ messages in thread
From: Jonathan Corbet @ 2022-09-21 21:00 UTC (permalink / raw)
To: Kees Cook
Cc: Kees Cook, Mauro Carvalho Chehab, linux-doc, linux-kernel,
linux-hardening
Kees Cook <keescook@chromium.org> writes:
> While Sphinx's "c_id_attributes" is needed for basic attributes, any
> attributes with arguments need to be defined in "c_paren_attributes"
> to avoid errors like:
>
> include/linux/fortify-string.h:116: warning: Function parameter or member '__builtin_strncpy' not described in '__diagnose_as'
> include/linux/fortify-string.h:116: warning: Function parameter or member '1' not described in '__diagnose_as'
> include/linux/fortify-string.h:116: warning: Function parameter or member '2' not described in '__diagnose_as'
> include/linux/fortify-string.h:116: warning: Function parameter or member '3' not described in '__diagnose_as'
>
> Move such attributes to "c_paren_attributes" and add __alloc_size
> and __diagnose_as to the list.
So which tree are those warnings coming from? I can't reproduce them
with linux-next.
As Akira noted, the kernel-doc script is the source of those warnings,
so changing the Sphinx configuration is unlikely to help. I think we
just need to teach kernel-doc to ignore those attributes.
Thanks,
jon
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC] docs: Define c_paren_attributes for attributes with arguments
2022-09-09 5:08 ` Akira Yokosawa
@ 2022-09-22 5:30 ` Kees Cook
0 siblings, 0 replies; 4+ messages in thread
From: Kees Cook @ 2022-09-22 5:30 UTC (permalink / raw)
To: Akira Yokosawa; +Cc: corbet, linux-doc, linux-hardening, linux-kernel, mchehab
On Fri, Sep 09, 2022 at 02:08:30PM +0900, Akira Yokosawa wrote:
> Hi Kees,
>
> I expected some responses from Jon, but looks like he's been busy
> elsewhere. Let me chime in.
>
> On Fri, 2 Sep 2022 15:35:07 -0700, Kees Cook wrote:
> > While Sphinx's "c_id_attributes" is needed for basic attributes, any
> > attributes with arguments need to be defined in "c_paren_attributes"
> > to avoid errors like:
> >
> > include/linux/fortify-string.h:116: warning: Function parameter or member '__builtin_strncpy' not described in '__diagnose_as'
> > include/linux/fortify-string.h:116: warning: Function parameter or member '1' not described in '__diagnose_as'
> > include/linux/fortify-string.h:116: warning: Function parameter or member '2' not described in '__diagnose_as'
> > include/linux/fortify-string.h:116: warning: Function parameter or member '3' not described in '__diagnose_as'
>
> These warnings are from ./scripts/kernel-doc.
> So I think you need to teach the script about "__diagnose_as" so that
> the kernel-doc comment of strncpy() can be converted to reST doc
> which Sphinx can understand.
Ah! Thank you, yeah, I couldn't figure out where it was coming from.
> Past changes in ./scripts/kernel-doc might give you some hints.
Yeah, including changes from me for similar things. How quickly I
forgot! :)
Thanks,
-Kees
--
Kees Cook
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-09-22 5:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-02 22:35 [RFC] docs: Define c_paren_attributes for attributes with arguments Kees Cook
2022-09-09 5:08 ` Akira Yokosawa
2022-09-22 5:30 ` Kees Cook
2022-09-21 21:00 ` Jonathan Corbet
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.