From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B2451E98FF for ; Sat, 2 May 2026 01:24:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=74.125.82.51 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777685080; cv=pass; b=IN9oL7yYidtVRDpGtovRnam4eIDfeIfxlc+ewMfEYoRdr+4jIvLFQIUf/VswMEeIZpEFAXT8/TUJP4xv8TQeWAmp3RD6yxkadTjzPG5Vmr2Q6s3WuUHlc4QcAD8l7NGLR3pPe+ywREnVaTVPB5QfqpzQh2qi/nVHBeV1fSnc7W0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777685080; c=relaxed/simple; bh=tlWzm/LweUKhSpUnvp6PcsofBh7GX2GlpWV4iQcCDA4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EKmluMFY8oU1516bLOuVAln0uz4cfGC0vXtM/pnXlCkTooUBu7Fnh3jg3EGfgx7jXDmgFd0/4GWis85UgLQn9aUnebK0h9KTcgSE9NmKhntT+8e3T/jRVXpEzVbFf2YelM9FYIzu9HVIjgzyA//ygLUnvvdc97hxmmctrbW17Ok= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tglJjcaN; arc=pass smtp.client-ip=74.125.82.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tglJjcaN" Received: by mail-dl1-f51.google.com with SMTP id a92af1059eb24-12c8f9846c8so3257970c88.0 for ; Fri, 01 May 2026 18:24:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777685078; cv=none; d=google.com; s=arc-20240605; b=gtOLMb0UEf7CC6zxoYCCzqwbYLb1Cqo0jiapPlUwml406C+lWugYm8ds+hpVvDrbkr pM/jy0+gXXA9lv2KpmTAJIKoXpN/cOmLIz7R7E5T0HsK9dWLx39bLJhqPDctol5P0cPG e39LZHg2PtwnXWEnrl4jumInNpKJAS0KCA/YkMlVw2nl3R57iwa8wS2W+2nsz8vshwNB JXyurjp9MEzKnR5teKJ187RrWK1Og5fz/1MOrObcn5EQXTQUPBJnqq1bQZ85HhiwRDf1 hbFPGIIaNh+MqE/eZ3dGD3w8RJzdu/sUvWlQaD+uFws73/T11ntftZigzq5BylZF/H9L VmCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=UTYEXtZbnOW94bihUSWzw/uzxtoul8H4TwtkWQ/OOcs=; fh=yKsCMOV9flN5W0rx7zAxt2eVMui7wVEYgdgTXCdUTQk=; b=AF3mjJuYCDymVvfyIJt1NpNrB/2uOixIBw/SxdrUjb6GyTxmS/4vlFg8FDoGVbTfSS TcC+7EXJ/8ikLBdBw0nzwjXOLYSfytU3GA6FN1RayXqTB9uy/o8KiaGI+0qBnWPJT0Qp Xmb3g74POy1fHXhC+jMO31Y8zckQr8U85Db4IBe5kDvj4HjbpoBcT9r7xYyCOreDvcQj jvPKtbUY9nHM7+ieXMU+5yHshKbMM/uq40rrxuu8ENqKzsqjaKkn7ippsd1LUZg1Ahk1 qypnQjl4iFyWQEGqC511mxAEvlUKwSGQX3R/J43fPAdDffZ3qYJdmCZ/rZupd8kQWI5q nOLw==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777685078; x=1778289878; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=UTYEXtZbnOW94bihUSWzw/uzxtoul8H4TwtkWQ/OOcs=; b=tglJjcaNWzt4y7utHMv+h2WL5OY5tf5X5qF5TicSwYXh7uIlMSi3KGJkcoVmkjYyk7 NRPdtihqKCqv0HTBx8FcZrVYkTJOT0IhjprmkHL88ahl8tGnbEw9q3Bk95tIRC4vPjC5 huKTLA6roSivAdw/1nwE/w+FaU0jaHvMhFPS+NGeD9YXIsDfXL9ZBp6UTL8rnABdmcGo K8PrvuslN0Hr8RQeiJhswis2WE5mgekajTIad+8M9TuDZ+BpNsyx0/qpGfUzlTwY6McZ ey407Z2nBmi+QqZU9C01XJBn+Jc9oWjE5MqdVr7mzP5cDy3FuvEdDLJvElRZHKhvSbHQ m7Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777685078; x=1778289878; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=UTYEXtZbnOW94bihUSWzw/uzxtoul8H4TwtkWQ/OOcs=; b=IYQWe6hi013cTBGkwv4ptYfeN/b4JGQGxxVZoZBiZj+kEiZbGMyBmHu5xtJvewhLeB 5hDe66UuBRu0ikdLxAxu1J4gfVOrwzxDHCLUs1iojguPVZaMZdWwDNGPCm/TCYUwGXtb HyQk8QnLfn7HI+OJ56xyxzTenjm2118bzBxFmBhhnHLnKWIhl+QXodAWUx2hcarA8BKY MhvBUNGvzNRdpKIcGgTkm9yMIBoUNQSqhvzNyLi0hPijYOcZkRtlvisSzVpo4s4fKiRS mdgyn6XYeYypU2YFmisaZSH8uxSZrX1qmrUfWdHkU3puQqBwjsSytQ1TuqQUrh+Bdb2I vQZQ== X-Forwarded-Encrypted: i=1; AFNElJ8uOYU9GcIesmDTlwoCdCIcUaVk481O2wNWg9P7YD9EkwHbOpzkpVg1inFrWIpblICQP4LYVaHYbPSmD94=@vger.kernel.org X-Gm-Message-State: AOJu0YxsQvQpjI7a/vEgFD9gFhKIPJz/1zwUKvbEjs3y1MbgzluvMSHZ 92oTww/UcNODoA/cUPlF5ev9GGYzBVDLmI8lQXy2D+zH+hjeW5jTcecTPCNBf6YBHydKILgA5V8 rc3aOSoSjC+J4j7gw79/66DmBCRM6YWCy9/KnGoGm X-Gm-Gg: AeBDievewLsoOM61mLId9fFWQx5bPxOzpnjoRHBNKSR6OxHp5jKrwE+/6jkLLc5W5Vr Ah2uPaf5uLLUMAcyt+B7giOb/slvKn9nKx1n58Q0soRNcqgRUkSVjRnF/Ps8UMyS+PYMozPtlyi MPRyWutqhtMC28MNsK42deNdtgsUjqvFI4cZ4PUN8fGYYfthhbkRu2XOqBOgoh7Sve6RtocT5zX aLZotV8Ehq5bJHe88TXFYiBJFR73JASlqzz2ZycI1jMdTYUvmXS3hFP9v8ezPFcuO7BpMsZiqae FsZ3d9f6Z05jaXS07QS/Uv2XeDEzMLeKds2qO04P3Le6zMA/eANWZ1fffR6s95/59VH9aH+K9Jk eQskAswEl1vpna2MqVf7cFGKtrIplts3NApcuBits4EPgVhMuILmQPhJtBQ4MrqY53W1sUox6pA == X-Received: by 2002:a05:7022:2514:b0:12d:de3f:f3d9 with SMTP id a92af1059eb24-12dfd8459ffmr501080c88.35.1777685077641; Fri, 01 May 2026 18:24:37 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260428175125.2705296-1-jkoolstra@xs4all.nl> <20260428175125.2705296-2-jkoolstra@xs4all.nl> <89346381.2074764.1777649680664@kpc.webmail.kpnmail.nl> In-Reply-To: <89346381.2074764.1777649680664@kpc.webmail.kpnmail.nl> From: Kuniyuki Iwashima Date: Fri, 1 May 2026 18:24:26 -0700 X-Gm-Features: AVHnY4Ivy4FFEa5elE6XvX0acVHEeFy5f9-HW7mgZQCbQK3BFpKAMdSRMm9bNLQ Message-ID: Subject: Re: [RFC PATCH 1/2] net: af_unix: Useful handling of LSM denials on SCM_RIGHTS To: Jori Koolstra Cc: Alexander Viro , Christian Brauner , Jan Kara , Eric Dumazet , Paolo Abeni , Willem de Bruijn , "David S . Miller" , Jakub Kicinski , Jens Axboe , Kees Cook , Simon Horman , Andy Lutomirski , Will Drewry , Jeff Layton , Oleg Nesterov , Andrei Vagin , Pavel Tikhomirov , Mateusz Guzik , Joel Granados , Charlie Mirabile , Aleksa Sarai , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, io-uring@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, May 1, 2026 at 8:34=E2=80=AFAM Jori Koolstra = wrote: > > > > Op 30-04-2026 04:04 CEST schreef Kuniyuki Iwashima : > > > > > > On Tue, Apr 28, 2026 at 10:51=E2=80=AFAM Jori Koolstra wrote: > > > > > > Right now if some LSM such as Smack denies an AF_UNIX socket peer to > > > receive an SCM_RIGHTS fd the SCM_RIGHTS fd array will be cut short at > > > that point, and MSG_CTRUNC is set on return of recvmsg(). This is > > > highly problematic behaviour, because it leaves the receiver > > > wondering what happened. As per man page MSG_CTRUNC is supposed to > > > indicate that the control buffer was sized too short, but suddenly > > > a permission error might result in the exact same flag being set. > > > Moreover, the receiver has no chance to determine how many fds got > > > originally sent and how many were suppressed.[1] > > > > > > Add two MSG_* flags: > > > > Since we only have 5 bits remaining for future extension, > > we need to consider the use case a bit more carefully. > > > > Right. Since it wasn't a lot of work I implemented it exactly as the requ= est > was made from userspace, and then discuss it from there. By the way, I su= ppose > nothing can be done about that small flag space? We could reuse an existing flag (e.g. MSG_FIN, MSG_RST) if we were confident enough that the userspace does not use the flag for a specific socket type. Another option is to add another syscall, recvmsg2. > > > > > > - MSG_RIGHTS_DENIAL is set whenever any file is rejected by the LSM > > > during recvmsg() of SCM_RIGHTS fds. > > > > Is this really needed ? > > > > Even if the fd array is truncated, the application will traverse > > the array anyway since it has some fds already installed (to > > clean up in case of MSG_CTRUNC ?). > > > > Then, it will find the -EPERM entry. > > > > I assume no one uses MSG_RIGHTS_DENIAL without > > MSG_RIGHTS_FILTER. > > > > I guess that is a fair assumption to make. We can certainly do without > MSG_RIGHTS_DENIAL if saving flags is important. I also suggested that > we may see whether we can make MSG_RIGHTS_FILTER the default behavior. > In the mean time I've found grep.app, and it turns out the answer is no. > Apparently almost no one checks even for the truncation flag (mostly 1 fd > is passed and then it is check the cmsg lenght). But cpython has this for > instance: > > /* Close all descriptors coming from SCM_RIGHTS, so they don't leak. = */ > for (cmsgh =3D ((msg.msg_controllen > 0) ? CMSG_FIRSTHDR(&msg) : NULL= ); > cmsgh !=3D NULL; cmsgh =3D CMSG_NXTHDR(&msg, cmsgh)) { > cmsg_status =3D get_cmsg_data_len(&msg, cmsgh, &cmsgdatalen); > if (cmsg_status < 0) > break; > if (cmsgh->cmsg_level =3D=3D SOL_SOCKET && > cmsgh->cmsg_type =3D=3D SCM_RIGHTS) { > size_t numfds; > int *fdp; > numfds =3D cmsgdatalen / sizeof(int); > fdp =3D (int *)CMSG_DATA(cmsgh); > while (numfds-- > 0) > close(*fdp++); > } > if (cmsg_status !=3D 0) > break; > } > > > > > > - If MSG_RIGHTS_FILTER is passed as a flag to recvmsg(), the SCM_RIG= HTS > > > > Does this flag need per-recvmsg() granularity ? > > > > Perhaps not. What would be the alternative? A fcntl option for the socket= fd? I'd add a new socket option like setsockopt(SOL_SOCKET, SO_RIGHTS_TRUNC, &(int){0}, sizeof(int)); > > > If the application does not welcome the truncated fd array, > > it would have passed MSG_RIGHTS_FILTER to every > > recvmsg(), no ? > > > > Correct. > > > Thanks, > Jori.