Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aff03bc7 authored by Pablo Gamito's avatar Pablo Gamito
Browse files

Check the calling uid to ensure ProtoLog commands can only be used by the shell or root user.

Test: manual, check command still works when executed from shell
Flag: EXEMPT minor change
Bug: 424466185
Change-Id: I01e6df88af8a50d6420dbff47bca87e5979521f6
parent 7f0e1c36
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -31,7 +31,9 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemService;
import android.content.Context;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.ShellCallback;
@@ -258,6 +260,12 @@ public class ProtoLogConfigurationServiceImpl extends IProtoLogConfigurationServ
    public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
            @Nullable FileDescriptor err, @NonNull String[] args, @Nullable ShellCallback callback,
            @NonNull ResultReceiver resultReceiver) throws RemoteException {
        final int callingUid = Binder.getCallingUid();
        if (callingUid != Process.ROOT_UID && callingUid != Process.SHELL_UID) {
            resultReceiver.send(-1, null);
            throw new SecurityException("Shell commands are only callable by ADB");
        }

        new ProtoLogCommandHandler(this)
                .exec(this, in, out, err, args, callback, resultReceiver);
    }