On Fri, Oct 26, 2018 at 09:51:06AM +0100, Ben Dooks wrote: > I have been looking into testing the address_space() pointers in > the current Linux kernel and came up with a case where I am not > sure how this should work (the kernel's __user attribute). > > We tested the following cases, In this case sparse correctly > identified the incorrect address space/no-dereference. The first > was not identified: > > # define __user __attribute__((noderef, address_space(1))) > > void test(char __user *ptr) > { > printk("%s\n", ptr); > printk("%c\n", ptr[0]); > } Hi, Yes, but everything here is as it should: * the 2nd line should trigger a message like test.c:8:27: warning: dereference of noderef expression since the pointer is dereferenced (before being passed to printk(). * no warning for the 1st line since there is no dereference and no pointer assignment to a pointer of a different address space.. > I know that there is a gcc printf format attribute to allow > specifying the positions of the format and start of variadic > arguments. > > I have had a quick look at the code but have not tried to make > any modifications yet, and would like some feedback or help > before making any: > > - Should we automatically warn on possible de-ref (or address space) > on passing to a variadic function (I think the simplest) I think this would be wrong. For example, there is no problems if the corresponding address is simply displayed (via "%p" or "%lu") but it would if the pointer is dereferenced (for example, via "%s"). > - Is adding support for __attribute__((format(printf,a,b))) a > good idea (and if so is anyone looking into this already) Yes, I think it's a good idea. I don't think anyone is looking to add this to sparse already (it's something I've added in my nice-to-have list but this list is quite long ...). > - If adding printf format a good idea, then should we extend it > to adding a kernel printk style one too (modern kernels seem > to love extending the printf formatting) I really think so, yes. > Any help would be appreciated. You're welcome, -- Luc Van Oostenryck