Re: Typecasting a void pointer to unsigned long in zsmalloc.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jan 23, 2025 at 11:09:47PM +0200, Costa Shulyupin wrote:
> Hi. I've found this:
> 
> Pointers are __u64, cast from/to a uintptr_t on the userspace side and
> from/to a void __user * in the kernel. Try really hard not to delay this
> conversion or worse, fiddle the raw __u64 through your code since that
> diminishes the checking tools like sparse can provide. The macro
> u64_to_user_ptr can be used in the kernel to avoid warnings about integers
> and pointers of different sizes.
> 
> https://origin.kernel.org/doc/html/latest/process/botching-up-ioctls.html#:~:text=Pointers%20are%20__u64

That is talking about the ioctl user/kernel boundry and passing pointers
across it.  Not the use of pointers directly in the kernel tree.

The goal of that paragraph is to tell people to always use a 64bit value
for a pointer they are putting into an ioctl, which ensures that the
structure remains the same size no matter if you are running on a system
that has 32bit or 64bit pointers.

So while this is great advice, and should be followed, it doesn't really
discuss the implicit rule that "unsigned long can always hold a pointer"
that Linux relies on.

hope this helps,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]

  Powered by Linux