Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:34:14+00:00 2026-05-24T16:34:14+00:00

I’m developing an application for Android and I need to elevate the Dalvik VM

  • 0

I’m developing an application for Android and I need to elevate the Dalvik VM to root uid, because in the alternative I need to write a lot of small applications that are started by the Java code using sh scripts (with superuser, they needs to be root) and I really don’t want to do that!

While I’m trying to use, right now, capsetp to set CAP_SETUID to the calling process, I don’t know if this will be widely supported by all Android kernels so I’m looking for possible alternatives.

My fallback solution would be to start a root process that will first use seteuid to switch to the right user, start Dalvik VM with the application (execl) and, using JNI, switch back to the root user …

Any alternative?


EDIT

I’m trying this code, but it fails to apply new capabilities (capsetp).

I’ve partially compiled libcap on Android (cap_file stuff is missing, but I don’t need it), but this code doesn’t work on a standard distro (Ubuntu).

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#ifndef __user
#define __user
#endif
#include <linux/capability.h>
#include <sys/capability.h>

int main(int argc, char** argv)
{
    cap_t caps;
    cap_value_t cap_list[1];

    pid_t process_id = atoi(argv[1]);

    caps = cap_get_pid(process_id);
    if (caps == NULL)
    {
        perror("Failed to get capabilities");
        exit(-1);
    }

    printf("%s\n", cap_to_text(caps, NULL));

    cap_list[0] = CAP_SETUID; 

    if (cap_set_flag(caps, CAP_EFFECTIVE, 1, cap_list, CAP_SET) == -1)
    {
        perror("Failed to add new capability");
        exit(-1);
    }

    if (capsetp(process_id, caps) == -1)     
    {
        perror("Failed to apply capabilities");
        exit(-1);
    }

    cap_free(&caps);

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:34:17+00:00Added an answer on May 24, 2026 at 4:34 pm

    I don’t think there’s a way to elevate another process’s privileges directly. The canonical way to do things like this is to exec a setuid-root binary which then determines whether to grant your program privileges before re-execing your program. Think su or sudo. Of course your setuid-root program like that could communicate with the original root process to determine if it’s safe to grant root. Keep in mind that there could be lots of dangerous corner cases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.