From nobody Sat Mar 23 14:25:26 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 4V21gv4M1Pz5F4g0 for ; Sat, 23 Mar 2024 14:25:31 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) (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 4V21gv2chBz54k7 for ; Sat, 23 Mar 2024 14:25:31 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Authentication-Results: mx1.freebsd.org; none Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-368713f2f23so6789915ab.3 for ; Sat, 23 Mar 2024 07:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; t=1711203929; x=1711808729; 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=xpkJayEPkJ9MS1ukzbVt7qy2QtdMm41loJxn3kOiLEs=; b=eVTkRtQH9cr+bHm7+5iKcgPymOwdZ+5x0V3j15/d1zp7JS9FA/k4/MP7k1ggEfz61/ 1kIEt2+3qMesmEPnOjpwcQUOsFnE58C7gORK6mVWXD1lQ/7bkB9WZ3TFNzwnI335M4Ih 8GjBayV212PZg7UstQWXjeIliaSOGwEBo+E1GFgwzYZOFWGfS3f0ggzJbMzYFHPauyk+ ddXHZFc8iMaKO7UECfoTlAOiOdskH/hjk5pthWlifJyw5QFgzt0fU1hXdlPjOKROEpiD B1y8RiyG+nxmM1KQ6hRUmGwMlcCqTkAm5loAzQEY4t2xJRRV9gJJQrMf9t/ATEn69yI0 R67A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711203929; x=1711808729; 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=xpkJayEPkJ9MS1ukzbVt7qy2QtdMm41loJxn3kOiLEs=; b=Iymj3SJ54xUQr1qg2hyZhc8sP2uVewRSIh7te+iVxGTpwPC0UL2Kn8fnQBz0Tu4aN5 kbSZqzTQVYPkmFYPMT/ukubFEYN3rLUBpOWjLdr00gSm6JCGSEfc2RqdXmWeZEIj2p4v 4/SokTl81o3c8yS4QPms52QSpdL6f6HSWwpyTZGC91YtpUwiiLxKckTvO/a9Ry1fOBEs rGfefRyLqciWnvQfvnU9M0Pdc+xfDLPQaW9ZNZkeLLaVT9+9FaHQ9Q+AYjTsuRm4qpuM 0A9lLaYu8z81L3faq1ycwBosfbsV7iU3zAvShXWySGZ92K59JMlttVeDTEh3722Vrz/Z xt6Q== X-Forwarded-Encrypted: i=1; AJvYcCVeqi67JZeD/r6tkHA9BYfHsQA03W6rYCrFz1qOCmD0wnGToVIu7Xz0YnPURqLb/9DRzKSaaGunCYgyPG87hNOahyTUA+O3rwjOTow= X-Gm-Message-State: AOJu0YzenjXl0/MNZoFGq15GIap6OuwQ0iPP9ZybGouTRwGEkfxAlFBF SQpUcML9cng3VECfPiHEyRiD2FpRYRQYInhdlpaEP7UYHQXMGVpkjibIg0rf0pc= X-Google-Smtp-Source: AGHT+IE1aP+rGqJ8AVZldw0VyOfPGX1VJxUc1VuCxTdYfDjWoxJEN5QrScv9iaNarEpfyQ1/abuzDQ== X-Received: by 2002:a92:b707:0:b0:365:c6ae:c40e with SMTP id k7-20020a92b707000000b00365c6aec40emr2372143ili.0.1711203929490; Sat, 23 Mar 2024 07:25:29 -0700 (PDT) Received: from mutt-hbsd (174-24-72-211.clsp.qwest.net. [174.24.72.211]) by smtp.gmail.com with ESMTPSA id z11-20020a92da0b000000b00366970137d7sm1222566ilm.16.2024.03.23.07.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 07:25:27 -0700 (PDT) Date: Sat, 23 Mar 2024 14:25:26 +0000 From: Shawn Webb To: alan somers Cc: Alan Somers , 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="u4vp3o3k5n256pfh" 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: 4V21gv2chBz54k7 --u4vp3o3k5n256pfh Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 23, 2024 at 07:58:37AM -0600, alan somers wrote: > On Fri, Mar 22, 2024 at 9:52=E2=80=AFPM Shawn Webb wrote: > > > > 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 ena= bled > > > > > > (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_EXTATT= R_GET, > > > > > > 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 c= alled: > > > > > > > > > > > > =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_E= NABLED, NULL, 0); > > > > > > if (sz <=3D 0) { > > > > > > if (errno =3D=3D ENOATTR) { > > > > > > /* > > > > > > * This is okay, it just means that noth= ing 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= _type=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/hard= ened/current/hbsdcontrol-v2/lib/libhbsdcontrol?ref_type=3Dheads > > > > > > > > > > > > From the rights(4) manual page, I'm instructed all I need are t= o apply > > > > > > 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/Sh= awn_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 somethi= ng > > > > > like this: > > > > > > > > > > dtrace -i 'fbt:kernel::return /arg1 =3D=3D 93 && pid =3D=3D $targ= et/ > > > > > {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 e= rror. > > > > > Then you can do > > > > > > > > DTrace is unavailable on this particular system. > > > > > > > > It does indeed fail with ENOTCAPABLE. I have the kern.trap_enotcap = sysctl > > > > 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 > > > > > > 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 $tar= get/ {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 . > > 3 50605 foffset_lock:return . > > 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. >=20 > That's red herring. Those functions return void, but dtrace doesn't > know it. So the "93" is just register garbage. I also notice that > kern_extattr_get_fd isn't listed. Are you sure that your program is > really failing with ENOTCAPABLE? You can also try running it with > ktrace. kdump will show you exactly what capabilities you limited the > file descriptor to. That can help you verify if you applied the > limits correctly. I'm pretty sure it's failing with ENOTCAPABLE, since the kern.trap_enotcap sysctl logic is being hit at the point of the extattr_get_fd syscall. I'll see what I can do with ktrace. 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 --u4vp3o3k5n256pfh Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAmX+5lAACgkQ/y5nonf4 4fpq9hAAmwzpv035tVfyfs4o4XF4K2k2Q/1oVUA3gFOya0uk/XBifnNIvpbxtlJL iM/dSx36xrkdJylqNIycfQMlpOn0NJ4IUuVxvPNelptBYtHH7dltX1T8t9SkjkTR AVWKLBKSC+cxxFXJJIJ9iWBghWPHt2/ysLC9hiUS8mD5HVrc4tVK2GyxN4g2qALd KtZMMFgHjSdvd2069sosyuuz7prNYy01c56I2VBvAHj0ZRkS0q2Uwk0bTkLUTm61 Yg1weBC4GFVpHi5nOGAlVkR5mFyDhI3AeSeludLPumMp+PtVMzlD14V2mRldtMPW 8DN9bY8YhCTENpZ4EAZi8s5gva7562Ws19+1nU1hcSWMso6H8hLvq6qbTV0xRXDP nAowhN+TPK+v4ZczlmlhXiwiJwxMckObRBW5ROtWQiNCrpN4RafmNTHFZMayi3hK Wiq2r2rDM75pS5ef+hymQh/vJ5EpLfoVIkivwBtGCHSBkXQF4VFTxr6cbnQEfD6Z PaOkm0VkU+Yvib+HjyIccllKKhEe3BXiiwuXkJ7gyQk1yFdww9nolKUXHbz0uubj HnwfoMeSrUWqvYvxcTFqrWkycPtg8NagbQ1/0joQJvsP41JG7zZ2rVZRxnJS6dCs jtSy+CVwrBD2mvqbd/p58HLZeNkYOKLF8KsqP8VcjHjig0xvklI= =8tmf -----END PGP SIGNATURE----- --u4vp3o3k5n256pfh--