linux: Check for SO_PASSCRED on client sockets before setting

Bug: crashpad:252
Change-Id: I742fc8923a8497fe83dc40a4a280217ffc691ae7
Reviewed-on: https://chromium-review.googlesource.com/1226115
Commit-Queue: Joshua Peraza <jperaza@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
This commit is contained in:
Joshua Peraza 2018-09-14 09:37:12 -07:00 committed by Commit Bot
parent b918119ca2
commit 076d760d63

View File

@ -307,12 +307,25 @@ void ExceptionHandlerServer::HandleEvent(Event* event, uint32_t event_type) {
} }
bool ExceptionHandlerServer::InstallClientSocket(ScopedFileHandle socket) { bool ExceptionHandlerServer::InstallClientSocket(ScopedFileHandle socket) {
int optval = 1; // The handler may not have permission to set SO_PASSCRED on the socket, but
// it doesn't need to if the client has already set it.
// https://bugs.chromium.org/p/crashpad/issues/detail?id=252
int optval;
socklen_t optlen = sizeof(optval); socklen_t optlen = sizeof(optval);
if (setsockopt(socket.get(), SOL_SOCKET, SO_PASSCRED, &optval, optlen) != 0) { if (getsockopt(socket.get(), SOL_SOCKET, SO_PASSCRED, &optval, &optlen) !=
0) {
PLOG(ERROR) << "getsockopt";
return false;
}
if (!optval) {
optval = 1;
optlen = sizeof(optval);
if (setsockopt(socket.get(), SOL_SOCKET, SO_PASSCRED, &optval, optlen) !=
0) {
PLOG(ERROR) << "setsockopt"; PLOG(ERROR) << "setsockopt";
return false; return false;
} }
}
auto event = std::make_unique<Event>(); auto event = std::make_unique<Event>();
event->type = Event::Type::kClientMessage; event->type = Event::Type::kClientMessage;