-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cast][Mojo] Support UDS abstract namespace for NamedPlatformChannel
Cast on Android uses a NamedPlatformChannel to interconnect the Cast Service and Cast Browser components. To avoid filesystem permission issues, Cast uses a Unix Domain Socket in the Linux abstract namespace. Filesystem permissions are not necessary since the socket is already guarded by the MediaShell security domain on SELinux. Bug: b/229029761 Test: Install cast_service_bundle, launch HBO Now. Change-Id: Ie703174508b5d94fff0a4dc987af7c138c7f7cc3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3595264 Reviewed-by: Joe Downing <joedow@chromium.org> Reviewed-by: David Benjamin <davidben@chromium.org> Reviewed-by: Junbo Ke <juke@chromium.org> Reviewed-by: Ken Rockot <rockot@google.com> Commit-Queue: Sean Topping <seantopping@chromium.org> Cr-Commit-Position: refs/heads/main@{#1001145}
- Loading branch information
Sean Topping
authored and
Chromium LUCI CQ
committed
May 9, 2022
1 parent
0a94135
commit 07616d4
Showing
18 changed files
with
269 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "net/base/sockaddr_util_posix.h" | ||
|
||
#include <string.h> | ||
|
||
#include <sys/socket.h> | ||
#include <sys/un.h> | ||
|
||
#include "build/build_config.h" | ||
#include "net/base/sockaddr_storage.h" | ||
|
||
namespace net { | ||
|
||
bool FillUnixAddress(const std::string& socket_path, | ||
bool use_abstract_namespace, | ||
SockaddrStorage* address) { | ||
// Caller should provide a non-empty path for the socket address. | ||
if (socket_path.empty()) | ||
return false; | ||
|
||
size_t path_max = address->addr_len - offsetof(struct sockaddr_un, sun_path); | ||
// Non abstract namespace pathname should be null-terminated. Abstract | ||
// namespace pathname must start with '\0'. So, the size is always greater | ||
// than socket_path size by 1. | ||
size_t path_size = socket_path.size() + 1; | ||
if (path_size > path_max) | ||
return false; | ||
|
||
struct sockaddr_un* socket_addr = | ||
reinterpret_cast<struct sockaddr_un*>(address->addr); | ||
memset(socket_addr, 0, address->addr_len); | ||
socket_addr->sun_family = AF_UNIX; | ||
address->addr_len = path_size + offsetof(struct sockaddr_un, sun_path); | ||
if (!use_abstract_namespace) { | ||
memcpy(socket_addr->sun_path, socket_path.c_str(), socket_path.size()); | ||
return true; | ||
} | ||
|
||
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) | ||
// Convert the path given into abstract socket name. It must start with | ||
// the '\0' character, so we are adding it. |addr_len| must specify the | ||
// length of the structure exactly, as potentially the socket name may | ||
// have '\0' characters embedded (although we don't support this). | ||
// Note that addr.sun_path is already zero initialized. | ||
memcpy(socket_addr->sun_path + 1, socket_path.c_str(), socket_path.size()); | ||
return true; | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
} // namespace net |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2022 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef NET_BASE_SOCKADDR_UTIL_POSIX_H_ | ||
#define NET_BASE_SOCKADDR_UTIL_POSIX_H_ | ||
|
||
#include <string> | ||
|
||
#include "net/base/net_export.h" | ||
|
||
namespace net { | ||
|
||
struct SockaddrStorage; | ||
|
||
// Fills |address| with |socket_path| and its length. For Android or Linux | ||
// platform, this supports abstract namespaces. | ||
NET_EXPORT bool FillUnixAddress(const std::string& socket_path, | ||
bool use_abstract_namespace, | ||
SockaddrStorage* address); | ||
|
||
} // namespace net | ||
|
||
#endif // NET_BASE_SOCKADDR_UTIL_POSIX_H_ |
Oops, something went wrong.