diff options
| author | Kevin F. Haggerty <haggertk@lineageos.org> | 2020-03-02 18:52:38 -0700 |
|---|---|---|
| committer | mosimchah <mosimchah@gmail.com> | 2020-03-10 05:07:00 -0400 |
| commit | 7f043c3c3ba765ca801dad7f2c49a1a6fda5c9a6 (patch) | |
| tree | 85652b3e017dc96bedae5d919322dedaec58921b /services/surfaceflinger/Client.cpp | |
| parent | c5f14bad81722c4eca8a81bffaca44167374f69e (diff) | |
Restrict Automerge: Fix reinterpret_cast security bugp9.0
This patch fixes a security bug in SurfaceFlinger. Bug is due to a
reinterpret_cast used when obtaining a sp<Layer> from an sp<IBinder> passed
from a client. Without a checking mechanism, client could pass a
malicious data packet. This is a modified cherry-pick of a patch by Rob Carr
that utilizes a map to identify the appropriate layer based on
the incoming IBinder token.
Original patch commit:
"Author: Robert Carr <racarr@google.com>
Date: Thu Apr 11 13:18:21 2019 -0700
SurfaceFlinger: Validate layers before casting.
Reinterpret casting random IBinder = no-fun. I first attempted
to use inheritance of "getInterfaceDescriptor" in Layer::Handle but
departing from "standard-layout" (e.g. using virtual methods) means that
downcasting with static/reinterpret_cast is no longer valid. Instead I opted
for the pattern the system-server uses of maintaing a map.
Now that we look up the handle in a map rather than casting IBinder
to Layer::Handle we need to make sure we have unique instances of the
handle. In general this is true but we weren't doing this in the
createWithSurfaceParent where we had an extra call to getHandle. Here
we both refactor createWithSurfaceParent so it works with the new
changes and also add protection for getHandle. We also fix an error
where the handle map was populated outside of lock.
"
Bug: 137284057
Test: build, boot, manual, SurfaceFlinger_test
Change-Id: I9b5f298db2da9cd974c423eb52f261a90f0d17dc
(cherry-picked from commit c4638082469e906c025c8c8a8614de65c59afc90)
Change-Id: Iabf5fb6f1b90c4d4d178ae2570b27e9417a4e10a
Diffstat (limited to 'services/surfaceflinger/Client.cpp')
| -rw-r--r-- | services/surfaceflinger/Client.cpp | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp index 0b59147c5a..09d87b29d6 100644 --- a/services/surfaceflinger/Client.cpp +++ b/services/surfaceflinger/Client.cpp @@ -118,7 +118,6 @@ sp<Layer> Client::getLayerUser(const sp<IBinder>& handle) const return lbc; } - status_t Client::onTransact( uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { @@ -144,34 +143,19 @@ status_t Client::onTransact( return BnSurfaceComposerClient::onTransact(code, data, reply, flags); } - status_t Client::createSurface( const String8& name, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, const sp<IBinder>& parentHandle, int32_t windowType, int32_t ownerUid, sp<IBinder>* handle, - sp<IGraphicBufferProducer>* gbp) -{ - sp<Layer> parent = nullptr; - if (parentHandle != nullptr) { - auto layerHandle = reinterpret_cast<Layer::Handle*>(parentHandle.get()); - parent = layerHandle->owner.promote(); - if (parent == nullptr) { - return NAME_NOT_FOUND; - } - } - if (parent == nullptr) { - bool parentDied; - parent = getParentLayer(&parentDied); - // If we had a parent, but it died, we've lost all - // our capabilities. - if (parentDied) { - return NAME_NOT_FOUND; - } + sp<IGraphicBufferProducer>* gbp) { + bool parentDied; + sp<Layer> parentLayer = getParentLayer(&parentDied); + if (parentHandle == nullptr && parentDied) { + return NAME_NOT_FOUND; } - return mFlinger->createLayer(name, this, w, h, format, flags, windowType, - ownerUid, handle, gbp, &parent); + ownerUid, handle, gbp, parentHandle, parentLayer); } status_t Client::destroySurface(const sp<IBinder>& handle) { |
