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)
Fri, Mar 22, 3:07 AM
Unknown Object (File)
Tue, Mar 19, 12:29 PM
Unknown Object (File)
Jan 29 2024, 10:45 PM
Unknown Object (File)
Jan 25 2024, 7:32 AM
Unknown Object (File)
Jan 25 2024, 7:32 AM
Unknown Object (File)
Jan 25 2024, 7:32 AM
Unknown Object (File)
Dec 31 2023, 4:11 AM
Unknown Object (File)
Dec 12 2023, 2:16 PM

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.