Article View: linux.kernel.netdev
Article #6576Re: [PATCH bpf-next 1/2] bpf: Add bpf_ksock_bind() kfunc
From: bot+bpf-ci
Date: Thu, 22 Oct 2026 18:45
Date: Thu, 22 Oct 2026 18:45
104 lines
11872 bytes
11872 bytes
--===============8279392703451209759==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
> bpf: Add bpf_ksock_bind() kfunc
TL;DR: bpf_ksock_bind() called from a bpf_wq callback runs with kworker's full
capabilities, so a CAP_BPF-only SYSCALL program may bypass the privileged-port
(CAP_NET_BIND_SERVICE) check; the review asks whether to block it.
> diff --git a/net/core/bpf_ksock.c b/net/core/bpf_ksock.c
> index 37168f43c16c..c7b487d90cd0 100644
> --- a/net/core/bpf_ksock.c
> +++ b/net/core/bpf_ksock.c
[ ... ]
> @@ -178,6 +178,33 @@ bpf_ksock_create(const struct bpf_ksock_create_opts *opts, u32 opts__sz,
> return NULL;
> }
>
> +/**
> + * bpf_ksock_bind() - Bind a BPF kernel socket to a local address.
[ ... ]
> +__bpf_kfunc int bpf_ksock_bind(struct bpf_ksock *ks,
> + const union bpf_ksock_addr *addr, u32 addr__sz)
> +{
> + struct sockaddr_storage sa;
> + int addrlen;
> +
> + addrlen = bpf_ksock_addr_to_sockaddr(addr, addr__sz, &sa);
> + if (addrlen < 0)
> + return addrlen;
> +
> + return __sys_bind_socket(ks->sock, &sa, addrlen);
> +}
> +
Can the CAP_NET_BIND_SERVICE check for privileged ports be bypassed when
this runs from a bpf_wq callback?
bpf_ksock_bind() is added to ksock_init_kfunc_btf_ids, the same set as
bpf_ksock_connect(). Commit 60bbe76a3f9e ("bpf: Allow ksock connect/send
calls from wq") made the kfuncs in this set callable from bpf_wq callbacks
of SYSCALL programs, and tools/testing/selftests/bpf/progs/ksock_wq.c
already calls bpf_ksock_connect() from such a callback.
bpf_wq_work() runs that callback in a kworker, where current->cred is
init_cred with cap_effective set to CAP_FULL_SET (see init/init_task.c).
The bind path is:
bpf_ksock_bind()
__sys_bind_socket()
security_socket_bind()
inet_bind() -> inet_bind_sk() -> __inet_bind()
and __inet_bind() then does:
snum = ntohs(addr->sin_port);
err = -EACCES;
if (!(flags & BIND_NO_CAP_NET_BIND_SERVICE) &&
snum && inet_port_requires_bind_service(net, snum) &&
!ns_capable(net->user_ns, CAP_NET_BIND_SERVICE))
goto out;
__inet6_bind() has the same check. With init_cred, cap_capable_helper()
walks up to init_user_ns and finds the capability raised, so the check
passes for any netns.
For example, a task holding only CAP_BPF can load a SYSCALL program, since
is_net_admin_prog_type() does not ask for CAP_NET_ADMIN for that type.
Such a program could bind its ksock to UDP port 53, 123 or 514 from a wq
callback, while the same call made synchronously from the SYSCALL program
returns -EACCES. A bpf_task_work callback looks like it has the same
problem in a different form, since the check would be evaluated against
whichever task the work was scheduled on.
Commit 60bbe76a3f9e only argued about LSM checks ("bypassing LSM checks for
BPF-created sockets could be acceptable"), and connect and send on a UDP
ksock have no capability gate. bind appears to be the first ksock
operation that does, and the commit message does not address the wq
context.
Should bpf_ksock_bind() refuse to run from kthread context, the way
bpf_ksock_create() does with its PF_KTHREAD check? Alternatively, should
it be kept out of the set that is reachable from wq callbacks, or should
the commit message state that bypassing the privileged-port check is
intended?
No fix for this was found in the provided range; 76406b1f799f
("selftests/bpf: Test bpf_ksock_bind() kfunc") only adds tests.
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/39831790314
--===============8279392703451209759==--
Technical Details
Message-ID:
<e31194dd72efd3c182707e870b7e7a6d67b78be23cea06aded0275678373c64c@mail.kernel.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350760-linux-kernel-netdev=dewy.ruReferences:
<20261022181620.247201-1-mahe.tardy@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-350760-linux-kernel-netdev=dewy.ru From: bot+bpf-ci@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH bpf-next 1/2] bpf: Add bpf_ksock_bind() kfunc Date: Thu, 22 Oct 2026 18:45:34 +0000 (UTC) Organization: Usenet Network Message-ID: <e31194dd72efd3c182707e870b7e7a6d67b78be23cea06aded0275678373c64c@mail.kernel.org> References: <20261022181620.247201-1-mahe.tardy@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============8279392703451209759==" Injection-Info: usenet.network; logging-data="295244"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:TwJhM3Mpvq1bIDPNXrw+bhgK3ag= sha256:BzNFvL8vHqOA0XvtGv3/j/UAiFlIjg8UcJZ7qBnV6Zo= sha1:JYmQl7utetjcisPt58XZE+x8E8I= sha256:SENv29NMG9mzkzfExWijVA3RVsaApdukR/z6+xtEvJU= 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 168A9111343; Thu, 22 Oct 2026 21:48:52 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.739 X-Spam-Status: No, score=-3.739 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.339, 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 vzYXxiS2_6VX; Thu, 22 Oct 2026 21:48:44 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-350760-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id DE7C711130A; Thu, 22 Oct 2026 21:48:35 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 3DB802AD7C; Thu, 22 Oct 2026 18:45:48 +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=1792694747; b=CwrX4ZXL02ZTtwz7XXMOmi/r+pOOSZR9wmbTiwomKgZvSWyPRFjij0QXuTdDwzAlIbFj jXGcsl0tlKx8LD+D6X4KP9PKSBVRzy27OlMCc/UWtkeBNQUTKAaHy+BjGb/G0TkF24sbT D3nySrz3CCT0RF0lhTG3L4u5WCN4SbDCP7vuPui0q++e8IFvqa78cYOUDIgyhU7MgUCrj WzJClO4vkK4AXQRt1WiOUzyL+7PnwL9oOFluOE71bBxwo08o1Gebcxe0UCvVuoMn9MKZh IVccf1XRy82duahXU4XSOYwwIyFrXprTre8Kqdo4t2U080beJupSHcSb39Cwgr2uK0g== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792694747; h=X-Original-To:Received:Received:DKIM-Signature:Content-Type: X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=G28HEn/VXJld9jkYtD/8yZsBEWZtFggug0SssZsruNY=; b=IBxnlQ5vcNmht/yAs5gVGdDEknoI2vNaZDP4thPAkM31NFdXU30+vfqmUoBuaHxEV1Nz VsHtIzZ+VHBkf0FDL3SyPyXu1VWAfCnFnfPpadaYya8ub8/VIPZVBdrmESFgux/ttEI68 IGoS5hODbrsdEHzVEAg0ywfjGgQglC92oSDB+MKqKH95sa0i8TiyZltYRA0RaYK00imoW 56Zz30V6EIjWotvZvDhV/P0V2uZaF/fzUvFwf+4GWOyuN5pgdpWgxpXdbjXDGCF3raYJz rC6MWTUPF891XDL0odtTwq1vJKmpYCnxx56g7irLotn9XwQl50v572x8NfMhoFcs2UQ== 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=h9U6yV6z; 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 7573B606A31D; Thu, 22 Oct 2026 18:45:47 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=h9U6yV6z 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=1792694736; b=KgkXJof7mm90Km3dkWFMueoyXS69uVOZqA/BvBivgrva8BjxUWVTKkGe2QKU9oM1B7Pj lAjpcgvrVJzNSvkM8bDCWX9PyXt0WDitV7tWzB0eyfZ4XKiF6kgEyhj5zGH29mpDg4p/b SVohUomZv131C9amOuvb9MeYgW1bJ492Elg8ghcUQLcPNHwV2LxOJJGO+JMGuwOntwlIp CCtbLG7RzfsceUEJ1NmcpzRxB4iPRMnCotIe5GoM1TCEunDU2tFu40pclvOeXbJtjzt37 3+adywQMuI0FtvgGiXZML8L/CjVRMJpzPcyUJ5C25Owsfjbq95GXtv9KSumK6R+UV1A== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792694736; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=G28HEn/VXJld9jkYtD/8yZsBEWZtFggug0SssZsruNY=; b=SkJ7jvtaAc21WN8/3HMuTi2IS8qvPShY29amGl3DkOHMqxSBhbzoDOmAkOtbPTas+tIN Tl8+rBVKmnt5o7Me1QwJmr8aRUFVKLN5cjjcLzEOhJDjoObRFM9Q63fJPOY9tO2OUVOAJ lwdKk3wu16F6XO9lHQeERm7Akk5AvywnthURq3re0mVANKLrT8SlHDJ1Fpke291d7CX51 hisj0e8tkjS4JZe6zwBouj83Ul7qpAGBPIMyBEMtJ6kUO5W3w+4QYkNpidfeWAjc3Cu9m TdlpXAFsez7OU6x1/X4+IS9/vOcdXYofDBhOIaMMCQGH9DpEXNzE8ylB4JJbfPi8nmA== 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=h9U6yV6z; 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 4F1F6606A31B; Thu, 22 Oct 2026 18:45:35 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76AE81F01825; Thu, 22 Oct 2026 18:45:34 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1792694735; bh=G28HEn/VXJld9jkYtD/8yZsBEWZtFggug0SssZsruNY=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=h9U6yV6zctGDT2s7FTFQvlXT/pcrtKGrr/d4BaOX6gvREBJ3jce3VwauedN+iElUr tyEFBos984982QJRYf+xj2sjb6P8y6x+9gaF+wu5KkN4cxDjtuMAdn4PaMYOfyX1/h ZVZ23TPw4t7+QHQkEtu1NUYWFjqJ+zqRP+E04PeX5idWkGqsWLaa6ybUAQt4IWAmOv 12qZhnJomhUI8ZwysUlQBoTvipZUaP84fHOD/aYkVPiaFh7neTBZBdVqf7aDgHrllV r1iDHHQ4+RFuNSs0muMfpGboKIaSQvnsAdJrVLljYVkHGIEJtBCgDasmd0rZa26LLe Lz5caL7PrK9Kw== 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: <20261022181620.247201-1-mahe.tardy@gmail.com> X-Cc: andrii@kernel.org,ast@kernel.org,daniel@iogearbox.net,davem@davemloft.net,willemb@google.com,eddyz87@gmail.com,edumazet@google.com,john.fastabend@gmail.com,kuba@kernel.org,horms@kernel.org,liamwisehart@meta.com,martin.lau@linux.dev,pabeni@redhat.com,song@kernel.org,netdev@vger.kernel.org,sdf.kernel@gmail.com,yonghong.song@linux.dev,jolsa@kernel.org,kuniyu@google.com,memxor@gmail.com,emil@etsalapatis.com,almagui@kernel.org,mahe.tardy@gmail.com,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev