From 9f6915631b918a56e0e6be958fb14d274cbab322 Mon Sep 17 00:00:00 2001 From: Mike Chan Date: Tue, 2 Mar 2010 10:55:58 -0800 Subject: bonic: libc: cpuacct support for setuid functions Any of the setuid functions now updates /acct/uid/ with its own tid before changing users. This is so we can properly account for cpu time per uid. Change-Id: I34186cf4d5228cac8439e582a9e26c01ef3011e4 Signed-off-by: Mike Chan --- libc/Android.mk | 4 +++ libc/SYSCALLS.TXT | 6 ++-- libc/arch-arm/syscalls.mk | 6 ++-- libc/arch-arm/syscalls/__setresuid.S | 19 ++++++++++++ libc/arch-arm/syscalls/__setreuid.S | 19 ++++++++++++ libc/arch-arm/syscalls/__setuid.S | 19 ++++++++++++ libc/arch-arm/syscalls/setresuid.S | 19 ------------ libc/arch-arm/syscalls/setreuid.S | 19 ------------ libc/arch-arm/syscalls/setuid.S | 19 ------------ libc/arch-sh/syscalls.mk | 6 ++-- libc/arch-sh/syscalls/__setresuid.S | 32 +++++++++++++++++++ libc/arch-sh/syscalls/__setreuid.S | 32 +++++++++++++++++++ libc/arch-sh/syscalls/__setuid.S | 32 +++++++++++++++++++ libc/arch-sh/syscalls/setresuid.S | 32 ------------------- libc/arch-sh/syscalls/setreuid.S | 32 ------------------- libc/arch-sh/syscalls/setuid.S | 32 ------------------- libc/arch-x86/syscalls.mk | 6 ++-- libc/arch-x86/syscalls/__setresuid.S | 29 +++++++++++++++++ libc/arch-x86/syscalls/__setreuid.S | 26 ++++++++++++++++ libc/arch-x86/syscalls/__setuid.S | 23 ++++++++++++++ libc/arch-x86/syscalls/setresuid.S | 29 ----------------- libc/arch-x86/syscalls/setreuid.S | 26 ---------------- libc/arch-x86/syscalls/setuid.S | 23 -------------- libc/bionic/cpuacct.c | 60 ++++++++++++++++++++++++++++++++++++ libc/bionic/fork.c | 8 +++++ libc/include/sys/linux-unistd.h | 6 ++-- libc/unistd/seteuid.c | 3 +- libc/unistd/setresuid.c | 35 +++++++++++++++++++++ libc/unistd/setreuid.c | 34 ++++++++++++++++++++ libc/unistd/setuid.c | 34 ++++++++++++++++++++ 30 files changed, 423 insertions(+), 247 deletions(-) create mode 100644 libc/arch-arm/syscalls/__setresuid.S create mode 100644 libc/arch-arm/syscalls/__setreuid.S create mode 100644 libc/arch-arm/syscalls/__setuid.S delete mode 100644 libc/arch-arm/syscalls/setresuid.S delete mode 100644 libc/arch-arm/syscalls/setreuid.S delete mode 100644 libc/arch-arm/syscalls/setuid.S create mode 100644 libc/arch-sh/syscalls/__setresuid.S create mode 100644 libc/arch-sh/syscalls/__setreuid.S create mode 100644 libc/arch-sh/syscalls/__setuid.S delete mode 100644 libc/arch-sh/syscalls/setresuid.S delete mode 100644 libc/arch-sh/syscalls/setreuid.S delete mode 100644 libc/arch-sh/syscalls/setuid.S create mode 100644 libc/arch-x86/syscalls/__setresuid.S create mode 100644 libc/arch-x86/syscalls/__setreuid.S create mode 100644 libc/arch-x86/syscalls/__setuid.S delete mode 100644 libc/arch-x86/syscalls/setresuid.S delete mode 100644 libc/arch-x86/syscalls/setreuid.S delete mode 100644 libc/arch-x86/syscalls/setuid.S create mode 100644 libc/bionic/cpuacct.c create mode 100644 libc/unistd/setresuid.c create mode 100644 libc/unistd/setreuid.c create mode 100644 libc/unistd/setuid.c diff --git a/libc/Android.mk b/libc/Android.mk index e820b60..97f4011 100644 --- a/libc/Android.mk +++ b/libc/Android.mk @@ -47,7 +47,10 @@ libc_common_src_files := \ unistd/sbrk.c \ unistd/send.c \ unistd/setegid.c \ + unistd/setuid.c \ unistd/seteuid.c \ + unistd/setreuid.c \ + unistd/setresuid.c \ unistd/setpgrp.c \ unistd/sigblock.c \ unistd/siginterrupt.c \ @@ -219,6 +222,7 @@ libc_common_src_files := \ bionic/__errno.c \ bionic/__set_errno.c \ bionic/_rand48.c \ + bionic/cpuacct.c \ bionic/arc4random.c \ bionic/basename.c \ bionic/basename_r.c \ diff --git a/libc/SYSCALLS.TXT b/libc/SYSCALLS.TXT index ca48cfb..8c664d7 100644 --- a/libc/SYSCALLS.TXT +++ b/libc/SYSCALLS.TXT @@ -42,7 +42,7 @@ pid_t __sys_clone:clone (int, void*, int*, void*, int*) 120 int execve (const char*, char* const*, char* const*) 11 -int setuid:setuid32 (uid_t) 213 +int __setuid:setuid32 (uid_t) 213 uid_t getuid:getuid32 () 199 gid_t getgid:getgid32 () 200 uid_t geteuid:geteuid32 () 201 @@ -56,8 +56,8 @@ pid_t getppid() 64 pid_t setsid() 66 int setgid:setgid32(gid_t) 214 int seteuid:seteuid32(uid_t) stub -int setreuid:setreuid32(uid_t, uid_t) 203 -int setresuid:setresuid32(uid_t, uid_t, uid_t) 208 +int __setreuid:setreuid32(uid_t, uid_t) 203 +int __setresuid:setresuid32(uid_t, uid_t, uid_t) 208 int setresgid:setresgid32(gid_t, gid_t, gid_t) 210 void* __brk:brk(void*) 45 # see comments in arch-arm/bionic/kill.S to understand why we don't generate an ARM stub for kill/tkill diff --git a/libc/arch-arm/syscalls.mk b/libc/arch-arm/syscalls.mk index 3020930..4a8caac 100644 --- a/libc/arch-arm/syscalls.mk +++ b/libc/arch-arm/syscalls.mk @@ -6,7 +6,7 @@ syscall_src += arch-arm/syscalls/__fork.S syscall_src += arch-arm/syscalls/waitid.S syscall_src += arch-arm/syscalls/__sys_clone.S syscall_src += arch-arm/syscalls/execve.S -syscall_src += arch-arm/syscalls/setuid.S +syscall_src += arch-arm/syscalls/__setuid.S syscall_src += arch-arm/syscalls/getuid.S syscall_src += arch-arm/syscalls/getgid.S syscall_src += arch-arm/syscalls/geteuid.S @@ -19,8 +19,8 @@ syscall_src += arch-arm/syscalls/getpgid.S syscall_src += arch-arm/syscalls/getppid.S syscall_src += arch-arm/syscalls/setsid.S syscall_src += arch-arm/syscalls/setgid.S -syscall_src += arch-arm/syscalls/setreuid.S -syscall_src += arch-arm/syscalls/setresuid.S +syscall_src += arch-arm/syscalls/__setreuid.S +syscall_src += arch-arm/syscalls/__setresuid.S syscall_src += arch-arm/syscalls/setresgid.S syscall_src += arch-arm/syscalls/__brk.S syscall_src += arch-arm/syscalls/__ptrace.S diff --git a/libc/arch-arm/syscalls/__setresuid.S b/libc/arch-arm/syscalls/__setresuid.S new file mode 100644 index 0000000..7710772 --- /dev/null +++ b/libc/arch-arm/syscalls/__setresuid.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setresuid, #function + .globl __setresuid + .align 4 + .fnstart + +__setresuid: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_setresuid32 + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-arm/syscalls/__setreuid.S b/libc/arch-arm/syscalls/__setreuid.S new file mode 100644 index 0000000..0c68866 --- /dev/null +++ b/libc/arch-arm/syscalls/__setreuid.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setreuid, #function + .globl __setreuid + .align 4 + .fnstart + +__setreuid: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_setreuid32 + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-arm/syscalls/__setuid.S b/libc/arch-arm/syscalls/__setuid.S new file mode 100644 index 0000000..efc6e56 --- /dev/null +++ b/libc/arch-arm/syscalls/__setuid.S @@ -0,0 +1,19 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setuid, #function + .globl __setuid + .align 4 + .fnstart + +__setuid: + .save {r4, r7} + stmfd sp!, {r4, r7} + ldr r7, =__NR_setuid32 + swi #0 + ldmfd sp!, {r4, r7} + movs r0, r0 + bxpl lr + b __set_syscall_errno + .fnend diff --git a/libc/arch-arm/syscalls/setresuid.S b/libc/arch-arm/syscalls/setresuid.S deleted file mode 100644 index 266c1a1..0000000 --- a/libc/arch-arm/syscalls/setresuid.S +++ /dev/null @@ -1,19 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setresuid, #function - .globl setresuid - .align 4 - .fnstart - -setresuid: - .save {r4, r7} - stmfd sp!, {r4, r7} - ldr r7, =__NR_setresuid32 - swi #0 - ldmfd sp!, {r4, r7} - movs r0, r0 - bxpl lr - b __set_syscall_errno - .fnend diff --git a/libc/arch-arm/syscalls/setreuid.S b/libc/arch-arm/syscalls/setreuid.S deleted file mode 100644 index 0f94b47..0000000 --- a/libc/arch-arm/syscalls/setreuid.S +++ /dev/null @@ -1,19 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setreuid, #function - .globl setreuid - .align 4 - .fnstart - -setreuid: - .save {r4, r7} - stmfd sp!, {r4, r7} - ldr r7, =__NR_setreuid32 - swi #0 - ldmfd sp!, {r4, r7} - movs r0, r0 - bxpl lr - b __set_syscall_errno - .fnend diff --git a/libc/arch-arm/syscalls/setuid.S b/libc/arch-arm/syscalls/setuid.S deleted file mode 100644 index 31cf446..0000000 --- a/libc/arch-arm/syscalls/setuid.S +++ /dev/null @@ -1,19 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setuid, #function - .globl setuid - .align 4 - .fnstart - -setuid: - .save {r4, r7} - stmfd sp!, {r4, r7} - ldr r7, =__NR_setuid32 - swi #0 - ldmfd sp!, {r4, r7} - movs r0, r0 - bxpl lr - b __set_syscall_errno - .fnend diff --git a/libc/arch-sh/syscalls.mk b/libc/arch-sh/syscalls.mk index c848954..ab2f3d1 100644 --- a/libc/arch-sh/syscalls.mk +++ b/libc/arch-sh/syscalls.mk @@ -7,7 +7,7 @@ syscall_src += arch-sh/syscalls/_waitpid.S syscall_src += arch-sh/syscalls/waitid.S syscall_src += arch-sh/syscalls/__sys_clone.S syscall_src += arch-sh/syscalls/execve.S -syscall_src += arch-sh/syscalls/setuid.S +syscall_src += arch-sh/syscalls/__setuid.S syscall_src += arch-sh/syscalls/getuid.S syscall_src += arch-sh/syscalls/getgid.S syscall_src += arch-sh/syscalls/geteuid.S @@ -20,8 +20,8 @@ syscall_src += arch-sh/syscalls/getpgid.S syscall_src += arch-sh/syscalls/getppid.S syscall_src += arch-sh/syscalls/setsid.S syscall_src += arch-sh/syscalls/setgid.S -syscall_src += arch-sh/syscalls/setreuid.S -syscall_src += arch-sh/syscalls/setresuid.S +syscall_src += arch-sh/syscalls/__setreuid.S +syscall_src += arch-sh/syscalls/__setresuid.S syscall_src += arch-sh/syscalls/setresgid.S syscall_src += arch-sh/syscalls/__brk.S syscall_src += arch-sh/syscalls/kill.S diff --git a/libc/arch-sh/syscalls/__setresuid.S b/libc/arch-sh/syscalls/__setresuid.S new file mode 100644 index 0000000..424100e --- /dev/null +++ b/libc/arch-sh/syscalls/__setresuid.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setresuid, @function + .globl __setresuid + .align 4 + +__setresuid: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(3 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_setresuid32_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_setresuid32_end: + rts + nop + + .align 2 +0: .long __NR_setresuid32 +1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/__setreuid.S b/libc/arch-sh/syscalls/__setreuid.S new file mode 100644 index 0000000..6990748 --- /dev/null +++ b/libc/arch-sh/syscalls/__setreuid.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setreuid, @function + .globl __setreuid + .align 4 + +__setreuid: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(2 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_setreuid32_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_setreuid32_end: + rts + nop + + .align 2 +0: .long __NR_setreuid32 +1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/__setuid.S b/libc/arch-sh/syscalls/__setuid.S new file mode 100644 index 0000000..f563de7 --- /dev/null +++ b/libc/arch-sh/syscalls/__setuid.S @@ -0,0 +1,32 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setuid, @function + .globl __setuid + .align 4 + +__setuid: + + /* invoke trap */ + mov.l 0f, r3 /* trap num */ + trapa #(1 + 0x10) + + /* check return value */ + cmp/pz r0 + bt __NR_setuid32_end + + /* keep error number */ + sts.l pr, @-r15 + mov.l 1f, r1 + jsr @r1 + mov r0, r4 + lds.l @r15+, pr + +__NR_setuid32_end: + rts + nop + + .align 2 +0: .long __NR_setuid32 +1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/setresuid.S b/libc/arch-sh/syscalls/setresuid.S deleted file mode 100644 index 41fe349..0000000 --- a/libc/arch-sh/syscalls/setresuid.S +++ /dev/null @@ -1,32 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setresuid, @function - .globl setresuid - .align 4 - -setresuid: - - /* invoke trap */ - mov.l 0f, r3 /* trap num */ - trapa #(3 + 0x10) - - /* check return value */ - cmp/pz r0 - bt __NR_setresuid32_end - - /* keep error number */ - sts.l pr, @-r15 - mov.l 1f, r1 - jsr @r1 - mov r0, r4 - lds.l @r15+, pr - -__NR_setresuid32_end: - rts - nop - - .align 2 -0: .long __NR_setresuid32 -1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/setreuid.S b/libc/arch-sh/syscalls/setreuid.S deleted file mode 100644 index 025df27..0000000 --- a/libc/arch-sh/syscalls/setreuid.S +++ /dev/null @@ -1,32 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setreuid, @function - .globl setreuid - .align 4 - -setreuid: - - /* invoke trap */ - mov.l 0f, r3 /* trap num */ - trapa #(2 + 0x10) - - /* check return value */ - cmp/pz r0 - bt __NR_setreuid32_end - - /* keep error number */ - sts.l pr, @-r15 - mov.l 1f, r1 - jsr @r1 - mov r0, r4 - lds.l @r15+, pr - -__NR_setreuid32_end: - rts - nop - - .align 2 -0: .long __NR_setreuid32 -1: .long __set_syscall_errno diff --git a/libc/arch-sh/syscalls/setuid.S b/libc/arch-sh/syscalls/setuid.S deleted file mode 100644 index 1fb3148..0000000 --- a/libc/arch-sh/syscalls/setuid.S +++ /dev/null @@ -1,32 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setuid, @function - .globl setuid - .align 4 - -setuid: - - /* invoke trap */ - mov.l 0f, r3 /* trap num */ - trapa #(1 + 0x10) - - /* check return value */ - cmp/pz r0 - bt __NR_setuid32_end - - /* keep error number */ - sts.l pr, @-r15 - mov.l 1f, r1 - jsr @r1 - mov r0, r4 - lds.l @r15+, pr - -__NR_setuid32_end: - rts - nop - - .align 2 -0: .long __NR_setuid32 -1: .long __set_syscall_errno diff --git a/libc/arch-x86/syscalls.mk b/libc/arch-x86/syscalls.mk index 6a528e3..ab026fe 100644 --- a/libc/arch-x86/syscalls.mk +++ b/libc/arch-x86/syscalls.mk @@ -7,7 +7,7 @@ syscall_src += arch-x86/syscalls/_waitpid.S syscall_src += arch-x86/syscalls/waitid.S syscall_src += arch-x86/syscalls/__sys_clone.S syscall_src += arch-x86/syscalls/execve.S -syscall_src += arch-x86/syscalls/setuid.S +syscall_src += arch-x86/syscalls/__setuid.S syscall_src += arch-x86/syscalls/getuid.S syscall_src += arch-x86/syscalls/getgid.S syscall_src += arch-x86/syscalls/geteuid.S @@ -20,8 +20,8 @@ syscall_src += arch-x86/syscalls/getpgid.S syscall_src += arch-x86/syscalls/getppid.S syscall_src += arch-x86/syscalls/setsid.S syscall_src += arch-x86/syscalls/setgid.S -syscall_src += arch-x86/syscalls/setreuid.S -syscall_src += arch-x86/syscalls/setresuid.S +syscall_src += arch-x86/syscalls/__setreuid.S +syscall_src += arch-x86/syscalls/__setresuid.S syscall_src += arch-x86/syscalls/setresgid.S syscall_src += arch-x86/syscalls/__brk.S syscall_src += arch-x86/syscalls/kill.S diff --git a/libc/arch-x86/syscalls/__setresuid.S b/libc/arch-x86/syscalls/__setresuid.S new file mode 100644 index 0000000..c492dfb --- /dev/null +++ b/libc/arch-x86/syscalls/__setresuid.S @@ -0,0 +1,29 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setresuid, @function + .globl __setresuid + .align 4 + +__setresuid: + pushl %ebx + pushl %ecx + pushl %edx + mov 16(%esp), %ebx + mov 20(%esp), %ecx + mov 24(%esp), %edx + movl $__NR_setresuid32, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %edx + popl %ecx + popl %ebx + ret diff --git a/libc/arch-x86/syscalls/__setreuid.S b/libc/arch-x86/syscalls/__setreuid.S new file mode 100644 index 0000000..111e999 --- /dev/null +++ b/libc/arch-x86/syscalls/__setreuid.S @@ -0,0 +1,26 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setreuid, @function + .globl __setreuid + .align 4 + +__setreuid: + pushl %ebx + pushl %ecx + mov 12(%esp), %ebx + mov 16(%esp), %ecx + movl $__NR_setreuid32, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %ecx + popl %ebx + ret diff --git a/libc/arch-x86/syscalls/__setuid.S b/libc/arch-x86/syscalls/__setuid.S new file mode 100644 index 0000000..1e5f285 --- /dev/null +++ b/libc/arch-x86/syscalls/__setuid.S @@ -0,0 +1,23 @@ +/* autogenerated by gensyscalls.py */ +#include + + .text + .type __setuid, @function + .globl __setuid + .align 4 + +__setuid: + pushl %ebx + mov 8(%esp), %ebx + movl $__NR_setuid32, %eax + int $0x80 + cmpl $-129, %eax + jb 1f + negl %eax + pushl %eax + call __set_errno + addl $4, %esp + orl $-1, %eax +1: + popl %ebx + ret diff --git a/libc/arch-x86/syscalls/setresuid.S b/libc/arch-x86/syscalls/setresuid.S deleted file mode 100644 index f81cb39..0000000 --- a/libc/arch-x86/syscalls/setresuid.S +++ /dev/null @@ -1,29 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setresuid, @function - .globl setresuid - .align 4 - -setresuid: - pushl %ebx - pushl %ecx - pushl %edx - mov 16(%esp), %ebx - mov 20(%esp), %ecx - mov 24(%esp), %edx - movl $__NR_setresuid32, %eax - int $0x80 - cmpl $-129, %eax - jb 1f - negl %eax - pushl %eax - call __set_errno - addl $4, %esp - orl $-1, %eax -1: - popl %edx - popl %ecx - popl %ebx - ret diff --git a/libc/arch-x86/syscalls/setreuid.S b/libc/arch-x86/syscalls/setreuid.S deleted file mode 100644 index 99e5d5b..0000000 --- a/libc/arch-x86/syscalls/setreuid.S +++ /dev/null @@ -1,26 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setreuid, @function - .globl setreuid - .align 4 - -setreuid: - pushl %ebx - pushl %ecx - mov 12(%esp), %ebx - mov 16(%esp), %ecx - movl $__NR_setreuid32, %eax - int $0x80 - cmpl $-129, %eax - jb 1f - negl %eax - pushl %eax - call __set_errno - addl $4, %esp - orl $-1, %eax -1: - popl %ecx - popl %ebx - ret diff --git a/libc/arch-x86/syscalls/setuid.S b/libc/arch-x86/syscalls/setuid.S deleted file mode 100644 index de334c0..0000000 --- a/libc/arch-x86/syscalls/setuid.S +++ /dev/null @@ -1,23 +0,0 @@ -/* autogenerated by gensyscalls.py */ -#include - - .text - .type setuid, @function - .globl setuid - .align 4 - -setuid: - pushl %ebx - mov 8(%esp), %ebx - movl $__NR_setuid32, %eax - int $0x80 - cmpl $-129, %eax - jb 1f - negl %eax - pushl %eax - call __set_errno - addl $4, %esp - orl $-1, %eax -1: - popl %ebx - ret diff --git a/libc/bionic/cpuacct.c b/libc/bionic/cpuacct.c new file mode 100644 index 0000000..abdbc51 --- /dev/null +++ b/libc/bionic/cpuacct.c @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include +#include +#include +#include +//#include + +int cpuacct_add(uid_t uid) +{ + int count; + FILE *fp; + char buf[80]; + + count = snprintf(buf, sizeof(buf), "/acct/uid/%d/tasks", uid); + fp = fopen(buf, "w+"); + if (!fp) { + /* Note: sizeof("tasks") returns 6, which includes the NULL char */ + buf[count - sizeof("tasks")] = 0; + if (mkdir(buf, 0775) < 0) + return -errno; + + /* Note: sizeof("tasks") returns 6, which includes the NULL char */ + buf[count - sizeof("tasks")] = '/'; + fp = fopen(buf, "w+"); + } + if (!fp) + return -errno; + + fprintf(fp, "0"); + if (fclose(fp)) + return -errno; + + return 0; +} diff --git a/libc/bionic/fork.c b/libc/bionic/fork.c index 1c6a4ba..e20f548 100644 --- a/libc/bionic/fork.c +++ b/libc/bionic/fork.c @@ -43,6 +43,14 @@ int fork(void) ret = __fork(); if (ret != 0) { /* not a child process */ __timer_table_start_stop(0); + } else { + /* + * Newly created process must update cpu accounting. + * Call cpuacct_add passing in our uid, which will take + * the current task id and add it to the uid group passed + * as a parameter. + */ + cpuacct_add(getuid()); } return ret; } diff --git a/libc/include/sys/linux-unistd.h b/libc/include/sys/linux-unistd.h index d6f706b..116d047 100644 --- a/libc/include/sys/linux-unistd.h +++ b/libc/include/sys/linux-unistd.h @@ -12,7 +12,7 @@ pid_t _waitpid (pid_t, int*, int, struct rusage*); int waitid (int, pid_t, struct siginfo_t*, int,void*); pid_t __sys_clone (int, void*, int*, void*, int*); int execve (const char*, char* const*, char* const*); -int setuid (uid_t); +int __setuid (uid_t); uid_t getuid (void); gid_t getgid (void); uid_t geteuid (void); @@ -26,8 +26,8 @@ pid_t getppid (void); pid_t setsid (void); int setgid (gid_t); int seteuid (uid_t); -int setreuid (uid_t, uid_t); -int setresuid (uid_t, uid_t, uid_t); +int __setreuid (uid_t, uid_t); +int __setresuid (uid_t, uid_t, uid_t); int setresgid (gid_t, gid_t, gid_t); void* __brk (void*); int kill (pid_t, int); diff --git a/libc/unistd/seteuid.c b/libc/unistd/seteuid.c index 42ee780..dd94932 100644 --- a/libc/unistd/seteuid.c +++ b/libc/unistd/seteuid.c @@ -29,5 +29,6 @@ int seteuid(uid_t euid) { - return setresuid(-1, euid,-1); + cpuacct_add(euid); + return __setresuid(-1, euid,-1); } diff --git a/libc/unistd/setresuid.c b/libc/unistd/setresuid.c new file mode 100644 index 0000000..1964881 --- /dev/null +++ b/libc/unistd/setresuid.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include + +int setresuid(uid_t ruid, uid_t euid, uid_t suid) +{ + cpuacct_add(euid); + return __setresuid(ruid, euid, suid); + +} diff --git a/libc/unistd/setreuid.c b/libc/unistd/setreuid.c new file mode 100644 index 0000000..04c2826 --- /dev/null +++ b/libc/unistd/setreuid.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include + +int setreuid(uid_t ruid, uid_t euid) +{ + cpuacct_add(euid); + return __setreuid(ruid, euid); +} diff --git a/libc/unistd/setuid.c b/libc/unistd/setuid.c new file mode 100644 index 0000000..8ab637d --- /dev/null +++ b/libc/unistd/setuid.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include + +int setuid(uid_t uid) +{ + cpuacct_add(uid); + return __setuid(uid); +} -- cgit v1.1