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>
* Drops the privileges for the calling process. Effective uid is to real uid.
*
*/
* Drops the privileges for the calling process. Effective uid is to real uid.
*
*/
-void
-gum_utils_drop_privileges ()
+void gum_utils_drop_privileges ()
+ if (getuid() == (uid_t)0) return;
+
DBG ("Before set: r-uid %d e-uid %d", getuid (), geteuid ());
if (seteuid (getuid()))
WARN ("seteuid() failed");
DBG ("Before set: r-uid %d e-uid %d", getuid (), geteuid ());
if (seteuid (getuid()))
WARN ("seteuid() failed");
* Gains the privileges for the calling process. Effective uid is to 0.
*
*/
* Gains the privileges for the calling process. Effective uid is to 0.
*
*/
-void
-gum_utils_gain_privileges ()
+void gum_utils_gain_privileges ()
- DBG ("Before set: r-uid %d e-uid %d", getuid (), geteuid ());
- if (seteuid (0))
- WARN ("seteuid() failed");
- DBG ("After set: r-uid %d e-uid %d", getuid (), geteuid ());
+ if (getuid() == (uid_t)0) return;
+
+ if (seteuid (0)) WARN ("seteuid() failed");