llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[libc] Implement `capget` and `capset` syscall wrappers

Open SchrodingerZhu opened this issue 1 year ago • 1 comments

Implement https://man7.org/linux/man-pages/man2/capset.2.html wrappers. The manpage mentioned that it was not provided by glibc but MUSL implement them as an extension: https://github.com/bminor/musl/blob/f314e133929b6379eccc632bef32eaebb66a7335/src/linux/cap.c#L8

This is helpful in #79645.

SchrodingerZhu avatar Jan 30 '24 17:01 SchrodingerZhu

@SchrodingerZhu hello! Could you give me a few pointers on where the code has to be placed? I can implement the wrappers, but I am unable to judge where to place them.

vinayakdsci avatar Mar 24 '24 12:03 vinayakdsci

sys/capability.h may be a good place to go. I am little bit concerned that we may conflict with libcap. @nickdesaulniers

SchrodingerZhu avatar Mar 25 '24 12:03 SchrodingerZhu

ah, that man page says:

The portable interfaces are cap_set_proc(3) and cap_get_proc(3); if possible, you should use those interfaces in applications;

Perhaps it would be better to implement those instead.

nickdesaulniers avatar Mar 25 '24 16:03 nickdesaulniers

Perhaps it would be better to implement those instead.

In sys/capability.h, if I am not wrong?

vinayakdsci avatar Mar 25 '24 17:03 vinayakdsci

I have a small doubt here. Neither glibc nor musl implement cap_set_proc() and cap_get_proc(), and musl only implements capget() and capset() just because of the simplicity of their implementation. As libcap already implements all of the capability functionality, would this not cause conflicts? One can simply link to libcap.

@SchrodingerZhu @nickdesaulniers?

vinayakdsci avatar Mar 25 '24 17:03 vinayakdsci

Yeah, the more I look into these APIs, the less interested I am in having implementations for them.

Perhaps we can instead rethink the use of SYS_capget in libc/test/src/sys/mman/linux/mlock_test.cpp ?

nickdesaulniers avatar Mar 25 '24 19:03 nickdesaulniers

@nickdesaulniers capget may be useful to have. For example, sched related tests may also want to check capabilities.

SchrodingerZhu avatar Mar 25 '24 19:03 SchrodingerZhu