From 076d760d636a5a4af6721f04ebcd7389f703704c Mon Sep 17 00:00:00 2001 From: Joshua Peraza Date: Fri, 14 Sep 2018 09:37:12 -0700 Subject: [PATCH] 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 Reviewed-by: Mark Mentovai --- handler/linux/exception_handler_server.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/handler/linux/exception_handler_server.cc b/handler/linux/exception_handler_server.cc index 748bf6e9..71a5dc74 100644 --- a/handler/linux/exception_handler_server.cc +++ b/handler/linux/exception_handler_server.cc @@ -307,12 +307,25 @@ void ExceptionHandlerServer::HandleEvent(Event* event, uint32_t event_type) { } 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); - if (setsockopt(socket.get(), SOL_SOCKET, SO_PASSCRED, &optval, optlen) != 0) { - PLOG(ERROR) << "setsockopt"; + 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"; + return false; + } + } auto event = std::make_unique(); event->type = Event::Type::kClientMessage;