🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27547

Re: [PATCH v2 bpf-next 0/4] af_unix: Allow BPF LSM to filter SCM_RIGHTS at sendmsg()

#27547
From: Christian Brauner
Date: Sat, 05 Dec 2026 23:42
83 lines
11702 bytes
On Sat, Dec 05, 2026 at 01:21:47AM +0000, Alexei Starovoitov wrote:
> On Fri, Dec 04, 2026 at 05:07 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
> > What has been changed then ?  Any context ?

What I objected to last year was that

a) only having lsm support wasn't good enough. We also needed to be able
   to turn this off completely without it.
b) fds cannot magically disappear or the fd list cut short as this
   messes up the order. With -EBADF in the slot, an opt-in and a flag
   the order is fine and it's transparent.

> bpf lsm can do a part of this filtering already:
>
>   hook                 runs in  socket types      limit
>   -------------------  -------  ----------------  ------------------------
>   socket_sock_rcv_skb  sendmsg  dgram, seqpacket  silent drop of the skb
>   file_receive         recvmsg  all               final fput() in receiver
>
> unix_dgram_sendmsg() calls sk_filter() after unix_scm_to_skb().
> So socket_sock_rcv_skb sees the receiver and UNIXCB(skb).fp.
> unix_stream_sendmsg() has no such hook.

We woulde us it in at a bunch of cases. Two immediate ones that we
already tried writing:

(1) System services that have to accept fds from unprivileged peers
    but must never end up holding certain types of files. FUSE files are
    an obvious example but there's an a lot more.

    SO_PASSRIGHTS doesn't help because we need ot receive some fds.
    Filtering in recvmsg() doesn't help either because by then the
    receiver may hold the last reference and has to put it.

(2) Request filtering. A service is sent sockets or pidfds with xattrs
    set on them and wants to reject the ones for requests it doesn't
    want to handle based on those xattrs (they can be read locklessly).

sk_filter() is a good place:

* we're in the sender's context
* we know the receiver
* the files haven't been queued yet

The crucial part for is that a file we reject is dropped right there and
never makes it to the receiver otherwise the receiver will be
responsible for cleaning it up which can be abused for a targeted DOS.

So file_receive() doesn't work for this. socket_sock_rcv_skb throws out
the whole skb so it doesn't work either. We need to be able to filter
for fds we expect and want.

The receive side has most of the pieces already since we did a lot of
work in that area in 2025. Ever since SO_RIGHTS_NOTRUNC a file that an
LSM denies in recvmsg() keeps its slot and gets the errno instead of
truncating the array naturally preserving the order and thus allowing
very targeted drops while leaving the array itself alone.

So what we need is:

* a per-file verdict in sendmsg() for all socket types, after
  unix_scm_to_skb() and before scm_stat_add():
  - unix_dgram_sendmsg() next to sk_filter()
  - unix_stream_sendmsg() and queue_oob() for the skb carrying the fds

* the file needs to be dropped right in sendmsg(). It can never show up
  in the receive queue, the inflight accounting of the gc graph

* recvmsg() puts -EBADF into the dropped slots and raises a new MSG_*
  flag so the receiver knows fds were dropped. It can't be MSG_CTRUNC as
  that will result in an abort in userspace.

* receivers without SO_RIGHTS_NOTRUNC don't expect holes, so for them a
  drop fails sendmsg() with EPERM like SO_PASSRIGHTS does

Given that last time there was opposition to the idea of letting lsms
modify data there's no need to pursue an lsm implementation.

I have a bpf only series for this that will also allow us to neatly
extend this for other filtering.

I'll send that out soon.
Technical Details
Message-ID: <20261205-wimpel-mitmachen-wachsen-c767aabe9f96@brauner>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378182-linux-kernel-netdev=dewy.ru
References: <CAHC9VhSDYwekbzzZB3LwQG=hVVX0-wfFg0i2n2Y_MuyAtv7OWA@mail.gmail.com> <20261204163412.988198-1-luca.boccassi@gmail.com> <axNi4aU78yaigWx-@google.com> <DNCELO8NT5RN.PNBJWTFAIKO@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-378182-linux-kernel-netdev=dewy.ru
From: brauner@kernel.org (Christian Brauner)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH v2 bpf-next 0/4] af_unix: Allow BPF LSM to filter
 SCM_RIGHTS at sendmsg()
