From nobody Sat Mar 23 03:52:00 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4V1lcz4q0tz5G609 for ; Sat, 23 Mar 2024 03:52:03 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "GTS CA 1D4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4V1lcz2cdNz41V0 for ; Sat, 23 Mar 2024 03:52:03 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Authentication-Results: mx1.freebsd.org; none Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-36699481c87so9963555ab.3 for ; Fri, 22 Mar 2024 20:52:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; t=1711165922; x=1711770722; darn=freebsd.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=lmONmFEWleASaytPb9T/QBlEJcoOdXQrvsMgJg69yTs=; b=coQku3hi2ga/f42xcQ27KIi3/L0jkO8407gyo7lmQL1DHXQCBGq6ZcuTWQ22bx+9u5 NfynQimtrtb/XdVaO3dfs3pPSuH0oz0eMRltsJDr3vjswpe/orPOhXhyKW2l8Li0zD5K q5UzwosEGjUXThzuJRaNsBIveaCqgmLkQL54xr5mwFutklGFchNtDVl4P5eoAdQG8Aux 5d+pEIEpYHXm/N7hgdikPTSWY01zmVWsdMvpQxOIWcM9LssF4zS+Bl0qOWILjwQTNKm+ pxVPqwK6SxNKZ2Bm/Tms0eJwcVDaj6MKWzlS2a5SzS3evABcq0nqnlitNGGnLsBbntto w8xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711165922; x=1711770722; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lmONmFEWleASaytPb9T/QBlEJcoOdXQrvsMgJg69yTs=; b=Zg5nDkH5bhI5k3Ugu+OCpSXhVAOha1nd68lCaGFAvXI2I+aQfloYkF9Qh/HGOa7DwE 4t1dAMVRjY/8OhJfiZzyXzjv0z8HBiTAZWeHYQdY7bzsmquaubsEWjbb8tByYsheJ4qo /j8FyUgC9a6yEIkZxQf97C3k+7vUl8JG+aqdulXqfhFzK9HuBhN7pAhJ4bU0W0sc1078 RH2AzU6f+WHRO4VBS8CgS4QIpjlaqLRfivYPN2b4Owfp00dseWQwbvmBFwORzthOTe3Z 0N9BRE0HTi9ymloW2/zWhfgVQYeu7WJSlOIl7gnneV+XiM24LOWq7JlRVrkEyk5Ol6KS oIYg== X-Gm-Message-State: AOJu0YwbrTyfNa0IUxawzRaeGmuMmbYebV7BeX0J7ZH3A434pGb8Sk9P RswUAZTbUGmaUeip4uHXXqLjVSrBZs+GRyZHhsrq8MEPhrRcjBEURey0TOp4BiI= X-Google-Smtp-Source: AGHT+IFHiLtn4i0Q3aF7ApxJBcezPF69reqIA/sc6fvuQI+sVfFiyeIwRwB/z9AogWmJ2maWKeNyGQ== X-Received: by 2002:a92:d851:0:b0:368:6b4f:3390 with SMTP id h17-20020a92d851000000b003686b4f3390mr1334423ilq.22.1711165921633; Fri, 22 Mar 2024 20:52:01 -0700 (PDT) Received: from mutt-hbsd (174-24-72-211.clsp.qwest.net. [174.24.72.211]) by smtp.gmail.com with ESMTPSA id q13-20020a92050d000000b003685b26d4afsm970557ile.23.2024.03.22.20.52.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 20:52:00 -0700 (PDT) Date: Sat, 23 Mar 2024 03:52:00 +0000 From: Shawn Webb To: Alan Somers Cc: freebsd-hackers@freebsd.org Subject: Re: Filesystem extended attributes and Capsicum Message-ID: X-Operating-System: FreeBSD mutt-hbsd 15.0-CURRENT-HBSD FreeBSD 15.0-CURRENT-HBSD X-PGP-Key: https://git.hardenedbsd.org/hardenedbsd/pubkeys/-/blob/master/Shawn_Webb/03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="u5ejocsibznm2xjw" Content-Disposition: inline In-Reply-To: X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US] X-Rspamd-Queue-Id: 4V1lcz2cdNz41V0 --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 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 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--