Skip to content

Commit e305075

Browse files
authored
implement getpgid (#1090)
* implement getpgid syscall Lind does not implement process groups. getpgid always returns the cage's own cageid (matching getpid behavior). This is platform-specific behavior that cannot be changed with a grate since getpgid is handled directly by RawPOSIX. Fixes #775 * fix getpgid test to pass on native linux * address review: remove unused includes, fix misleading comment
1 parent c23b544 commit e305075

6 files changed

Lines changed: 65 additions & 4 deletions

File tree

‎src/glibc/lind_syscall/lind_syscall_num.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#define GETEUID_SYSCALL 107
105105
#define GETEGID_SYSCALL 108
106106
#define GETPPID_SYSCALL 110
107+
#define GETPGID_SYSCALL 121
107108
#define MKNOD_SYSCALL 133
108109
#define STATFS_SYSCALL 137
109110
#define FSTATFS_SYSCALL 138
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include <unistd.h>
2+
#include <syscall-template.h>
3+
#include <lind_syscall_num.h>
24

35
pid_t
46
__getpgid (pid_t pid)
57
{
6-
return pid;
8+
return MAKE_LEGACY_SYSCALL (GETPGID_SYSCALL, "syscall|getpgid",
9+
(uint64_t) pid, NOTUSED, NOTUSED,
10+
NOTUSED, NOTUSED, NOTUSED, TRANSLATE_ERRNO_ON);
711
}
8-
9-
12+
weak_alias (__getpgid, getpgid)

‎src/rawposix/src/sys_calls.rs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,50 @@ pub extern "C" fn getpid_syscall(
676676
return cage.cageid as i32;
677677
}
678678

679+
/// Reference to Linux: https://man7.org/linux/man-pages/man2/getpgid.2.html
680+
///
681+
/// Returns the process group ID of the process specified by pid.
682+
/// If pid is 0, returns the process group ID of the calling process.
683+
///
684+
/// Lind does not implement process groups. The default RawPOSIX behavior
685+
/// always returns the cage's own cageid. A grate can interpose on this
686+
/// syscall to provide different process group semantics.
687+
///
688+
/// ## Returns
689+
/// - The cageid (as process group ID) on success.
690+
pub extern "C" fn getpgid_syscall(
691+
cageid: u64,
692+
pid_arg: u64,
693+
pid_cageid: u64,
694+
arg2: u64,
695+
arg2_cageid: u64,
696+
arg3: u64,
697+
arg3_cageid: u64,
698+
arg4: u64,
699+
arg4_cageid: u64,
700+
arg5: u64,
701+
arg5_cageid: u64,
702+
arg6: u64,
703+
arg6_cageid: u64,
704+
) -> i32 {
705+
if !(sc_unusedarg(arg2, arg2_cageid)
706+
&& sc_unusedarg(arg3, arg3_cageid)
707+
&& sc_unusedarg(arg4, arg4_cageid)
708+
&& sc_unusedarg(arg5, arg5_cageid)
709+
&& sc_unusedarg(arg6, arg6_cageid))
710+
{
711+
panic!(
712+
"{}: unused arguments contain unexpected values -- security violation",
713+
"getpgid_syscall"
714+
);
715+
}
716+
717+
// Lind doesn't implement process groups. Return own cageid regardless
718+
// of the pid argument (matching the behavior of getpid).
719+
let cage = get_cage(cageid).unwrap();
720+
cage.cageid as i32
721+
}
722+
679723
/// Reference to Linux: https://man7.org/linux/man-pages/man3/getppid.3p.html
680724
///
681725
/// See comments of `getpid_syscall` for more details

‎src/rawposix/src/syscall_table.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use super::net_calls::{
2626
};
2727
use super::sys_calls::{
2828
exec_syscall, exit_group_syscall, exit_syscall, fork_syscall, getegid_syscall, geteuid_syscall,
29-
getgid_syscall, getpid_syscall, getppid_syscall, getuid_syscall, kill_syscall,
29+
getgid_syscall, getpgid_syscall, getpid_syscall, getppid_syscall, getuid_syscall, kill_syscall,
3030
prlimit64_syscall, sched_yield_syscall, setitimer_syscall, sigaction_syscall,
3131
sigprocmask_syscall, waitpid_syscall,
3232
};
@@ -125,6 +125,7 @@ pub const SYSCALL_TABLE: &[(u64, RawCallFunc)] = &[
125125
(syscall_const::GETEUID_SYSCALL as u64, geteuid_syscall),
126126
(syscall_const::GETEGID_SYSCALL as u64, getegid_syscall),
127127
(syscall_const::GETPPID_SYSCALL as u64, getppid_syscall),
128+
(syscall_const::GETPGID_SYSCALL as u64, getpgid_syscall),
128129
(syscall_const::MKNOD_SYSCALL as u64, mknod_syscall),
129130
(syscall_const::STATFS_SYSCALL as u64, statfs_syscall),
130131
(syscall_const::FSTATFS_SYSCALL as u64, fstatfs_syscall),

‎src/sysdefs/src/constants/syscall_const.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub const GETGID_SYSCALL: i32 = 104;
8484
pub const GETEUID_SYSCALL: i32 = 107;
8585
pub const GETEGID_SYSCALL: i32 = 108;
8686
pub const GETPPID_SYSCALL: i32 = 110;
87+
pub const GETPGID_SYSCALL: i32 = 121;
8788
pub const MKNOD_SYSCALL: i32 = 133;
8889
pub const STATFS_SYSCALL: i32 = 137;
8990
pub const FSTATFS_SYSCALL: i32 = 138;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <stdio.h>
2+
#include <unistd.h>
3+
#include <assert.h>
4+
5+
int main(void) {
6+
pid_t pgid = getpgid(0);
7+
assert(pgid > 0);
8+
9+
printf("getpgid: all tests passed\n");
10+
return 0;
11+
}

0 commit comments

Comments
 (0)