From cf2a3f6eb5016803d99991f6e1f204aacb9d4bdb Mon Sep 17 00:00:00 2001 From: Alessandro Astone Date: Mon, 13 Mar 2023 01:09:38 +0100 Subject: [PATCH] Zygote: Fix dropping capabilities in containers Casting a int to long will sign-extend it, so if capability bit 31 was set the bitmask would always have all the upper 32 bits set, failing to drop any of the upper capabilities. Instead of plain casting, use Integer.toUnsignedLong to always zero-extend the bitmask Change-Id: I9b4c9273e8eb09f7e231b5c579e7906d05b6e475 --- core/java/com/android/internal/os/ZygoteInit.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 076e4e118e667..2db9e0918d721 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -716,7 +716,8 @@ public class ZygoteInit { } catch (ErrnoException ex) { throw new RuntimeException("Failed to capget()", ex); } - capabilities &= ((long) data[0].effective) | (((long) data[1].effective) << 32); + capabilities &= Integer.toUnsignedLong(data[0].effective) | + (Integer.toUnsignedLong(data[1].effective) << 32); /* Hardcoded command line to start the system server */ String[] args = {