diff mbox series

[29/32] bsd-user: Implement pdgetpid(2) and the undocumented setugid.

Message ID 20230827155746.84781-30-kariem.taha2.7@gmail.com
State New
Headers show
Series bsd-user: Implement freebsd process related system calls. | expand

Commit Message

Karim Taha Aug. 27, 2023, 3:57 p.m. UTC
From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
 bsd-user/freebsd/os-proc.h    | 23 +++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  8 ++++++++
 2 files changed, 31 insertions(+)

Comments

Richard Henderson Aug. 29, 2023, 8:36 p.m. UTC | #1
On 8/27/23 08:57, Karim Taha wrote:
> From: Stacey Son <sson@FreeBSD.org>
> 
> Signed-off-by: Stacey Son <sson@FreeBSD.org>
> Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
> ---
>   bsd-user/freebsd/os-proc.h    | 23 +++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c |  8 ++++++++
>   2 files changed, 31 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

> +/* undocumented __setugid */
> +static inline abi_long do_freebsd___setugid(abi_long arg1)
> +{
> +    return get_errno(__setugid(arg1));
> +}

Given that this is

#ifdef REGRESSION
...
#else /* !REGRESSION */
         return (ENOSYS);
#endif /* REGRESSION */

in current freebsd, we could probably just stub this out?


r~
Warner Losh Aug. 29, 2023, 9:14 p.m. UTC | #2
On Tue, Aug 29, 2023 at 2:36 PM Richard Henderson <
richard.henderson@linaro.org> wrote:

> On 8/27/23 08:57, Karim Taha wrote:
> > From: Stacey Son <sson@FreeBSD.org>
> >
> > Signed-off-by: Stacey Son <sson@FreeBSD.org>
> > Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
> > ---
> >   bsd-user/freebsd/os-proc.h    | 23 +++++++++++++++++++++++
> >   bsd-user/freebsd/os-syscall.c |  8 ++++++++
> >   2 files changed, 31 insertions(+)
>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
> > +/* undocumented __setugid */
> > +static inline abi_long do_freebsd___setugid(abi_long arg1)
> > +{
> > +    return get_errno(__setugid(arg1));
> > +}
>
> Given that this is
>
> #ifdef REGRESSION
> ...
> #else /* !REGRESSION */
>          return (ENOSYS);
> #endif /* REGRESSION */
>
> in current freebsd, we could probably just stub this out?
>

I agree...

The REGRESSION kernel option exists only so that the
tools/regression/security/proc_to_proc tests
can run. this is an interesting set of tests, but hasn't been updated since
2004, except for the
usual 'churn' commits required by sweeps for new-compiler things, or
project policy changes.
So it's not even clear if this specific regression test is still
interesting (though there are many
other tests in the tree that are recent and under active development).

So it's irrelevant to the bsd-user emulator, and returning ENOSYS will
match perfectly what almost any
kernel deployed will do.

Warner
diff mbox series

Patch

diff --git a/bsd-user/freebsd/os-proc.h b/bsd-user/freebsd/os-proc.h
index 7d26d09148..bfd72c726c 100644
--- a/bsd-user/freebsd/os-proc.h
+++ b/bsd-user/freebsd/os-proc.h
@@ -34,6 +34,8 @@  pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage);
 pid_t safe_wait6(idtype_t idtype, id_t id, int *status, int options,
     struct __wrusage *wrusage, siginfo_t *infop);
 
+extern int __setugid(int flag);
+
 /* execve(2) */
 static inline abi_long do_freebsd_execve(abi_ulong path_or_fd, abi_ulong argp,
         abi_ulong envp)
@@ -153,4 +155,25 @@  static inline abi_long do_freebsd_getloginclass(abi_ulong arg1, abi_ulong arg2)
     return ret;
 }
 
+/* pdgetpid(2) */
+static inline abi_long do_freebsd_pdgetpid(abi_long fd, abi_ulong target_pidp)
+{
+    abi_long ret;
+    pid_t pid;
+
+    ret = get_errno(pdgetpid(fd, &pid));
+    if (!is_error(ret)) {
+        if (put_user_u32(pid, target_pidp)) {
+            return -TARGET_EFAULT;
+        }
+    }
+    return ret;
+}
+
+/* undocumented __setugid */
+static inline abi_long do_freebsd___setugid(abi_long arg1)
+{
+    return get_errno(__setugid(arg1));
+}
+
 #endif /* BSD_USER_FREEBSD_OS_PROC_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 63e6c6d478..52be71546a 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -380,6 +380,14 @@  static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         ret = do_freebsd_getloginclass(arg1, arg2);
         break;
 
+    case TARGET_FREEBSD_NR_pdgetpid: /* pdgetpid(2) */
+        ret = do_freebsd_pdgetpid(arg1, arg2);
+        break;
+
+    case TARGET_FREEBSD_NR___setugid: /* undocumented */
+        ret = do_freebsd___setugid(arg1);
+        break;
+
     case TARGET_FREEBSD_NR_utrace: /* utrace(2) */
         ret = do_bsd_utrace(arg1, arg2);
         break;