Page MenuHomeFreeBSD

Add strndup_user() to LinuxKPI <linux/string.h>
ClosedPublic

Authored by jfree on Aug 25 2022, 4:14 PM.
Referenced Files
Unknown Object (File)
Sat, Nov 9, 1:51 AM
Unknown Object (File)
Tue, Oct 29, 10:54 AM
Unknown Object (File)
Fri, Oct 18, 11:04 AM
Unknown Object (File)
Oct 15 2024, 7:30 AM
Unknown Object (File)
Oct 10 2024, 7:40 AM
Unknown Object (File)
Oct 10 2024, 7:26 AM
Unknown Object (File)
Oct 10 2024, 7:25 AM
Unknown Object (File)
Oct 10 2024, 7:25 AM

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jfree requested review of this revision.Aug 25 2022, 4:14 PM
hselasky added a subscriber: hselasky.

Assuming there is no special case for n = 0.

This revision is now accepted and ready to land.Aug 25 2022, 4:43 PM

Added simple error checking

This revision now requires review to proceed.Aug 25 2022, 5:14 PM
This revision is now accepted and ready to land.Aug 26 2022, 10:19 AM
sys/compat/linuxkpi/common/include/linux/string.h
107

There's no need for this check, memdup_user() will handle it. A user-supplied pointer can never be trusted, so there's no real reason to check for NULL specifically (it could be 0x1, or any other invalid value).

Removed NULL pointer error checking thanks to @markj. General user pointers are safely checked in memdup_user().

This revision now requires review to proceed.Aug 27 2022, 8:04 PM
This revision is now accepted and ready to land.Aug 28 2022, 1:13 AM
sys/compat/linuxkpi/common/include/linux/string.h
109

I think "n" excludes the NUL character.

Why can't you simply do:

return (memdup_user_nul(ustr, n));
jfree marked 2 inline comments as done.

Used memdup_user_nul() instead of memdup_user() to duplicate memory from userspace. Relevant documentation can be found here:

https://www.kernel.org/doc/html/v5.0/core-api/kernel-api.html

This revision now requires review to proceed.Aug 29 2022, 1:57 PM
This revision is now accepted and ready to land.Sep 20 2022, 5:20 PM
This revision was automatically updated to reflect the committed changes.