From nobody Sun Feb 8 20:58:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20E34EB64D9 for ; Thu, 6 Jul 2023 10:03:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231592AbjGFKDg (ORCPT ); Thu, 6 Jul 2023 06:03:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjGFKDf (ORCPT ); Thu, 6 Jul 2023 06:03:35 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69C0E3; Thu, 6 Jul 2023 03:03:33 -0700 (PDT) Received: from dggpeml500010.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QxX9V0bgpzPjtb; Thu, 6 Jul 2023 18:01:18 +0800 (CST) Received: from huawei.com (10.175.101.6) by dggpeml500010.china.huawei.com (7.185.36.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 6 Jul 2023 18:03:30 +0800 From: Xin Liu To: CC: , , , , , , , , , , , , , , , , , , , Subject: [PATCH bpf-next] bpf, sockops: Enhance the return capability of sockops Date: Thu, 6 Jul 2023 18:02:43 +0800 Message-ID: <20230706100243.318109-1-liuxin350@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500010.china.huawei.com (7.185.36.155) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since commit 2585cd62f098 ("bpf: Only reply field should be writeable"), sockops is not allowd to modify the replylong field except replylong[0]. The reason is that the replylong[1] to replylong[3] field is not used at that time. But in actual use, we can call `BPF_CGROUP_RUN_PROG_SOCK_OPS` in the kernel modules and expect sockops to return some useful data. The design comment about bpf_sock_ops::replylong in=20 include/uapi/linux/bpf.h is described as follows: ``` struct bpf_sock_ops { __u32 op; union { __u32 args[4]; /* Optionally passed to bpf program */ __u32 reply; /* Returned by bpf program */ __u32 replylong[4]; /* Optioznally returned by bpf prog */ }; ... ``` It seems to contradict the purpose for which the field was originally designed. Let's remove this restriction. Fixes: 2585cd62f098 ("bpf: Only reply field should be writeable") Signed-off-by: Xin Liu --- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index 06ba0e56e369..4662d2d3a0af 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -9063,7 +9063,7 @@ static bool sock_ops_is_valid_access(int off, int siz= e, =20 if (type =3D=3D BPF_WRITE) { switch (off) { - case offsetof(struct bpf_sock_ops, reply): + case bpf_ctx_range_till(struct bpf_sock_ops, reply, replylong[3]): case offsetof(struct bpf_sock_ops, sk_txhash): if (size !=3D size_default) return false; --=20 2.33.0