Article View: linux.kernel.netdev
Article #17980Re: [PATCH net 1/2] net: don't leak pidfds through a short SO_PEERPIDFD optlen
From: Alexander Mikhalitsyn
Date: Tue, 17 Nov 2026 16:39
Date: Tue, 17 Nov 2026 16:39
64 lines
14034 bytes
14034 bytes
On Tue, 2026-11-17 at 16:25 +0100, Christian Brauner wrote:
> sk_getsockopt_peerpidfd() caps the caller's optlen at sizeof(int) but
> never checks that it is at least that large. sk_getsockopt() only
> rejects a negative optlen. So with an optlen of 0 to 3 we still
> allocate a pidfd via pidfd_prepare(), copy zero to three bytes of the
> fd number to userspace, write the short optlen back and then
> fd_install() the pidfd anyway.
>
> getsockopt() reports success but the caller only got part of the fd
> number or none of it at all. It has no sane way to find out which fd
> it
> has to close and the pidfd stays in its file descriptor table until
> the
> process exits. Calling it in a loop fills up the table.
>
> scm_pidfd_recv() deals with the same problem for SCM_PIDFD. Since
> put_cmsg() doesn't fail on truncation it checks the size of the
> control
> buffer itself and sets MSG_CTRUNC before it allocates a pidfd.
>
> There's no point in handing out part of a file descriptor number. So
> fail with EINVAL if optlen is smaller than sizeof(int) before we
> prepare a pidfd. Since commit e10899b2a098 ("net: add
> SO_PEERPIDFD_THREAD to get a thread-specific pidfd") SO_PEERPIDFD and
> SO_PEERPIDFD_THREAD share the helper and the latter inherited the
> bug,
> so this fixes both.
>
> Fixes: 7b26952a91cf ("net: core: add getsockopt SO_PEERPIDFD")
> Cc: stable@vger.kernel.org
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://lore.kernel.org/all/sashiko-outbox-205984@kernel.org
Ugh, I wonder how I didn't notice this before... :(
Thanks, Christian!
Reviewed-by: Alexander Mikhalitsyn <alex@amutable.com>
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
> ---
> net/core/sock.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index ad414878dc5ba..74a00a5e2d116 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1746,8 +1746,10 @@ static int sk_getsockopt_peerpidfd(struct sock
> *sk, enum pid_type type,
> struct pid *peer_pid;
> int pidfd;
>
> - if (len > sizeof(pidfd))
> - len = sizeof(pidfd);
> + /* Userspace can't close a pidfd whose number it didn't get.
> */
> + if (len < sizeof(pidfd))
> + return -EINVAL;
> + len = sizeof(pidfd);
>
> spin_lock(&sk->sk_peer_lock);
> peer_pid = get_pid(sk->sk_peer_pid[type]);
Technical Details
Message-ID:
<a0f9a7e10bee8b5d328de14e1bbdbf74f5712d43.camel@amutable.com>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365438-linux-kernel-netdev=dewy.ruReferences:
<20261117-work-net-peerpidfd_short_optlen-v1-0-a93f56288501@kernel.org> <20261117-work-net-peerpidfd_short_optlen-v1-1-a93f56288501@kernel.org>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-365438-linux-kernel-netdev=dewy.ru
From: alex@amutable.com (Alexander Mikhalitsyn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net 1/2] net: don't leak pidfds through a short
SO_PEERPIDFD optlen
Date: Tue, 17 Nov 2026 17:39:20 +0100
Organization: Usenet Network
Message-ID: <a0f9a7e10bee8b5d328de14e1bbdbf74f5712d43.camel@amutable.com>
References: <20261117-work-net-peerpidfd_short_optlen-v1-0-a93f56288501@kernel.org>
<20261117-work-net-peerpidfd_short_optlen-v1-1-a93f56288501@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="2378368"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:VxHAwnkH7OepoEElOtiZipw3Ebo= sha256:Pieg0PskoaL+jix+aSK0QOygDNatIybhAggLy40yXVs=
sha1:uYXeVSmY4et+wcTWJfhL8N1N+xY= sha256:ccxm+/dFwQFhZXuqGMtxzgMvDPAGK9OG7JYgyzsoZA4=
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 240FF114FF1; Tue, 17 Nov 2026 19:40:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.951
X-Spam-Status: No, score=-2.951 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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=amutable-com.20260707.gappssmtp.com
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 NmEBOnZ-6g8f;
Tue, 17 Nov 2026 19:40:10 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-365438-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=none (p=none dis=none) header.from=amutable.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id E7E45114FEB; Tue, 17 Nov 2026 19:40:01 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 9778547B96; Tue, 17 Nov 2026 16:39:32 +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=1794933566;
b=aTmZ6F6jk6coi+0lOoKQnq5Qg1qL1TZOTTm2sfF361WihuOL4GoCGkBmNE/Ra1Ie055w
FO4GCNcj0XmTtwLsNYjSFujLzv6n7ANicFuvuEJC8S1MCd2yAETRzWs4UDRjAaGCDWSQw
eEteFVHHdR7XVwWrETxmyALeLff/2FN+FThaudQl3pk5zcuj1LePtKpnUyWyxYdILwctI
IZ64MF5tJ2ll0HAMRIAGOJojsTG7XAUqdQmjdc0mpRLQ+HQ8H6TqpLGUdB1y2GURPPhE4
pmrXW9yyvSSdpdpVrexMVo24BwbEML3ssTOYN9YelwTNCRXxgO2vby5gtGu1OasFIGA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794933566;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:Message-ID:Subject:From:To:Cc:Date:
In-Reply-To:References:Content-Type:Content-Transfer-Encoding:
User-Agent:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version;
bh=1yMLSDxkDlgkYE94GCll9k9idUAgyt2V1MICT6ujyig=;
b=wtQvhfeKSdxvn2WThlv+Ri//kNZxvzp3sXzU3p0Dp7V/SRHdP5wdj6/TbA4g7t9OGwCp
aQ2tL2Y5dyBGMlVc+AwazOQAyG8kpcwbSnD3HyeHEjJCWkBntVv61S6CXKvot0iVOjxoA
VCai4aD62zCXExLmtAjMMwZoifYxa7k6FxTqiHb7uPQbn7kGTHnkcWr/QdKNa/ovrW2v+
jpwvb2PXnHGC0WHbgHWX1Gi7Nrocbe0yTObaTN2ZCmjwvb59hnsSkfV/zDuy+d+Q1KGtc
96k+sZq05Bt7OK31XfM64aIGs/sO2d17lB1zowyXd7RLEVqKyRgIWL1NxkpV13tS2Tw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=fTE72B86;
dmarc=none header.from=amutable.com;
spf=pass smtp.mailfrom=amutable.com;
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 2EBAF606A333;
Tue, 17 Nov 2026 16:39:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=fTE72B86
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.47
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1794933565;
b=4k/FXukWuzJzQs3z+LHJIJDAwebmQTEnUMSy8rMUlBS9WfyofDYGbF9ZSmLFBQMvaXZC
naf6KFtOWnSlZ4HbqE4T0qnFLVL2ZMB/mmKyu9/tp4FlvobEV3oGiq+QbmMd7K0+ucW/x
ENS1J3huqUIeR5jNRoQ8IKQKxbH76t7M/OueAsA765/P0ihUZcnhbhaZ8Xbtv30BCLtF7
t8DskWta0nOEzSChsYzbv8o6bFwnrSazpxedrGcxXGwqIThDLdPNWrI0uHVXcWvGdn/Lu
L39U37mg7u11Ox30I855Uxd2LHj7JXMWe+iHfwJ4a3HeBUOOJN+7g9VwP+dCVCSuNHA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1794933565;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References:
Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version;
bh=1yMLSDxkDlgkYE94GCll9k9idUAgyt2V1MICT6ujyig=;
b=46bnBrip5Lw6wJMMSpj8/voB+A7SJeDKlgvpmnsT9775zn1RQMP6Vv+8WWZSB68fiLnj
9vcn/k+IrvVpv6X1k0Gg037QRIsl0vxqRltSWI/V/KU0yESWW/xBLHmJL/OoxXS0Rr7kt
LyhV6Noup1z9PUD3d0sFbji2PRVvCUTM4nid6ny0hzLw16RpJq8SgsWujWXSR4EIC5zk1
48F9+y0Kuiiif6e8U0NgomZZwsbqOWJr3ZuhiDqr57wqwkr64MZdWCE69H7/FlR+qbopb
KH4kMzxrjVZzCMOzbGRX6DunZsplipGEuraJ4n7QXKeyFJESWFhhEO+z0yz1Z+W8vjw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=none header.from=amutable.com;
spf=pass smtp.mailfrom=amutable.com;
dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=fTE72B86;
arc=none smtp.remote-ip=209.85.221.47
X-Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id B869B606A898
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 16:39:23 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B869B606A898
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=amutable.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amutable.com
X-Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-4a5506f09f5so386131f8f.0
for <netdev@vger.kernel.org>; Tue, 17 Nov 2026 08:39:23 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=amutable-com.20260707.gappssmtp.com; s=20260707; t=1794933562; x=1795538362; darn=vger.kernel.org;
h=mime-version:user-agent:content-transfer-encoding:content-type
:references:in-reply-to:date:cc:to:from:subject:message-id:from:to
:cc:subject:date:message-id:reply-to:content-type;
bh=1yMLSDxkDlgkYE94GCll9k9idUAgyt2V1MICT6ujyig=;
b=fTE72B86Z5rEBpDKAc4NHne/GnXGff3y7H6Jsc0ARGDiGlXWQffN+vDa57pln4ARyL
+1G26BfEIl+HbVOj8TA3zSW1iNP9Exo768h3A9fSHxf1A+G4JzKjyZmNEbRVK3OkKcg2
ZEYnzKWCZf2SHWcITYJs9lOAqrrzZPxMt6krNLkAMsJlTuduP0x2y7nYx9OSgn5tmOQc
3GQldmEymfObWSixuhNM6I5Mvd8VHZwvi+nOGLSVWlk5ZzEm+E3HJN1gWAo3zwQFeuvx
9iNDKhUwBHSxIZWVigOWMhavG6aeEqqoqaTE87khyMl0FdFXi08urXs13qAdOls/ZlVA
Zdfg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1794933562; x=1795538362;
h=mime-version:user-agent:content-transfer-encoding:content-type
:references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=1yMLSDxkDlgkYE94GCll9k9idUAgyt2V1MICT6ujyig=;
b=qegQL+QWpwkC+ZTdVM4a6U19aLpryuw4GJhBzZcFy/JCHR95sBFNFGHMHk8D2S5/98
1qmSB6riDVOKXfk1RiRBX6y0klgBsC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whA0ZwTBYDmsAUpYkAiM47h5EGLm/8bfWVmrlnAkeU3Kh4jabU
IVqjrQ78Fl3DbdMTTE4vTCvHqiHWkMI/mNT2OWEMyf6COzRKZ5XtEXL8rInR5k9K1u+ep/y60Mg
yFPq3k86F5ed3SO6TXkaKEeTC4TQL7obsj3nxkPUXWJ7rOJiZHaU6jazI
X-Received: by 2002:a05:6000:15d7:b0:48e:e98:8b6a with SMTP id ffacd0b85a97d-4a6332bcccfmr19985f8f.4.1794933562080;
Tue, 17 Nov 2026 08:39:22 -0800 (PST)
X-Received: from ?IPv6:2003:cf:572c:2800:dd2a:c8cf:5d96:bf5b? (p200300cf572c2800dd2ac8cf5d96bf5b.dip0.t-ipconnect.de. [2003:cf:572c:2800:dd2a:c8cf:5d96:bf5b])
by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4a43d41ec38sm4564311f8f.19.2026.11.17.08.39.21
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Tue, 17 Nov 2026 08:39:21 -0800 (PST)
X-Cc: Simon Horman <horms@kernel.org>, Kuniyuki Iwashima <kuniyu@google.com>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>, netdev@vger.kernel.org,
linux-fsdevel@vger.kernel.org, stable@vger.kernel.org, Sashiko
<sashiko-bot@kernel.org>
X-In-Reply-To: <20261117-work-net-peerpidfd_short_optlen-v1-1-a93f56288501@kernel.org>
X-User-Agent: Evolution 3.56.2-0+deb13u1
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