Date: Sun, 6 Dec 2026 00:42:16 +0100
Organization: Usenet Network
Message-ID: <20261205-wimpel-mitmachen-wachsen-c767aabe9f96@brauner>
References: <CAHC9VhSDYwekbzzZB3LwQG=hVVX0-wfFg0i2n2Y_MuyAtv7OWA@mail.gmail.com>
 <20261204163412.988198-1-luca.boccassi@gmail.com>
 <axNi4aU78yaigWx-@google.com>
 <DNCELO8NT5RN.PNBJWTFAIKO@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Injection-Info: usenet.network;
	logging-data="3145082"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:vDyEovX7lHQn2uhfScX+5ublcOY= sha256:SLC8V/i/d8wCXj7C98TD7Eze8bbaHJjD3NOwITvmdcQ=
	sha1:VGVnYCqQjJZ2ledtkpwP4P/z4zk= sha256:RXP8VPz73J3CU05t+PAClx3bweSc6w1CLSl8GLBY/VQ=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9BE2B117EF3; Sun,  6 Dec 2026 02:42:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.64
X-Spam-Status: No, score=-3.64 tagged_above=-9999 required=6.31
	tests=[DKIMWL_WL_HIGH=-0.14, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id oaB2ESW1i-9B;
	Sun,  6 Dec 2026 02:42:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-378182-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id DC559117EE8; Sun,  6 Dec 2026 02:42:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id F3AE028C9B; Sat,  5 Dec 2026 23:42:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796514156;
	b=2uMxdV2oLNRx2V1uAvO5DGWcYv9JuRNLgAnvKagp9lqCO8sSYsAcCfiyvcoFOLkjNkld
	 C1+0dv8nrBukJLCfBkxZQLj39aCoe+GynIZYftV5qTKcHrAzkXk4Jn1MJW7XLRrIvXSJC
	 aUbrUlt6BuUathVbR9TQ4PAiLwSI7CFFSATn8kJ8raSleV3Fb7JJCaJ+JxsCRBdpLHtyN
	 S/Qtq1/6ERo0e5/lKCTJFVyELq2EGVdbs1+fzP6PM/BiM38uYISucQ4hUmugf3jV/fUC6
	 1zCU+/k5IIgxFo6n/vN6Vi699IuZa8kGAqlB+1BQOiMnEax3frM3vktuYb6iXFaJeyA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796514156;
	h=X-Original-To:Received:Received:DKIM-Signature:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=oC1PXMdWb0SF9evmNhMQ22X5d/eouWl4ahA8XgvA8GQ=;
	b=OPgmerlOaSAS/3jI9tNnvygBFYjTseLY9bbD4eaP7Z7eZa8cPW55cpT1ZXjIhSt8+b4P
	 ssu+JjS59yFNge+SFRrIJFMP9sgeg3BOaCmwhscJcwUIEZj3CnVVrS7ExcJzK5422H8fv
	 pAM2zSOdmfNq9ZeOHj7fejixhwvDWM+83GzfJOG79bvFbgsbdjHr+DX3f6RAYhbZA+wAe
	 u58fVigQyga0H1Q0bGEs74QjeUMOTLGSfmON3jaZ7Z8NAl6sFW+mUDzNWE5yn8AGIM5wV
	 Usuf5QIOGeVKarYJoe0pADFLzn+eulr05bbVYHy9wkhgymA9jroBqiuwB6QGXi88fcw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b1JR2Jae;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 58E71606A335;
	Sat,  5 Dec 2026 23:42:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b1JR2Jae
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796514145;
	b=JiU5mCC2Gv9oposi9GOvEtlJWIM1TAlm5mjC1bKCv+PXBAra9E1F7bl5Vb2H6JadluoN
	 Xm4O2V8nGV+/U6jVpCwsXOCVyn7lbps1H6BKLgv5Z7ixYVQT1lDi6cZXBNDLn0KHZyGG+
	 ySJWn0ryLiSgCfYA711mqxcv0sIleqJybeDy0hXGxuXz9PvW/0nE4rQeAX2f0AEw+zRA7
	 Ctr5pB2n1X51ceRcrcEcncOlmCn/jIqOoU9ai/RcNN3ksoMcHABZflc5eWqVjQ0+rO7sc
	 jq3Aqy+max6c87wkm480+WSTfEKcrHpiwQS0bRNBqFu834O69QeSfJTfhhzHy25gG/g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796514145;
	h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=oC1PXMdWb0SF9evmNhMQ22X5d/eouWl4ahA8XgvA8GQ=;
	b=oL0fTunKbSiz9n5O5CKf3urq6gQwEtXBxixzwoUC+BWyvkO2Ppp0ozmupqkd3QoZK9Ea
	 9wbdSzrM+Lfn81qbYJZSTTYVPv9M4QsnNDMhZU/xHT8LwRp04Jy8RDTBkbT/Oz2+eXEER
	 N/Sde+j9ZSfGS3FSLxainikf0LBKC+XCyvoOGX2vf7dfYT7wJVPFhjmvfZ9dIeqWhKp/j
	 isTABzlyc8kVPFwnDG1P0hHOVXgR3rQha7nDXElDWeB2uG7daEurT6CICcV38vWB+8Y2g
	 VezsXv51CpqNBTC0aaSPqrOBT+ASHpkf0PojYIscPL3FKo1ckoHdmDLSd5+KZ1agQ2A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=b1JR2Jae;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 730F7606A31F;
	Sat,  5 Dec 2026 23:42:25 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C9251F0092B;
	Sat,  5 Dec 2026 23:42:18 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796514145;
	bh=oC1PXMdWb0SF9evmNhMQ22X5d/eouWl4ahA8XgvA8GQ=;
	h=Date:From:To:Cc:Subject:References:In-Reply-To;
	b=b1JR2Jae/T4GmFNJK+HbJ7h0nIlIPKLSHj3N+njEwBU/wG4UICTp7uplNMwpbV5Y6
	 0US0nLkZaxk5oBr2aQ5Kcbzs1jhFrtO9yKWoy/HREMa+lZ4LiwgxW3tuMqxruAmvBy
	 Y3B95sNVIwEp8Xu80HakaLnp9EugEkZY0FWpE+lmGU3MMNkizip5AM8IEGZ9CtZIlB
	 X8ipVbmVmi6kxpQjiwvc+nTPDiWiV5YqxpP0l/OoG32HJNETyz3xTWgKxlzW/ugUTa
	 4lZEVQ2A+cyrwgY3l+XvGD8A64Ww+MGv0WADjrKGOw8Aml7jMYzMrzSI2Wufh39NPz
	 HSxNK6YGNhKtA==
X-Cc: paul@paul-moore.com, andrii@kernel.org, bpf@vger.kernel.org, 
	casey@schaufler-ca.com, daniel@iogearbox.net, eddyz87@gmail.com, gnoack@google.com, 
	haoluo@google.com, jmorris@namei.org, john.fastabend@gmail.com, jolsa@kernel.org, 
	kpsingh@kernel.org, kuni1840@gmail.com, linux-security-module@vger.kernel.org, 
	martin.lau@linux.dev, memxor@gmail.com, mic@digikod.net, netdev@vger.kernel.org, 
	omosnace@redhat.com, sdf@fomichev.me, selinux@vger.kernel.org, serge@hallyn.com, 
	song@kernel.org, stephen.smalley.work@gmail.com, yonghong.song@linux.dev
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <DNCELO8NT5RN.PNBJWTFAIKO@gmail.com>