Skip to contentSkip to conversation

Linux Kernel Markers format string idea

DISCUSSION Mathieu Desnoyers 2 participants 2 messages Dec 21, 2006 – Dec 26, 2006 Sparse checker

lore
Share & tools
lore
#0 lore raw

Hi,

First, some context : I created the Linux Kernel Markers as a lightweight code instrumentation mechanism with which we can connect a probe dynamically. Type checking is done dynamically by comparing the string in the probe to the string found at the instrumentation site. If we want to have strong type checking with this mechanism, all the information used for typing must be in the format string and validated. Frank showed some concerns about the use of format strings regarding type checking. Here is a proposal to fix this.

I just had an idea about a format string extension that would help fix the missing type checking with format strings for Linux Kernel Markers. It would however imply that we extend the format string standard. One of the goals is to keep backward compatibility with existing format strings.

The two sample cases I would like to "dynamically type check" are the following :

- Passing a "struct mystruct *" as an argument.
- Passing a "__be64" as an argument
(typedef as "__u64 __bitwise", where __bitwise is undefined when compiled by gcc but is defined as __attribute__((bitwise)) when compiled with __CHECKER__ for sparse).
(http://kernel.org/pub/linux/kernel/people/josh/sparse/)

The idea is to add the type between brackets after the conversion specifier.

For a pointer to a structure :
"%p[struct mystruct *]"

For a __be64 :
"%llu[__be64]"

The current format string validation of gcc will not perform more or less validation than what is actually done, which is to verify that the type is a pointer or a 64 bytes integer. Printing it through printk will show, for instance :

0xfffffff[struct mystruct *]
1152921504606846976[__be64]

However, an enhanced format string verificator could check the type of the pointer and the complete type of the __be64. It could start by being integrated to the "checker", and only later make its way into gcc.

Comments on this idea are welcome.

Mathieu

Signature · 2 lines
OpenPGP public key:              http://krystal.dyndns.org:8080/key/compudj.gpg
Key fingerprint:     8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68 
#1 lore raw

Hi -

Quoted 5 lines · Mathieu Desnoyers

[...] I just had an idea about a format string extension that would help fix the missing type checking with format strings for Linux Kernel Markers. [...] The idea is to add the type between brackets after the conversion specifier. For a pointer to a structure :
"%p[struct mystruct *]" [...]

It's probably an improvement, though as it is still at the programmers' discretion, it is less useful for checking and more as documenting. I remain ambivalent about whether exposing this level of detail (complex typing) is a good idea, or whether imposing a small fixed set of types (string/number/blob) is better.

- FChE