Skip to content

Commit 2b488eb

Browse files
marconeandi34
authored andcommitted
Check mprotect result
mprotect can theoretically fail, which could then let one exploit a vulnerable codec if one exists on the device. Bug: 31350239 Change-Id: I7b99c190619f0fb2eb93119596e6da0d2deb8ba5 (cherry picked from commit 866c800)
1 parent 6516053 commit 2b488eb

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

media/libmedia/IOMX.cpp

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -637,31 +637,35 @@ status_t BnOMX::onTransact(
637637
// mark the last page as inaccessible, to avoid exploitation
638638
// of codecs that access past the end of the allocation because
639639
// they didn't check the size
640-
mprotect((char*)params + allocSize - pageSize, pageSize, PROT_NONE);
641-
switch (code) {
642-
case GET_PARAMETER:
643-
err = getParameter(node, index, params, size);
644-
break;
645-
case SET_PARAMETER:
646-
err = setParameter(node, index, params, size);
647-
break;
648-
case GET_CONFIG:
649-
err = getConfig(node, index, params, size);
650-
break;
651-
case SET_CONFIG:
652-
err = setConfig(node, index, params, size);
653-
break;
654-
case SET_INTERNAL_OPTION:
655-
{
656-
InternalOptionType type =
657-
(InternalOptionType)data.readInt32();
658-
659-
err = setInternalOption(node, index, type, params, size);
660-
break;
640+
if (mprotect((char*)params + allocSize - pageSize, pageSize,
641+
PROT_NONE) != 0) {
642+
ALOGE("mprotect failed: %s", strerror(errno));
643+
} else {
644+
switch (code) {
645+
case GET_PARAMETER:
646+
err = getParameter(node, index, params, size);
647+
break;
648+
case SET_PARAMETER:
649+
err = setParameter(node, index, params, size);
650+
break;
651+
case GET_CONFIG:
652+
err = getConfig(node, index, params, size);
653+
break;
654+
case SET_CONFIG:
655+
err = setConfig(node, index, params, size);
656+
break;
657+
case SET_INTERNAL_OPTION:
658+
{
659+
InternalOptionType type =
660+
(InternalOptionType)data.readInt32();
661+
662+
err = setInternalOption(node, index, type, params, size);
663+
break;
664+
}
665+
666+
default:
667+
TRESPASS();
661668
}
662-
663-
default:
664-
TRESPASS();
665669
}
666670
}
667671
}

0 commit comments

Comments
 (0)