From nobody Sat Mar 23 00:56:10 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 4V1gk919LQz5FnXw for ; Sat, 23 Mar 2024 00:56:17 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) (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 4V1gk86Nq6z4fdv for ; Sat, 23 Mar 2024 00:56:16 +0000 (UTC) (envelope-from shawn.webb@hardenedbsd.org) Authentication-Results: mx1.freebsd.org; none Received: by mail-io1-xd2a.google.com with SMTP id ca18e2360f4ac-7d03a6a11a2so27762039f.2 for ; Fri, 22 Mar 2024 17:56:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hardenedbsd.org; s=google; t=1711155375; x=1711760175; 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=7SIiqkxfxYgzBs4ZkuDYLH0hFivmQEbLbWaI++r3G4Y=; b=FKM0t9piHEECJDRS1k2+vs8tD5j+n8c7nL0bY8+amexaZdQc/Zp9FONKRCdsVs3VHB uKv0PHY+Lc2CPyNnqgFGufkHEcGX90/RrT5y+L71S+kpzG/oX8rIcv0gZCGC/tQjxv+U qrBQ0aGK4DRUCHpAdMuAumSr5kvMQfUbHaYGnvK2F/lHZqq/uU5o7vjhA6cv0n4jSCg9 B+xFZru2wxgMqJUbSvMGOS9cIldxh7eXaNeZ/O3wbewVUQZfQgHhvbaUyCiupO2FOAgN R+QlCaA9NplIgIxOGvgZhiyRqa+jZaPQCF+OBYha/Iibo0y1ltSxrOheXXcL/vC2YnHb 7REQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711155375; x=1711760175; 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=7SIiqkxfxYgzBs4ZkuDYLH0hFivmQEbLbWaI++r3G4Y=; b=Gbsao574B00L4KLuOKXftXRQt++DfPfF542NEeceJBspp2n89DdVAdiRwYuWZq7BQJ BbY+qdcpF+wcDEr/gXqtpVSuhG86bvsWikoHy7NQbBUSB6czZ4cjBQcUrQt6UGBkGmk2 JiIr6l4BY0UlqDZ8m4sk4upOedN77Fsssl16vb6DQ3P2cElhk5X7BmKqp8p9wowp3jBY S+nglmZHjac7glDGHTaR7YDGPG3htAZ42C1jnm8AUt9d/sY8fpELgju9s8oolzZ29WeR C7/WMvT2pdYkHJpyjxR2PhoESw4e+p+Lq33bdmqZz7YkWIqLFXew2uYUvaNjs9BrOtbF FGOg== X-Gm-Message-State: AOJu0Yw0Hd4F2uaLB3l9Zm9oQqDqM5tq/rnjfmlL77utVvRPF7VwtIgw qY/n2OjtC5KktBkoIY6zvVaiRe38Hm+x8bb1Wkq03OXNhrs186k6NU47mJ5sZgc= X-Google-Smtp-Source: AGHT+IHvyCIl7s7iOR4X5tGWYyG/OzDPfVUDSEcYStZmKSGbCIAwgtV7HgOmrIds9H0uo34H9ATBIA== X-Received: by 2002:a5d:9b94:0:b0:7cc:ca7:c653 with SMTP id r20-20020a5d9b94000000b007cc0ca7c653mr1026073iom.21.1711155371441; Fri, 22 Mar 2024 17:56:11 -0700 (PDT) Received: from mutt-hbsd (174-24-72-211.clsp.qwest.net. [174.24.72.211]) by smtp.gmail.com with ESMTPSA id o18-20020a6b5a12000000b007d032b05766sm604574iob.36.2024.03.22.17.56.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 17:56:10 -0700 (PDT) Date: Sat, 23 Mar 2024 00:56:10 +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="hyz62y55337uhzt7" 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: 4V1gk86Nq6z4fdv --hyz62y55337uhzt7 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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_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 called: > > > > =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_ENABLED, = 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_type=3D= heads > > > > 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/cur= rent/hbsdcontrol-v2/lib/libhbsdcontrol?ref_type=3Dheads > > > > From the rights(4) manual page, I'm instructed all I need are to 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/Shawn_Webb= /03A4CBEBB82EA5A67D9F3853FF2E67A277F8E1FA.pub.asc >=20 > 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: >=20 > dtrace -i 'fbt:kernel::return /arg1 =3D=3D 93 && pid =3D=3D $target/ > {trace(".");}' -c ./my_application >=20 > 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 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, --=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 --hyz62y55337uhzt7 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEA6TL67gupaZ9nzhT/y5nonf44foFAmX+KKEACgkQ/y5nonf4 4fq64Q/6AkaAYz9Vo1Ld32z0VlRPoBeLuIY6KFF/5wc0tWbGSD6k8Q15u1RIuplp MM/gTX6QC9fpD7FR9ywasGBGBUtzGDnOtOvyjtJkmSFR9fc6umhn7kpxPLaxzHlF 65bFRD/+b37ePnoB/LOcOduPN9a9XFMhJiIte/UWJPFlYCDSTTkD9wkZsraxAFGS NGj0LfmgpD2DLVXckqoXRxuyZ0xqOpJBxUzfT+a+A5s0/FLLzJ1odcRouqm8jYI2 HjR9Jdnr8MPM2VAIrY8ug2Bs4mYmrdhjfPSXpd/+MiP3qwa8gNzKZUMvwSgZsNyg otmtR5EkJRA9UJ0kwWBe75MWMCOBKlE8liZ6sfwyaMp+rK1A6iVpp0sDqWzgifHG P+k9aBTtZwAgZIm/uiZkTmwrJ5vbnhd6OdFZyYYut9+F3cOTPHukqF+sGSpPz6/6 fzJHGpQFtTKE6WCxQLnPyzmsycB7zY2NxmUASNzR1N4v5WoZV5n6vgPxho0F6DMb 4Z82m7gu+pe4/E9XIGV9rXEd02aY84tBuKAsw7Z4QM+DsNmPuiyN82xIi0muG0Sv zn+3bA8/b8AU9KJeV+qDw2U/DXVk0fEDQNOgiURc0MEpqvRAakNkkFM28OrrHsaC HYsTcsMuoF6JRmeDEKrJsaBV2NgBuUjsuACkoQNCfU/xpYA4wnM= =0WA5 -----END PGP SIGNATURE----- --hyz62y55337uhzt7--