Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Call prctl(2) with long integers, specify 5 arguments, and avoid casts #3085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

karelzak
Copy link
Collaborator

@karelzak karelzak commented Jun 6, 2024

Since libc's prctl(2) wrapper is a variadic function, arguments must have the right width. Otherwise, the behavior is undefined.

Also, the 5 arguments must be specified always, or the behavior is also undefined. libc reads 5 values and passes them all to the kernel, so if one is uninitialized, the kernel will receive garbagge, which could result in EINVAL (most likely), or worse, a different action.

Also, avoid some casts to unsigned long, by changing the type of the parameter to some local wrappers.

And use consistently 0L. 0UL is basically the same, and uses one more character. Keep it short.

Link: https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=6698b096a6f5342cb9b338c237ed875a8635497a
Link: https://lore.kernel.org/linux-man/ddbdyaiptesjalgfmztxideej67e3yaob7ucsmbf6qvriwxiif@dohhxrqgwhrf/T/#med306b5b003f9cc7cc2de69fcdd7ee2d056d0954
Cc: Xi Ruoyao [email protected]

Since libc's prctl(2) wrapper is a variadic function, arguments must
have the right width.  Otherwise, the behavior is undefined.

Also, the 5 arguments must be specified always, or the behavior is also
undefined.  libc reads 5 values and passes them all to the kernel, so if
one is uninitialized, the kernel will receive garbagge, which could
result in EINVAL (most likely), or worse, a different action.

Also, avoid some casts to unsigned long, by changing the type of the
parameter to some local wrappers.

And use consistently 0L.  0UL is basically the same, and uses one more
character.  Keep it short.

Link: <https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=6698b096a6f5342cb9b338c237ed875a8635497a>
Link: <https://lore.kernel.org/linux-man/ddbdyaiptesjalgfmztxideej67e3yaob7ucsmbf6qvriwxiif@dohhxrqgwhrf/T/#med306b5b003f9cc7cc2de69fcdd7ee2d056d0954>
Cc: Xi Ruoyao <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar
Copy link

I will send a smaller v2 patch with just the change from 0 to 0L and removing the casts. I'll keep the short calls without the 0L, as @t-8ch pointed out.

@karelzak
Copy link
Collaborator Author

karelzak commented Jun 6, 2024

I will send a smaller v2 patch with just the change from 0 to 0L and removing the casts. I'll keep the short calls without the 0L, as @t-8ch pointed out.

You can also create PR on github :-)

@alejandro-colomar
Copy link

I will send a smaller v2 patch with just the change from 0 to 0L and removing the casts. I'll keep the short calls without the 0L, as @t-8ch pointed out.

You can also create PR on github :-)

I personally dislike the centralizing that GH represents for free software projects, and the lock-in that many projects have chosen for staying on GH. Also, I find git-send-email(1) much simpler than having to set up a GH fork, and accessing a webUI interface.

On the other hand, I understand that it might be simpler for you as a reviewer, since it runs CI automatically for you.

If you want me to open a PR, I can do it. By default, I prefer a mailing list. :-)

@karelzak
Copy link
Collaborator Author

karelzak commented Jun 6, 2024

Mailing list is absolutely OK :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants