Page MenuHomeFreeBSD

MAC: syscalls: mac_label_copyin(): 32-bit compatibility
ClosedPublic

Authored by olce on Dec 3 2024, 2:54 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 1, 2:49 PM
Unknown Object (File)
Fri, Oct 31, 1:00 AM
Unknown Object (File)
Tue, Oct 28, 3:34 AM
Unknown Object (File)
Mon, Oct 27, 9:23 AM
Unknown Object (File)
Mon, Oct 27, 8:52 AM
Unknown Object (File)
Sat, Oct 25, 11:52 AM
Unknown Object (File)
Thu, Oct 23, 3:18 AM
Unknown Object (File)
Sun, Oct 19, 11:37 PM

Details

Summary

A step on the way to support 32-bit compatibility for MAC-related system
calls. Needed by the upcoming setcred() system call.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 60950
Build 57834: arc lint + arc unit

Event Timeline

olce requested review of this revision.Dec 3 2024, 2:54 PM
sys/security/mac/mac_syscalls.c
154–159

Well, sometimes it's enough to just upload some diff to get a problem back... Bracketing test for COMPAT_FREEBSD32 is missing here, will add.

brooks added inline comments.
sys/security/mac/mac_syscalls.c
98

Why _int? Maybe _impl?

sys/security/mac/mac_syscalls.h
27

This must be named struct mac32 to support freebsd32 system call stub generation.

I'd also be tempted to forward declare it here and keep the real definition in mac_syscalls.c.

olce marked 2 inline comments as done.

Apply brooks@'s request and suggestion.

sys/security/mac/mac_syscalls.c
98

_int for "internal". Renamed it to _impl.

This revision is now accepted and ready to land.Dec 4 2024, 4:29 PM

Blech, this conflicted quite a bit with CheriBSD downstream which has COMPAT_FREEBSD64 and used SV_CURPROC_FLAG to determine the ABI instead of a bool (that needs to not be a bool). At some point I will probably just have to upstream reworking this to remove all the bool stuff as you don't need it since you can just check the ABI here and do the fixup as needed. In CheriBSD we also fix the copying in of struct mac for exec which also needs to honor the ABI.

In D47878#1226543, @jhb wrote:

Blech, this conflicted quite a bit with CheriBSD downstream which has COMPAT_FREEBSD64 and used SV_CURPROC_FLAG to determine the ABI instead of a bool (that needs to not be a bool). At some point I will probably just have to upstream reworking this to remove all the bool stuff as you don't need it since you can just check the ABI here and do the fixup as needed. In CheriBSD we also fix the copying in of struct mac for exec which also needs to honor the ABI.

Yes, more or less expected, didn't look at what CheriBSD was doing back then. We perhaps could have used SV_ILP32 in advance here. So you have COMPAT_FREEBSD64, which basically means you can compile it out?

In D47878#1226543, @jhb wrote:

Blech, this conflicted quite a bit with CheriBSD downstream which has COMPAT_FREEBSD64 and used SV_CURPROC_FLAG to determine the ABI instead of a bool (that needs to not be a bool). At some point I will probably just have to upstream reworking this to remove all the bool stuff as you don't need it since you can just check the ABI here and do the fixup as needed. In CheriBSD we also fix the copying in of struct mac for exec which also needs to honor the ABI.

Yes, more or less expected, didn't look at what CheriBSD was doing back then. We perhaps could have used SV_ILP32 in advance here. So you have COMPAT_FREEBSD64, which basically means you can compile it out?

Actually, I found a bug in the compat32 setcred() as well. Yes, we have COMPAT_FREEBSD64 downstream. I will work on some patches though I'll try to post for review today/tomorrow.

In D47878#1226923, @jhb wrote:

Actually, I found a bug in the compat32 setcred() as well. (...) I will work on some patches though I'll try to post for review today/tomorrow.

I've quickly reviewed again that code and fail to see any practical problem (there's a memcpy() that conceptually should operate on &wcred32.setcred32_copy_start instead of &wcred32, but that makes no difference in practice).

If you're unable to produce quickly a separate patch for this, could you please point me at the problem you've seen? I'd like to quickly assess if it's very easily fixable and, if that's the case, produce a minimal fix and then ask re@/cperciva@ whether they are OK to include it in 15.0.

In D47878#1226923, @jhb wrote:

Actually, I found a bug in the compat32 setcred() as well. (...) I will work on some patches though I'll try to post for review today/tomorrow.

I've quickly reviewed again that code and fail to see any practical problem (there's a memcpy() that conceptually should operate on &wcred32.setcred32_copy_start instead of &wcred32, but that makes no difference in practice).

If you're unable to produce quickly a separate patch for this, could you please point me at the problem you've seen? I'd like to quickly assess if it's very easily fixable and, if that's the case, produce a minimal fix and then ask re@/cperciva@ whether they are OK to include it in 15.0.

The memcpy size is wrong. Subtracting two int *'s is not the same as subtracting two char *'s. My fix is to avoid the (IMO overly clever) memcpy and just use plain CP assignments. Compilers are smart enough to optimize this, and this is more typical style. I can upload my small series of fixes for now. I can't test them because kernels on HEAD are broken (my VM locks up and panics in make buildkernel now and I need to bisect to where that broke).

In D47878#1227393, @jhb wrote:

The memcpy size is wrong.

Indeed. I should have cast the pointers to uintptr_t or ptrdiff_t to avoid that. I don't think the memcpy() is particularly clever, but these structures are not supposed to change often, so explicitly listing all fields another time is not horrible (avoiding this is the real point for using memcpy(), not performance optimization). The really "clever" fix would be to use X macros, but given I'd like to ask for inclusion of a fix in 15.0, let's forget about it for the time being.

So, yes, please upload your fix, and I'll test it on an earlier HEAD and ask for inclusion in 15.0.