Page MenuHomeFreeBSD

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

Authored by jfree on Aug 25 2022, 4:14 PM.
Referenced Files
F106194020: D36350.diff
Thu, Dec 26, 10:56 PM
Unknown Object (File)
Sun, Dec 8, 12:59 PM
Unknown Object (File)
Tue, Dec 3, 7:42 AM
Unknown Object (File)
Nov 21 2024, 2:42 PM
Unknown Object (File)
Nov 19 2024, 11:51 AM
Unknown Object (File)
Nov 17 2024, 8:05 PM
Unknown Object (File)
Nov 17 2024, 7:54 PM
Unknown Object (File)
Nov 16 2024, 11:42 PM

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

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.