Summary: | [cam] fix negative array index in ctl.c | ||||||
---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | CTurt <ecturt> | ||||
Component: | kern | Assignee: | Edward Tomasz Napierala <trasz> | ||||
Status: | Closed FIXED | ||||||
Severity: | Affects Only Me | CC: | delphij, emaste, mav, op, ryan, secteam, shawn.webb, trasz | ||||
Priority: | --- | Keywords: | patch | ||||
Version: | CURRENT | ||||||
Hardware: | Any | ||||||
OS: | Any | ||||||
Attachments: |
|
Description
CTurt
2016-03-01 21:11:42 UTC
Created attachment 172594 [details]
Proposed patch for #207627
Comment on attachment 172594 [details]
Proposed patch for #207627
After looking over the code I wanted to propose a patch to fix this problem.
If the name length or value length was 0, a negative array index would occur while checking for a NUL terminator. This patch adds a check preventing a 0 name length or value length.
Since the length of value shouldn't be negative, this patch changes the type of namelen and vallen to unsigned.
If memory couldn't be allocated for the argument name or value, the bailout path would attempt to free() a null pointer. This patch adds a check to prevent that from happening.
I also updated some comments detailing which values need a nul termination.
Edward can you take a look at this one? Checking whether the argument is NULL before calling free(9) is pointless, just like in userspace. I'd also prefer the "argument is invalid" replaced by "must be greater than zero", or something like that. Apart from that, the patch looks fine. Have you verified it doesn't break binary compatibility? (In reply to Edward Tomasz Napierala from comment #4) I don't believe the change of signedness would change ABI. Note however that in ctl_copyin_alloc(), the allocation is done with M_WAITOK, which means we could block when the length from userland is sufficiently large. I think we should probably either add a sanity check here to prevent sufficiently large request, or to use M_NOWAIT and bail out as soon as it failed. A commit references this bug: Author: trasz Date: Thu Nov 3 10:11:59 UTC 2016 New revision: 308250 URL: https://svnweb.freebsd.org/changeset/base/308250 Log: Check for lengths being <= 0. Note that this interface can only be accessed by root. It uses unsigned ints instead of size_t to preserve the ABI. PR: 207627 Submitted by: ryan@ryanday.net (with slight tweaks) MFC after: 1 month Changes: head/sys/cam/ctl/ctl.c head/sys/cam/ctl/ctl_ioctl.h A commit references this bug: Author: trasz Date: Sat Dec 3 21:27:19 UTC 2016 New revision: 309516 URL: https://svnweb.freebsd.org/changeset/base/309516 Log: MFC r308250: Check for lengths being <= 0. Note that this interface can only be accessed by root. It uses unsigned ints instead of size_t to preserve the ABI. PR: 207627 Changes: _U stable/11/ stable/11/sys/cam/ctl/ctl.c stable/11/sys/cam/ctl/ctl_ioctl.h Committed back in 2016. |