Date: Sat, 23 Mar 2024 03:52:00 +0000 From: Shawn Webb <shawn.webb@hardenedbsd.org> To: Alan Somers <asomers@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Filesystem extended attributes and Capsicum Message-ID: <gmrellzwibhxqazp3vt22tqk2flrsyklrcwrufr4mgnhjnj3cn@rufmfxktmop5> In-Reply-To: <CAOtMX2hiWRPQM5mbrhTifnycgroQ2Y_MeCHN8bZ9mfypQYR_GA@mail.gmail.com> References: <bjeg3z2aa5owo7uur75olwuw6le2g3whzxwfgef4ozyy6w6kog@33b426ax6inf> <CAOtMX2gC3iZ6X6HotpgxgfAfPN-8C7rg3ZCP%2Bpr5e8KddasUsQ@mail.gmail.com> <ae4isfrqtyc7l3rwqd2rz6efmuztwqxw5h67xqaqts6ra6br3l@ly347trhgdoq> <CAOtMX2hiWRPQM5mbrhTifnycgroQ2Y_MeCHN8bZ9mfypQYR_GA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--u5ejocsibznm2xjw Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Mar 22, 2024 at 08:07:17PM -0600, Alan Somers wrote: > On Fri, Mar 22, 2024 at 6:56=E2=80=AFPM Shawn Webb <shawn.webb@hardenedbs= d.org> wrote: > > > > On Fri, Mar 22, 2024 at 06:20:48PM -0600, Alan Somers wrote: > > > On Fri, Mar 22, 2024 at 5:38=E2=80=AFPM Shawn Webb <shawn.webb@harden= edbsd.org> wrote: > > > > > > > > Hey all, > > > > > > > > I'm writing an application in which I hope to enable Capsicum. I'm > > > > experiencing an issue whereby extattr_get_fd fails with a file > > > > descriptor that has all the extended attribute capabilities enabled > > > > (CAP_EXTATTR_DELETE, CAP_EXTATTR_GET, CAP_EXTATTR_LIST, and > > > > CAP_EXTATTR_SET). > > > > > > > > Looking at the kernel source (sys/kern/vfs_extattr.c) tells me that > > > > kern_extattr_get_fd only requires CAP_EXTATTR_GET. > > > > > > > > So I'm a bit puzzled as to why my call to extattr_get_fd(2) is > > > > failing. Am I doing something wrong or are filesystem extended > > > > attributes not supported in a Capabilities-enabled process? > > > > > > > > Here's how I'm creating the file descriptor (before calling > > > > cap_enter(2)): > > > > > > > > =3D=3D=3D=3D BEGIN CODE =3D=3D=3D=3D > > > > static int > > > > open_file(const char *path) > > > > { > > > > cap_rights_t rights; > > > > int fd; > > > > > > > > fd =3D open(path, O_PATH | O_CLOEXEC); > > > > if (fd =3D=3D -1) { > > > > return (-1); > > > > } > > > > > > > > memset(&rights, 0, sizeof(rights)); > > > > cap_rights_init(&rights, CAP_EXTATTR_DELETE, CAP_EXTATTR_GE= T, > > > > CAP_EXTATTR_LIST, CAP_EXTATTR_SET); > > > > cap_rights_limit(fd, &rights); > > > > > > > > return (fd); > > > > } > > > > =3D=3D=3D=3D END CODE =3D=3D=3D=3D > > > > > > > > Eventually, after calling cap_enter(2), the following code is calle= d: > > > > > > > > =3D=3D=3D=3D BEGIN CODE =3D=3D=3D=3D > > > > #define ATTRNAME_ENABLED "hbsd.pax.aslr" > > > > sz =3D extattr_get_fd(fd, ctx->hc_namespace, ATTRNAME_ENABL= ED, NULL, 0); > > > > if (sz <=3D 0) { > > > > if (errno =3D=3D ENOATTR) { > > > > /* > > > > * This is okay, it just means that nothing = has been set. > > > > * No error condition here. > > > > */ > > > > return (RES_SUCCESS); > > > > } > > > > return (RES_FAIL); > > > > } > > > > =3D=3D=3D=3D END CODE =3D=3D=3D=3D > > > > > > > > For reference, the program's code is here: > > > > https://git.hardenedbsd.org/shawn.webb/hbsdctrl/-/tree/main?ref_typ= e=3Dheads > > > > > > > > The library code, which is what's responsible for calling the > > > > filesystem extended attribute related syscalls is here: > > > > > > > > https://git.hardenedbsd.org/hardenedbsd/HardenedBSD/-/tree/hardened= /current/hbsdcontrol-v2/lib/libhbsdcontrol?ref_type=3Dheads > > > > > > > > From the rights(4) manual page, I'm instructed all I need are to ap= ply > > > > those capabilities to that file descriptor: > > > > > > > > =3D=3D=3D=3D BEGIN PASTE =3D=3D=3D=3D > > > > CAP_EXTATTR_DELETE Permit extattr_delete_fd(2). > > > > > > > > CAP_EXTATTR_GET Permit extattr_get_fd(2). > > > > > > > > CAP_EXTATTR_LIST Permit extattr_list_fd(2). > > > > > > > > CAP_EXTATTR_SET Permit extattr_set_fd(2). > > > > =3D=3D=3D=3D END PASTE =3D=3D=3D=3D > > > > > > > > So I'm a bit unsure if I'm doing something wrong. > > > > > > > > Thanks, > > > > > > > > -- > > > > Shawn Webb > > > > Cofounder / Security Engineer > > > > HardenedBSD > > > > > > > > Tor-ified Signal: +1 303-901-1600 / shawn_webb_opsec.50 > > > > https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/raw/master/Shawn_= Webb/03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc > > > > > > What error code does it fail with? If it's ENOTCAPABLE, then I > > > suggest using dtrace to find the reason why it fails. Do something > > > like this: > > > > > > dtrace -i 'fbt:kernel::return /arg1 =3D=3D 93 && pid =3D=3D $target/ > > > {trace(".");}' -c ./my_application > > > > > > That will print the name of every non-inlined kernel function that > > > returns ENOTCAPABLE during your process. But it will also print the > > > names of any other kernel functions that return an integer value of > > > 93. From there, guess which function is the real source of the error. > > > Then you can do > > > > DTrace is unavailable on this particular system. > > > > It does indeed fail with ENOTCAPABLE. I have the kern.trap_enotcap sysc= tl > > set to 1 so that I can know at exactly what point we're failing, and > > it's indeed at extattr_get_fd. > > > > Thanks, > > > > -- > > Shawn Webb > > Cofounder / Security Engineer > > HardenedBSD > > > > Tor-ified Signal: +1 303-901-1600 / shawn_webb_opsec.50 > > https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/raw/master/Shawn_Webb= /03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc >=20 > Without dtrace, you've got your work cut out for you. I suggest > simply adding all capabilities, verifying that extattr_get_fd works, > and then removing capabilities until it fails. Or, run your program > on vanilla FreeBSD with dtrace. HardenedBSD doesn't have any modifications that would affect Capsicum in this manner. Regardless, I reproduced the problem successfully on FreeBSD 14.0-RELEASE without any code changes. I tried running your DTrace script on FreeBSD 14.0-RELEASE and got this output: =3D=3D=3D=3D BEGIN OUTPUT =3D=3D=3D=3D $ sudo dtrace -i 'fbt:kernel::return /arg1 =3D=3D 93 && pid =3D=3D $target/= {trace(".");}' -c "obj/hbsdctrl pax list /bin/ls" dtrace: description 'fbt:kernel::return ' matched 31396 probes aslr: sysdef mprotect: sysdef pageexec: sysdef segvguard: sysdef dtrace: pid 29270 has exited CPU ID FUNCTION:NAME 3 47780 foffset_unlock_uio:return . = =20 3 50605 foffset_lock:return . = =20 3 47778 foffset_lock_uio:return . =3D=3D=3D=3D END OUTPUT =3D=3D=3D=3D But I'm still unsure what I'm missing, if anything. Thanks, --=20 Shawn Webb Cofounder / Security Engineer HardenedBSD Tor-ified Signal: +1 303-901-1600 / shawn_webb_opsec.50 https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/raw/master/Shawn_Webb/03A= 4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc --u5ejocsibznm2xjw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAmX+UdMACgkQ/y5nonf4 4fqBBg//cDEqfDfoHbgVkLnnkph8Xkmj6K2gEq07BeJENv2YAQAatk1QfLhrpylj zbmfhpCazdQD2aTeaQP0wo4+qRD3cIWqRYsTfDt+800osCrRBBWeQxEzlMOIvEGe Ec+PT6MdvM5BjeCqBX8NPM+LQ8i0YLiOLiw0EY5esEisF8R89Z3vTC5Ulez/ErNg ZqIaMCqtuh2O+RM1iZRw97zDRGSmj4SoL47zTJ2op8CWj1HmoawGkOEJ0pkAs6YS HaQWfG3GGzrRJImuZyoACPTL8MVjRZDRZqewI0cwjmMTWGc5/EV29cUOAxowh7mY EQfawwWjcVPzkOqQP0rxOuVjpHEs8xVXYs6FivlenxVMH5EXSV/DUTzTxcymd3nM lQVZldsOPLfkLU+l4gakih69s5fDQZbc7Rroo6UTt8c6WKAzjGx/KNVxgqHqEZhg wbJ0mZoK96I9zQpQF+dri9faIAHui6VbLNHzVh30tSHlA3nwUg8w+2NVmyyMSeeF 8dxahXt2w4oxJAHeJlssJdgmSmKWZAei7e/7fktFsAPAKTRXtywpkj7e/+eV2JJX IYCya9etRgZfqT5KVXq8Bk7fbAFKLB46wnwqaZWOwWnclt1r16RRr4qJyqODxPUF WRysyl+7yBCNBQmwOW7kKC0DUh/E9pJekKkqjRh9VqxoFASfhpc= =tRsU -----END PGP SIGNATURE----- --u5ejocsibznm2xjw--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?gmrellzwibhxqazp3vt22tqk2flrsyklrcwrufr4mgnhjnj3cn>