Remove unnecessary privilege change codes (Bypass seteuid(0) when the calling process... 10/134010/9 accepted/tizen/4.0/unified/20170816.011606 accepted/tizen/unified/20170629.085741 submit/tizen/20170622.043014 submit/tizen_4.0/20170811.094300
authorINSUN PYO <insun.pyo@samsung.com>
Wed, 14 Jun 2017 07:59:43 +0000 (16:59 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 14 Jun 2017 10:10:15 +0000 (19:10 +0900)
commit85f39117886ea3a7d5539f435eb5a2a13822b70b
tree9cb8d78bbc75b431982974e63cb3fe849c633779
parent367ee721025ef322b5d8b0c9a219cb626876d2b1
Remove unnecessary privilege change codes (Bypass seteuid(0) when the calling process is root)

While MIC-building a Tizen image, /usr/bin/tpk-backend with libgum calls gum_utils_gain_privileges() and is crashed.

void gum_utils_gain_privileges ()
{
    if (seteuid(0)) WARN ("seteuid() failed");
}

It is found that seteuid(0) system calls with created threads
result in Segmentation Fault (SIGSEGV) in qemu-arm 2.7 and even in up-to-date qemu-arm 2.9

void *thread_main(void *);

int main(void) {
        int status;
        pthread_t thread;

        pthread_create(&thread, NULL, &thread_main, NULL);  <-- After creating a thread

        sleep(1);
        seteuid(0);  <-- Call seteuid(0)

        pthread_join(thread, (void **)&status);

        return 0;
}

void *thread_main(void *arg) {
        printf ("Thread.\n");
        pause();
}

$) armv7l-tizen-linux-gnueabi-c++ -static -o test test.cc -lpthread
$) qemu-arm test
Segmentation fault (core dumped)

It seems a kind of QEMU bug.
When this patch (https://bugs.launchpad.net/qemu/+bug/1594394) is applied to QEMU 2.9, the problem is resolved.
To avoid the crash during MIC build without the qemu patch, this workaround patch needs to be submitted.

Signed-off-by: INSUN PYO <insun.pyo@samsung.com>
Change-Id: I59a3d37a43864e0f4147c8088fe21db3ad692df5
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
src/common/gum-utils.c