linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* undefined behavior (-Wvarargs) in security/keys/trusted.c#TSS_authhmac()
@ 2018-10-09 22:11 Nick Desaulniers
  2018-10-11 16:02 ` Arnd Bergmann
  0 siblings, 1 reply; 33+ messages in thread
From: Nick Desaulniers @ 2018-10-09 22:11 UTC (permalink / raw)
  To: James E.J. Bottomley, zohar, dhowells, jmorris, serge
  Cc: linux-integrity, keyrings, linux-security-module, LKML,
	Nathan Chancellor, Eric Biggers

Hello,
I noticed that compiling with
CONFIG_TCG_TPM=y
CONFIG_HW_RANDOM_TPM=y
and Clang produced the warning:

  CC      security/keys/trusted.o
security/keys/trusted.c:146:17: warning: passing an object that
undergoes default
      argument promotion to 'va_start' has undefined behavior [-Wvarargs]
        va_start(argp, h3);
                       ^
security/keys/trusted.c:126:37: note: parameter of type 'unsigned
char' is declared here
unsigned char *h2, unsigned char h3, ...)
                               ^

Specifically, it seems that both the C90 (4.8.1.1) and C11 (7.16.1.4)
standards explicitly call this out as undefined behavior:

The parameter parmN is the identifier of the rightmost parameter in
the variable parameter list in the function definition (the one just
before the ...). If the parameter parmN is declared with ... or with a
type that is not compatible with the type that results after
application of the default argument promotions, the behavior is
undefined.

So if I understand my C promotion/conversion rules correctly, unsigned
char would be promoted to int?

We had a few ideas for possible fixes in:
https://github.com/ClangBuiltLinux/linux/issues/41

Do the maintainers have feedback on these suggestions or a more appropriate fix?

Note: https://www.gnu.org/software/libc/manual/html_node/Calling-Variadics.html
and `man 3 va_start` mention more about promotions, but just for
va_arg, not va_start. But the standard seems explicit about parmN
which is passed to va_start.

https://www.eskimo.com/~scs/cclass/int/sx11c.html is also an
interesting read on the subject, which states: `Finally, for vaguely
related reasons, the last fixed argument (the one whose name is passed
as the second argument to the va_start() macro) should not be of type
char, short int, or float, either.`
-- 
Thanks,
~Nick Desaulniers

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

end of thread, other threads:[~2019-02-14 10:52 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-09 22:11 undefined behavior (-Wvarargs) in security/keys/trusted.c#TSS_authhmac() Nick Desaulniers
2018-10-11 16:02 ` Arnd Bergmann
2018-10-11 16:10   ` James Bottomley
2018-10-11 20:31     ` [PATCH] KEYS: trusted: fix -Wvarags warning ndesaulniers
2018-10-12  1:50       ` Nathan Chancellor
2018-10-12 16:55         ` Nick Desaulniers
2018-10-12 17:03           ` Nathan Chancellor
2018-10-12 12:29       ` Denis Kenzior
2018-10-12 15:05         ` James Bottomley
2018-10-12 15:13           ` Denis Kenzior
2018-10-12 15:22             ` James Bottomley
2018-10-12 15:44               ` Denis Kenzior
2018-10-12 15:46                 ` James Bottomley
2018-10-12 15:53                   ` Denis Kenzior
2018-10-12 16:01                     ` James Bottomley
2018-10-12 17:14                       ` Nick Desaulniers
2018-10-12 15:25             ` James Bottomley
2018-10-12 17:05             ` Nick Desaulniers
2018-10-12 17:17               ` Nick Desaulniers
2018-10-12 17:27               ` Denis Kenzior
2018-10-12 18:39                 ` Nick Desaulniers
2018-10-12 17:02         ` Nick Desaulniers
2018-10-12 17:15           ` Denis Kenzior
2018-10-15  9:26       ` David Laight
2018-10-15 21:53         ` Nick Desaulniers
2018-10-16  8:13           ` David Laight
2018-10-22 23:43             ` [PATCH v2] " ndesaulniers
2018-10-23  0:00               ` Nathan Chancellor
2018-10-24  8:36               ` Jarkko Sakkinen
2018-10-29 17:54                 ` Nick Desaulniers
2019-02-11 18:36                   ` Nick Desaulniers
2019-02-12 23:12                     ` Jarkko Sakkinen
2019-02-14 10:52                       ` Jarkko Sakkinen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).