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)
Wed, May 29, 1:16 AM
Unknown Object (File)
Tue, May 28, 2:35 PM
Unknown Object (File)
Thu, May 16, 11:26 AM
Unknown Object (File)
Mon, May 13, 2:51 AM
Unknown Object (File)
Mon, May 13, 1:49 AM
Unknown Object (File)
Apr 27 2024, 4:28 AM
Unknown Object (File)
Apr 26 2024, 10:35 PM
Unknown Object (File)
Apr 26 2024, 8:53 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.