Skip to content

Commit d5a85d6

Browse files
committed
snap-confine: interfaces: Address review comments
- Cleanup and remove TLS-padding permit from AppArmor rules - Only allow binder access on Halium/libhybris systems - Die in case the Halium environment cannot be mounted into the target - Restructure binder device mount operation to iterate through a list of allowed device paths
1 parent 71687e0 commit d5a85d6

3 files changed

Lines changed: 21 additions & 21 deletions

File tree

cmd/snap-confine/mount-support-hybris.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,17 @@ static void sc_hybris_mount_android_rootfs(const char *rootfs_dir)
100100
sc_identity old = sc_set_effective_identity(sc_root_group_identity());
101101
int res = mkdir(android_rootfs_dir, 0755);
102102
if (res != 0 && errno != EEXIST) {
103-
die("cannot create tmpfs target %s", android_rootfs_dir);
103+
die("cannot create bind-mount target %s", android_rootfs_dir);
104104
}
105105
if (res == 0 && (chown(android_rootfs_dir, 0, 0) < 0)) {
106106
// Adjust the ownership only if we created the directory.
107107
die("cannot change ownership of %s", android_rootfs_dir);
108108
}
109109
(void)sc_set_effective_identity(old);
110110

111-
(void)mount(SC_HYBRIS_ROOTFS, android_rootfs_dir, NULL, MS_BIND | MS_REC | MS_RDONLY, NULL);
111+
if (mount(SC_HYBRIS_ROOTFS, android_rootfs_dir, NULL, MS_BIND | MS_REC | MS_RDONLY, NULL)) {
112+
die("Cannot mount Halium environment into target");
113+
}
112114

113115
sc_must_snprintf(path_buf, sizeof(path_buf), "%s%s", rootfs_dir, SC_HYBRIS_SYSTEM_SYMLINK);
114116
const char *android_system_symlink = path_buf;

cmd/snap-confine/udev-support.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,24 @@ static void sc_udev_allow_nvidia(sc_device_cgroup *cgroup)
124124
**/
125125
static void sc_udev_allow_hybris(sc_device_cgroup *cgroup)
126126
{
127-
struct stat sbuf;
128-
129-
if (stat("/dev/binderfs/binder", &sbuf) == 0) {
130-
sc_device_cgroup_allow(cgroup, S_IFCHR, major(sbuf.st_rdev),
131-
minor(sbuf.st_rdev));
132-
}
133-
if (stat("/dev/binderfs/hwbinder", &sbuf) == 0) {
134-
sc_device_cgroup_allow(cgroup, S_IFCHR, major(sbuf.st_rdev),
135-
minor(sbuf.st_rdev));
136-
}
137-
if (stat("/dev/binder", &sbuf) == 0) {
138-
sc_device_cgroup_allow(cgroup, S_IFCHR, major(sbuf.st_rdev),
139-
minor(sbuf.st_rdev));
127+
/* Only go on here if this has been identified as a Halium/libhybris system
128+
*
129+
* In case the host happens to have binder available, but isn't identified as
130+
* a system requiring it to drive host-residing Android drivers, then return early,
131+
* otherwise we would open a hole between confined apps and unconfined Anbox or other
132+
* which causes them to communicate over a potentially unmediated IPC interface.
133+
*/
134+
struct stat propbuf;
135+
if (stat("/system/build.prop", &propbuf) != 0) {
136+
return;
140137
}
141-
if (stat("/dev/hwbinder", &sbuf) == 0) {
142-
sc_device_cgroup_allow(cgroup, S_IFCHR, major(sbuf.st_rdev),
143-
minor(sbuf.st_rdev));
138+
139+
const char *paths[] = {"/dev/binderfs/binder", "/dev/binderfs/hwbinder", "/dev/binder", "/dev/hwbinder"};
140+
for (int i = 0; i < sizeof(paths)/sizeof(paths[0]); i++) {
141+
struct stat sbuf;
142+
if (stat(paths[i], &sbuf) == 0) {
143+
sc_device_cgroup_allow(cgroup, S_IFCHR, major(sbuf.st_rdev), minor(sbuf.st_rdev));
144+
}
144145
}
145146
}
146147

interfaces/builtin/opengl.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ unix (send, receive) type=dgram peer=(addr="@var/run/nvidia-xdriver-*"),
189189
190190
# Hybris support
191191
/{,var/}run/shm/hybris_shm_data rw, # FIXME: LP: #1226569 (make app-specific)
192-
# This is a LD_PRELOADed TLS padding library allowing use of both
193-
# Android 9 and glibc TLS slots at the same time. Only used on Halium 9.
194-
/var/lib/snapd/hostfs/usr/lib/@{multiarch}/libtls-padding.so mr,
195192
/android{,/**} r,
196193
/{,android/}system/build.prop r,
197194
/{,android/}vendor/lib{,64}/** r,

0 commit comments

Comments
 (0)