Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp257533rwd; Wed, 31 May 2023 23:01:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ67v5RzM7M8Id9HWN7q72051KQkym9VPFzLmiCzMmfGwHJvB1+SB8qJSOTtSdd5YP9Gn64e X-Received: by 2002:a05:6a20:8e1d:b0:10c:1047:68b9 with SMTP id y29-20020a056a208e1d00b0010c104768b9mr8089318pzj.50.1685599285398; Wed, 31 May 2023 23:01:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685599285; cv=none; d=google.com; s=arc-20160816; b=BBzAIH5xdc8CmjxlsPHum4K0PLYtpJokWYmR3hTNyHIaL1aODkfc3Q0+DjScjj9n6Y cqOx4sLmiouHjCC9Mvd8MYWt9OfdazfVoG0nFhPhwYd9G1hU6+nmmexYdBmIyoj/Fwxr VJfOTK2c3fMF7ueMouN6At1BOM66obUVOUHO4z8nzJGmUC6GySu7hqc7ZkKCgQlT55wo ZaIFCRuOiwfvSXQAgKm/GqfOhXjHMCaURMBQ9I+0aEFaaXEXrt1+HXG9FYMB/OjSdoc2 5TrYgpZu6vAFJdwKCTuHVnLA9a3uUFqAtJ9kznyGG/nlWg86Msuy4SB2nmuXBDrTPFeV rUSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:mime-version:date :dkim-signature:message-id; bh=f8KKClr4mwxkP83/QvliDYMt02i03s7p/NNDdJNcids=; b=u6hm3wgzEkesTmLieRg3yopwhCNW+RsxFcpihNJzDgphSdagAO/mGBbkOO+MYdw5j1 sc6hI6gWSix9cPzfT2xMrbOwt6hvFqk4Z688SwCirgGxIgG479vTUFA9XOwB6t3Tx1EK YQPqdcobp25aQL+ptAxMrscMpfC/9AP2awGtmbZuVyxt9XA7/BrJjK9WEp8ZvGfB1PZt nfhwEzHcCYcYtdBQYihxVMHGolkSngfbJxz5mnz8Gr3gJK0WVgptjJ7tOOSQI0bZIeYn ZpBWGxCc4P6v6VZtY3Cz1ZIVT0eLCp3pbbxjUEntpnhkZmdyBd+0p218+UX6aVxOk7+w fZvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=fH3TdsVq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e7-20020a636907000000b0053fb75162cdsi2193194pgc.573.2023.05.31.23.01.08; Wed, 31 May 2023 23:01:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=fH3TdsVq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231586AbjFAFkN (ORCPT + 99 others); Thu, 1 Jun 2023 01:40:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231575AbjFAFjm (ORCPT ); Thu, 1 Jun 2023 01:39:42 -0400 Received: from out-61.mta0.migadu.com (out-61.mta0.migadu.com [91.218.175.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA1E31732 for ; Wed, 31 May 2023 22:38:45 -0700 (PDT) Message-ID: <5bc1ac0d-cea8-19e5-785a-cd72140d8cdb@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685597879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f8KKClr4mwxkP83/QvliDYMt02i03s7p/NNDdJNcids=; b=fH3TdsVq8CEbPsRnt5077VpAg6MQuK/X+xLlj3QRaXIQmwgx1k9xXsw7S0z3/lDuo8eJXV qu+8Mf1VW6lISAHxq1ruB7QBTi3ywmuixstKQ9twPtpS+JwXvZ0z3bHYPVbbe3qqIP8jR/ m6OLSlJDITn/dx3ZdC6dtrQWoZFOrRQ= Date: Wed, 31 May 2023 22:37:52 -0700 MIME-Version: 1.0 Subject: Re: [PATCH bpf-next] bpf: getsockopt hook to get optval without checking kernel retval Content-Language: en-US To: Feng zhou Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, yangzhenze@bytedance.com, wangdongdong.6@bytedance.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org References: <20230601024900.22902-1-zhoufeng.zf@bytedance.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau In-Reply-To: <20230601024900.22902-1-zhoufeng.zf@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/31/23 7:49 PM, Feng zhou wrote: > From: Feng Zhou > > Remove the judgment on retval and pass bpf ctx by default. The > advantage of this is that it is more flexible. Bpf getsockopt can > support the new optname without using the module to call the > nf_register_sockopt to register. > > Signed-off-by: Feng Zhou > --- > kernel/bpf/cgroup.c | 35 +++++++++++++---------------------- > 1 file changed, 13 insertions(+), 22 deletions(-) > > diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c > index 5b2741aa0d9b..ebad5442d8bb 100644 > --- a/kernel/bpf/cgroup.c > +++ b/kernel/bpf/cgroup.c > @@ -1896,30 +1896,21 @@ int __cgroup_bpf_run_filter_getsockopt(struct sock *sk, int level, > if (max_optlen < 0) > return max_optlen; > > - if (!retval) { > - /* If kernel getsockopt finished successfully, > - * copy whatever was returned to the user back > - * into our temporary buffer. Set optlen to the > - * one that kernel returned as well to let > - * BPF programs inspect the value. > - */ > - > - if (get_user(ctx.optlen, optlen)) { > - ret = -EFAULT; > - goto out; > - } > + if (get_user(ctx.optlen, optlen)) { > + ret = -EFAULT; > + goto out; > + } > > - if (ctx.optlen < 0) { > - ret = -EFAULT; > - goto out; > - } > - orig_optlen = ctx.optlen; > + if (ctx.optlen < 0) { > + ret = -EFAULT; > + goto out; > + } > + orig_optlen = ctx.optlen; > > - if (copy_from_user(ctx.optval, optval, > - min(ctx.optlen, max_optlen)) != 0) { > - ret = -EFAULT; > - goto out; > - } > + if (copy_from_user(ctx.optval, optval, > + min(ctx.optlen, max_optlen)) != 0) { What is in optval that is useful to copy from if the kernel didn't handle the optname? and there is no selftest also. > + ret = -EFAULT; > + goto out; > } > > lock_sock(sk);