[PATCH] tomoyo: fix clang pointer arithmetic warning

Tetsuo Handa penguin-kernel at i-love.sakura.ne.jp
Wed Oct 28 13:22:59 UTC 2020


Thank you for a patch. I have two questions.

On 2020/10/27 6:52, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd at arndb.de>
> 
> clang warns about additions on NULL pointers being undefined in C:
> 
> security/tomoyo/securityfs_if.c:226:59: warning: arithmetic on a null pointer treated as a cast from integer to pointer is a GNU extension [-Wnull-pointer-arithmetic]
>         securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
> 
> Change the code to instead use a cast through uintptr_t to avoid
> the warning.
> 

> -	securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
> +	securityfs_create_file(name, mode, parent, (u8 *)(uintptr_t)key,
>  			       &tomoyo_operations);

(1) Does clang warn if "(void *)key" is used instead of "(u8 *)(uintptr_t)key" ?

(2) tomoyo_open() has

	const int key = ((u8 *) file_inode(file)->i_private) - ((u8 *) NULL);

    which decodes the "u8 key" passed to tomoyo_create_entry(). For symmetry,
    I'd like to remove NULL from tomoyo_open() as well. Does clang warn if

	const int key = (u8) (file_inode(file)->i_private);

    is used?



More information about the Linux-security-module-archive mailing list