Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security Patches :D #2

Open
wants to merge 18 commits into
base: eleven
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drm/mediadrm/plugins/clearkey/hidl/DrmPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ Return<void> DrmPlugin::getSecurityLevel(const hidl_vec<uint8_t>& sessionId,
return Void();
}

Mutex::Autolock lock(mSecurityLevelLock);
std::map<std::vector<uint8_t>, SecurityLevel>::iterator itr =
mSecurityLevel.find(sid);
if (itr == mSecurityLevel.end()) {
Expand Down Expand Up @@ -653,6 +654,7 @@ Return<Status> DrmPlugin::setSecurityLevel(const hidl_vec<uint8_t>& sessionId,
return Status::ERROR_DRM_SESSION_NOT_OPENED;
}

Mutex::Autolock lock(mSecurityLevelLock);
std::map<std::vector<uint8_t>, SecurityLevel>::iterator itr =
mSecurityLevel.find(sid);
if (itr != mSecurityLevel.end()) {
Expand Down
4 changes: 3 additions & 1 deletion drm/mediadrm/plugins/clearkey/hidl/include/DrmPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ struct DrmPlugin : public IDrmPlugin {
std::map<std::string, std::string> mStringProperties;
std::map<std::string, std::vector<uint8_t> > mByteArrayProperties;
std::map<std::string, std::vector<uint8_t> > mReleaseKeysMap;
std::map<std::vector<uint8_t>, SecurityLevel> mSecurityLevel;
std::map<std::vector<uint8_t>, SecurityLevel> mSecurityLevel
GUARDED_BY(mSecurityLevelLock);
sp<IDrmPluginListener> mListener;
sp<IDrmPluginListener_V1_2> mListenerV1_2;
SessionLibrary *mSessionLibrary;
Expand All @@ -419,6 +420,7 @@ struct DrmPlugin : public IDrmPlugin {
DeviceFiles mFileHandle GUARDED_BY(mFileHandleLock);
Mutex mFileHandleLock;
Mutex mSecureStopLock;
Mutex mSecurityLevelLock;

CLEARKEY_DISALLOW_COPY_AND_ASSIGN_AND_NEW(DrmPlugin);
};
Expand Down
2 changes: 1 addition & 1 deletion media/codec2/components/mp3/C2SoftMp3Dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ void C2SoftMP3::process(
mConfig->inputBufferCurrentLength = (inSize - inPos);
mConfig->inputBufferMaxLength = 0;
mConfig->inputBufferUsedLength = 0;
mConfig->outputFrameSize = (calOutSize - outSize);
mConfig->outputFrameSize = (calOutSize - outSize) / sizeof(int16_t);
mConfig->pOutputBuffer = reinterpret_cast<int16_t *> (wView.data() + outSize);

ERROR_CODE decoderErr;
Expand Down
37 changes: 22 additions & 15 deletions media/codec2/vndk/C2AllocatorIon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class C2AllocationIon::Impl {

c2_status_t err = mapInternal(mapSize, mapOffset, alignmentBytes, prot, flags, &(map.addr), addr);
if (map.addr) {
std::lock_guard<std::mutex> guard(mMutexMappings);
mMappings.push_back(map);
}
return err;
Expand All @@ -212,22 +213,26 @@ class C2AllocationIon::Impl {
ALOGD("tried to unmap unmapped buffer");
return C2_NOT_FOUND;
}
for (auto it = mMappings.begin(); it != mMappings.end(); ++it) {
if (addr != (uint8_t *)it->addr + it->alignmentBytes ||
size + it->alignmentBytes != it->size) {
continue;
{ // Scope for the lock_guard of mMutexMappings.
std::lock_guard<std::mutex> guard(mMutexMappings);
for (auto it = mMappings.begin(); it != mMappings.end(); ++it) {
if (addr != (uint8_t *)it->addr + it->alignmentBytes ||
size + it->alignmentBytes != it->size) {
continue;
}
int err = munmap(it->addr, it->size);
if (err != 0) {
ALOGD("munmap failed");
return c2_map_errno<EINVAL>(errno);
}
if (fence) {
*fence = C2Fence(); // not using fences
}
(void)mMappings.erase(it);
ALOGV("successfully unmapped: addr=%p size=%zu fd=%d", addr, size,
mHandle.bufferFd());
return C2_OK;
}
int err = munmap(it->addr, it->size);
if (err != 0) {
ALOGD("munmap failed");
return c2_map_errno<EINVAL>(errno);
}
if (fence) {
*fence = C2Fence(); // not using fences
}
(void)mMappings.erase(it);
ALOGV("successfully unmapped: addr=%p size=%zu fd=%d", addr, size, mHandle.bufferFd());
return C2_OK;
}
ALOGD("unmap failed to find specified map");
return C2_BAD_VALUE;
Expand All @@ -236,6 +241,7 @@ class C2AllocationIon::Impl {
virtual ~Impl() {
if (!mMappings.empty()) {
ALOGD("Dangling mappings!");
std::lock_guard<std::mutex> guard(mMutexMappings);
for (const Mapping &map : mMappings) {
(void)munmap(map.addr, map.size);
}
Expand Down Expand Up @@ -315,6 +321,7 @@ class C2AllocationIon::Impl {
size_t size;
};
std::list<Mapping> mMappings;
std::mutex mMutexMappings;
};

class C2AllocationIon::ImplV2 : public C2AllocationIon::Impl {
Expand Down
17 changes: 14 additions & 3 deletions media/extractors/mp4/MPEG4Extractor.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static const size_t kMaxPcmFrameSize = 8192;

MediaBufferHelper *mBuffer;

size_t mSrcBufferSize;
uint8_t *mSrcBuffer;

bool mIsHeif;
Expand Down Expand Up @@ -4572,7 +4573,7 @@ status_t MPEG4Extractor::updateAudioTrackInfoFromESDS_MPEG4Audio(
if (len2 == 0) {
return ERROR_MALFORMED;
}
if (offset >= csd_size || csd[offset] != 0x01) {
if (offset + len1 > csd_size || csd[offset] != 0x01) {
return ERROR_MALFORMED;
}
// formerly kKeyVorbisInfo
Expand Down Expand Up @@ -4882,6 +4883,7 @@ MPEG4Source::MPEG4Source(
mNALLengthSize(0),
mStarted(false),
mBuffer(NULL),
mSrcBufferSize(0),
mSrcBuffer(NULL),
mIsHeif(itemTable != NULL),
mItemTable(itemTable),
Expand Down Expand Up @@ -5060,6 +5062,7 @@ media_status_t MPEG4Source::start() {
// file probably specified a bad max size
return AMEDIA_ERROR_MALFORMED;
}
mSrcBufferSize = max_size;

mStarted = true;

Expand All @@ -5076,6 +5079,7 @@ media_status_t MPEG4Source::stop() {
mBuffer = NULL;
}

mSrcBufferSize = 0;
delete[] mSrcBuffer;
mSrcBuffer = NULL;

Expand Down Expand Up @@ -6242,13 +6246,20 @@ media_status_t MPEG4Source::read(
// Whole NAL units are returned but each fragment is prefixed by
// the start code (0x00 00 00 01).
ssize_t num_bytes_read = 0;
num_bytes_read = mDataSource->readAt(offset, mSrcBuffer, size);
bool mSrcBufferFitsDataToRead = size <= mSrcBufferSize;
if (mSrcBufferFitsDataToRead) {
num_bytes_read = mDataSource->readAt(offset, mSrcBuffer, size);
} else {
// We are trying to read a sample larger than the expected max sample size.
// Fall through and let the failure be handled by the following if.
android_errorWriteLog(0x534e4554, "188893559");
}

if (num_bytes_read < (ssize_t)size) {
mBuffer->release();
mBuffer = NULL;

return AMEDIA_ERROR_IO;
return mSrcBufferFitsDataToRead ? AMEDIA_ERROR_IO : AMEDIA_ERROR_MALFORMED;
}

uint8_t *dstData = (uint8_t *)mBuffer->data();
Expand Down
9 changes: 8 additions & 1 deletion media/libheif/HeifDecoderImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <binder/IMemory.h>
#include <binder/MemoryDealer.h>
#include <drm/drm_framework_common.h>
#include <log/log.h>
#include <media/mediametadataretriever.h>
#include <media/stagefright/MediaSource.h>
#include <media/stagefright/foundation/ADebug.h>
Expand Down Expand Up @@ -421,7 +422,13 @@ bool HeifDecoderImpl::reinit(HeifFrameInfo* frameInfo) {

initFrameInfo(&mSequenceInfo, videoFrame);

mSequenceLength = atoi(mRetriever->extractMetadata(METADATA_KEY_VIDEO_FRAME_COUNT));
const char* frameCount = mRetriever->extractMetadata(METADATA_KEY_VIDEO_FRAME_COUNT);
if (frameCount == nullptr) {
android_errorWriteWithInfoLog(0x534e4554, "215002587", -1, NULL, 0);
ALOGD("No valid sequence information in metadata");
return false;
}
mSequenceLength = atoi(frameCount);

if (defaultInfo == nullptr) {
defaultInfo = &mSequenceInfo;
Expand Down
11 changes: 6 additions & 5 deletions media/libmediametrics/include/media/MediaMetricsItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <variant>

#include <binder/Parcel.h>
#include <log/log.h>
#include <utils/Errors.h>
#include <utils/Timers.h> // nsecs_t

Expand Down Expand Up @@ -466,16 +467,16 @@ class BaseItem {
template <> // static
status_t extract(std::string *val, const char **bufferpptr, const char *bufferptrmax) {
const char *ptr = *bufferpptr;
while (*ptr != 0) {
do {
if (ptr >= bufferptrmax) {
ALOGE("%s: buffer exceeded", __func__);
android_errorWriteLog(0x534e4554, "204445255");
return BAD_VALUE;
}
++ptr;
}
const size_t size = (ptr - *bufferpptr) + 1;
} while (*ptr++ != 0);
// ptr is terminator+1, == bufferptrmax if we finished entire buffer
*val = *bufferpptr;
*bufferpptr += size;
*bufferpptr = ptr;
return NO_ERROR;
}
template <> // static
Expand Down
Loading